diff --git a/platformio.ini b/platformio.ini index eee8e627..c33784cf 100644 --- a/platformio.ini +++ b/platformio.ini @@ -36,7 +36,6 @@ build_flags = -Wno-missing-field-initializers -Isrc -Isrc/mesh -Isrc/gps -Ilib/n ;upload_port = /dev/ttyUSB0 ;monitor_port = /dev/ttyUSB0 -; geeksville: I think setting this should not be required - it breaks linux ;upload_port = /dev/cu.SLAB_USBtoUART ;monitor_port = /dev/cu.SLAB_USBtoUART diff --git a/src/configuration.h b/src/configuration.h index 179c4946..5e8964d2 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -434,3 +434,6 @@ along with this program. If not, see . #define GPS_POWER_CTRL_CH 3 #define LORA_POWER_CTRL_CH 2 + +// Default Bluetooth PIN +#define defaultBLEPin 123456 diff --git a/src/main.cpp b/src/main.cpp index f5d279b6..0f24e1bc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -174,12 +174,14 @@ class ButtonThread : public OSThread userButton = OneButton(BUTTON_PIN, true, true); userButton.attachClick(userButtonPressed); userButton.attachDuringLongPress(userButtonPressedLong); + userButton.attachDoubleClick(userButtonDoublePressed); wakeOnIrq(BUTTON_PIN, FALLING); #endif #ifdef BUTTON_PIN_ALT userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true); userButtonAlt.attachClick(userButtonPressed); userButtonAlt.attachDuringLongPress(userButtonPressedLong); + userButtonAlt.attachDoubleClick(userButtonDoublePressed); wakeOnIrq(BUTTON_PIN_ALT, FALLING); #endif } @@ -215,6 +217,13 @@ class ButtonThread : public OSThread DEBUG_MSG("Long press!\n"); screen->adjustBrightness(); } + + static void userButtonDoublePressed() +{ +#ifndef NO_ESP32 + disablePin(); +#endif +} }; static Periodic *ledPeriodic; @@ -270,6 +279,7 @@ void setup() // Buttons & LED buttonThread = new ButtonThread(); + #ifdef LED_PIN pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, 1 ^ LED_INVERTED); // turn on for now diff --git a/src/nimble/BluetoothUtil.cpp b/src/nimble/BluetoothUtil.cpp index 0b6a30c6..8009f5d2 100644 --- a/src/nimble/BluetoothUtil.cpp +++ b/src/nimble/BluetoothUtil.cpp @@ -15,6 +15,7 @@ #include static bool pinShowing; +static uint32_t doublepressed; static void startCb(uint32_t pin) { @@ -123,6 +124,7 @@ static int gap_event(struct ble_gap_event *event, void *arg) { struct ble_gap_conn_desc desc; int rc; + uint32_t now = millis(); switch (event->type) { case BLE_GAP_EVENT_CONNECT: @@ -221,8 +223,17 @@ static int gap_event(struct ble_gap_event *event, void *arg) if (event->passkey.params.action == BLE_SM_IOACT_DISP) { pkey.action = event->passkey.params.action; - pkey.passkey = random( - 100000, 999999); // This is the passkey to be entered on peer - we pick a number >100,000 to ensure 6 digits + DEBUG_MSG("dp: %d now:%d\n",doublepressed, now); + if (doublepressed > 0 && (doublepressed + (30*1000)) > now) + { + DEBUG_MSG("User has overridden passkey or no display available\n"); + pkey.passkey = defaultBLEPin; + } + else { + DEBUG_MSG("Using random passkey\n"); + pkey.passkey = random( + 100000, 999999); // This is the passkey to be entered on peer - we pick a number >100,000 to ensure 6 digits + } DEBUG_MSG("*** Enter passkey %d on the peer side ***\n", pkey.passkey); startCb(pkey.passkey); @@ -443,6 +454,13 @@ int chr_readwrite8(uint8_t *v, size_t vlen, struct ble_gatt_access_ctxt *ctxt) return 0; // success } +void disablePin() +{ + DEBUG_MSG("User Override, disabling bluetooth pin requirement\n"); + // keep track of when it was pressed, so we know it was within X seconds + doublepressed = millis(); +} + // This routine is called multiple times, once each time we come back from sleep void reinitBluetooth() { diff --git a/src/nimble/BluetoothUtil.h b/src/nimble/BluetoothUtil.h index 453fadb5..fe6d0e67 100644 --- a/src/nimble/BluetoothUtil.h +++ b/src/nimble/BluetoothUtil.h @@ -15,6 +15,7 @@ void updateBatteryLevel(uint8_t level); void deinitBLE(); void loopBLE(); void reinitBluetooth(); +void disablePin(); /** * A helper function that implements simple read and write handling for a uint32_t