@@ -29,6 +29,7 @@ connectToWii(false),
29
29
pairWithWii(false ),
30
30
connectToHIDDevice(false ),
31
31
pairWithHIDDevice(false ),
32
+ pairWithOtherDevice(false ),
32
33
pUsb(p), // Pointer to USB class instance - mandatory
33
34
bAddress(0 ), // Device address - mandatory
34
35
bNumEP(1 ), // If config descriptor needs to be parsed
@@ -301,6 +302,7 @@ void BTD::Initialize() {
301
302
connectToWii = false ;
302
303
incomingWii = false ;
303
304
connectToHIDDevice = false ;
305
+ connectToOtherDevice = false ;
304
306
incomingHIDDevice = false ;
305
307
incomingPS4 = false ;
306
308
bAddress = 0 ; // Clear device address
@@ -410,18 +412,22 @@ void BTD::HCI_event_task() {
410
412
break ;
411
413
412
414
case EV_INQUIRY_COMPLETE:
413
- if (inquiry_counter >= 5 && (pairWithWii || pairWithHIDDevice)) {
415
+ if (inquiry_counter >= 5 && (pairWithWii || pairWithHIDDevice || pairWithOtherDevice )) {
414
416
inquiry_counter = 0 ;
415
417
#ifdef DEBUG_USB_HOST
416
418
if (pairWithWii)
417
419
Notify (PSTR (" \r\n Couldn't find Wiimote" ), 0x80 );
420
+ else if (pairWithOtherDevice)
421
+ Notify (PSTR (" \r\n Couldn't find 'Other' device" ), 0x80 );
418
422
else
419
423
Notify (PSTR (" \r\n Couldn't find HID device" ), 0x80 );
420
424
#endif
421
425
connectToWii = false ;
422
426
pairWithWii = false ;
423
427
connectToHIDDevice = false ;
424
428
pairWithHIDDevice = false ;
429
+ connectToOtherDevice = false ;
430
+ pairWithOtherDevice = false ;
425
431
hci_state = HCI_SCANNING_STATE;
426
432
}
427
433
inquiry_counter++;
@@ -464,17 +470,37 @@ void BTD::HCI_event_task() {
464
470
disc_bdaddr[j] = hcibuf[j + 3 + 6 * i];
465
471
466
472
hci_set_flag (HCI_FLAG_DEVICE_FOUND);
467
- }
473
+ } else {
468
474
#ifdef EXTRADEBUG
469
- else {
470
475
Notify (PSTR (" \r\n Class of device: " ), 0x80 );
471
476
D_PrintHex<uint8_t > (classOfDevice[2 ], 0x80 );
472
477
Notify (PSTR (" " ), 0x80 );
473
478
D_PrintHex<uint8_t > (classOfDevice[1 ], 0x80 );
474
479
Notify (PSTR (" " ), 0x80 );
475
480
D_PrintHex<uint8_t > (classOfDevice[0 ], 0x80 );
476
- }
477
481
#endif
482
+ uint8_t discovered = true ;
483
+ for (uint8_t j = 0 ; j < 6 ; j++) {
484
+ if (hcibuf[j + 3 + 6 * i] != remote_bdaddr[j])
485
+ discovered = false ;
486
+ disc_bdaddr[j] = hcibuf[j + 3 + 6 * i];
487
+ }
488
+ if (discovered) {
489
+ #ifdef DEBUG_USB_HOST
490
+ Notify (PSTR (" \r\n Device: " ), 0x80 );
491
+ for (int8_t j = 5 ; j > 0 ; j--) {
492
+ D_PrintHex<uint8_t > (disc_bdaddr[j], 0x80 );
493
+ Notify (PSTR (" :" ), 0x80 );
494
+ }
495
+ D_PrintHex<uint8_t > (disc_bdaddr[0 ], 0x80 );
496
+
497
+ Notify (PSTR (" has been found" ), 0x80 );
498
+ #endif
499
+ hci_set_flag (HCI_FLAG_DEVICE_FOUND);
500
+ }
501
+
502
+ }
503
+
478
504
}
479
505
}
480
506
break ;
@@ -582,6 +608,11 @@ void BTD::HCI_event_task() {
582
608
Notify (PSTR (" \r\n Pairing successful with HID device" ), 0x80 );
583
609
#endif
584
610
connectToHIDDevice = true ; // Used to indicate to the BTHID service, that it should connect to this device
611
+ } else if (pairWithOtherDevice && !connectToOtherDevice) {
612
+ #ifdef DEBUG_USB_HOST
613
+ Notify (PSTR (" \r\n Pairing successful with 'Other' device" ), 0x80 );
614
+ #endif
615
+ connectToOtherDevice = true ;
585
616
}
586
617
break ;
587
618
/* We will just ignore the following events */
@@ -694,12 +725,14 @@ void BTD::HCI_task() {
694
725
break ;
695
726
696
727
case HCI_CHECK_DEVICE_SERVICE:
697
- if (pairWithHIDDevice || pairWithWii) { // Check if it should try to connect to a Wiimote
728
+ if (pairWithHIDDevice || pairWithWii || pairWithOtherDevice ) { // Check if it should try to connect to a HID device, Wiimote or 'Other device'
698
729
#ifdef DEBUG_USB_HOST
699
730
if (pairWithWii)
700
731
Notify (PSTR (" \r\n Starting inquiry\r\n Press 1 & 2 on the Wiimote\r\n Or press sync if you are using a Wii U Pro Controller" ), 0x80 );
701
- else
732
+ else if (pairWithHIDDevice)
702
733
Notify (PSTR (" \r\n Please enable discovery of your device" ), 0x80 );
734
+ else
735
+ Notify (PSTR (" \r\n Pairing with 'Other' device with predefined address" ), 0x80 );
703
736
#endif
704
737
hci_inquiry ();
705
738
hci_state = HCI_INQUIRY_STATE;
@@ -713,20 +746,28 @@ void BTD::HCI_task() {
713
746
#ifdef DEBUG_USB_HOST
714
747
if (pairWithWii)
715
748
Notify (PSTR (" \r\n Wiimote found" ), 0x80 );
749
+ else if (pairWithOtherDevice)
750
+ Notify (PSTR (" \r\n 'Other' device found" ), 0x80 );
716
751
else
717
752
Notify (PSTR (" \r\n HID device found" ), 0x80 );
718
753
719
- Notify (PSTR (" \r\n Now just create the instance like so:" ), 0x80 );
720
- if (pairWithWii)
721
- Notify (PSTR (" \r\n WII Wii(&Btd);" ), 0x80 );
722
- else
723
- Notify (PSTR (" \r\n BTHID bthid(&Btd);" ), 0x80 );
754
+ if (!pairWithOtherDevice) {
755
+ Notify (PSTR (" \r\n Now just create the instance like so:" ), 0x80 );
756
+ if (pairWithWii)
757
+ Notify (PSTR (" \r\n WII Wii(&Btd);" ), 0x80 );
758
+ else
759
+ #ifdef _ps4bt_h_ // Check if the PS4 driver is being used
760
+ Notify (PSTR (" \r\n PS4BT PS4(&Btd);" ), 0x80 );
761
+ #else
762
+ Notify (PSTR (" \r\n BTHID bthid(&Btd);" ), 0x80 );
763
+ #endif
724
764
725
- Notify (PSTR (" \r\n And then press any button on the " ), 0x80 );
726
- if (pairWithWii)
727
- Notify (PSTR (" Wiimote" ), 0x80 );
728
- else
729
- Notify (PSTR (" device" ), 0x80 );
765
+ Notify (PSTR (" \r\n And then press any button on the " ), 0x80 );
766
+ if (pairWithWii)
767
+ Notify (PSTR (" Wiimote" ), 0x80 );
768
+ else
769
+ Notify (PSTR (" device" ), 0x80 );
770
+ }
730
771
#endif
731
772
if (motionPlusInside) {
732
773
hci_remote_name (); // We need to know the name to distinguish between a Wiimote and a Wii U Pro Controller
@@ -741,6 +782,8 @@ void BTD::HCI_task() {
741
782
#ifdef DEBUG_USB_HOST
742
783
if (pairWithWii)
743
784
Notify (PSTR (" \r\n Connecting to Wiimote" ), 0x80 );
785
+ else if (pairWithOtherDevice)
786
+ Notify (PSTR (" \r\n Connecting to 'Other' device" ), 0x80 );
744
787
else
745
788
Notify (PSTR (" \r\n Connecting to HID device" ), 0x80 );
746
789
#endif
@@ -755,6 +798,8 @@ void BTD::HCI_task() {
755
798
#ifdef DEBUG_USB_HOST
756
799
if (pairWithWii)
757
800
Notify (PSTR (" \r\n Connected to Wiimote" ), 0x80 );
801
+ else if (pairWithOtherDevice)
802
+ Notify (PSTR (" \r\n Connected to 'Other' device" ), 0x80 );
758
803
else
759
804
Notify (PSTR (" \r\n Connected to HID device" ), 0x80 );
760
805
#endif
@@ -770,7 +815,8 @@ void BTD::HCI_task() {
770
815
break ;
771
816
772
817
case HCI_SCANNING_STATE:
773
- if (!connectToWii && !pairWithWii && !connectToHIDDevice && !pairWithHIDDevice) {
818
+ if (!connectToWii && !pairWithWii && !connectToHIDDevice && !pairWithHIDDevice && !connectToOtherDevice && !pairWithOtherDevice) {
819
+
774
820
#ifdef DEBUG_USB_HOST
775
821
Notify (PSTR (" \r\n Wait For Incoming Connection Request" ), 0x80 );
776
822
#endif
@@ -879,6 +925,7 @@ void BTD::HCI_task() {
879
925
880
926
connectToWii = incomingWii = pairWithWii = false ;
881
927
connectToHIDDevice = incomingHIDDevice = pairWithHIDDevice = false ;
928
+ pairWithOtherDevice = connectToOtherDevice = false ;
882
929
incomingPS4 = false ;
883
930
884
931
hci_state = HCI_SCANNING_STATE;
@@ -1040,7 +1087,10 @@ void BTD::hci_inquiry_cancel() {
1040
1087
}
1041
1088
1042
1089
void BTD::hci_connect () {
1043
- hci_connect (disc_bdaddr); // Use last discovered device
1090
+ if (pairWithOtherDevice)
1091
+ hci_connect (remote_bdaddr);
1092
+ else
1093
+ hci_connect (disc_bdaddr); // Use last discovered device
1044
1094
}
1045
1095
1046
1096
void BTD::hci_connect (uint8_t *bdaddr) {
0 commit comments