// Simple test of USB Host Mouse/Keyboard
//
#include "USBHost_t36.h"
//#include "debug_tt.h"
USBHost myusb;
USBHub hub1(myusb);
BluetoothController bluet(myusb, true, "0000"); // Version does pairing to device
//BluetoothController bluet(myusb); // version assumes it already was paired
USBDriver *drivers[] = {&hub1, &bluet };
#define CNT_DEVICES (sizeof(drivers)/sizeof(drivers[0]))
const char * driver_names[CNT_DEVICES] = {"Hub1", "Bluet"};
bool driver_active[CNT_DEVICES] = {false, false};
uint8_t last_bdaddr[6] = {0, 0, 0, 0, 0, 0};
void setup()
{
Serial1.begin(2000000);
while (!Serial) ; // wait for Arduino Serial Monitor
Serial.println("\n\nUSB Host Testing");
Serial.println(sizeof(USBHub), DEC);
myusb.begin();
delay(2000);
}
void loop()
{
myusb.Task();
// check to see if the device list has changed:
UpdateActiveDeviceInfo();
}
//=============================================================================
// UpdateActiveDeviceInfo
//=============================================================================
void UpdateActiveDeviceInfo() {
for (uint8_t i = 0; i < CNT_DEVICES; i++) {
if (*drivers[i] != driver_active[i]) {
if (driver_active[i]) {
Serial.printf("*** Device %s - disconnected ***\n", driver_names[i]);
driver_active[i] = false;
} else {
Serial.printf("*** Device %s %x:%x - connected ***\n", driver_names[i], drivers[i]->idVendor(), drivers[i]->idProduct());
driver_active[i] = true;
const uint8_t *psz = drivers[i]->manufacturer();
if (psz && *psz) Serial.printf(" Vendor: %s\n", psz);
psz = drivers[i]->product();
if (psz && *psz) Serial.printf(" Item: %s\n", psz);
psz = drivers[i]->serialNumber();
if (psz && *psz) Serial.printf(" Serial number: %s\n", psz);
if (drivers[i] == &bluet) {
const uint8_t *bdaddr = bluet.myBDAddr();
// remember it...
Serial.printf(" Code BDADDR: %02X:%02X:%02X:%02X:%02X:%02X\n", bdaddr[5], bdaddr[4], bdaddr[3], bdaddr[2], bdaddr[1], bdaddr[0]);
for (uint8_t i = 0; i < 6; i++) last_bdaddr[i] = bdaddr[i];
}
}
}
}
// See about maybe pair...
// so far just try call temporary pair info call...
//********************
Serial.print("\n Pairing Request");
if (!last_bdaddr[0] && !last_bdaddr[1] && !last_bdaddr[2] && !last_bdaddr[3] && !last_bdaddr[4] && !last_bdaddr[5]) {
Serial.println(" - failed - no Bluetooth adapter has been plugged in");
} else if (!drivers[0]) { // Kludge see if we are connected as HID?
Serial.println(" - failed - PS3 device not plugged into USB");
} else {
Serial.printf(" - Attempt pair to: %02X:%02X:%02X:%02X:%02X:%02X\n", last_bdaddr[5], last_bdaddr[4], last_bdaddr[3], last_bdaddr[2], last_bdaddr[1], last_bdaddr[0]);
// if (!bluet.PS3Pair(last_bdaddr)) {
// Serial.println(" Pairing call Failed");
// } else {
// Serial.println(" Pairing complete (I hope), make sure Bluetooth adapter is plugged in and try PS3 without USB");
// }
}
}