Updated build system and added page to select host mode or auto detection
This commit is contained in:
60
main/HID.cpp
60
main/HID.cpp
@@ -886,30 +886,48 @@ void HID::init(const char *className, enum HID_DEVICE_TYPES deviceType)
|
||||
ps2Keyboard = new PS2KeyAdvanced();
|
||||
ps2Keyboard->begin(CONFIG_PS2_HW_DATAPIN, CONFIG_PS2_HW_CLKPIN);
|
||||
|
||||
// If no PS/2 keyboard detected then default to Bluetooth.
|
||||
if(checkPS2Keyboard() == false)
|
||||
// PS/2 keyboards need 300-750ms after power-on to complete their BAT (Basic Assurance Test).
|
||||
// Retry detection several times to avoid a race condition where the ESP32 boots faster than
|
||||
// the keyboard and incorrectly falls back to Bluetooth.
|
||||
{
|
||||
// Remove the PS/2 keyboard object, free up memory and disable the interrupts.
|
||||
ESP_LOGW(INITTAG, "PS2 keyboard not available.");
|
||||
delete ps2Keyboard;
|
||||
hidCtrl.hidDevice = HID_DEVICE_BT_KEYBOARD;
|
||||
|
||||
// Instantiate Bluetooth HID object.
|
||||
ESP_LOGW(INITTAG, "Initialise Bluetooth keyboard.");
|
||||
btHID = new BTHID();
|
||||
btHID->setup(btPairingHandler);
|
||||
sw->setBTPairingEventCallback(&HID::btStartPairing, this);
|
||||
bool ps2Found = false;
|
||||
for(int retry = 0; retry < 10 && !ps2Found; retry++)
|
||||
{
|
||||
if(checkPS2Keyboard() == true)
|
||||
{
|
||||
ps2Found = true;
|
||||
} else
|
||||
{
|
||||
ESP_LOGW(INITTAG, "PS2 keyboard not detected, retry %d/10...", retry + 1);
|
||||
vTaskDelay(100);
|
||||
}
|
||||
}
|
||||
|
||||
// Setup a mouse callback as it is possible to receive mouse data when the primary input method is a keyboard. This data can be used by a registered
|
||||
// mouse interface to provide dual services to a host.
|
||||
btHID->setMouseDataCallback(&HID::mouseReceiveData, this);
|
||||
// If no PS/2 keyboard detected after retries then default to Bluetooth.
|
||||
if(!ps2Found)
|
||||
{
|
||||
// Remove the PS/2 keyboard object, free up memory and disable the interrupts.
|
||||
ESP_LOGW(INITTAG, "PS2 keyboard not available.");
|
||||
delete ps2Keyboard;
|
||||
hidCtrl.hidDevice = HID_DEVICE_BT_KEYBOARD;
|
||||
|
||||
hidCtrl.deviceType = HID_DEVICE_TYPE_BLUETOOTH;
|
||||
hidCtrl.hidDevice = HID_DEVICE_BLUETOOTH;
|
||||
} else
|
||||
{
|
||||
hidCtrl.deviceType = HID_DEVICE_TYPE_KEYBOARD;
|
||||
hidCtrl.hidDevice = HID_DEVICE_PS2_KEYBOARD;
|
||||
// Instantiate Bluetooth HID object.
|
||||
ESP_LOGW(INITTAG, "Initialise Bluetooth keyboard.");
|
||||
btHID = new BTHID();
|
||||
btHID->setup(btPairingHandler);
|
||||
sw->setBTPairingEventCallback(&HID::btStartPairing, this);
|
||||
|
||||
// Setup a mouse callback as it is possible to receive mouse data when the primary input method is a keyboard. This data can be used by a registered
|
||||
// mouse interface to provide dual services to a host.
|
||||
btHID->setMouseDataCallback(&HID::mouseReceiveData, this);
|
||||
|
||||
hidCtrl.deviceType = HID_DEVICE_TYPE_BLUETOOTH;
|
||||
hidCtrl.hidDevice = HID_DEVICE_BLUETOOTH;
|
||||
} else
|
||||
{
|
||||
hidCtrl.deviceType = HID_DEVICE_TYPE_KEYBOARD;
|
||||
hidCtrl.hidDevice = HID_DEVICE_PS2_KEYBOARD;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user