93 control_dcid[0] = 0x60;
94 control_dcid[1] = 0x00;
95 interrupt_dcid[0] = 0x61;
96 interrupt_dcid[1] = 0x00;
105 activateNunchuck =
false;
106 motionValuesReset =
false;
107 activeConnection =
false;
108 motionPlusInside =
false;
117 if(!motionPlusInside) {
119 #ifdef DEBUG_USB_HOST 120 Notify(
PSTR(
"\r\nDeactivating Motion Plus"), 0x80);
124 timer = millis() + 1000;
136 if((l2capinbuf[12] | (l2capinbuf[13] << 8)) ==
HID_CTRL_PSM) {
140 activeConnection =
true;
148 if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) {
150 #ifdef DEBUG_USB_HOST 151 Notify(
PSTR(
"\r\nL2CAP Command Rejected - Reason: "), 0x80);
152 D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
154 D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
156 D_PrintHex<uint8_t > (l2capinbuf[17], 0x80);
158 D_PrintHex<uint8_t > (l2capinbuf[16], 0x80);
160 D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
162 D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
165 if(((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) && ((l2capinbuf[18] | (l2capinbuf[19] << 8)) ==
SUCCESSFUL)) {
166 if(l2capinbuf[14] == control_dcid[0] && l2capinbuf[15] == control_dcid[1]) {
169 control_scid[0] = l2capinbuf[12];
170 control_scid[1] = l2capinbuf[13];
172 }
else if(l2capinbuf[14] == interrupt_dcid[0] && l2capinbuf[15] == interrupt_dcid[1]) {
175 interrupt_scid[0] = l2capinbuf[12];
176 interrupt_scid[1] = l2capinbuf[13];
182 Notify(
PSTR(
"\r\nL2CAP Connection Request - PSM: "), 0x80);
183 D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
185 D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
187 D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
189 D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
191 D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
193 if((l2capinbuf[12] | (l2capinbuf[13] << 8)) ==
HID_CTRL_PSM) {
195 control_scid[0] = l2capinbuf[14];
196 control_scid[1] = l2capinbuf[15];
198 }
else if((l2capinbuf[12] | (l2capinbuf[13] << 8)) ==
HID_INTR_PSM) {
200 interrupt_scid[0] = l2capinbuf[14];
201 interrupt_scid[1] = l2capinbuf[15];
205 if((l2capinbuf[16] | (l2capinbuf[17] << 8)) == 0x0000) {
206 if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
210 }
else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
217 if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
220 }
else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
225 if(l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
226 #ifdef DEBUG_USB_HOST 227 Notify(
PSTR(
"\r\nDisconnect Request: Control Channel"), 0x80);
232 }
else if(l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
233 #ifdef DEBUG_USB_HOST 234 Notify(
PSTR(
"\r\nDisconnect Request: Interrupt Channel"), 0x80);
241 if(l2capinbuf[12] == control_scid[0] && l2capinbuf[13] == control_scid[1]) {
245 }
else if(l2capinbuf[12] == interrupt_scid[0] && l2capinbuf[13] == interrupt_scid[1]) {
254 Notify(
PSTR(
"\r\nL2CAP Unknown Signaling Command: "), 0x80);
255 D_PrintHex<uint8_t > (l2capinbuf[8], 0x80);
258 }
else if(l2capinbuf[6] == interrupt_dcid[0] && l2capinbuf[7] == interrupt_dcid[1]) {
260 if(l2capinbuf[8] == 0xA1) {
261 if((l2capinbuf[9] >= 0x20 && l2capinbuf[9] <= 0x22) || (l2capinbuf[9] >= 0x30 && l2capinbuf[9] <= 0x37) || l2capinbuf[9] == 0x3e || l2capinbuf[9] == 0x3f) {
262 if((l2capinbuf[9] >= 0x20 && l2capinbuf[9] <= 0x22) || l2capinbuf[9] == 0x31 || l2capinbuf[9] == 0x33)
263 ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8));
265 ButtonState = (uint32_t)(((~l2capinbuf[23]) & 0xFE) | ((uint16_t)(~l2capinbuf[24]) << 8) | ((uint32_t)((~l2capinbuf[25]) & 0x03) << 16));
267 if(l2capinbuf[20] & 0x02)
268 ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)(ButtonState & 0xFFFF0000)));
270 ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)((~l2capinbuf[20]) & 0x0C) << 14));
273 ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)((~l2capinbuf[20]) & 0x03) << 16));
275 else if(!unknownExtensionConnected)
276 ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8));
279 D_PrintHex<uint32_t > (ButtonState, 0x80);
282 if(ButtonState != OldButtonState) {
283 ButtonClickState = ButtonState & ~OldButtonState;
284 OldButtonState = ButtonState;
287 if(l2capinbuf[9] == 0x31 || l2capinbuf[9] == 0x33 || l2capinbuf[9] == 0x35 || l2capinbuf[9] == 0x37) {
288 accXwiimote = ((l2capinbuf[12] << 2) | (l2capinbuf[10] & 0x60 >> 5)) - 500;
289 accYwiimote = ((l2capinbuf[13] << 2) | (l2capinbuf[11] & 0x20 >> 4)) - 500;
290 accZwiimote = ((l2capinbuf[14] << 2) | (l2capinbuf[11] & 0x40 >> 5)) - 500;
292 switch(l2capinbuf[9]) {
295 Notify(
PSTR(
"\r\nStatus report was received"), 0x80);
297 wiiState = l2capinbuf[12];
298 batteryLevel = l2capinbuf[15];
300 if(!checkBatteryLevel) {
301 if(l2capinbuf[12] & 0x02) {
302 #ifdef DEBUG_USB_HOST 303 if(!unknownExtensionConnected)
304 Notify(
PSTR(
"\r\nExtension connected"), 0x80);
306 unknownExtensionConnected =
true;
310 setReportMode(
false, 0x35);
312 #ifdef DEBUG_USB_HOST 313 Notify(
PSTR(
"\r\nExtension disconnected"), 0x80);
316 #ifdef DEBUG_USB_HOST 320 if(!activateNunchuck)
324 #ifdef DEBUG_USB_HOST 330 setReportMode(
false, 0x31);
332 setReportMode(
false, 0x31);
337 Notify(
PSTR(
"\r\nChecking battery level"), 0x80);
339 checkBatteryLevel =
false;
341 #ifdef DEBUG_USB_HOST 342 if(l2capinbuf[12] & 0x01)
343 Notify(
PSTR(
"\r\nWARNING: Battery is nearly empty"), 0x80);
348 if((l2capinbuf[12] & 0x0F) == 0) {
349 uint8_t reportLength = (l2capinbuf[12] >> 4) + 1;
351 if(l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x00 && l2capinbuf[20] == 0x00) {
352 #ifdef DEBUG_USB_HOST 356 }
else if(l2capinbuf[16] == 0x00 && (l2capinbuf[17] == 0xA6 || l2capinbuf[17] == 0xA4) && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x00 && l2capinbuf[20] == 0x05) {
357 #ifdef DEBUG_USB_HOST 358 Notify(
PSTR(
"\r\nMotion Plus connected"), 0x80);
361 }
else if(l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x04 && l2capinbuf[20] == 0x05) {
362 #ifdef DEBUG_USB_HOST 363 Notify(
PSTR(
"\r\nMotion Plus activated in normal mode"), 0x80);
369 setReportMode(
false, 0x35);
370 }
else if(l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x05 && l2capinbuf[20] == 0x05) {
371 #ifdef DEBUG_USB_HOST 372 Notify(
PSTR(
"\r\nMotion Plus activated in Nunchuck pass-through mode"), 0x80);
374 activateNunchuck =
false;
380 setReportMode(
false, 0x35);
381 }
else if(l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA6 && l2capinbuf[18] == 0x20 && (l2capinbuf[19] == 0x00 || l2capinbuf[19] == 0x04 || l2capinbuf[19] == 0x05 || l2capinbuf[19] == 0x07) && l2capinbuf[20] == 0x05) {
382 #ifdef DEBUG_USB_HOST 383 Notify(
PSTR(
"\r\nInactive Wii Motion Plus"), 0x80);
384 Notify(
PSTR(
"\r\nPlease unplug the Motion Plus, disconnect the Wiimote and then replug the Motion Plus Extension"), 0x80);
387 }
else if(l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x01 && l2capinbuf[20] == 0x20) {
388 #ifdef DEBUG_USB_HOST 389 Notify(
PSTR(
"\r\nWii U Pro Controller connected"), 0x80);
392 }
else if(l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x04 && l2capinbuf[20] == 0x02) {
393 #ifdef DEBUG_USB_HOST 394 Notify(
PSTR(
"\r\nWii Balance Board connected"), 0x80);
396 setReportMode(
false, 0x32);
400 else if(l2capinbuf[13] == 0x00 && l2capinbuf[14] == 0x24 && reportLength == 16) {
401 for(uint8_t i = 0; i < 2; i++) {
402 for(uint8_t j = 0; j < 4; j++)
403 wiiBalanceBoardCal[i][j] = l2capinbuf[16 + 8 * i + 2 * j] | l2capinbuf[15 + 8 * i + 2 * j] << 8;
405 }
else if(l2capinbuf[13] == 0x00 && l2capinbuf[14] == 0x34 && reportLength == 8) {
406 for(uint8_t j = 0; j < 4; j++)
407 wiiBalanceBoardCal[2][j] = l2capinbuf[16 + 2 * j] | l2capinbuf[15 + 2 * j] << 8;
408 #ifdef DEBUG_USB_HOST 409 Notify(
PSTR(
"\r\nWii Balance Board calibration values read successfully"), 0x80);
414 #ifdef DEBUG_USB_HOST 417 D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
418 D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
420 for(uint8_t i = 0; i < reportLength; i++) {
421 D_PrintHex<uint8_t > (l2capinbuf[15 + i], 0x80);
430 D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
431 D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
436 #ifdef DEBUG_USB_HOST 437 if(l2capinbuf[13] != 0x00) {
439 D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
449 wiiBalanceBoardRaw[
TopRight] = l2capinbuf[13] | l2capinbuf[12] << 8;
450 wiiBalanceBoardRaw[
BotRight] = l2capinbuf[15] | l2capinbuf[14] << 8;
451 wiiBalanceBoardRaw[
TopLeft] = l2capinbuf[17] | l2capinbuf[16] << 8;
452 wiiBalanceBoardRaw[
BotLeft] = l2capinbuf[19] | l2capinbuf[18] << 8;
457 IR_object_x1 = (l2capinbuf[15] | ((uint16_t)(l2capinbuf[17] & 0x30) << 4));
458 IR_object_y1 = (l2capinbuf[16] | ((uint16_t)(l2capinbuf[17] & 0xC0) << 2));
459 IR_object_s1 = (l2capinbuf[17] & 0x0F);
461 IR_object_x2 = (l2capinbuf[18] | ((uint16_t)(l2capinbuf[20] & 0x30) << 4));
462 IR_object_y2 = (l2capinbuf[19] | ((uint16_t)(l2capinbuf[20] & 0xC0) << 2));
463 IR_object_s2 = (l2capinbuf[20] & 0x0F);
465 IR_object_x3 = (l2capinbuf[21] | ((uint16_t)(l2capinbuf[23] & 0x30) << 4));
466 IR_object_y3 = (l2capinbuf[22] | ((uint16_t)(l2capinbuf[23] & 0xC0) << 2));
467 IR_object_s3 = (l2capinbuf[23] & 0x0F);
469 IR_object_x4 = (l2capinbuf[24] | ((uint16_t)(l2capinbuf[26] & 0x30) << 4));
470 IR_object_y4 = (l2capinbuf[25] | ((uint16_t)(l2capinbuf[26] & 0xC0) << 2));
471 IR_object_s4 = (l2capinbuf[26] & 0x0F);
498 #if 1 // Set this to 0 if you don't want to use an extension, this reduceds the size of the library a lot! 500 if(l2capinbuf[20] & 0x02) {
501 if(motionValuesReset) {
511 if(!(l2capinbuf[18] & 0x02))
513 if(!(l2capinbuf[18] & 0x01))
515 if(!(l2capinbuf[19] & 0x02))
541 if((micros() - timer) > 1000000) {
542 #ifdef DEBUG_USB_HOST 543 Notify(
PSTR(
"\r\nThe gyro values has been reset"), 0x80);
545 gyroYawZero = (l2capinbuf[15] | ((l2capinbuf[18] & 0xFC) << 6));
546 gyroRollZero = (l2capinbuf[16] | ((l2capinbuf[19] & 0xFC) << 6));
547 gyroPitchZero = (l2capinbuf[17] | ((l2capinbuf[20] & 0xFC) << 6));
557 motionValuesReset =
true;
563 hatValues[
HatX] = l2capinbuf[15];
564 hatValues[
HatY] = l2capinbuf[16];
565 accXnunchuck = ((l2capinbuf[17] << 2) | (l2capinbuf[20] & 0x10 >> 3)) - 416;
566 accYnunchuck = ((l2capinbuf[18] << 2) | (l2capinbuf[20] & 0x20 >> 4)) - 416;
567 accZnunchuck = (((l2capinbuf[19] & 0xFE) << 2) | (l2capinbuf[20] & 0xC0 >> 5)) - 416;
571 if(l2capinbuf[19] & 0x01) {
572 if(!extensionConnected) {
573 extensionConnected =
true;
574 unknownExtensionConnected =
true;
575 #ifdef DEBUG_USB_HOST 576 Notify(
PSTR(
"\r\nExtension connected to Motion Plus"), 0x80);
580 if(extensionConnected && !unknownExtensionConnected) {
581 extensionConnected =
false;
582 unknownExtensionConnected =
true;
583 #ifdef DEBUG_USB_HOST 584 Notify(
PSTR(
"\r\nExtension disconnected from Motion Plus"), 0x80);
591 hatValues[
HatX] = l2capinbuf[15];
592 hatValues[
HatY] = l2capinbuf[16];
593 accXnunchuck = ((l2capinbuf[17] << 2) | (l2capinbuf[20] & 0x0C >> 2)) - 416;
594 accYnunchuck = ((l2capinbuf[18] << 2) | (l2capinbuf[20] & 0x30 >> 4)) - 416;
595 accZnunchuck = ((l2capinbuf[19] << 2) | (l2capinbuf[20] & 0xC0 >> 6)) - 416;
597 hatValues[
LeftHatX] = (l2capinbuf[15] | l2capinbuf[16] << 8);
598 hatValues[
RightHatX] = (l2capinbuf[17] | l2capinbuf[18] << 8);
599 hatValues[
LeftHatY] = (l2capinbuf[19] | l2capinbuf[20] << 8);
600 hatValues[
RightHatY] = (l2capinbuf[21] | l2capinbuf[22] << 8);
604 #ifdef DEBUG_USB_HOST 606 Notify(
PSTR(
"\r\nUnknown Report type: "), 0x80);
607 D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
617 void WII::L2CAP_task() {
618 switch(l2cap_state) {
622 #ifdef DEBUG_USB_HOST 623 Notify(
PSTR(
"\r\nHID Control Successfully Configured"), 0x80);
631 #ifdef DEBUG_USB_HOST 632 Notify(
PSTR(
"\r\nHID Interrupt Incoming Connection Request"), 0x80);
648 #ifdef DEBUG_USB_HOST 649 Notify(
PSTR(
"\r\nSend HID Control Config Request"), 0x80);
659 #ifdef DEBUG_USB_HOST 660 Notify(
PSTR(
"\r\nSend HID Interrupt Connection Request"), 0x80);
670 #ifdef DEBUG_USB_HOST 671 Notify(
PSTR(
"\r\nSend HID Interrupt Config Request"), 0x80);
681 #ifdef DEBUG_USB_HOST 682 Notify(
PSTR(
"\r\nHID Channels Established"), 0x80);
695 #ifdef DEBUG_USB_HOST 696 Notify(
PSTR(
"\r\nDisconnected Interrupt Channel"), 0x80);
706 #ifdef DEBUG_USB_HOST 707 Notify(
PSTR(
"\r\nDisconnected Control Channel"), 0x80);
722 switch(l2cap_state) {
726 activeConnection =
true;
728 #ifdef DEBUG_USB_HOST 729 Notify(
PSTR(
"\r\nSend HID Control Connection Request"), 0x80);
737 #ifdef DEBUG_USB_HOST 738 Notify(
PSTR(
"\r\nHID Control Incoming Connection Request"), 0x80);
751 #ifdef DEBUG_USB_HOST 752 if(stateCounter == 0)
753 Notify(
PSTR(
"\r\nChecking if a Motion Plus is connected"), 0x80);
756 if(stateCounter % 200 == 0)
757 checkMotionPresent();
763 if(unknownExtensionConnected) {
764 #ifdef DEBUG_USB_HOST 765 Notify(
PSTR(
"\r\nA extension is also connected"), 0x80);
767 activateNunchuck =
true;
770 }
else if(stateCounter == 601) {
771 #ifdef DEBUG_USB_HOST 772 Notify(
PSTR(
"\r\nNo Motion Plus was detected"), 0x80);
780 #ifdef DEBUG_USB_HOST 781 if(stateCounter == 0)
782 Notify(
PSTR(
"\r\nChecking if there is any extension connected"), 0x80);
785 if(stateCounter == 1)
787 if(stateCounter == 100) {
788 if(unknownExtensionConnected)
792 }
else if(stateCounter == 200)
794 else if(stateCounter == 300) {
796 unknownExtensionConnected =
false;
797 }
else if(stateCounter == 400) {
799 #ifdef DEBUG_USB_HOST 800 Notify(
PSTR(
"\r\nReading Wii Balance Board calibration values"), 0x80);
802 readWiiBalanceBoardCalibration();
805 }
else if(stateCounter == 500) {
813 if(stateCounter == 1)
815 else if(stateCounter == 100)
816 activateMotionPlus();
817 else if(stateCounter == 200)
819 else if(stateCounter == 300) {
821 unknownExtensionConnected =
false;
835 if(unknownExtensionConnected) {
836 #ifdef DEBUG_USB_HOST 837 if(stateCounter == 0)
838 Notify(
PSTR(
"\r\nChecking extension port"), 0x80);
841 if(stateCounter == 50)
843 else if(stateCounter == 100)
845 else if(stateCounter == 150)
850 else if(stateCounter == 200)
852 else if(stateCounter == 250) {
854 #ifdef DEBUG_USB_HOST 855 Notify(
PSTR(
"\r\nNunchuck was reconnected"), 0x80);
857 activateNunchuck =
true;
862 }
else if(stateCounter == 300) {
864 #ifdef DEBUG_USB_HOST 865 Notify(
PSTR(
"\r\nReactivating the Motion Plus"), 0x80);
870 }
else if(stateCounter == 350)
871 activateMotionPlus();
872 else if(stateCounter == 400)
874 else if(stateCounter == 450) {
877 unknownExtensionConnected =
false;
889 void WII::HID_Command(uint8_t* data, uint8_t nbytes) {
899 HID_Command(HIDBuffer, 3);
904 HIDBuffer[2] &= ~0x01;
905 HID_Command(HIDBuffer, 3);
910 HIDBuffer[2] |= 0x01;
911 HID_Command(HIDBuffer, 3);
916 HIDBuffer[2] ^= 0x01;
917 HID_Command(HIDBuffer, 3);
922 HIDBuffer[2] = value | (HIDBuffer[2] & 0x01);
923 HID_Command(HIDBuffer, 3);
929 HID_Command(HIDBuffer, 3);
938 HID_Command(HIDBuffer, 3);
945 HID_Command(HIDBuffer, 3);
950 HIDBuffer[2] = (HIDBuffer[2] & 0x01);
952 HIDBuffer[2] |= 0x10;
954 HIDBuffer[2] |= 0x20;
956 HIDBuffer[2] |= 0x40;
958 HID_Command(HIDBuffer, 3);
962 checkBatteryLevel =
true;
967 void WII::setReportMode(
bool continuous, uint8_t mode) {
972 cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01);
974 cmd_buf[2] = 0x00 | (HIDBuffer[2] & 0x01);
976 HID_Command(cmd_buf, 4);
979 void WII::statusRequest() {
983 cmd_buf[2] = (HIDBuffer[2] & 0x01);
984 HID_Command(cmd_buf, 3);
991 void WII::writeData(uint32_t offset, uint8_t size, uint8_t* data) {
995 cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01);
996 cmd_buf[3] = (uint8_t)((offset & 0xFF0000) >> 16);
997 cmd_buf[4] = (uint8_t)((offset & 0xFF00) >> 8);
998 cmd_buf[5] = (uint8_t)(offset & 0xFF);
1001 for(; i < size; i++)
1002 cmd_buf[7 + i] = data[i];
1004 cmd_buf[7 + i] = 0x00;
1005 HID_Command(cmd_buf, 23);
1008 void WII::initExtension1() {
1011 writeData(0xA400F0, 1, buf);
1014 void WII::initExtension2() {
1017 writeData(0xA400FB, 1, buf);
1020 void WII::initMotionPlus() {
1023 writeData(0xA600F0, 1, buf);
1026 void WII::activateMotionPlus() {
1029 #ifdef DEBUG_USB_HOST 1030 Notify(
PSTR(
"\r\nActivating Wii U Pro Controller"), 0x80);
1033 }
else if(activateNunchuck) {
1034 #ifdef DEBUG_USB_HOST 1035 Notify(
PSTR(
"\r\nActivating Motion Plus in pass-through mode"), 0x80);
1041 #ifdef DEBUG_USB_HOST 1042 Notify(
PSTR(
"\r\nActivating Motion Plus in normal mode"), 0x80);
1046 writeData(0xA600FE, 1, buf);
1049 void WII::readData(uint32_t offset, uint16_t size,
bool EEPROM) {
1054 cmd_buf[2] = 0x00 | (HIDBuffer[2] & 0x01);
1056 cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01);
1057 cmd_buf[3] = (uint8_t)((offset & 0xFF0000) >> 16);
1058 cmd_buf[4] = (uint8_t)((offset & 0xFF00) >> 8);
1059 cmd_buf[5] = (uint8_t)(offset & 0xFF);
1060 cmd_buf[6] = (uint8_t)((size & 0xFF00) >> 8);
1061 cmd_buf[7] = (uint8_t)(size & 0xFF);
1063 HID_Command(cmd_buf, 8);
1066 void WII::readExtensionType() {
1067 readData(0xA400FA, 6,
false);
1070 void WII::readCalData() {
1071 readData(0x0016, 8,
true);
1074 void WII::checkMotionPresent() {
1075 readData(0xA600FA, 6,
false);
1078 void WII::readWiiBalanceBoardCalibration() {
1079 readData(0xA40024, 24,
false);
1099 bool click = (ButtonClickState & button);
1100 ButtonClickState &= ~button;
1108 uint8_t output = hatValues[(uint8_t)a];
1109 if(output == 0xFF || output == 0x00)
1120 uint16_t output = hatValues[(uint8_t)a];
1144 if(wiiBalanceBoardRaw[pos] < wiiBalanceBoardCal[0][pos])
1146 else if(wiiBalanceBoardRaw[pos] < wiiBalanceBoardCal[1][pos])
1147 return 17.0f * (float)(wiiBalanceBoardRaw[pos] - wiiBalanceBoardCal[0][pos]) / (float)(wiiBalanceBoardCal[1][pos] - wiiBalanceBoardCal[0][pos]);
1149 return 17.0f + 17.0f * (float)(wiiBalanceBoardRaw[pos] - wiiBalanceBoardCal[1][pos]) / (float)(wiiBalanceBoardCal[2][pos] - wiiBalanceBoardCal[1][pos]);
1165 #ifdef DEBUG_USB_HOST 1166 Notify(
PSTR(
"\r\nEnable IR Camera1 Complete"), 0x80);
1171 #ifdef DEBUG_USB_HOST 1172 Notify(
PSTR(
"\r\nEnable IR Camera2 Complete"), 0x80);
1177 #ifdef DEBUG_USB_HOST 1178 Notify(
PSTR(
"\r\nWrote hex number 0x08"), 0x80);
1182 writeSensitivityBlock1();
1183 #ifdef DEBUG_USB_HOST 1184 Notify(
PSTR(
"\r\nWrote Sensitivity Block 1"), 0x80);
1188 writeSensitivityBlock2();
1189 #ifdef DEBUG_USB_HOST 1190 Notify(
PSTR(
"\r\nWrote Sensitivity Block 2"), 0x80);
1194 uint8_t mode_num = 0x03;
1195 setWiiModeNumber(mode_num);
1196 #ifdef DEBUG_USB_HOST 1197 Notify(
PSTR(
"\r\nSet Wii Mode Number To 0x"), 0x80);
1198 D_PrintHex<uint8_t > (mode_num, 0x80);
1203 #ifdef DEBUG_USB_HOST 1204 Notify(
PSTR(
"\r\nWrote Hex Number 0x08"), 0x80);
1208 setReportMode(
false, 0x33);
1210 #ifdef DEBUG_USB_HOST 1211 Notify(
PSTR(
"\r\nSet Report Mode to 0x33"), 0x80);
1216 #ifdef DEBUG_USB_HOST 1221 void WII::enableIRCamera1() {
1225 cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01);
1226 HID_Command(cmd_buf, 3);
1229 void WII::enableIRCamera2() {
1233 cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01);
1234 HID_Command(cmd_buf, 3);
1237 void WII::writeSensitivityBlock1() {
1249 writeData(0xB00000, 9, buf);
1252 void WII::writeSensitivityBlock2() {
1257 writeData(0xB0001A, 2, buf);
1260 void WII::write0x08Value() {
1262 writeData(0xb00030, 1, &cmd);
1265 void WII::setWiiModeNumber(uint8_t mode_number) {
1266 writeData(0xb00033, 1, &mode_number);
#define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE
#define pgm_read_dword(addr)
#define wii_clear_flag(flag)
#define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS
#define L2CAP_INTERRUPT_CONFIG_REQUEST
#define L2CAP_INTERRUPT_SETUP
void l2cap_connection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid, uint8_t result)
void l2cap_connection_request(uint16_t handle, uint8_t rxid, uint8_t *scid, uint16_t psm)
#define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST
void setLedToggle(LEDEnum a)
void setLedRaw(uint8_t value)
uint8_t getAnalogHat(HatEnum a)
#define WII_FLAG_NUNCHUCK_CONNECTED
void l2cap_disconnection_request(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
void ACLData(uint8_t *ACLData)
uint8_t getBatteryLevel()
#define wii_set_flag(flag)
#define L2CAP_CONTROL_SUCCESS
#define pgm_read_byte(addr)
#define L2CAP_CONTROL_CONFIG_REQUEST
void l2cap_disconnection_response(uint16_t handle, uint8_t rxid, uint8_t *dcid, uint8_t *scid)
#define L2CAP_CONTROL_CONNECT_REQUEST
WII(BTD *p, bool pair=false)
#define WII_CHECK_EXTENSION_STATE
void hci_disconnect(uint16_t handle)
#define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE
#define WII_FLAG_MOTION_PLUS_CONNECTED
bool getButtonClick(ButtonEnum b)
bool wiiUProControllerConnected
void(* pFuncOnInit)(void)
#define WII_FLAG_CALIBRATE_BALANCE_BOARD
#define l2cap_check_flag(flag)
bool wiiBalanceBoardConnected
#define L2CAP_CMD_CONFIG_REQUEST
#define L2CAP_FLAG_CONTROL_CONNECTED
#define L2CAP_CMD_DISCONNECT_REQUEST
#define L2CAP_CONTROL_DISCONNECT
const uint32_t WII_BUTTONS[]
#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST
#define WII_CHECK_MOTION_PLUS_STATE
bool l2capConnectionClaimed
const uint32_t WII_PROCONTROLLER_BUTTONS[]
#define L2CAP_CMD_DISCONNECT_RESPONSE
#define L2CAP_CMD_CONNECTION_RESPONSE
#define L2CAP_CMD_CONFIG_RESPONSE
uint32_t l2cap_event_flag
#define wii_check_flag(flag)
#define WII_INIT_MOTION_PLUS_STATE
void L2CAP_Command(uint16_t handle, uint8_t *data, uint8_t nbytes, uint8_t channelLow=0x01, uint8_t channelHigh=0x00)
void l2cap_config_response(uint16_t handle, uint8_t rxid, uint8_t *scid)
#define L2CAP_FLAG_INTERRUPT_CONNECTED
#define l2cap_set_flag(flag)
void l2cap_config_request(uint16_t handle, uint8_t rxid, uint8_t *dcid)
bool getButtonPress(ButtonEnum b)
#define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS
#define L2CAP_CMD_CONNECTION_REQUEST
bool checkHciHandle(uint8_t *buf, uint16_t handle)
#define L2CAP_INTERRUPT_CONNECT_REQUEST
#define L2CAP_INTERRUPT_DISCONNECT
float getWeight(BalanceBoardEnum pos)
#define L2CAP_CMD_COMMAND_REJECT