From 05cd36d2ec884a999db1551ee930c741b562098d Mon Sep 17 00:00:00 2001 From: R0ck Date: Thu, 15 Oct 2026 19:33:35 +0100 Subject: [PATCH 1/6] Add T1000-E custom CLI command to toggle the buzzer --- variants/t1000-e/T1000eBoard.cpp | 70 +++++++++++++++++++++++++++++++- variants/t1000-e/T1000eBoard.h | 8 ++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/variants/t1000-e/T1000eBoard.cpp b/variants/t1000-e/T1000eBoard.cpp index 0d390f79..a4713017 100644 --- a/variants/t1000-e/T1000eBoard.cpp +++ b/variants/t1000-e/T1000eBoard.cpp @@ -3,6 +3,10 @@ #include "T1000eBoard.h" +#ifdef PIN_BUZZER_EN + #include +#endif + void T1000eBoard::begin() { NRF52BoardDCDC::begin(); btn_prev_state = HIGH; @@ -20,4 +24,68 @@ void T1000eBoard::begin() { Wire.begin(); delay(10); // give sx1262 some time to power up -} \ No newline at end of file +} + +void T1000eBoard::attachDynamicPrefs(KeyValueStore* prefs) { + _prefs = prefs; +#ifdef PIN_BUZZER_EN + char val[8]; + val[0] = 0; + _prefs->getByKey("buzzer", val, sizeof(val)); + _buzzer_muted = strcmp(val, "0") == 0; +#endif +} + +#ifdef PIN_BUZZER_EN +static void playTune(const char* tune) { + if (rtttl::isPlaying()) rtttl::stop(); + rtttl::begin(PIN_BUZZER, tune); +} +#endif + +void T1000eBoard::setBuzzerEnabled(bool enable) { +#ifdef PIN_BUZZER_EN + _buzzer_muted = !enable; + digitalWrite(PIN_BUZZER_EN, enable ? HIGH : LOW); +#endif +} + +void T1000eBoard::loop() { + NRF52BoardDCDC::loop(); +#ifdef PIN_BUZZER_EN + if (!rtttl::done()) rtttl::play(); + if (_buzzer_mute_pending && rtttl::done()) { // mute once the confirmation beep has finished + _buzzer_mute_pending = false; + setBuzzerEnabled(false); + } + if (_buzzer_muted) digitalWrite(PIN_BUZZER_EN, LOW); // keep it off even if the UI re-enables it +#endif +} + +bool T1000eBoard::handleCommand(const char* command, uint32_t sender_timestamp, char* reply) { +#ifdef PIN_BUZZER_EN + if (strcmp(command, "get buzzer") == 0) { + sprintf(reply, "> %s", (_buzzer_muted || _buzzer_mute_pending) ? "off" : "on"); + return true; + } + if (memcmp(command, "set buzzer ", 11) == 0) { + if (strcmp(&command[11], "on") == 0) { + _buzzer_mute_pending = false; + setBuzzerEnabled(true); + if (_prefs) _prefs->setByKey("buzzer", "1"); + playTune("MsgRcv3:d=4,o=6,b=200:32e,32g,32b,16c7"); // same tune as a new message + strcpy(reply, "OK - buzzer on"); + } else if (strcmp(&command[11], "off") == 0) { + setBuzzerEnabled(true); + _buzzer_mute_pending = true; + if (_prefs) _prefs->setByKey("buzzer", "0"); + playTune("ack:d=32,o=8,b=120:c"); // same beep as an ack, before going quiet + strcpy(reply, "OK - buzzer off"); + } else { + strcpy(reply, "Error: state must be on or off"); + } + return true; + } +#endif + return false; // not handled +} diff --git a/variants/t1000-e/T1000eBoard.h b/variants/t1000-e/T1000eBoard.h index ba8bf0c1..846c7df2 100644 --- a/variants/t1000-e/T1000eBoard.h +++ b/variants/t1000-e/T1000eBoard.h @@ -7,10 +7,18 @@ class T1000eBoard : public NRF52BoardDCDC { protected: uint8_t btn_prev_state; + KeyValueStore* _prefs = NULL; + bool _buzzer_muted = false; + bool _buzzer_mute_pending = false; + + void setBuzzerEnabled(bool enable); public: T1000eBoard() : NRF52Board("T1000E_OTA") {} void begin(); + void attachDynamicPrefs(KeyValueStore* prefs); + bool handleCommand(const char* command, uint32_t sender_timestamp, char* reply) override; + void loop() override; uint16_t getBattMilliVolts() override { #ifdef BATTERY_PIN From bb84f293b79885dbaedaa83b2eaba10519b078fb Mon Sep 17 00:00:00 2001 From: R0ck Date: Thu, 15 Oct 2026 20:12:13 +0100 Subject: [PATCH 2/6] Fix off-by-one when loading the T1000-E buzzer setting --- variants/t1000-e/T1000eBoard.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/t1000-e/T1000eBoard.cpp b/variants/t1000-e/T1000eBoard.cpp index a4713017..ff42f5e4 100644 --- a/variants/t1000-e/T1000eBoard.cpp +++ b/variants/t1000-e/T1000eBoard.cpp @@ -31,7 +31,7 @@ void T1000eBoard::attachDynamicPrefs(KeyValueStore* prefs) { #ifdef PIN_BUZZER_EN char val[8]; val[0] = 0; - _prefs->getByKey("buzzer", val, sizeof(val)); + _prefs->getByKey("buzzer", val, sizeof(val) - 1); _buzzer_muted = strcmp(val, "0") == 0; #endif } From 0769d68ed628c9cf346057f33df3c94ef5f82f60 Mon Sep 17 00:00:00 2001 From: R0ck Date: Thu, 15 Oct 2026 20:12:23 +0100 Subject: [PATCH 3/6] Report an error when the buzzer setting fails to save --- variants/t1000-e/T1000eBoard.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/variants/t1000-e/T1000eBoard.cpp b/variants/t1000-e/T1000eBoard.cpp index ff42f5e4..9bdeff89 100644 --- a/variants/t1000-e/T1000eBoard.cpp +++ b/variants/t1000-e/T1000eBoard.cpp @@ -70,17 +70,23 @@ bool T1000eBoard::handleCommand(const char* command, uint32_t sender_timestamp, } if (memcmp(command, "set buzzer ", 11) == 0) { if (strcmp(&command[11], "on") == 0) { - _buzzer_mute_pending = false; - setBuzzerEnabled(true); - if (_prefs) _prefs->setByKey("buzzer", "1"); - playTune("MsgRcv3:d=4,o=6,b=200:32e,32g,32b,16c7"); // same tune as a new message - strcpy(reply, "OK - buzzer on"); + if (_prefs && !_prefs->setByKey("buzzer", "1")) { + strcpy(reply, "Error: failed to save buzzer setting"); + } else { + _buzzer_mute_pending = false; + setBuzzerEnabled(true); + playTune("MsgRcv3:d=4,o=6,b=200:32e,32g,32b,16c7"); // same tune as a new message + strcpy(reply, "OK - buzzer on"); + } } else if (strcmp(&command[11], "off") == 0) { - setBuzzerEnabled(true); - _buzzer_mute_pending = true; - if (_prefs) _prefs->setByKey("buzzer", "0"); - playTune("ack:d=32,o=8,b=120:c"); // same beep as an ack, before going quiet - strcpy(reply, "OK - buzzer off"); + if (_prefs && !_prefs->setByKey("buzzer", "0")) { + strcpy(reply, "Error: failed to save buzzer setting"); + } else { + setBuzzerEnabled(true); + _buzzer_mute_pending = true; + playTune("ack:d=32,o=8,b=120:c"); // same beep as an ack, before going quiet + strcpy(reply, "OK - buzzer off"); + } } else { strcpy(reply, "Error: state must be on or off"); } From 36f2b1d163ed158688e0a50e681b57e5123503a1 Mon Sep 17 00:00:00 2001 From: R0ck Date: Sat, 17 Oct 2026 23:27:43 +0100 Subject: [PATCH 4/6] Remove the acknowledgement tones --- variants/t1000-e/T1000eBoard.cpp | 24 ++---------------------- variants/t1000-e/T1000eBoard.h | 1 - 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/variants/t1000-e/T1000eBoard.cpp b/variants/t1000-e/T1000eBoard.cpp index 9bdeff89..649ae9d6 100644 --- a/variants/t1000-e/T1000eBoard.cpp +++ b/variants/t1000-e/T1000eBoard.cpp @@ -3,10 +3,6 @@ #include "T1000eBoard.h" -#ifdef PIN_BUZZER_EN - #include -#endif - void T1000eBoard::begin() { NRF52BoardDCDC::begin(); btn_prev_state = HIGH; @@ -36,13 +32,6 @@ void T1000eBoard::attachDynamicPrefs(KeyValueStore* prefs) { #endif } -#ifdef PIN_BUZZER_EN -static void playTune(const char* tune) { - if (rtttl::isPlaying()) rtttl::stop(); - rtttl::begin(PIN_BUZZER, tune); -} -#endif - void T1000eBoard::setBuzzerEnabled(bool enable) { #ifdef PIN_BUZZER_EN _buzzer_muted = !enable; @@ -53,11 +42,6 @@ void T1000eBoard::setBuzzerEnabled(bool enable) { void T1000eBoard::loop() { NRF52BoardDCDC::loop(); #ifdef PIN_BUZZER_EN - if (!rtttl::done()) rtttl::play(); - if (_buzzer_mute_pending && rtttl::done()) { // mute once the confirmation beep has finished - _buzzer_mute_pending = false; - setBuzzerEnabled(false); - } if (_buzzer_muted) digitalWrite(PIN_BUZZER_EN, LOW); // keep it off even if the UI re-enables it #endif } @@ -65,7 +49,7 @@ void T1000eBoard::loop() { bool T1000eBoard::handleCommand(const char* command, uint32_t sender_timestamp, char* reply) { #ifdef PIN_BUZZER_EN if (strcmp(command, "get buzzer") == 0) { - sprintf(reply, "> %s", (_buzzer_muted || _buzzer_mute_pending) ? "off" : "on"); + sprintf(reply, "> %s", _buzzer_muted ? "off" : "on"); return true; } if (memcmp(command, "set buzzer ", 11) == 0) { @@ -73,18 +57,14 @@ bool T1000eBoard::handleCommand(const char* command, uint32_t sender_timestamp, if (_prefs && !_prefs->setByKey("buzzer", "1")) { strcpy(reply, "Error: failed to save buzzer setting"); } else { - _buzzer_mute_pending = false; setBuzzerEnabled(true); - playTune("MsgRcv3:d=4,o=6,b=200:32e,32g,32b,16c7"); // same tune as a new message strcpy(reply, "OK - buzzer on"); } } else if (strcmp(&command[11], "off") == 0) { if (_prefs && !_prefs->setByKey("buzzer", "0")) { strcpy(reply, "Error: failed to save buzzer setting"); } else { - setBuzzerEnabled(true); - _buzzer_mute_pending = true; - playTune("ack:d=32,o=8,b=120:c"); // same beep as an ack, before going quiet + setBuzzerEnabled(false); strcpy(reply, "OK - buzzer off"); } } else { diff --git a/variants/t1000-e/T1000eBoard.h b/variants/t1000-e/T1000eBoard.h index 846c7df2..e6ceb4fe 100644 --- a/variants/t1000-e/T1000eBoard.h +++ b/variants/t1000-e/T1000eBoard.h @@ -9,7 +9,6 @@ protected: uint8_t btn_prev_state; KeyValueStore* _prefs = NULL; bool _buzzer_muted = false; - bool _buzzer_mute_pending = false; void setBuzzerEnabled(bool enable); From b9fa77ed69cdb03229801f086eae79e02305f937 Mon Sep 17 00:00:00 2001 From: R0ck Date: Sat, 17 Oct 2026 23:37:14 +0100 Subject: [PATCH 5/6] Move to companion firmware, remove from varient --- examples/companion_radio/MyMesh.cpp | 17 +++++++++ variants/t1000-e/T1000eBoard.cpp | 56 +---------------------------- variants/t1000-e/T1000eBoard.h | 7 ---- 3 files changed, 18 insertions(+), 62 deletions(-) diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index f32ea67a..ebe0636a 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -2122,6 +2122,23 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char* return true; } +#ifdef PIN_BUZZER + if (strcmp(command, "get buzzer") == 0) { + sprintf(reply, "> %s", _prefs.buzzer_quiet ? "off" : "on"); + return true; + } + if (memcmp(command, "set buzzer ", 11) == 0) { + if (strcmp(&command[11], "on") == 0 || strcmp(&command[11], "off") == 0) { + _prefs.buzzer_quiet = strcmp(&command[11], "off") == 0; + savePrefs(); + strcpy(reply, "OK"); + } else { + strcpy(reply, "Error: state must be on or off"); + } + return true; + } +#endif + if (memcmp(command, "set pin ", 8) == 0) { _prefs.ble_pin = atoi(&command[8]); savePrefs(); diff --git a/variants/t1000-e/T1000eBoard.cpp b/variants/t1000-e/T1000eBoard.cpp index 649ae9d6..0d390f79 100644 --- a/variants/t1000-e/T1000eBoard.cpp +++ b/variants/t1000-e/T1000eBoard.cpp @@ -20,58 +20,4 @@ void T1000eBoard::begin() { Wire.begin(); delay(10); // give sx1262 some time to power up -} - -void T1000eBoard::attachDynamicPrefs(KeyValueStore* prefs) { - _prefs = prefs; -#ifdef PIN_BUZZER_EN - char val[8]; - val[0] = 0; - _prefs->getByKey("buzzer", val, sizeof(val) - 1); - _buzzer_muted = strcmp(val, "0") == 0; -#endif -} - -void T1000eBoard::setBuzzerEnabled(bool enable) { -#ifdef PIN_BUZZER_EN - _buzzer_muted = !enable; - digitalWrite(PIN_BUZZER_EN, enable ? HIGH : LOW); -#endif -} - -void T1000eBoard::loop() { - NRF52BoardDCDC::loop(); -#ifdef PIN_BUZZER_EN - if (_buzzer_muted) digitalWrite(PIN_BUZZER_EN, LOW); // keep it off even if the UI re-enables it -#endif -} - -bool T1000eBoard::handleCommand(const char* command, uint32_t sender_timestamp, char* reply) { -#ifdef PIN_BUZZER_EN - if (strcmp(command, "get buzzer") == 0) { - sprintf(reply, "> %s", _buzzer_muted ? "off" : "on"); - return true; - } - if (memcmp(command, "set buzzer ", 11) == 0) { - if (strcmp(&command[11], "on") == 0) { - if (_prefs && !_prefs->setByKey("buzzer", "1")) { - strcpy(reply, "Error: failed to save buzzer setting"); - } else { - setBuzzerEnabled(true); - strcpy(reply, "OK - buzzer on"); - } - } else if (strcmp(&command[11], "off") == 0) { - if (_prefs && !_prefs->setByKey("buzzer", "0")) { - strcpy(reply, "Error: failed to save buzzer setting"); - } else { - setBuzzerEnabled(false); - strcpy(reply, "OK - buzzer off"); - } - } else { - strcpy(reply, "Error: state must be on or off"); - } - return true; - } -#endif - return false; // not handled -} +} \ No newline at end of file diff --git a/variants/t1000-e/T1000eBoard.h b/variants/t1000-e/T1000eBoard.h index e6ceb4fe..ba8bf0c1 100644 --- a/variants/t1000-e/T1000eBoard.h +++ b/variants/t1000-e/T1000eBoard.h @@ -7,17 +7,10 @@ class T1000eBoard : public NRF52BoardDCDC { protected: uint8_t btn_prev_state; - KeyValueStore* _prefs = NULL; - bool _buzzer_muted = false; - - void setBuzzerEnabled(bool enable); public: T1000eBoard() : NRF52Board("T1000E_OTA") {} void begin(); - void attachDynamicPrefs(KeyValueStore* prefs); - bool handleCommand(const char* command, uint32_t sender_timestamp, char* reply) override; - void loop() override; uint16_t getBattMilliVolts() override { #ifdef BATTERY_PIN From edb94d3fdcd0fb91397fa37720e39e132bf4865d Mon Sep 17 00:00:00 2001 From: R0ck Date: Sat, 17 Oct 2026 23:53:27 +0100 Subject: [PATCH 6/6] Apply buzzer setting changes in the UI so no reboot needed. --- examples/companion_radio/ui-new/UITask.cpp | 1 + examples/companion_radio/ui-orig/UITask.cpp | 1 + examples/companion_radio/ui-tiny/UITask.cpp | 1 + 3 files changed, 3 insertions(+) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index bc25de79..e43fc5ea 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -1015,6 +1015,7 @@ void UITask::loop() { userLedHandler(); #ifdef PIN_BUZZER + if (buzzer.isQuiet() != (bool)_node_prefs->buzzer_quiet) buzzer.quiet(_node_prefs->buzzer_quiet); if (buzzer.isPlaying()) buzzer.loop(); #endif diff --git a/examples/companion_radio/ui-orig/UITask.cpp b/examples/companion_radio/ui-orig/UITask.cpp index db8772f4..8ae57c7a 100644 --- a/examples/companion_radio/ui-orig/UITask.cpp +++ b/examples/companion_radio/ui-orig/UITask.cpp @@ -485,6 +485,7 @@ void UITask::loop() { userLedHandler(); #ifdef PIN_BUZZER + if (buzzer.isQuiet() != (bool)_node_prefs->buzzer_quiet) buzzer.quiet(_node_prefs->buzzer_quiet); if (buzzer.isPlaying()) buzzer.loop(); #endif diff --git a/examples/companion_radio/ui-tiny/UITask.cpp b/examples/companion_radio/ui-tiny/UITask.cpp index 7b70f836..6bf33849 100644 --- a/examples/companion_radio/ui-tiny/UITask.cpp +++ b/examples/companion_radio/ui-tiny/UITask.cpp @@ -691,6 +691,7 @@ void UITask::loop() { userLedHandler(); #ifdef PIN_BUZZER + if (buzzer.isQuiet() != (bool)_node_prefs->buzzer_quiet) buzzer.quiet(_node_prefs->buzzer_quiet); if (buzzer.isPlaying()) buzzer.loop(); #endif