25 const uint8_t
LEDS[] PROGMEM = {
95 control_dcid[0] = 0x60;
96 control_dcid[1] = 0x00;
97 interrupt_dcid[0] = 0x61;
98 interrupt_dcid[1] = 0x00;
107 activateNunchuck =
false;
108 motionValuesReset =
false;
109 activeConnection =
false;
110 motionPlusInside =
false;
113 l2cap_event_flag = 0;
118 if (!motionPlusInside) {
120 #ifdef DEBUG_USB_HOST
121 Notify(PSTR(
"\r\nDeactivating Motion Plus"), 0x80);
125 timer = millis() + 1000;
137 if ((l2capinbuf[12] | (l2capinbuf[13] << 8)) ==
HID_CTRL_PSM) {
141 activeConnection =
true;
147 if ((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000)) {
148 if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) {
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]) {
168 identifier = l2capinbuf[9];
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]) {
174 identifier = l2capinbuf[9];
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);
186 Notify(PSTR(
" SCID: "), 0x80);
187 D_PrintHex<uint8_t > (l2capinbuf[15], 0x80);
189 D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
190 Notify(PSTR(
" Identifier: "), 0x80);
191 D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
193 if ((l2capinbuf[12] | (l2capinbuf[13] << 8)) ==
HID_CTRL_PSM) {
194 identifier = l2capinbuf[9];
195 control_scid[0] = l2capinbuf[14];
196 control_scid[1] = l2capinbuf[15];
198 }
else if ((l2capinbuf[12] | (l2capinbuf[13] << 8)) ==
HID_INTR_PSM) {
199 identifier = l2capinbuf[9];
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]) {
208 identifier = l2capinbuf[9];
210 }
else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
212 identifier = l2capinbuf[9];
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);
229 identifier = l2capinbuf[9];
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);
236 identifier = l2capinbuf[9];
241 if (l2capinbuf[12] == control_scid[0] && l2capinbuf[13] == control_scid[1]) {
243 identifier = l2capinbuf[9];
245 }
else if (l2capinbuf[12] == interrupt_scid[0] && l2capinbuf[13] == interrupt_scid[1]) {
247 identifier = l2capinbuf[9];
253 identifier = l2capinbuf[9];
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));
278 Notify(PSTR(
"ButtonState: "), 0x80);
279 D_PrintHex<uint32_t > (ButtonState, 0x80);
280 Notify(PSTR(
"\r\n"), 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 accX = ((l2capinbuf[12] << 2) | (l2capinbuf[10] & 0x60 >> 5)) - 500;
289 accY = ((l2capinbuf[13] << 2) | (l2capinbuf[11] & 0x20 >> 4)) - 500;
290 accZ = ((l2capinbuf[14] << 2) | (l2capinbuf[11] & 0x40 >> 5)) - 500;
294 switch (l2capinbuf[9]) {
297 Notify(PSTR(
"\r\nStatus report was received"), 0x80);
299 wiiState = l2capinbuf[12];
300 batteryLevel = l2capinbuf[15];
301 #ifdef DEBUG_USB_HOST
302 if (l2capinbuf[12] & 0x01)
303 Notify(PSTR(
"\r\nWARNING: Battery is nearly empty"), 0x80);
305 if (checkExtension) {
306 if (l2capinbuf[12] & 0x02) {
307 #ifdef DEBUG_USB_HOST
308 if (!unknownExtensionConnected)
309 Notify(PSTR(
"\r\nExtension connected"), 0x80);
311 unknownExtensionConnected =
true;
315 setReportMode(
false, 0x35);
317 #ifdef DEBUG_USB_HOST
318 Notify(PSTR(
"\r\nExtension disconnected"), 0x80);
321 #ifdef DEBUG_USB_HOST
322 Notify(PSTR(
" - from Motion Plus"), 0x80);
325 if (!activateNunchuck)
329 #ifdef DEBUG_USB_HOST
330 Notify(PSTR(
" - Nunchuck"), 0x80);
335 setReportMode(
false, 0x31);
337 setReportMode(
false, 0x31);
340 checkExtension =
true;
343 if ((l2capinbuf[12] & 0x0F) == 0) {
345 if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x00 && l2capinbuf[20] == 0x00) {
346 #ifdef DEBUG_USB_HOST
347 Notify(PSTR(
"\r\nNunchuck connected"), 0x80);
350 }
else if (l2capinbuf[16] == 0x00 && (l2capinbuf[17] == 0xA6 || l2capinbuf[17] == 0xA4) && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x00 && l2capinbuf[20] == 0x05) {
351 #ifdef DEBUG_USB_HOST
352 Notify(PSTR(
"\r\nMotion Plus connected"), 0x80);
355 }
else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x04 && l2capinbuf[20] == 0x05) {
356 #ifdef DEBUG_USB_HOST
357 Notify(PSTR(
"\r\nMotion Plus activated in normal mode"), 0x80);
363 setReportMode(
false, 0x35);
364 }
else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x05 && l2capinbuf[20] == 0x05) {
365 #ifdef DEBUG_USB_HOST
366 Notify(PSTR(
"\r\nMotion Plus activated in Nunchuck pass-through mode"), 0x80);
368 activateNunchuck =
false;
374 setReportMode(
false, 0x35);
375 }
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) {
376 #ifdef DEBUG_USB_HOST
377 Notify(PSTR(
"\r\nInactive Wii Motion Plus"), 0x80);
378 Notify(PSTR(
"\r\nPlease unplug the Motion Plus, disconnect the Wiimote and then replug the Motion Plus Extension"), 0x80);
381 }
else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x01 && l2capinbuf[20] == 0x20) {
382 #ifdef DEBUG_USB_HOST
383 Notify(PSTR(
"\r\nWii U Pro Controller connected"), 0x80);
387 #ifdef DEBUG_USB_HOST
389 Notify(PSTR(
"\r\nUnknown Device: "), 0x80);
390 D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
391 D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
392 Notify(PSTR(
"\r\nData: "), 0x80);
393 for (uint8_t i = 0; i < ((l2capinbuf[12] >> 4) + 1); i++) {
394 D_PrintHex<uint8_t > (l2capinbuf[15 + i], 0x80);
402 Notify(PSTR(
"\r\nReport Error: "), 0x80);
403 D_PrintHex<uint8_t > (l2capinbuf[13], 0x80);
404 D_PrintHex<uint8_t > (l2capinbuf[14], 0x80);
409 #ifdef DEBUG_USB_HOST
410 if (l2capinbuf[13] != 0x00) {
411 Notify(PSTR(
"\r\nCommand failed: "), 0x80);
412 D_PrintHex<uint8_t > (l2capinbuf[12], 0x80);
429 IR_object_x1 = (l2capinbuf[15] | ((uint16_t)(l2capinbuf[17] & 0x30) << 4));
430 IR_object_y1 = (l2capinbuf[16] | ((uint16_t)(l2capinbuf[17] & 0xC0) << 2));
431 IR_object_s1 = (l2capinbuf[17] & 0x0F);
433 IR_object_x2 = (l2capinbuf[18] | ((uint16_t)(l2capinbuf[20] & 0x30) << 4));
434 IR_object_y2 = (l2capinbuf[19] | ((uint16_t)(l2capinbuf[20] & 0xC0) << 2));
435 IR_object_s2 = (l2capinbuf[20] & 0x0F);
437 IR_object_x3 = (l2capinbuf[21] | ((uint16_t)(l2capinbuf[23] & 0x30) << 4));
438 IR_object_y3 = (l2capinbuf[22] | ((uint16_t)(l2capinbuf[23] & 0xC0) << 2));
439 IR_object_s3 = (l2capinbuf[23] & 0x0F);
441 IR_object_x4 = (l2capinbuf[24] | ((uint16_t)(l2capinbuf[26] & 0x30) << 4));
442 IR_object_y4 = (l2capinbuf[25] | ((uint16_t)(l2capinbuf[26] & 0xC0) << 2));
443 IR_object_s4 = (l2capinbuf[26] & 0x0F);
471 if (l2capinbuf[20] & 0x02) {
472 if (motionValuesReset) {
482 if (!(l2capinbuf[18] & 0x02))
484 if (!(l2capinbuf[18] & 0x01))
486 if (!(l2capinbuf[19] & 0x02))
512 if ((micros() - timer) > 1000000) {
513 #ifdef DEBUG_USB_HOST
514 Notify(PSTR(
"\r\nThe gyro values has been reset"), 0x80);
516 gyroYawZero = (l2capinbuf[15] | ((l2capinbuf[18] & 0xFC) << 6));
517 gyroRollZero = (l2capinbuf[16] | ((l2capinbuf[19] & 0xFC) << 6));
518 gyroPitchZero = (l2capinbuf[17] | ((l2capinbuf[20] & 0xFC) << 6));
528 motionValuesReset =
true;
534 hatValues[
HatX] = l2capinbuf[15];
535 hatValues[
HatY] = l2capinbuf[16];
536 accX = ((l2capinbuf[17] << 2) | (l2capinbuf[20] & 0x10 >> 3)) - 416;
537 accY = ((l2capinbuf[18] << 2) | (l2capinbuf[20] & 0x20 >> 4)) - 416;
538 accZ = (((l2capinbuf[19] & 0xFE) << 2) | (l2capinbuf[20] & 0xC0 >> 5)) - 416;
544 if (l2capinbuf[19] & 0x01) {
545 if (!extensionConnected) {
546 extensionConnected =
true;
547 unknownExtensionConnected =
true;
548 #ifdef DEBUG_USB_HOST
549 Notify(PSTR(
"\r\nExtension connected to Motion Plus"), 0x80);
553 if (extensionConnected && !unknownExtensionConnected) {
554 extensionConnected =
false;
555 unknownExtensionConnected =
true;
556 #ifdef DEBUG_USB_HOST
557 Notify(PSTR(
"\r\nExtension disconnected from Motion Plus"), 0x80);
564 hatValues[
HatX] = l2capinbuf[15];
565 hatValues[
HatY] = l2capinbuf[16];
566 accX = ((l2capinbuf[17] << 2) | (l2capinbuf[20] & 0x0C >> 2)) - 416;
567 accY = ((l2capinbuf[18] << 2) | (l2capinbuf[20] & 0x30 >> 4)) - 416;
568 accZ = ((l2capinbuf[19] << 2) | (l2capinbuf[20] & 0xC0 >> 6)) - 416;
575 hatValues[
LeftHatX] = (l2capinbuf[15] | l2capinbuf[16] << 8);
576 hatValues[
RightHatX] = (l2capinbuf[17] | l2capinbuf[18] << 8);
577 hatValues[
LeftHatY] = (l2capinbuf[19] | l2capinbuf[20] << 8);
578 hatValues[
RightHatY] = (l2capinbuf[21] | l2capinbuf[22] << 8);
581 #ifdef DEBUG_USB_HOST
583 Notify(PSTR(
"\r\nUnknown Report type: "), 0x80);
584 D_PrintHex<uint8_t > (l2capinbuf[9], 0x80);
594 void WII::L2CAP_task() {
595 switch (l2cap_state) {
599 #ifdef DEBUG_USB_HOST
600 Notify(PSTR(
"\r\nHID Control Successfully Configured"), 0x80);
608 #ifdef DEBUG_USB_HOST
609 Notify(PSTR(
"\r\nHID Interrupt Incoming Connection Request"), 0x80);
625 #ifdef DEBUG_USB_HOST
626 Notify(PSTR(
"\r\nSend HID Control Config Request"), 0x80);
636 #ifdef DEBUG_USB_HOST
637 Notify(PSTR(
"\r\nSend HID Interrupt Connection Request"), 0x80);
647 #ifdef DEBUG_USB_HOST
648 Notify(PSTR(
"\r\nSend HID Interrupt Config Request"), 0x80);
658 #ifdef DEBUG_USB_HOST
659 Notify(PSTR(
"\r\nHID Channels Established"), 0x80);
672 #ifdef DEBUG_USB_HOST
673 Notify(PSTR(
"\r\nDisconnected Interrupt Channel"), 0x80);
683 #ifdef DEBUG_USB_HOST
684 Notify(PSTR(
"\r\nDisconnected Control Channel"), 0x80);
688 l2cap_event_flag = 0;
699 switch (l2cap_state) {
703 activeConnection =
true;
705 #ifdef DEBUG_USB_HOST
706 Notify(PSTR(
"\r\nSend HID Control Connection Request"), 0x80);
709 l2cap_event_flag = 0;
714 #ifdef DEBUG_USB_HOST
715 Notify(PSTR(
"\r\nHID Control Incoming Connection Request"), 0x80);
728 #ifdef DEBUG_USB_HOST
729 if (stateCounter == 0)
730 Notify(PSTR(
"\r\nChecking if a Motion Plus is connected"), 0x80);
733 if (stateCounter % 200 == 0)
734 checkMotionPresent();
740 if (unknownExtensionConnected) {
741 #ifdef DEBUG_USB_HOST
742 Notify(PSTR(
"\r\nA extension is also connected"), 0x80);
744 activateNunchuck =
true;
747 }
else if (stateCounter == 601) {
748 #ifdef DEBUG_USB_HOST
749 Notify(PSTR(
"\r\nNo Motion Plus was detected"), 0x80);
757 #ifdef DEBUG_USB_HOST
758 if (stateCounter == 0)
759 Notify(PSTR(
"\r\nChecking if there is any extension connected"), 0x80);
762 if (stateCounter == 1)
764 if (stateCounter == 100) {
765 if (unknownExtensionConnected)
769 }
else if (stateCounter == 200)
771 else if (stateCounter == 300) {
773 unknownExtensionConnected =
false;
774 }
else if (stateCounter == 400) {
782 if (stateCounter == 1)
784 else if (stateCounter == 100)
785 activateMotionPlus();
786 else if (stateCounter == 200)
788 else if (stateCounter == 300) {
790 unknownExtensionConnected =
false;
804 if (unknownExtensionConnected) {
805 #ifdef DEBUG_USB_HOST
806 if (stateCounter == 0)
807 Notify(PSTR(
"\r\nChecking extension port"), 0x80);
810 if (stateCounter == 50)
812 else if (stateCounter == 100)
814 else if (stateCounter == 150)
819 else if (stateCounter == 200)
821 else if (stateCounter == 250) {
823 #ifdef DEBUG_USB_HOST
824 Notify(PSTR(
"\r\nNunchuck was reconnected"), 0x80);
826 activateNunchuck =
true;
831 }
else if (stateCounter == 300) {
833 #ifdef DEBUG_USB_HOST
834 Notify(PSTR(
"\r\nReactivating the Motion Plus"), 0x80);
839 }
else if (stateCounter == 350)
840 activateMotionPlus();
841 else if (stateCounter == 400)
843 else if (stateCounter == 450) {
846 unknownExtensionConnected =
false;
858 void WII::HID_Command(uint8_t* data, uint8_t nbytes) {
859 if (motionPlusInside)
860 pBtd->
L2CAP_Command(hci_handle, data, nbytes, interrupt_scid[0], interrupt_scid[1]);
862 pBtd->
L2CAP_Command(hci_handle, data, nbytes, control_scid[0], control_scid[1]);
868 HID_Command(HIDBuffer, 3);
873 HIDBuffer[2] &= ~0x01;
874 HID_Command(HIDBuffer, 3);
879 HIDBuffer[2] |= 0x01;
880 HID_Command(HIDBuffer, 3);
885 HIDBuffer[2] ^= 0x01;
886 HID_Command(HIDBuffer, 3);
891 HIDBuffer[2] = value | (HIDBuffer[2] & 0x01);
892 HID_Command(HIDBuffer, 3);
896 HIDBuffer[2] &= ~(pgm_read_byte(&
LEDS[(uint8_t)a]));
897 HID_Command(HIDBuffer, 3);
902 HIDBuffer[2] |= pgm_read_byte(&
LEDS[(uint8_t)a]);
903 HID_Command(HIDBuffer, 3);
908 HIDBuffer[2] ^= pgm_read_byte(&
LEDS[(uint8_t)a]);
909 HID_Command(HIDBuffer, 3);
914 HIDBuffer[2] = (HIDBuffer[2] & 0x01);
916 HIDBuffer[2] |= 0x10;
918 HIDBuffer[2] |= 0x20;
920 HIDBuffer[2] |= 0x40;
922 HID_Command(HIDBuffer, 3);
926 checkExtension =
false;
931 void WII::setReportMode(
bool continuous, uint8_t mode) {
936 cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01);
938 cmd_buf[2] = 0x00 | (HIDBuffer[2] & 0x01);
940 HID_Command(cmd_buf, 4);
943 void WII::statusRequest() {
947 cmd_buf[2] = (HIDBuffer[2] & 0x01);
948 HID_Command(cmd_buf, 3);
955 void WII::writeData(uint32_t offset, uint8_t size, uint8_t* data) {
959 cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01);
960 cmd_buf[3] = (uint8_t)((offset & 0xFF0000) >> 16);
961 cmd_buf[4] = (uint8_t)((offset & 0xFF00) >> 8);
962 cmd_buf[5] = (uint8_t)(offset & 0xFF);
965 for (; i < size; i++)
966 cmd_buf[7 + i] = data[i];
968 cmd_buf[7 + i] = 0x00;
969 HID_Command(cmd_buf, 23);
972 void WII::initExtension1() {
975 writeData(0xA400F0, 1, buf);
978 void WII::initExtension2() {
981 writeData(0xA400FB, 1, buf);
984 void WII::initMotionPlus() {
987 writeData(0xA600F0, 1, buf);
990 void WII::activateMotionPlus() {
993 #ifdef DEBUG_USB_HOST
994 Notify(PSTR(
"\r\nActivating Wii U Pro Controller"), 0x80);
997 }
else if (activateNunchuck) {
998 #ifdef DEBUG_USB_HOST
999 Notify(PSTR(
"\r\nActivating Motion Plus in pass-through mode"), 0x80);
1005 #ifdef DEBUG_USB_HOST
1006 Notify(PSTR(
"\r\nActivating Motion Plus in normal mode"), 0x80);
1010 writeData(0xA600FE, 1, buf);
1013 void WII::readData(uint32_t offset, uint16_t size,
bool EEPROM) {
1018 cmd_buf[2] = 0x00 | (HIDBuffer[2] & 0x01);
1020 cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01);
1021 cmd_buf[3] = (uint8_t)((offset & 0xFF0000) >> 16);
1022 cmd_buf[4] = (uint8_t)((offset & 0xFF00) >> 8);
1023 cmd_buf[5] = (uint8_t)(offset & 0xFF);
1024 cmd_buf[6] = (uint8_t)((size & 0xFF00) >> 8);
1025 cmd_buf[7] = (uint8_t)(size & 0xFF);
1027 HID_Command(cmd_buf, 8);
1030 void WII::readExtensionType() {
1031 readData(0xA400FA, 6,
false);
1034 void WII::readCalData() {
1035 readData(0x0016, 8,
true);
1038 void WII::checkMotionPresent() {
1039 readData(0xA600FA, 6,
false);
1051 return (ButtonState & pgm_read_dword(&
BUTTONS[(uint8_t)b]));
1059 button = pgm_read_dword(&
BUTTONS[(uint8_t)b]);
1060 bool click = (ButtonClickState & button);
1061 ButtonClickState &= ~button;
1069 uint8_t output = hatValues[(uint8_t)a];
1070 if (output == 0xFF || output == 0x00)
1081 uint16_t output = hatValues[(uint8_t)a];
1089 void WII::onInit() {
1105 #ifdef DEBUG_USB_HOST
1106 Notify(PSTR(
"\r\nEnable IR Camera1 Complete"), 0x80);
1111 #ifdef DEBUG_USB_HOST
1112 Notify(PSTR(
"\r\nEnable IR Camera2 Complete"), 0x80);
1117 #ifdef DEBUG_USB_HOST
1118 Notify(PSTR(
"\r\nWrote hex number 0x08"), 0x80);
1122 writeSensitivityBlock1();
1123 #ifdef DEBUG_USB_HOST
1124 Notify(PSTR(
"\r\nWrote Sensitivity Block 1"), 0x80);
1128 writeSensitivityBlock2();
1129 #ifdef DEBUG_USB_HOST
1130 Notify(PSTR(
"\r\nWrote Sensitivity Block 2"), 0x80);
1134 uint8_t mode_num = 0x03;
1135 setWiiModeNumber(mode_num);
1136 #ifdef DEBUG_USB_HOST
1137 Notify(PSTR(
"\r\nSet Wii Mode Number To 0x"), 0x80);
1138 D_PrintHex<uint8_t > (mode_num, 0x80);
1143 #ifdef DEBUG_USB_HOST
1144 Notify(PSTR(
"\r\nWrote Hex Number 0x08"), 0x80);
1148 setReportMode(
false, 0x33);
1150 #ifdef DEBUG_USB_HOST
1151 Notify(PSTR(
"\r\nSet Report Mode to 0x33"), 0x80);
1156 #ifdef DEBUG_USB_HOST
1157 Notify(PSTR(
"\r\nIR Initialized"), 0x80);
1161 void WII::enableIRCamera1() {
1165 cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01);
1166 HID_Command(cmd_buf, 3);
1169 void WII::enableIRCamera2() {
1173 cmd_buf[2] = 0x04 | (HIDBuffer[2] & 0x01);
1174 HID_Command(cmd_buf, 3);
1177 void WII::writeSensitivityBlock1() {
1189 writeData(0xB00000, 9, buf);
1192 void WII::writeSensitivityBlock2() {
1197 writeData(0xB0001A, 2, buf);
1200 void WII::write0x08Value() {
1202 writeData(0xb00030, 1, &cmd);
1205 void WII::setWiiModeNumber(uint8_t mode_number) {
1206 writeData(0xb00033, 1, &mode_number);