mirror of
https://github.com/jhuebert/MeshCore.git
synced 2026-12-03 10:54:13 +00:00
feat: companion CLI set buzzer / set led
Add CLI control for the two things that until now only the button combo could change, and which targets without a button could not change at all: set buzzer on|off / get buzzer -- received-message buzzer set led on|off / get led -- status LED heartbeat `buzzer_quiet` already exists upstream; the CLI now reaches it, and the ui-*/UITask.cpp loops push the pref to the live buzzer object (the triple-press path keeps working unchanged). The LED needs a new `led_quiet` pref, honoured at the top of userLedHandler() in all three UIs, so it also covers the RGB status LED variants; default 0 keeps the existing blink. Both prefs are persisted (`led_q` rides the ConfigSerializer, so old prefs files load with the LED on) and apply within one UI tick, no reboot.
This commit is contained in:
1 parent
4cde9b2a80
commit
45ffce427e
6 files changed
+94
-7
No files matched your search
+43
-7
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user