Add saved Companion sound and vibration controls

Default fresh settings to sound off and vibration on, and keep existing saved choices. Apply changes immediately across all three UIs and make custom notification patterns respect the same mute controls.

Keep the Wio Mini Companion within its existing flash boundary by storing its LED switch in a reserved preference byte and shortening CLI help without removing commands. Add coverage for live output changes, persistence, and storage failures.

Adapted from https://github.com/meshcore-dev/MeshCore/pull/3603.

Co-authored-by: R0ck <develop@hectospark.co.uk>
This commit is contained in:
mikecarperandR0ck committed 2026-10-20 09:33:43 -07:00
1 parent 9d52b1fd68
commit f57dffa2be
30 files changed
+1074 -108

No files matched your search

@@ -68,6 +68,7 @@ public:
virtual void notificationVibration(bool on) { (void)on; }
virtual void notificationMelody(const char* text) { (void)text; }
virtual void notificationScreen(int8_t mode) { (void)mode; }
virtual void syncAlertPreferences() {}
void setShutdownGuard(UIShutdownGuard* guard) { _shutdownGuard = guard; }
void setHasConnection(bool connected) { _connected = connected; }
bool hasConnection() const { return _interfaceManager->isConnected(); }
+61 -60
View File
@@ -294,7 +294,7 @@ static bool save_filter(const ContactInfo& c);
#define DEFAULT_AUTOADD_CONFIG 0
#endif
#ifndef DEFAULT_BUZZER_QUIET
#define DEFAULT_BUZZER_QUIET 0
#define DEFAULT_BUZZER_QUIET 1
#endif
#ifndef DEFAULT_CAD_ENABLED
// Preserve the tuned Companion behavior that preceded the runtime setting.
@@ -2833,6 +2833,7 @@ MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMe
_prefs.manual_add_contacts = DEFAULT_MANUAL_ADD_CONTACTS;
_prefs.tx_power_dbm = LORA_TX_POWER;
_prefs.buzzer_quiet = DEFAULT_BUZZER_QUIET ? 1 : 0;
_prefs.vibe_quiet = 0;
_prefs.gps_enabled = 0; // GPS disabled by default
_prefs.gps_interval = 0; // Use the default 1-second fix-processing interval
_prefs.gps_sync_interval_hours = 0; // Retain the board's default time-sync cadence
@@ -3320,6 +3321,13 @@ void MyMesh::begin(bool has_display, bool radio_available,
void MyMesh::configureRadioFromPrefs() {
board.attachDynamicPrefs(_prefs.getCustom());
#if defined(WIO_E5_MINI_HEADLESS_COMPANION_UI)
// The reserved preference byte keeps the existing image and filesystem size.
_prefs.leds_quiet = _prefs.leds_quiet == 1 ? 1 : 0;
mesh::leds::setEnabled(!_prefs.leds_quiet);
board.applyLedPolicy();
mesh::leds::applyStatusPolicy();
#endif
if (!_radio_available) {
saved_radio_apply_pending = false;
@@ -10315,17 +10323,17 @@ void MyMesh::handleTerminalCommand(char* command, bool reader_prompt,
terminalOutput().print(
"Commands:\r\n"
" stats-core / stats-radio / stats-radio-diag / stats-packets\r\n"
" get prv.key (when private key export is enabled)\r\n"
" get prv.key (if export enabled)\r\n"
#if defined(ESP32_PLATFORM) && defined(WIFI_SSID)
" password <new-password> (shared setup WiFi, WebConfig and WiFi OTA)\r\n"
" get password (management password status)\r\n"
#else
" get password (this role has no admin password)\r\n"
" get password (no admin password)\r\n"
#endif
" erase (erase stored settings and identity)\r\n"
" erase (settings and identity)\r\n"
" board\r\n"
" version\r\n");
terminalOutput().print(" get storage.layout\r\n");
" version\r\n"
" get storage.layout\r\n");
#if MESH_ENABLE_TX_BEACONS
terminalOutput().print(" get beacon [slot] / set beacon <slot> <meshcore|meshtext> ...\r\n"
" delete beacon <slot|all> / set beacon.interval <12|24|36|48> (default 24h)\r\n");
@@ -10363,58 +10371,52 @@ void MyMesh::handleTerminalCommand(char* command, bool reader_prompt,
terminalOutput().print(" get eth / set eth on|off (physical RAK13800; default off, this boot)\r\n"
" get sdcard [free] / ota cache [on|off] (RAK15002; mutually exclusive with Ethernet)\r\n");
#endif
terminalOutput().print(" get pwrmgt.bootreason\r\n");
terminalOutput().print(" get pwrmgt.bootreason\r\n"
#if COMPANION_FEATURE_MEMORY_DIAGNOSTICS
terminalOutput().print(" memory\r\n");
" memory\r\n"
#endif
" get/set display.rotation <0|90|180|270>\r\n"
#ifdef PIN_BUZZER
" get/set buzzer on|off\r\n"
#endif
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
" get/set vibration on|off\r\n"
#endif
terminalOutput().print(" get display.rotation\r\n");
#if COMPANION_FEATURE_NOTIFICATIONS
terminalOutput().print(" get notify / get notify.rules / get notify.gpio.pins\r\n");
terminalOutput().print(" set notify.{sound|vibration|led|screen|gpio} on|off\r\n");
terminalOutput().print(" set notify.<output> <all|contact:key|room:key|channel:slot> <pattern>\r\n");
terminalOutput().print(" set notify.remote <contact:key|room:key> on|off (!notify, max 15s, no GPIO)\r\n");
terminalOutput().print(" notify.test <target> / notify.stop / notify.delete <target>\r\n");
" get notify / get notify.rules / get notify.gpio.pins\r\n"
" set notify.{sound|vibration|led|screen|gpio} on|off\r\n"
" set notify.<output> <all|contact:key|room:key|channel:slot> <pattern>\r\n"
" set notify.remote <contact:key|room:key> on|off (!notify, max 15s, no GPIO)\r\n"
" notify.test <target> / notify.stop / notify.delete <target>\r\n"
#endif
terminalOutput().print(
" get display.inbox\r\n"
" set display.inbox <history|pending|unread>\r\n"
" set display.rotation <0|90|180|270>\r\n"
" get display.touch\r\n"
" set display.touch <on|off> (this boot only)\r\n"
" get public.key\r\n");
terminalOutput().print(
" get/set display.inbox <history|pending|unread>\r\n"
" get/set display.touch <on|off> (this boot)\r\n"
" get public.key\r\n"
" set {name|lat|lon|freq|tx|af} {value}\r\n"
" get wifi|espnow|2.4ghz\r\n"
" set wifi|espnow on|off [force] (force only with off)\r\n"
" set 2.4ghz on [all|force]|off [force] (this boot)\r\n"
" get bluetooth.name\r\n"
" set bluetooth.name <name|default>\r\n");
" get/set bluetooth.name <name|default>\r\n"
#if defined(BLE_PIN_CODE)
terminalOutput().print(" get bluetooth (alias: get ble)\r\n");
terminalOutput().print(" set bluetooth <on|off> [force] (saved; force only with off)\r\n");
terminalOutput().print(" get bluetooth.mac\r\n");
terminalOutput().print(
" set bluetooth.mac <address|random|random-every-boot|random-after-connect|default>\r\n");
terminalOutput().print(" get bluetooth.stealth\r\n");
terminalOutput().print(" set bluetooth.stealth on|off\r\n");
" get bluetooth (alias: get ble)\r\n"
" set bluetooth <on|off> [force] (saved; force only with off)\r\n"
" get bluetooth.mac\r\n"
" set bluetooth.mac <address|random|random-every-boot|random-after-connect|default>\r\n"
" get/set bluetooth.stealth on|off\r\n"
#endif
#if MESH_ENABLE_LOST_REPLY
terminalOutput().print(" get lost.reply\r\n" " set lost.reply <off|no|yes>\r\n");
" get/set lost.reply <off|no|yes>\r\n"
#endif
terminalOutput().print(" set pin <0-999999>\r\n" " powersaving [on|off]\r\n");
" set pin <0-999999>\r\n" " powersaving [on|off]\r\n"
#if MESH_USB_LOGGING_AVAILABLE
terminalOutput().print(
" get usb.logging\r\n"
" set usb.logging <on|off|stream> [reboot]\r\n"
" get usb.debug\r\n"
" set usb.debug <on|off>\r\n"
" get/set usb.logging <on|off|stream> [reboot]\r\n"
" get/set usb.debug <on|off>\r\n"
#if MESH_USB_CONSOLE_COOPERATIVE
" get usb.watchdog\r\n"
" get usb.watchdog.last\r\n"
" set usb.watchdog <off|on|auto> (saved; default auto)\r\n"
" get/set usb.watchdog <off|on|auto> (saved; default auto)\r\n"
#endif
#endif
);
#endif
#if defined(ESP32) && defined(WIFI_SSID)
#if defined(COMPANION_RADIO_FULL)
terminalOutput().print(" start ota [ap] (WiFi firmware update on port 8080)\r\n");
@@ -10447,23 +10449,15 @@ void MyMesh::handleTerminalCommand(char* command, bool reader_prompt,
terminalOutput().print(" get espnow.channel\r\n");
terminalOutput().print(" set espnow.channel <1-13>\r\n");
#endif
// Keep identical help text in bounded chunks. Fewer virtual Print calls
// leave room for USB controls on small-flash boards without cutting CLI.
// Concise help and grouped Print calls preserve small-board flash space.
terminalOutput().print(
" get radio.rxps\r\n"
" get radio.rxps.config\r\n"
" set radio.rxps <off|on|level 1-10 [preamble 16|32]|rx_us sleep_us>\r\n"
" get radio.cad\r\n"
" set radio.cad <on|off>\r\n"
" set radio.cad timings <scan_ms|auto> <retry_ms|auto> <max_ms|auto>\r\n");
terminalOutput().print(
" get radio.rxgain\r\n"
" set radio.rxgain <on|off>\r\n"
" get radio.fem.rxgain\r\n"
" set radio.fem.rxgain <on|off>\r\n"
" get radio.fem.txgain\r\n"
" set radio.fem.txgain <on|off>\r\n");
terminalOutput().print(
" get/set radio.rxps <off|on|level 1-10 [preamble 16|32]|rx_us sleep_us>\r\n"
" get/set radio.cad <on|off>\r\n"
" set radio.cad timings <scan_ms|auto> <retry_ms|auto> <max_ms|auto>\r\n"
" get/set radio.rxgain <on|off>\r\n"
" get/set radio.fem.rxgain <on|off>\r\n"
" get/set radio.fem.txgain <on|off>\r\n"
" get/set flood.retry.count <0-15>\r\n"
" get/set flood.retry.path <0-63|off>\r\n"
" get/set flood.retry.group.path <0-63|off>\r\n"
@@ -10475,13 +10469,13 @@ void MyMesh::handleTerminalCommand(char* command, bool reader_prompt,
terminalOutput().print(
" list [n]\r\n"
" show [adverts|channels|emergency] [on|off]\r\n"
" to [recipient name or prefix]\r\n"
" path [direct|clear|hops separated by spaces or commas]\r\n"
" to [name|prefix]\r\n"
" path [direct|clear|hop,...]\r\n"
" send <text>\r\n"
" login <admin-password>\r\n"
" cmd <remote-command>\r\n");
terminalOutput().print(
" trace [recipient name or prefix]\r\n"
" trace [name|prefix]\r\n"
" trace path <1|2|4> <prefixes...>\r\n"
" advert\r\n"
" reset path\r\n"
@@ -10508,7 +10502,7 @@ void MyMesh::handleTerminalCommand(char* command, bool reader_prompt,
if (_terminal_mode) {
terminalOutput().print(" +++MESHCORE-TERM-STOP\r\n");
} else {
terminalOutput().print(" disconnect (closes the network terminal)\r\n");
terminalOutput().print(" disconnect (network terminal)\r\n");
}
} else if (handleCommand(command, 0, local_reply)) {
// Fill the same safe shared-command surface for getters (`get name`,
@@ -10726,7 +10720,14 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp,
}
if (mesh::power::handleRegulatorCommand(command, reply, reply_capacity)) return true;
#if defined(WIO_E5_MINI_HEADLESS_COMPANION_UI)
if (handleCompactLedCommand(command, reply, reply_capacity)) return true;
#else
if (mesh::leds::handleCommand(command, reply, reply_capacity)) return true;
#endif
#if defined(PIN_BUZZER) || defined(PIN_VIBRATION) || defined(HAS_DRV2605)
if (handleAlertCommand(command, reply, reply_capacity)) return true;
#endif
#if COMPANION_FEATURE_READER
if (sender_timestamp == 0 && mesh::morseTimingActive(_radio)
+4
View File
@@ -295,6 +295,10 @@ public:
void setNotificationOutputMute(mesh::notify::Output, bool) {}
#endif
bool handleNotificationCommand(const char* command, char* reply, size_t size);
bool handleAlertCommand(const char* command, char* reply, size_t size);
#if defined(WIO_E5_MINI_HEADLESS_COMPANION_UI)
bool handleCompactLedCommand(const char* command, char* reply, size_t size);
#endif
#if defined(STM32_PLATFORM)
// Keep this large dispatcher separate from contact streaming on flash-
// constrained STM32 targets; merging their branches increases code size.
+5 -1
View File
@@ -49,8 +49,12 @@ public:
float rx_delay_base = 0;
uint32_t ble_pin = 0;
uint8_t advert_loc_policy = 0;
uint8_t buzzer_quiet = 0;
uint8_t buzzer_quiet = 1;
uint8_t gps_enabled = 0; // GPS enabled flag (0=disabled, 1=enabled)
#if defined(WIO_E5_MINI_HEADLESS_COMPANION_UI)
// Uses existing alignment space; stored in the reserved wire byte at 79.
uint8_t leds_quiet = 0;
#endif
uint32_t gps_interval = 0; // seconds; 0 uses the 1-second default
uint8_t autoadd_config = 0; // bitmask for auto-add contacts config
uint8_t rx_boosted_gain = 0; // SX126x RX boosted gain mode
@@ -2,6 +2,88 @@
#include "target.h"
#include "NotificationSettingsFile.h"
#if defined(WIO_E5_MINI_HEADLESS_COMPANION_UI)
bool MyMesh::handleCompactLedCommand(const char* command, char* reply, size_t size) {
if (!command || !reply || !size) return false;
if (strcmp(command, "get leds") == 0) {
snprintf(reply, size, "> %s", mesh::leds::enabled() ? "on" : "off");
return true;
}
if (strncmp(command, "set leds", 8) != 0
|| (command[8] && command[8] != ' ' && command[8] != '\t')) return false;
const char* value = command + 8;
while (*value == ' ' || *value == '\t') ++value;
if (strcmp(value, "on") != 0 && strcmp(value, "off") != 0) {
snprintf(reply, size, "Error: usage set leds on|off");
return true;
}
const bool on = strcmp(value, "on") == 0;
const uint8_t previous = _prefs.leds_quiet;
_prefs.leds_quiet = !on;
if (_prefs.leds_quiet != previous) {
if (!savePrefs()) {
_prefs.leds_quiet = previous;
snprintf(reply, size, "Error: LED setting save unconfirmed; reboot may differ");
return true;
}
}
mesh::leds::setEnabled(on);
board.applyLedPolicy();
mesh::leds::applyStatusPolicy();
snprintf(reply, size, "OK");
return true;
}
#endif
bool MyMesh::handleAlertCommand(const char* command, char* reply, size_t size) {
if (!command || !reply || !size) return false;
const bool get = strncmp(command, "get ", 4) == 0;
if (!get && strncmp(command, "set ", 4) != 0) return false;
const char* name = command + 4;
uint8_t* quiet = nullptr;
size_t length = 0;
bool supported = false;
if (strncmp(name, "buzzer", 6) == 0) {
length = 6;
quiet = &_prefs.buzzer_quiet;
#ifdef PIN_BUZZER
supported = true;
#endif
} else if (strncmp(name, "vibration", 9) == 0) {
length = 9;
quiet = &_prefs.vibe_quiet;
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
supported = true;
#endif
} else return false;
const char* value = name + length;
if (*value && *value != ' ' && *value != '\t') return false;
if (!supported) {
snprintf(reply, size, "Error: %.*s unavailable on this build", int(length), name);
return true;
}
if (get) {
if (*value) snprintf(reply, size, "Error: usage get %.*s", int(length), name);
else snprintf(reply, size, "> %s", *quiet ? "off" : "on");
return true;
}
while (*value == ' ' || *value == '\t') ++value;
if (strcmp(value, "on") != 0 && strcmp(value, "off") != 0) {
snprintf(reply, size, "Error: usage set %.*s on|off", int(length), name);
return true;
}
const uint8_t previous = *quiet;
*quiet = strcmp(value, "off") == 0;
if (*quiet != previous && !savePrefs()) {
*quiet = previous;
snprintf(reply, size, "Error: failed to save %.*s setting", int(length), name);
return true;
}
if (_ui) _ui->syncAlertPreferences();
snprintf(reply, size, "OK");
return true;
}
#if COMPANION_FEATURE_NOTIFICATIONS
// The UI's STATUS_LED_RGB define is local to its own translation unit.
uint8_t MyMesh::capabilities() const {
@@ -67,7 +67,11 @@ static constexpr PrefField PREF_FIELDS[] = {
PREF_FIELD(advert_loc_policy, 1),
PREF_FIELD(multi_acks, 1),
PREF_FIELD(path_hash_mode, 1),
#if defined(WIO_E5_MINI_HEADLESS_COMPANION_UI)
PREF_FIELD(leds_quiet, 1),
#else
prefSpecial<PrefsPad, 1>(),
#endif
PREF_FIELD(ble_pin, 4),
PREF_FIELD(buzzer_quiet, 1),
PREF_FIELD(gps_enabled, 1),
+2
View File
@@ -3635,7 +3635,9 @@ void setup() {
if (!mesh::storage::internalPrimaryFilesystemReady(primary_fs_boot)
|| store.isVolatilePrimaryFS()) regulator_prefs_fs = nullptr;
#endif
#if !defined(WIO_E5_MINI_HEADLESS_COMPANION_UI)
mesh::leds::beginSettings(board, regulator_prefs_fs);
#endif
if (!mesh::power::beginRegulatorSettings(board, radio_driver, regulator_prefs_fs)) {
MESH_DEBUG_PRINTLN("Regulator selection could not be applied");
}
+17 -6
View File
@@ -1965,6 +1965,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, CompanionNode
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
vibration.begin();
vibration.quiet(_node_prefs->vibe_quiet);
#endif
ui_started_at = millis();
@@ -2051,7 +2052,7 @@ if (_notification_outputs & mesh::notify::Sound) switch(t){
}
#endif
#ifdef PIN_VIBRATION
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
// Trigger vibration for all UI events except none
if ((_notification_outputs & mesh::notify::Vibration) && t != UIEventType::none) {
vibration.trigger();
@@ -2276,7 +2277,20 @@ bool UITask::isButtonGesturePending() const {
#endif
}
void UITask::syncAlertPreferences() {
if (!_node_prefs) return;
#ifdef PIN_BUZZER
if (buzzer.isQuiet() != bool(_node_prefs->buzzer_quiet))
buzzer.quiet(_node_prefs->buzzer_quiet);
#endif
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
if (vibration.isQuiet() != bool(_node_prefs->vibe_quiet))
vibration.quiet(_node_prefs->vibe_quiet);
#endif
}
void UITask::loop() {
syncAlertPreferences();
// Observe startup expiry even while display/Morse/input defers rendering.
if (!_startup_complete && static_cast<uint32_t>(millis() - ui_started_at) >= 8000u) {
_startup_complete = true;
@@ -2730,7 +2744,7 @@ uint8_t UITask::notificationCapabilities() const {
}
void UITask::notificationMelody(const char* text) {
#ifdef PIN_BUZZER
if (text) buzzer.playNotification(text); else buzzer.stop();
if (text) buzzer.playNotification(text); else buzzer.stopNotification();
#endif
}
void UITask::notificationScreen(int8_t mode) {
@@ -2739,10 +2753,7 @@ void UITask::notificationScreen(int8_t mode) {
_next_refresh = millis();
}
void UITask::notificationVibration(bool on) {
#ifdef HAS_DRV2605
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
vibration.pulse(on);
#elif defined(PIN_VIBRATION)
vibration.stop();
digitalWrite(PIN_VIBRATION, on ? HIGH : LOW);
#endif
}
+2 -1
View File
@@ -43,7 +43,7 @@ class UITask : public AbstractUITask {
unsigned long _pairing_screen_until;
bool _deferred_msg_preview;
bool _startup_complete = false;
CompanionNodePrefs* _node_prefs;
CompanionNodePrefs* _node_prefs = nullptr;
char _alert[80];
uint32_t _alert_expiry;
int _msgcount;
@@ -200,6 +200,7 @@ public:
void notificationVibration(bool on) override;
void notificationMelody(const char* text) override;
void notificationScreen(int8_t mode) override;
void syncAlertPreferences() override;
void loop() override;
void shutdown(bool restart = false);
+17 -10
View File
@@ -124,11 +124,9 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, CompanionNode
buzzer.startup();
#endif
#ifdef HAS_DRV2605
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
vibration.begin();
vibration.quiet(_node_prefs->vibe_quiet);
#elif defined(PIN_VIBRATION)
vibration.begin();
#endif
// Initialize digital button if available
@@ -719,13 +717,26 @@ void UITask::servicePairingState() {
}
}
void UITask::syncAlertPreferences() {
if (!_node_prefs) return;
#ifdef PIN_BUZZER
if (buzzer.isQuiet() != bool(_node_prefs->buzzer_quiet))
buzzer.quiet(_node_prefs->buzzer_quiet);
#endif
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
if (vibration.isQuiet() != bool(_node_prefs->vibe_quiet))
vibration.quiet(_node_prefs->vibe_quiet);
#endif
}
void UITask::loop() {
syncAlertPreferences();
// Observe startup expiry before button callbacks and optional rendering.
if (!_startup_complete && static_cast<uint32_t>(millis() - ui_started_at) >= 8000u) {
_startup_complete = true;
}
const bool morse_timing = mesh::morseTimingActive(&radio_driver);
#ifdef PIN_VIBRATION
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
vibration.loop();
#endif
servicePairingState();
@@ -1132,18 +1143,14 @@ void UITask::notificationScreen(int8_t mode) {
_need_refresh = true;
}
void UITask::notificationVibration(bool on) {
#ifdef HAS_DRV2605
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
#if defined(PIN_BUZZER) && MESH_GPS_VOICE
// The saved physical alert mode stays authoritative even if the separate
// notification-mask write fails. Off callbacks must still stop the driver.
// Keep the committed physical mode authoritative if a mask save failed.
if (on && _node_prefs && _node_prefs->vibe_quiet) {
vibration.stop();
return;
}
#endif
vibration.pulse(on);
#elif defined(PIN_VIBRATION)
vibration.stop();
digitalWrite(PIN_VIBRATION, on ? HIGH : LOW);
#endif
}
+2 -1
View File
@@ -32,7 +32,7 @@ class UITask : public AbstractUITask {
GenericVibration vibration;
#endif
uint32_t _next_refresh;
CompanionNodePrefs* _node_prefs;
CompanionNodePrefs* _node_prefs = nullptr;
char _version_info[32];
char _origin[62];
#if UI_SMALL_MESSAGE_FONT == 1
@@ -125,6 +125,7 @@ public:
void notificationVibration(bool on) override;
void notificationMelody(const char* text) override;
void notificationScreen(int8_t mode) override;
void syncAlertPreferences() override;
void loop() override;
#ifdef MESH_BUTTON_AUDIO_HIL
bool handleButtonAudioTest(const char* command, char* reply, size_t size) override;
+17 -6
View File
@@ -666,6 +666,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, CompanionNode
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
vibration.begin();
vibration.quiet(_node_prefs->vibe_quiet);
#endif
ui_started_at = millis();
@@ -708,7 +709,7 @@ if (_notification_outputs & mesh::notify::Sound) switch(t){
}
#endif
#ifdef PIN_VIBRATION
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
// Trigger vibration for all UI events except none
if ((_notification_outputs & mesh::notify::Vibration) && t != UIEventType::none) {
vibration.trigger();
@@ -867,7 +868,20 @@ bool UITask::isButtonPressed() const {
#endif
}
void UITask::syncAlertPreferences() {
if (!_node_prefs) return;
#ifdef PIN_BUZZER
if (buzzer.isQuiet() != bool(_node_prefs->buzzer_quiet))
buzzer.quiet(_node_prefs->buzzer_quiet);
#endif
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
if (vibration.isQuiet() != bool(_node_prefs->vibe_quiet))
vibration.quiet(_node_prefs->vibe_quiet);
#endif
}
void UITask::loop() {
syncAlertPreferences();
// Observe startup expiry even while display/Morse/input defers rendering.
if (!_startup_complete && static_cast<uint32_t>(millis() - ui_started_at) >= 8000u) {
_startup_complete = true;
@@ -1167,7 +1181,7 @@ uint8_t UITask::notificationCapabilities() const {
}
void UITask::notificationMelody(const char* text) {
#ifdef PIN_BUZZER
if (text) buzzer.playNotification(text); else buzzer.stop();
if (text) buzzer.playNotification(text); else buzzer.stopNotification();
#endif
}
void UITask::notificationScreen(int8_t mode) {
@@ -1176,10 +1190,7 @@ void UITask::notificationScreen(int8_t mode) {
_next_refresh = millis();
}
void UITask::notificationVibration(bool on) {
#ifdef HAS_DRV2605
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
vibration.pulse(on);
#elif defined(PIN_VIBRATION)
vibration.stop();
digitalWrite(PIN_VIBRATION, on ? HIGH : LOW);
#endif
}
+2 -1
View File
@@ -40,7 +40,7 @@ class UITask : public AbstractUITask {
GenericVibration vibration;
#endif
uint32_t _next_refresh;
CompanionNodePrefs* _node_prefs;
CompanionNodePrefs* _node_prefs = nullptr;
char _alert[80];
uint32_t _alert_expiry;
unsigned long _pairing_screen_until;
@@ -137,6 +137,7 @@ public:
void notificationVibration(bool on) override;
void notificationMelody(const char* text) override;
void notificationScreen(int8_t mode) override;
void syncAlertPreferences() override;
void loop() override;
void shutdown(bool restart = false);