diff --git a/src/events.c b/src/events.c index 116075e..5e67358 100644 --- a/src/events.c +++ b/src/events.c @@ -657,6 +657,71 @@ static void event_status(struct wiimote_t* wm, byte* msg) { } #endif + +#if 0 + switch(wm->expansion_state) + { + case 0: // regular expansion detection + { + if(attachment && wm->exp.type != EXP_NONE) + { + wm->expansion_dattempts = 0; + wm->expansion_state++; + } + + else + { + // give it another chance still + if(wm->expansion_dattempts < 10) + { + wm->expansion_dattempts++; + wiiuse_status(wm); + return; + } + + // likely no attachment, give up and try M+ + else { + wm->expansion_dattempts = 0; + wiiuse_set_motion_plus(wm, WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP) ? 2 : 1); + wm->expansion_state++; + } + } + + break; + } + + case 1: // try to init Motion+ + { + if(attachment && wm->exp.type != EXP_NONE) + { + wm->expansion_dattempts = 0; + wm->expansion_state++; + } + + else + { + // give it another chance still + if(wm->expansion_dattempts < 10) + { + wm->expansion_dattempts++; + wiiuse_status(wm); + return; + } + + else { + // give up and move on + wm->expansion_state++; + } + } + break; + } + + default: + break; + } + +#endif + /* * From now on the remote will only send status packets. * We need to send a WIIMOTE_CMD_REPORT_TYPE packet to @@ -690,7 +755,9 @@ static void event_status(struct wiimote_t* wm, byte* msg) { wiiuse_send_next_pending_write_request(wm); } else + { wiiuse_set_report_type(wm); + } } @@ -714,6 +781,11 @@ static void handle_expansion(struct wiimote_t* wm, byte* msg) { case EXP_WII_BOARD: wii_board_event(&wm->exp.wb, msg); break; + case EXP_MOTION_PLUS: + case EXP_MOTION_PLUS_CLASSIC: + case EXP_MOTION_PLUS_NUNCHUK: + motion_plus_event(&wm->exp.mp, wm->exp.type, msg); + break; default: break; } @@ -789,6 +861,15 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) { wm->event = WIIUSE_WII_BOARD_CTRL_INSERTED; break; } + + case EXP_ID_CODE_MOTION_PLUS: + case EXP_ID_CODE_MOTION_PLUS_CLASSIC: + case EXP_ID_CODE_MOTION_PLUS_NUNCHUK: + //wiiuse_motion_plus_handshake(wm, data, len); + wm->event = WIIUSE_MOTION_PLUS_ACTIVATED; + break; + + default: { WIIUSE_WARNING("Unknown expansion type. Code: 0x%x", id); @@ -833,6 +914,12 @@ void disable_expansion(struct wiimote_t* wm) { wii_board_disconnected(&wm->exp.wb); wm->event = WIIUSE_WII_BOARD_CTRL_REMOVED; break; + case EXP_MOTION_PLUS: + case EXP_MOTION_PLUS_CLASSIC: + case EXP_MOTION_PLUS_NUNCHUK: + motion_plus_disconnected(&wm->exp.mp); + wm->event = WIIUSE_MOTION_PLUS_REMOVED; + break; default: break; } diff --git a/src/io.c b/src/io.c index 0fbb7ea..5bd9e33 100644 --- a/src/io.c +++ b/src/io.c @@ -91,7 +91,8 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) { accel->cal_zero.x, accel->cal_zero.y, accel->cal_zero.z, accel->cal_g.x, accel->cal_g.y, accel->cal_g.z); - wiiuse_set_motion_plus(wm, 0); + /*wiiuse_set_motion_plus(wm, 0);*/ + wiiuse_status(wm); /* request the status of the wiimote to check for any expansion */ wiiuse_status(wm); @@ -107,7 +108,6 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) { } wm->event = WIIUSE_CONNECT; - wm->expansion_state = 0; wiiuse_status(wm); break; diff --git a/src/wiiuse.c b/src/wiiuse.c index 07dbce8..f1189a6 100644 --- a/src/wiiuse.c +++ b/src/wiiuse.c @@ -147,6 +147,8 @@ struct wiimote_t** wiiuse_init(int wiimotes) { wm[i]->event = WIIUSE_NONE; wm[i]->exp.type = EXP_NONE; + wm[i]->expansion_state = 0; + wm[i]->expansion_dattempts = 0; wiiuse_set_aspect_ratio(wm[i], WIIUSE_ASPECT_4_3); wiiuse_set_ir_position(wm[i], WIIUSE_IR_ABOVE); diff --git a/src/wiiuse.h b/src/wiiuse.h index b1a003d..87de021 100644 --- a/src/wiiuse.h +++ b/src/wiiuse.h @@ -714,7 +714,8 @@ typedef struct wiimote_t { WCONST int flags; /**< options flag */ WCONST byte handshake_state; /**< the state of the connection handshake */ - WCONST unsigned char expansion_state; /**< the state of the expansion handshake */ + WCONST byte expansion_state; /**< the state of the expansion handshake */ + WCONST byte expansion_dattempts; /**< how many times did we wait already */ WCONST struct data_req_t* data_req; /**< list of data read requests */ WCONST struct read_req_t* read_req; /**< list of data read requests */