Permalink
Browse files

Skip events that don't belong to the Wiimote

  • Loading branch information...
1 parent 70ed4a7 commit ae4820c6501684dced233324f8949ff0409cf9a0 @xerpi committed Dec 26, 2016
Showing with 22 additions and 2 deletions.
  1. +22 −2 main.c
View
@@ -389,6 +389,15 @@ static int bt_cb_func(int notifyId, int notifyCount, int notifyArg, void *common
LOG(" %02X", hid_event.data[i]);
LOG("\n");
+ /*
+ * If we get an event with a MAC, and the MAC is different
+ * from the connected Wiimote, skip the event.
+ */
+ if (wiimote_connected && hid_event.mac0 != 0 && hid_event.mac1 != 0) {
+ if (hid_event.mac0 != wiimote_mac0 || hid_event.mac1 != wiimote_mac1)
+ continue;
+ }
+
switch (hid_event.id) {
case 0x01: { /* Inquiry result event */
unsigned short vid_pid[2];
@@ -406,9 +415,11 @@ static int bt_cb_func(int notifyId, int notifyCount, int notifyArg, void *common
}
case 0x02: /* Inquiry stop event */
- if (wiimote_mac0 || wiimote_mac1) {
- ksceBtStartConnect(wiimote_mac0, wiimote_mac1);
+ if (!wiimote_connected) {
+ if (wiimote_mac0 || wiimote_mac1)
+ ksceBtStartConnect(wiimote_mac0, wiimote_mac1);
}
+
break;
case 0x03: { /* Pin request event */
@@ -433,6 +444,8 @@ static int bt_cb_func(int notifyId, int notifyCount, int notifyArg, void *common
case 0x05: /* Connection accepted event */
wiimote_set_led(hid_event.mac0, hid_event.mac1, 1);
+ wiimote_mac0 = hid_event.mac0;
+ wiimote_mac1 = hid_event.mac1;
wiimote_connected = 1;
break;
@@ -446,6 +459,13 @@ static int bt_cb_func(int notifyId, int notifyCount, int notifyArg, void *common
*/
break;
+ case 0x09: /* Connect request without being paired? event */
+ /*
+ * The Vita needs to have a pairing with the Wiimote,
+ * otherwise it won't connect.
+ */
+ break;
+
case 0x0A: /* HID reply to 0-type request */
LOG("Wiimote 0x0A event: 0x%02X\n", recv_buff[0]);

0 comments on commit ae4820c

Please sign in to comment.