diff --git a/CUSTOM_COMPANION.md b/CUSTOM_COMPANION.md index 2c5f733f..40ac130d 100644 --- a/CUSTOM_COMPANION.md +++ b/CUSTOM_COMPANION.md @@ -2,8 +2,8 @@ Fork-only, unpublished notes for the `custom-companion-easysky` branch. That branch is `IoTThinks/MeshCore`'s `PowerSaving-v18` — the source behind the -EasySkyMesh PowerSaving18 release — plus a deliberately tiny diff (four -commits, four files) so it stays easy to rebase: it adds two commands to the +EasySkyMesh PowerSaving18 release — plus a deliberately tiny diff (five +commits, eight files) so it stays easy to rebase: it adds four commands to the companion (client) firmware's CLI. This is not a release channel — no CI, no release workflow. Build and flash @@ -47,7 +47,7 @@ export FIRMWARE_VERSION=v1.18.0-custom bash build.sh build-firmware Xiao_S3_WIO_companion_radio_ble ``` -Both commands below are reached the same way on every companion build: the +The commands below are reached the same way on every companion build: the serial "CLI rescue" prompt (display long-press) and the app's remote CLI console (`CMD_RUN_CLI_COMMAND`). @@ -76,6 +76,39 @@ parameters: it re-sends repeat-enabled with the current frequency, which the firmware rejects. Run `set repeat off` before editing radio settings in the app. +## `set buzzer on|off` / `get buzzer` + +Mute or unmute the received-message buzzer — the same flag the triple-press +button combo flips on boards that have a button, but reachable from the CLI: + +``` +get buzzer # > on / > off +set buzzer off # OK - buzzer is now OFF +set buzzer on # OK - buzzer is now ON +``` + +Only `off` turns it off; anything else is treated as `on`, as with +`set repeat`. Persisted as `buzz_q` and applied to the buzzer by the UI loop on +its next tick, so no reboot — and no button — is needed. + +## `set led on|off` / `get led` + +Stop the status LED from blinking: + +``` +get led # > on / > off +set led off # OK - status LED is now OFF +set led on # OK - status LED is now ON +``` + +`on` (the default) is the normal heartbeat: a short flash every 4 s, green when +idle, amber while messages are unread, blue while the app is connected, red on +low battery; boards with an RGB status LED also run their boot/new-message +colour sweeps. `off` silences all of it — the same effect as the +`-D PIN_STATUS_LED`-less builds, but per device and reversible. Persisted as +`led_q` and re-read by the UI every loop, so it takes effect immediately +(no reboot). + ## `start ota` Start an over-the-air firmware update, like the repeater/room-server command: @@ -106,11 +139,14 @@ attempts may briefly disturb the hotspot. ## Scope -Only these two commands are ours; everything else is IoTThinks' PowerSaving -firmware. The diff against `PowerSaving-v18` is three code files plus this -document: +Only these commands and prefs are ours; everything else is IoTThinks' +PowerSaving firmware. The diff against `PowerSaving-v18` is: -- `examples/companion_radio/MyMesh.cpp` — the two CLI commands. +- `examples/companion_radio/MyMesh.cpp` — the CLI commands. +- `examples/companion_radio/NodePrefs.h` — the `led_q` pref (`buzzer_quiet` + already exists upstream; `set buzzer` only reaches it from the CLI). +- `examples/companion_radio/ui-{orig,new,tiny}/UITask.cpp` — honour `led_q` in + the status LED handler and apply `buzzer_quiet` to the buzzer each loop. - `src/helpers/ESP32Board.cpp` — serve the ESP32 OTA page on the current Wi-Fi network when connected, otherwise the usual `MeshCore-OTA` hotspot. - `variants/xiao_s3_wio/platformio.ini` — enable OTA on the Xiao S3 WIO diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index 29e8e305..cc70ecdf 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -2267,6 +2267,30 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char* return true; } + // Same flags the UI button combo flips, reachable without the buttons. The + // ui-*/UITask.cpp loops apply both to the live hardware within one tick. + if (memcmp(command, "set buzzer ", 11) == 0) { + _prefs.buzzer_quiet = memcmp(&command[11], "off", 3) == 0 ? 1 : 0; + savePrefs(); + strcpy(reply, _prefs.buzzer_quiet ? "OK - buzzer is now OFF" : "OK - buzzer is now ON"); + return true; + } + if (strcmp(command, "get buzzer") == 0) { + sprintf(reply, "> %s", _prefs.buzzer_quiet ? "off" : "on"); + return true; + } + + if (memcmp(command, "set led ", 8) == 0) { + _prefs.led_quiet = memcmp(&command[8], "off", 3) == 0 ? 1 : 0; + savePrefs(); + strcpy(reply, _prefs.led_quiet ? "OK - status LED is now OFF" : "OK - status LED is now ON"); + return true; + } + if (strcmp(command, "get led") == 0) { + sprintf(reply, "> %s", _prefs.led_quiet ? "off" : "on"); + return true; + } + return false; // not handled } diff --git a/examples/companion_radio/NodePrefs.h b/examples/companion_radio/NodePrefs.h index f16fc22a..a9203ff9 100644 --- a/examples/companion_radio/NodePrefs.h +++ b/examples/companion_radio/NodePrefs.h @@ -33,6 +33,7 @@ public: uint8_t advert_loc_policy = 0; uint8_t buzzer_quiet = 0; uint8_t vibe_quiet = 0; + uint8_t led_quiet = 0; // 1 = status LED heartbeat disabled uint8_t gps_enabled = 0; // GPS enabled flag (0=disabled, 1=enabled) uint32_t gps_interval = 0; // GPS read interval in seconds uint8_t autoadd_config = 0; // bitmask for auto-add contacts config @@ -177,6 +178,7 @@ private: def("pin", _parent->ble_pin); def("buzz_q", _parent->buzzer_quiet); def("vibe_q", _parent->vibe_quiet); + def("led_q", _parent->led_quiet); def("auto_add", _parent->autoadd_config); // bitmask for auto-add contacts config def("man_add", _parent->manual_add_contacts); def("tel_base", _parent->telemetry_mode_base); diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 6d727ff1..5ad82dc9 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -895,6 +895,10 @@ void UITask::onControlDataRecv(const mesh::Packet* packet) { void UITask::userLedHandler() { #ifdef PIN_STATUS_LED + if (_node_prefs->led_quiet) { // `set led off` + digitalWrite(PIN_STATUS_LED, !LED_STATE_ON); + return; + } int cur_time = millis(); if (cur_time > next_led_change) { if (led_state == 0) { @@ -1051,6 +1055,9 @@ void UITask::loop() { userLedHandler(); #ifdef PIN_BUZZER + if (buzzer.isQuiet() != (_node_prefs->buzzer_quiet != 0)) { + buzzer.quiet(_node_prefs->buzzer_quiet); // pref can also change via CLI + } 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..709ff501 100644 --- a/examples/companion_radio/ui-orig/UITask.cpp +++ b/examples/companion_radio/ui-orig/UITask.cpp @@ -336,6 +336,10 @@ static void statusLedWheel(uint8_t pos) { // smooth hue sweep, 0..255 void UITask::userLedHandler() { #ifdef STATUS_LED_RGB + if (_node_prefs->led_quiet) { // `set led off` + statusLedWrite(0, 0, 0); + return; + } static bool booted = false; static bool flourish_active = false; static unsigned long flourish_until = 0; @@ -422,6 +426,10 @@ void UITask::userLedHandler() { } } #elif defined(PIN_STATUS_LED) + if (_node_prefs->led_quiet) { // `set led off` + digitalWrite(PIN_STATUS_LED, !LED_STATE_ON); + return; + } static int state = 0; static int next_change = 0; static int last_increment = 0; @@ -485,6 +493,9 @@ void UITask::loop() { userLedHandler(); #ifdef PIN_BUZZER + if (buzzer.isQuiet() != (_node_prefs->buzzer_quiet != 0)) { + buzzer.quiet(_node_prefs->buzzer_quiet); // pref can also change via CLI + } 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..e059e44c 100644 --- a/examples/companion_radio/ui-tiny/UITask.cpp +++ b/examples/companion_radio/ui-tiny/UITask.cpp @@ -551,6 +551,10 @@ void UITask::onDiscoveredContact(ContactInfo &contact, bool is_new, uint8_t path void UITask::userLedHandler() { #ifdef PIN_STATUS_LED + if (_node_prefs->led_quiet) { // `set led off` + digitalWrite(PIN_STATUS_LED, !LED_STATE_ON); + return; + } int cur_time = millis(); if (cur_time > next_led_change) { if (led_state == 0) { @@ -691,6 +695,9 @@ void UITask::loop() { userLedHandler(); #ifdef PIN_BUZZER + if (buzzer.isQuiet() != (_node_prefs->buzzer_quiet != 0)) { + buzzer.quiet(_node_prefs->buzzer_quiet); // pref can also change via CLI + } if (buzzer.isPlaying()) buzzer.loop(); #endif