Skip to content

Commit ee90afd

Browse files
committed
Merged SPPi class in from @magictaler - see: #79
I have made several improvements. Including making a new SPPBase class.
1 parent d9dfa3c commit ee90afd

File tree

13 files changed

+1356
-377
lines changed

13 files changed

+1356
-377
lines changed

BTD.cpp

Lines changed: 68 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ connectToWii(false),
2929
pairWithWii(false),
3030
connectToHIDDevice(false),
3131
pairWithHIDDevice(false),
32+
pairWithOtherDevice(false),
3233
pUsb(p), // Pointer to USB class instance - mandatory
3334
bAddress(0), // Device address - mandatory
3435
bNumEP(1), // If config descriptor needs to be parsed
@@ -301,6 +302,7 @@ void BTD::Initialize() {
301302
connectToWii = false;
302303
incomingWii = false;
303304
connectToHIDDevice = false;
305+
connectToOtherDevice = false;
304306
incomingHIDDevice = false;
305307
incomingPS4 = false;
306308
bAddress = 0; // Clear device address
@@ -410,18 +412,22 @@ void BTD::HCI_event_task() {
410412
break;
411413

412414
case EV_INQUIRY_COMPLETE:
413-
if(inquiry_counter >= 5 && (pairWithWii || pairWithHIDDevice)) {
415+
if (inquiry_counter >= 5 && (pairWithWii || pairWithHIDDevice || pairWithOtherDevice)) {
414416
inquiry_counter = 0;
415417
#ifdef DEBUG_USB_HOST
416418
if(pairWithWii)
417419
Notify(PSTR("\r\nCouldn't find Wiimote"), 0x80);
420+
else if (pairWithOtherDevice)
421+
Notify(PSTR("\r\nCouldn't find 'Other' device"), 0x80);
418422
else
419423
Notify(PSTR("\r\nCouldn't find HID device"), 0x80);
420424
#endif
421425
connectToWii = false;
422426
pairWithWii = false;
423427
connectToHIDDevice = false;
424428
pairWithHIDDevice = false;
429+
connectToOtherDevice = false;
430+
pairWithOtherDevice = false;
425431
hci_state = HCI_SCANNING_STATE;
426432
}
427433
inquiry_counter++;
@@ -464,17 +470,37 @@ void BTD::HCI_event_task() {
464470
disc_bdaddr[j] = hcibuf[j + 3 + 6 * i];
465471

466472
hci_set_flag(HCI_FLAG_DEVICE_FOUND);
467-
}
473+
} else {
468474
#ifdef EXTRADEBUG
469-
else {
470475
Notify(PSTR("\r\nClass of device: "), 0x80);
471476
D_PrintHex<uint8_t > (classOfDevice[2], 0x80);
472477
Notify(PSTR(" "), 0x80);
473478
D_PrintHex<uint8_t > (classOfDevice[1], 0x80);
474479
Notify(PSTR(" "), 0x80);
475480
D_PrintHex<uint8_t > (classOfDevice[0], 0x80);
476-
}
477481
#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\nDevice: "), 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+
478504
}
479505
}
480506
break;
@@ -582,6 +608,11 @@ void BTD::HCI_event_task() {
582608
Notify(PSTR("\r\nPairing successful with HID device"), 0x80);
583609
#endif
584610
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\nPairing successful with 'Other' device"), 0x80);
614+
#endif
615+
connectToOtherDevice = true;
585616
}
586617
break;
587618
/* We will just ignore the following events */
@@ -694,12 +725,14 @@ void BTD::HCI_task() {
694725
break;
695726

696727
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'
698729
#ifdef DEBUG_USB_HOST
699730
if(pairWithWii)
700731
Notify(PSTR("\r\nStarting inquiry\r\nPress 1 & 2 on the Wiimote\r\nOr press sync if you are using a Wii U Pro Controller"), 0x80);
701-
else
732+
else if (pairWithHIDDevice)
702733
Notify(PSTR("\r\nPlease enable discovery of your device"), 0x80);
734+
else
735+
Notify(PSTR("\r\nPairing with 'Other' device with predefined address"), 0x80);
703736
#endif
704737
hci_inquiry();
705738
hci_state = HCI_INQUIRY_STATE;
@@ -713,20 +746,28 @@ void BTD::HCI_task() {
713746
#ifdef DEBUG_USB_HOST
714747
if(pairWithWii)
715748
Notify(PSTR("\r\nWiimote found"), 0x80);
749+
else if (pairWithOtherDevice)
750+
Notify(PSTR("\r\n'Other' device found"), 0x80);
716751
else
717752
Notify(PSTR("\r\nHID device found"), 0x80);
718753

719-
Notify(PSTR("\r\nNow just create the instance like so:"), 0x80);
720-
if(pairWithWii)
721-
Notify(PSTR("\r\nWII Wii(&Btd);"), 0x80);
722-
else
723-
Notify(PSTR("\r\nBTHID bthid(&Btd);"), 0x80);
754+
if (!pairWithOtherDevice) {
755+
Notify(PSTR("\r\nNow just create the instance like so:"), 0x80);
756+
if(pairWithWii)
757+
Notify(PSTR("\r\nWII Wii(&Btd);"), 0x80);
758+
else
759+
#ifdef _ps4bt_h_ // Check if the PS4 driver is being used
760+
Notify(PSTR("\r\nPS4BT PS4(&Btd);"), 0x80);
761+
#else
762+
Notify(PSTR("\r\nBTHID bthid(&Btd);"), 0x80);
763+
#endif
724764

725-
Notify(PSTR("\r\nAnd 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\nAnd then press any button on the "), 0x80);
766+
if(pairWithWii)
767+
Notify(PSTR("Wiimote"), 0x80);
768+
else
769+
Notify(PSTR("device"), 0x80);
770+
}
730771
#endif
731772
if(motionPlusInside) {
732773
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() {
741782
#ifdef DEBUG_USB_HOST
742783
if(pairWithWii)
743784
Notify(PSTR("\r\nConnecting to Wiimote"), 0x80);
785+
else if (pairWithOtherDevice)
786+
Notify(PSTR("\r\nConnecting to 'Other' device"), 0x80);
744787
else
745788
Notify(PSTR("\r\nConnecting to HID device"), 0x80);
746789
#endif
@@ -755,6 +798,8 @@ void BTD::HCI_task() {
755798
#ifdef DEBUG_USB_HOST
756799
if(pairWithWii)
757800
Notify(PSTR("\r\nConnected to Wiimote"), 0x80);
801+
else if (pairWithOtherDevice)
802+
Notify(PSTR("\r\nConnected to 'Other' device"), 0x80);
758803
else
759804
Notify(PSTR("\r\nConnected to HID device"), 0x80);
760805
#endif
@@ -770,7 +815,8 @@ void BTD::HCI_task() {
770815
break;
771816

772817
case HCI_SCANNING_STATE:
773-
if(!connectToWii && !pairWithWii && !connectToHIDDevice && !pairWithHIDDevice) {
818+
if (!connectToWii && !pairWithWii && !connectToHIDDevice && !pairWithHIDDevice && !connectToOtherDevice && !pairWithOtherDevice) {
819+
774820
#ifdef DEBUG_USB_HOST
775821
Notify(PSTR("\r\nWait For Incoming Connection Request"), 0x80);
776822
#endif
@@ -879,6 +925,7 @@ void BTD::HCI_task() {
879925

880926
connectToWii = incomingWii = pairWithWii = false;
881927
connectToHIDDevice = incomingHIDDevice = pairWithHIDDevice = false;
928+
pairWithOtherDevice = connectToOtherDevice = false;
882929
incomingPS4 = false;
883930

884931
hci_state = HCI_SCANNING_STATE;
@@ -1040,7 +1087,10 @@ void BTD::hci_inquiry_cancel() {
10401087
}
10411088

10421089
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
10441094
}
10451095

10461096
void BTD::hci_connect(uint8_t *bdaddr) {

BTD.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,19 @@ class BTD : public USBDeviceConfig, public UsbConfigXtracter {
524524
/** True when it should pair with a device like a mouse or keyboard. */
525525
bool pairWithHIDDevice;
526526

527+
/** True when it should pair with a device with a specific Bluetooth address. */
528+
bool pairWithOtherDevice;
529+
/* True when it should connect to a device with a specific Bluetooth address. */
530+
bool connectToOtherDevice;
531+
/** Call this to pair with a device with a specific Bluetooth address. */
532+
void pairWithOther() {
533+
pairWithOtherDevice = true;
534+
hci_state = HCI_CONNECT_DEVICE_STATE;
535+
};
536+
537+
/** Remote address of Bluetooth device to connect to. */
538+
uint8_t remote_bdaddr[6];
539+
527540
/**
528541
* Read the poll interval taken from the endpoint descriptors.
529542
* @return The poll interval in ms.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Currently the following boards are supported by the library:
7373
* Balanduino
7474
* Sanguino
7575
* Black Widdow
76+
* Luminardo
7677
7778
The following boards need to be activated manually in [settings.h](settings.h):
7879

0 commit comments

Comments
 (0)