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