From a6ae9e80c8cded4a038783995ea12d0bc60d345c Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Fri, 5 Jun 2026 12:03:38 +0200 Subject: [PATCH] fix(ble): show pairing PIN on dual (BLE+USB) builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Bluetooth-page PIN prompt was gated on hasConnection(), which is fed by the serial interface's isConnected(). DualSerialInterface::isConnected() always returns true (USB always "connected"), so waiting_for_pair was always false and the PIN was never drawn — on every dual build, i.e. the published OLED + e-ink firmware. Pure-BLE builds were unaffected (there isConnected() reflects bond state). Gate the PIN on actual BLE-bonded state instead: add AbstractUITask::isBLEConnected() (forwards to BaseSerialInterface:: isBLEConnected(), which DualSerialInterface overrides with the real BLE state and pure-BLE inherits as its bond-aware isConnected()). The PIN now shows on the Bluetooth page while BLE is on and not yet bonded. Co-Authored-By: Claude Opus 4.8 --- examples/companion_radio/AbstractUITask.h | 4 ++++ examples/companion_radio/ui-new/UITask.cpp | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/companion_radio/AbstractUITask.h b/examples/companion_radio/AbstractUITask.h index 7cd8fe24..0941a106 100644 --- a/examples/companion_radio/AbstractUITask.h +++ b/examples/companion_radio/AbstractUITask.h @@ -35,6 +35,10 @@ protected: public: void setHasConnection(bool connected) { _connected = connected; } bool hasConnection() const { return _connected; } + // True only when a BLE central is actually bonded/connected. On a dual + // (BLE+USB) interface hasConnection() is always true (USB counts), so use + // this for BLE-specific UI like the pairing-PIN prompt. + bool isBLEConnected() const { return _serial->isBLEConnected(); } uint16_t getBattMilliVolts() const { return _board->getBattMilliVolts(); } bool isSerialEnabled() const { return _serial->isEnabled(); } void enableSerial() { _serial->enable(); } diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 6aad9505..c4d7258e 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -740,7 +740,10 @@ public: display.drawXbm((display.width() - 32) / 2, content_y, _task->isSerialEnabled() ? bluetooth_on : bluetooth_off, 32, 32); const int text_y = content_y + 32 + 3; - const bool waiting_for_pair = _task->isSerialEnabled() && !_task->hasConnection() && the_mesh.getBLEPin() != 0; + // Gate on BLE-bonded state, not hasConnection(): on a dual BLE+USB + // interface hasConnection() is always true (USB), which would hide the + // PIN forever — the exact e-ink dual-build pairing bug. + const bool waiting_for_pair = _task->isSerialEnabled() && !_task->isBLEConnected() && the_mesh.getBLEPin() != 0; if (waiting_for_pair && !display.isLandscape()) { char pin_buf[16]; snprintf(pin_buf, sizeof(pin_buf), "PIN: %d", the_mesh.getBLEPin());