void wiiuse_disable_expansion(struct wiimote_t *wm) { if(!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) return; /* tell the associated module the expansion was removed */ switch(wm->exp.type) { case EXP_NUNCHUK: nunchuk_disconnected(&wm->exp.nunchuk); wm->event = WIIUSE_NUNCHUK_REMOVED; break; case EXP_CLASSIC: classic_ctrl_disconnected(&wm->exp.classic); wm->event = WIIUSE_CLASSIC_CTRL_REMOVED; break; case EXP_GUITAR_HERO_3: guitar_hero_3_disconnected(&wm->exp.gh3); wm->event = WIIUSE_GUITAR_HERO_3_CTRL_REMOVED; break; case EXP_WII_BOARD: wii_board_disconnected(&wm->exp.wb); wm->event = WIIUSE_WII_BOARD_REMOVED; break; default: break; } WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP); wm->exp.type = EXP_NONE; wiiuse_set_ir_mode(wm); wiiuse_status(wm,NULL); }
static void wiiuse_set_motion_plus_clear2(struct wiimote_t *wm,ubyte *data,uword len) { WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_FAILED); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE); wiiuse_set_ir_mode(wm); wiiuse_status(wm,NULL); }
static void wiiuse_disable_motion_plus2(struct wiimote_t *wm, byte *data, unsigned short len) { WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_FAILED); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE); wiiuse_set_ir_mode(wm); wm->handshake_state++; wiiuse_handshake(wm, NULL, 0); }
void wiiuse_handshake_expansion(struct wiimote_t *wm,ubyte *data,uword len) { int id; ubyte val; ubyte *buf = NULL; switch(wm->expansion_state) { /* These two initialization writes disable the encryption */ case 0: wm->expansion_state = 1; val = 0x55; wiiuse_write_data(wm,WM_EXP_MEM_ENABLE1,&val,1,wiiuse_handshake_expansion); break; case 1: wm->expansion_state = 2; val = 0x00; wiiuse_write_data(wm,WM_EXP_MEM_ENABLE2,&val,1,wiiuse_handshake_expansion); break; case 2: wm->expansion_state = 3; buf = __lwp_wkspace_allocate(sizeof(ubyte)*EXP_HANDSHAKE_LEN); wiiuse_read_data(wm,buf,WM_EXP_MEM_CALIBR,EXP_HANDSHAKE_LEN,wiiuse_handshake_expansion); break; case 3: if(!data || !len) return; id = BIG_ENDIAN_LONG(*(int*)(&data[220])); switch(id) { case EXP_ID_CODE_NUNCHUK: if(!nunchuk_handshake(wm,&wm->exp.nunchuk,data,len)) return; break; case EXP_ID_CODE_CLASSIC_CONTROLLER: if(!classic_ctrl_handshake(wm,&wm->exp.classic,data,len)) return; break; case EXP_ID_CODE_GUITAR: if(!guitar_hero_3_handshake(wm,&wm->exp.gh3,data,len)) return; break; case EXP_ID_CODE_WIIBOARD: if(!wii_board_handshake(wm,&wm->exp.wb,data,len)) return; break; default: WIIMOTE_DISABLE_STATE(wm,WIIMOTE_STATE_EXP_HANDSHAKE); WIIMOTE_ENABLE_STATE(wm,WIIMOTE_STATE_EXP_FAILED); __lwp_wkspace_free(data); wiiuse_status(wm,NULL); return; } __lwp_wkspace_free(data); WIIMOTE_DISABLE_STATE(wm,WIIMOTE_STATE_EXP_HANDSHAKE); WIIMOTE_ENABLE_STATE(wm,WIIMOTE_STATE_EXP); wiiuse_set_ir_mode(wm); wiiuse_status(wm,NULL); break; } }
void wiiuse_motion_plus_check(struct wiimote_t *wm,ubyte *data,uword len) { u32 val; if(data == NULL) { wiiuse_read_data(wm, wm->motion_plus_id, WM_EXP_ID, 6, wiiuse_motion_plus_check); } else { WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_FAILED); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE); val = (data[3] << 16) | (data[2] << 24) | (data[4] << 8) | data[5]; if(val == EXP_ID_CODE_MOTION_PLUS) { /* handshake done */ wm->event = WIIUSE_MOTION_PLUS_ACTIVATED; wm->exp.type = EXP_MOTION_PLUS; WIIMOTE_ENABLE_STATE(wm,WIIMOTE_STATE_EXP); wiiuse_set_ir_mode(wm); } } }