Add programmable Companion alerts and trusted DM and room notifications

This commit is contained in:
mikecarper committed 2026-09-30 03:44:22 -07:00
1 parent bc8fe0c66c
commit 4bc391ef36
33 files changed
+1846 -24

No files matched your search

+17 -1
View File
@@ -35,6 +35,10 @@ protected:
MultiSerialInterface* _interfaceManager;
UIShutdownGuard* _shutdownGuard;
bool _connected;
bool _message_notification_override = false;
bool _message_notification_screen_override = false;
bool _notification_led_owned = false;
uint8_t _notification_outputs = 31;
AbstractUITask(mesh::MainBoard* board, MultiSerialInterface* interfaceManager)
: _board(board), _interfaceManager(interfaceManager),
@@ -49,9 +53,21 @@ protected:
bool shouldWakeDisplayForMessage() const { return !hasConnection(); }
bool shouldWakeDisplayForMessage() const {
return (_notification_outputs & 8) && !_message_notification_screen_override && !hasConnection();
}
public:
void setMessageNotificationOverride(bool managed, bool screen = false) {
_message_notification_override = managed;
_message_notification_screen_override = managed && screen;
}
void setNotificationLedOwnership(bool owned) { _notification_led_owned = owned; }
void setNotificationOutputs(uint8_t outputs) { _notification_outputs = outputs; }
virtual uint8_t notificationCapabilities() const { return 0; }
virtual void notificationVibration(bool on) { (void)on; }
virtual void notificationMelody(const char* text) { (void)text; }
virtual void notificationScreen(int8_t mode) { (void)mode; }
void setShutdownGuard(UIShutdownGuard* guard) { _shutdownGuard = guard; }
void setHasConnection(bool connected) { _connected = connected; }
bool hasConnection() const { return _interfaceManager->isConnected(); }
@@ -2,6 +2,16 @@
#include <helpers/CompanionReaderConfig.h>
#include <helpers/ota/OtaMemoryPolicy.h>
// STM32WL has only 224 KiB of application flash. Keep its established image
// within that boundary; larger targets provide the programmable alert engine.
#ifndef COMPANION_FEATURE_NOTIFICATIONS
#if defined(STM32_PLATFORM)
#define COMPANION_FEATURE_NOTIFICATIONS 0
#else
#define COMPANION_FEATURE_NOTIFICATIONS 1
#endif
#endif
// The role terminal is also used by WebConfig on WiFi-only Companions. Its
// parser and reply tracking do not require a physical USB transport.
#if defined(ENABLE_USB_INTERFACE) \
+65 -4
View File
@@ -1,4 +1,5 @@
#include <helpers/ui/DisplayPowerSettings.h>
#include "NotificationSettingsFile.h"
#include "MyMesh.h"
#include <helpers/CompanionTxRoutingCLI.h>
#include "CompanionBluetooth.h"
@@ -1482,17 +1483,29 @@ void MyMesh::queueMessage(const ContactInfo &from, uint8_t txt_type, mesh::Packe
}
#endif
#if COMPANION_FEATURE_NOTIFICATIONS
const bool plain_notification = txt_type == TXT_TYPE_PLAIN || txt_type == TXT_TYPE_SIGNED_PLAIN;
const bool remote_notification = plain_notification
&& _notifications.remoteMessage(from.id.pub_key, text, millis(), sender_timestamp);
const bool notification_managed = remote_notification || (plain_notification
&& _notifications.message(from.id.pub_key, nullptr, _serial->isConnected(), millis()));
if (_ui) _ui->setMessageNotificationOverride(notification_managed, _notifications.overridesScreen());
#else
const bool notification_managed = false;
#endif
#ifdef DISPLAY_CLASS
// we only want to show text messages on display, not cli data
bool should_display = txt_type == TXT_TYPE_PLAIN || txt_type == TXT_TYPE_SIGNED_PLAIN;
if (should_display && _ui) {
_ui->newMsg(path_len, from.name, text, offline_queue_len,
-1, nullptr, queued ? offline_queue_len - 1 : -1);
if (!_serial->isConnected()) {
if (!notification_managed && !_serial->isConnected()) {
_ui->notify(UIEventType::contactMessage);
}
}
#endif
if (_ui) _ui->setMessageNotificationOverride(false);
}
static uint16_t emergencyClientRepeatKey(const mesh::Packet* packet) {
@@ -1700,13 +1713,19 @@ void MyMesh::onChannelMessageRecv(const mesh::GroupChannel &channel, mesh::Packe
i += tlen;
const bool queued = addToOfflineQueue(out_frame, i);
#if COMPANION_FEATURE_NOTIFICATIONS
const bool notification_managed = _notifications.message(nullptr, channel.secret, _serial->isConnected(), millis());
if (_ui) _ui->setMessageNotificationOverride(notification_managed, _notifications.overridesScreen());
#else
const bool notification_managed = false;
#endif
if (_serial->isConnected()) {
uint8_t frame[1];
frame[0] = PUSH_CODE_MSG_WAITING; // send push 'tickle'
frame[0] = PUSH_CODE_MSG_WAITING;
_serial->writeFrame(frame, 1);
} else {
#ifdef DISPLAY_CLASS
if (_ui) _ui->notify(UIEventType::channelMessage);
if (_ui && !notification_managed) _ui->notify(UIEventType::channelMessage);
#endif
}
@@ -1736,6 +1755,8 @@ void MyMesh::onChannelMessageRecv(const mesh::GroupChannel &channel, mesh::Packe
}
#endif
if (_ui) _ui->setMessageNotificationOverride(false);
if (pkt->isRouteFlood() && is_emergency_channel) {
bool zero_path = pkt->getPathHashCount() == 0;
uint16_t key = emergencyClientRepeatKey(pkt);
@@ -2379,6 +2400,18 @@ void MyMesh::begin(bool has_display, bool radio_available) {
#endif
);
#if COMPANION_FEATURE_NOTIFICATIONS
auto& notification_settings = _notifications.settings();
FILESYSTEM* notification_fs = _store->getPrimaryFS();
if (!(mesh::notify::readSettings(notification_fs, "/notify_prefs", notification_settings)
&& _notifications.validSettings(notification_settings))) {
if (!(mesh::notify::readSettings(notification_fs, "/notify_prefs.bak", notification_settings)
&& _notifications.validSettings(notification_settings)))
notification_settings = mesh::notify::Settings();
}
#endif
// load persisted prefs
const bool prefs_ready =
_store->loadPrefs(_prefs, sensors.node_lat, sensors.node_lon);
@@ -9028,6 +9061,13 @@ void MyMesh::handleTerminalCommand(char* command) {
terminalOutput().print(" memory\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");
#endif
terminalOutput().print(" get display.inbox\r\n");
terminalOutput().print(" set display.inbox <history|pending|unread>\r\n");
terminalOutput().print(" set display.rotation <0|90|180|270>\r\n");
@@ -9338,6 +9378,7 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp,
command = profile_command;
}
if (sender_timestamp == 0 && handleDirectCommand(command, reply, reply_capacity)) return true;
if (handleNotificationCommand(command, reply, reply_capacity)) return true;
if (mesh::companion::handleRetryCommand(
_prefs, command, reply, reply_capacity,
@@ -9868,6 +9909,15 @@ void MyMesh::checkSerialInterface() {
}
void MyMesh::loop() {
#if COMPANION_FEATURE_NOTIFICATIONS
_notifications.loop(millis(), _serial->isConnected());
#if defined(PIN_USER_BTN) && defined(USER_BTN_PRESSED)
const bool notification_button_down = digitalRead(PIN_USER_BTN) == USER_BTN_PRESSED;
if (notification_button_down && !_notification_button_down) _notifications.button();
_notification_button_down = notification_button_down;
#endif
#endif
_radio_profiles.loop();
#if defined(WITH_MQTT_BRIDGE) && defined(ESP32_PLATFORM) && defined(WIFI_SSID)
if (_mqtt_bridge) _mqtt_bridge->servicePendingClockCorrection();
@@ -9971,7 +10021,15 @@ void MyMesh::loop() {
}
#ifdef DISPLAY_CLASS
if (_ui) _ui->setHasConnection(_serial->isConnected());
if (_ui) {
_ui->setHasConnection(_serial->isConnected());
#if COMPANION_FEATURE_NOTIFICATIONS
const auto& notifications = _notifications.settings();
_ui->setNotificationOutputs(notifications.enabled ? notifications.outputs : 31);
_ui->setNotificationLedOwnership(_notifications.ownsLed());
if (notifications.enabled && !(notifications.outputs & mesh::notify::Led)) pulse(mesh::notify::Led, false, -1);
#endif
}
#endif
}
@@ -9992,6 +10050,9 @@ bool MyMesh::advert() {
// To check if there is pending work
bool MyMesh::hasPendingWork() const {
#if COMPANION_FEATURE_NOTIFICATIONS
if (_notifications.active()) return true;
#endif
if (isDualRadioActive()) return true;
if (_radio_available
&& (radio_driver.isWatchdogObserving()
+22
View File
@@ -26,6 +26,7 @@
#include "DataStore.h"
#include <helpers/RadioProfileCLI.h>
#include <helpers/CompanionNotificationPolicy.h>
#include "NodePrefs.h"
#if defined(ESP32_PLATFORM) && defined(WIFI_SSID) && !defined(WEBCONFIG_DISABLED)
@@ -161,6 +162,9 @@ struct DiscoveredNode {
#endif
class MyMesh : public BaseChatMesh, public DataStoreHost, public UIShutdownGuard
#if COMPANION_FEATURE_NOTIFICATIONS
, public mesh::notify::Sink, public mesh::notify::Store
#endif
#if COMPANION_FEATURE_TEXT_TERMINAL
, public ContactVisitor
#endif
@@ -246,6 +250,20 @@ public:
#endif
void loop();
#if COMPANION_FEATURE_NOTIFICATIONS
uint8_t capabilities() const override;
bool gpioAvailable(uint8_t pin) const override;
void pulse(mesh::notify::Output output, bool on, int8_t pin) override;
void melody(const char* text) override;
void screen(int8_t mode) override;
bool save(const mesh::notify::Settings& settings) override;
bool notificationButton() { return _notifications.button(); }
void setNotificationOutputMute(mesh::notify::Output output, bool muted);
#else
bool notificationButton() { return false; }
void setNotificationOutputMute(mesh::notify::Output, bool) {}
#endif
bool handleNotificationCommand(const char* command, char* reply, size_t size);
void handleCmdFrame(size_t len);
bool advert();
void enterCLIRescue();
@@ -560,6 +578,10 @@ private:
mesh::RadioProfileCLI _radio_profiles;
uint16_t _temp_radio_preamble = 0;
CompanionNodePrefs _prefs;
#if COMPANION_FEATURE_NOTIFICATIONS
mesh::notify::Controller _notifications{*this, *this};
bool _notification_button_down = false;
#endif
#ifdef COMPANION_MESH_CLOCK_SYNC
ArduinoMillis _clock_sync_millis;
ClientACL _clock_sync_acl;
@@ -0,0 +1,62 @@
#pragma once
#include <helpers/IdentityStore.h>
#include <helpers/CompanionNotificationPolicy.h>
namespace mesh { namespace notify {
// Separate versioned storage keeps old CompanionNodePrefs layouts unchanged.
// Record size detects an incompatible layout rather than applying stale pins.
inline uint32_t checksum(const Settings& prefs) {
uint32_t h=2166136261UL;
const uint8_t* p=reinterpret_cast<const uint8_t*>(&prefs);
for(size_t i=0;i<sizeof(prefs);++i)h=(h^p[i])*16777619UL;
return h;
}
inline bool readSettings(FILESYSTEM* fs,const char* path,Settings& prefs) {
if(!fs)return false;
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
File file(*fs);if(!file.open(path,FILE_O_READ))return false;
#else
File file=fs->open(path,"r");if(!file)return false;
#endif
uint8_t head[6]={};uint32_t digest=0;
bool ok=file.size()==sizeof(prefs)+sizeof(head)+sizeof(digest)
&&file.read(head,sizeof(head))==sizeof(head)&&!memcmp(head,"NTF1",4)
&&(uint16_t(head[4])|(uint16_t(head[5])<<8))==sizeof(prefs)
&&file.read(reinterpret_cast<uint8_t*>(&prefs),sizeof(prefs))==sizeof(prefs)
&&file.read(reinterpret_cast<uint8_t*>(&digest),sizeof(digest))==sizeof(digest);
file.close();return ok&&digest==checksum(prefs);
}
inline bool writeSettings(FILESYSTEM* fs,const Settings& prefs) {
if(!fs)return false;
const char* path="/notify_prefs",*temporary="/notify_prefs.tmp",*backup="/notify_prefs.bak";
fs->remove(temporary);
if(fs->exists(temporary))return false;
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
File file(*fs);if(!file.open(temporary,FILE_O_WRITE))return false;
#elif defined(ESP32_PLATFORM)
File file=fs->open(temporary,"w",true);if(!file)return false;
#else
File file=fs->open(temporary,"w");if(!file)return false;
#endif
uint8_t head[]={ 'N','T','F','1',uint8_t(sizeof(prefs)),uint8_t(sizeof(prefs)>>8) };
uint32_t digest=checksum(prefs);
bool ok=file.write(head,sizeof(head))==sizeof(head)
&&file.write(reinterpret_cast<const uint8_t*>(&prefs),sizeof(prefs))==sizeof(prefs)
&&file.write(reinterpret_cast<uint8_t*>(&digest),sizeof(digest))==sizeof(digest);
file.close();
Settings checked;
if(!ok||!readSettings(fs,temporary,checked)||memcmp(&checked,&prefs,sizeof(prefs)))return false;
if(fs->exists(path)) {
if(readSettings(fs,path,checked)) {
if(fs->exists(backup)&&!fs->remove(backup))return false;
if(!fs->rename(path,backup))return false;
} else if(!fs->remove(path))return false; // Keep the good recovery copy.
}
if(!fs->rename(temporary,path)) {
if(fs->exists(backup))fs->rename(backup,path);
return false;
}
fs->remove(backup);return true;
}
static_assert(sizeof(Settings)<=3072,"Keep notification settings within the nRF52 RAM budget");
} }
@@ -0,0 +1,81 @@
#include "MyMesh.h"
#include "target.h"
#include "NotificationSettingsFile.h"
#if COMPANION_FEATURE_NOTIFICATIONS
uint8_t MyMesh::capabilities() const {
uint8_t bits = _ui ? _ui->notificationCapabilities() : 0;
#if defined(PIN_STATUS_LED) || defined(STATUS_LED_RGB)
bits |= mesh::notify::Led;
#endif
for(unsigned pin=0;pin<64;++pin)if(gpioAvailable(pin)) { bits|=mesh::notify::Gpio;break; }
return bits;
}
bool MyMesh::gpioAvailable(uint8_t pin) const { return board.isUserGpioAvailable(pin); }
void MyMesh::pulse(mesh::notify::Output output,bool on,int8_t pin) {
if(output==mesh::notify::Gpio && pin>=0 && gpioAvailable(pin)) {
pinMode(pin,OUTPUT);digitalWrite(pin,on?HIGH:LOW);
} else if(output==mesh::notify::Vibration) {
if(_ui)_ui->notificationVibration(on);
} else if(output==mesh::notify::Led) {
#ifdef STATUS_LED_RGB
analogWrite(PIN_STATUS_LED_R,on?255:0);
analogWrite(PIN_STATUS_LED_G,on?90:0);
analogWrite(PIN_STATUS_LED_B,0);
#elif defined(PIN_STATUS_LED)
pinMode(PIN_STATUS_LED,OUTPUT);
#ifdef LED_STATE_ON
digitalWrite(PIN_STATUS_LED,on?LED_STATE_ON:!LED_STATE_ON);
#else
digitalWrite(PIN_STATUS_LED,on?HIGH:LOW);
#endif
#endif
}
}
void MyMesh::melody(const char* text) { if(_ui)_ui->notificationMelody(text); }
void MyMesh::screen(int8_t mode) { if(_ui)_ui->notificationScreen(mode); }
bool MyMesh::save(const mesh::notify::Settings& settings) {
return mesh::notify::writeSettings(_store->getPrimaryFS(),settings);
}
void MyMesh::setNotificationOutputMute(mesh::notify::Output output,bool muted) {
if(!_notifications.settings().enabled)return;
char command[40],reply[160];
snprintf(command,sizeof(command),"set notify.%s %s",
output==mesh::notify::Sound?"sound":"vibration",muted?"off":"on");
_notifications.handle(command,reply,sizeof(reply),millis(),_serial->isConnected());
}
bool MyMesh::handleNotificationCommand(const char* command,char* reply,size_t size) {
if(strncmp(command,"set notify.",11)&&strncmp(command,"get notify",10)
&&strncmp(command,"notify.",7))return false;
// Resolve channel slots now and store their secret, so a replaced slot does
// not inherit a previous channel's VIP/page rule. Full keys also work.
char normalized[240];
const char* token=strstr(command,"channel:");
if(token) {
const char* value=token+8;const char* end=value;
while(*end && *end!=' ' && *end!='@')++end;
if(end-value<4) {
char digits[4]={};memcpy(digits,value,end-value);uint32_t index;
ChannelDetails details;
if(!mesh::notify::unsignedValue(digits,index,MAX_GROUP_CHANNELS-1)
||!getChannel(index,details)||!details.name[0]) {
snprintf(reply,size,"Error: channel slot not found");return true;
}
char key[33];mesh::Utils::toHex(key,details.channel.secret,16);
int prefix=value-command;
int n=snprintf(normalized,sizeof(normalized),"%.*s%s%s",prefix,command,key,end);
if(n<0||size_t(n)>=sizeof(normalized)) { snprintf(reply,size,"Error: command too long");return true; }
command=normalized;
}
}
return _notifications.handle(command,reply,size,millis(),_serial->isConnected());
}
#else
bool MyMesh::handleNotificationCommand(const char* command,char* reply,size_t size) {
if(strncmp(command,"set notify.",11)&&strncmp(command,"get notify",10)
&&strncmp(command,"notify.",7))return false;
snprintf(reply,size,"Error: programmable alerts unavailable on this compact STM32 build");
return true;
}
#endif
+40 -4
View File
@@ -1950,7 +1950,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, CompanionNode
buzzer.startup();
#endif
#ifdef PIN_VIBRATION
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
vibration.begin();
#endif
@@ -2016,7 +2016,7 @@ void UITask::renderMessageSummary(DisplayDriver& display) const {
void UITask::notify(UIEventType t) {
#if defined(PIN_BUZZER)
switch(t){
if (_notification_outputs & mesh::notify::Sound) switch(t){
case UIEventType::contactMessage:
// gemini's pick
buzzer.play("MsgRcv3:d=4,o=6,b=200:32e,32g,32b,16c7");
@@ -2037,7 +2037,7 @@ switch(t){
#ifdef PIN_VIBRATION
// Trigger vibration for all UI events except none
if (t != UIEventType::none) {
if ((_notification_outputs & mesh::notify::Vibration) && t != UIEventType::none) {
vibration.trigger();
}
#endif
@@ -2089,6 +2089,7 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text,
}
void UITask::userLedHandler() {
if (_notification_led_owned || !(_notification_outputs & mesh::notify::Led)) return;
#ifdef PIN_STATUS_LED
int cur_time = millis();
if (cur_time > next_led_change) {
@@ -2482,7 +2483,7 @@ void UITask::loop() {
#endif
}
#ifdef PIN_VIBRATION
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
vibration.loop();
#endif
@@ -2540,6 +2541,7 @@ void UITask::getTouchControls(mesh::ui::TouchSplitSelector& transport_touch_sele
#endif
char UITask::checkDisplayOn(char c) {
the_mesh.notificationButton();
if (_display != NULL) {
const bool was_on = _display->isOn();
_display->wake(mesh::ui::DisplayWake::Button);
@@ -2644,8 +2646,42 @@ void UITask::toggleBuzzer() {
buzzer.quiet(true);
}
_node_prefs->buzzer_quiet = buzzer.isQuiet();
the_mesh.setNotificationOutputMute(mesh::notify::Sound, _node_prefs->buzzer_quiet);
the_mesh.savePrefs();
showAlert(buzzer.isQuiet() ? "Buzzer: OFF" : "Buzzer: ON", 800);
_next_refresh = 0; // trigger refresh
#endif
}
uint8_t UITask::notificationCapabilities() const {
uint8_t bits = 0;
#ifdef PIN_BUZZER
bits |= mesh::notify::Sound;
#endif
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
bits |= mesh::notify::Vibration;
#endif
#ifdef MESHCORE_HAS_REAL_DISPLAY
if (_display) bits |= mesh::notify::Screen;
#endif
return bits;
}
void UITask::notificationMelody(const char* text) {
#ifdef PIN_BUZZER
if (text) buzzer.playNotification(text); else buzzer.stop();
#endif
}
void UITask::notificationScreen(int8_t mode) {
if (!_display) return;
_display->notificationPower(mode);
_next_refresh = 0;
}
void UITask::notificationVibration(bool on) {
#ifdef HAS_DRV2605
vibration.pulse(on);
#elif defined(PIN_VIBRATION)
vibration.stop();
digitalWrite(PIN_VIBRATION, on ? HIGH : LOW);
#endif
}
+10 -2
View File
@@ -18,7 +18,9 @@
#ifdef PIN_BUZZER
#include <helpers/ui/buzzer.h>
#endif
#ifdef PIN_VIBRATION
#ifdef HAS_DRV2605
#include <helpers/ui/DRV2605Vibration.h>
#elif defined(PIN_VIBRATION)
#include <helpers/ui/GenericVibration.h>
#endif
@@ -32,7 +34,9 @@ class UITask : public AbstractUITask {
#ifdef PIN_BUZZER
genericBuzzer buzzer;
#endif
#ifdef PIN_VIBRATION
#ifdef HAS_DRV2605
DRV2605Vibration vibration;
#elif defined(PIN_VIBRATION)
GenericVibration vibration;
#endif
unsigned long _next_refresh;
@@ -187,6 +191,10 @@ public:
const char* channel_name = nullptr,
int queue_index = -1) override;
void notify(UIEventType t = UIEventType::none) override;
uint8_t notificationCapabilities() const override;
void notificationVibration(bool on) override;
void notificationMelody(const char* text) override;
void notificationScreen(int8_t mode) override;
void loop() override;
void shutdown(bool restart = false);
+46 -3
View File
@@ -127,6 +127,8 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, CompanionNode
#ifdef HAS_DRV2605
vibration.begin();
vibration.quiet(_node_prefs->vibe_quiet);
#elif defined(PIN_VIBRATION)
vibration.begin();
#endif
// Initialize digital button if available
@@ -208,7 +210,7 @@ bool UITask::shouldPlayMessageTone() const {
void UITask::notify(UIEventType t) {
#if defined(PIN_BUZZER)
switch(t){
if (_notification_outputs & mesh::notify::Sound) switch(t){
case UIEventType::contactMessage:
// gemini's pick
if (shouldPlayMessageTone()) {
@@ -255,8 +257,8 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text,
(void)channel_name;
_msgcount = msgcount;
#ifdef HAS_DRV2605
vibration.trigger(); // vibrate even while the app is connected (honors quiet + cooldown)
#if defined(HAS_DRV2605) || defined(PIN_VIBRATION)
if (!_message_notification_override && (_notification_outputs & mesh::notify::Vibration)) vibration.trigger();
#endif
if (path_len == 0xFF) {
@@ -459,6 +461,7 @@ static void statusLedWheel(uint8_t pos) { // smooth hue sweep, 0..255
#endif
void UITask::userLedHandler() {
if (_notification_led_owned || !(_notification_outputs & mesh::notify::Led)) return;
#ifdef STATUS_LED_RGB
static bool booted = false;
static bool flourish_active = false;
@@ -647,6 +650,9 @@ void UITask::servicePairingState() {
}
void UITask::loop() {
#ifdef PIN_VIBRATION
vibration.loop();
#endif
servicePairingState();
#ifdef PIN_USER_BTN
@@ -686,6 +692,7 @@ void UITask::loop() {
}
void UITask::handleButtonAnyPress() {
the_mesh.notificationButton();
MESH_DEBUG_PRINTLN("UITask: any press triggered");
// called on any button press before other events, to wake up the display quickly
// do not refresh the display here, as it may block the button handler
@@ -749,6 +756,8 @@ void UITask::handleButtonTriplePress() {
_node_prefs->vibe_quiet = (mode & 1) ? 1 : 0;
buzzer.quiet(_node_prefs->buzzer_quiet);
vibration.quiet(_node_prefs->vibe_quiet);
the_mesh.setNotificationOutputMute(mesh::notify::Sound, _node_prefs->buzzer_quiet);
the_mesh.setNotificationOutputMute(mesh::notify::Vibration, _node_prefs->vibe_quiet);
// audible/tactile confirmation of the new mode (no screen on some boards)
if (!_node_prefs->buzzer_quiet) notify(UIEventType::ack);
if (!_node_prefs->vibe_quiet) vibration.trigger(true);
@@ -770,6 +779,7 @@ void UITask::handleButtonTriplePress() {
sprintf(_alert, "Buzzer: OFF");
}
_node_prefs->buzzer_quiet = buzzer.isQuiet();
the_mesh.setNotificationOutputMute(mesh::notify::Sound, _node_prefs->buzzer_quiet);
the_mesh.savePrefs();
_need_refresh = true;
#endif
@@ -806,3 +816,36 @@ void UITask::handleButtonLongPress() {
shutdown();
}
}
uint8_t UITask::notificationCapabilities() const {
uint8_t bits = 0;
#ifdef PIN_BUZZER
bits |= mesh::notify::Sound;
#endif
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
bits |= mesh::notify::Vibration;
#endif
#ifdef MESHCORE_HAS_REAL_DISPLAY
if (_display) bits |= mesh::notify::Screen;
#endif
return bits;
}
void UITask::notificationMelody(const char* text) {
#ifdef PIN_BUZZER
if (text) buzzer.playNotification(text); else buzzer.stop();
#endif
}
void UITask::notificationScreen(int8_t mode) {
if (!_display) return;
_display->notificationPower(mode);
_need_refresh = true;
}
void UITask::notificationVibration(bool on) {
#ifdef HAS_DRV2605
vibration.pulse(on);
#elif defined(PIN_VIBRATION)
vibration.stop();
digitalWrite(PIN_VIBRATION, on ? HIGH : LOW);
#endif
}
@@ -16,6 +16,8 @@
#ifdef HAS_DRV2605
#include <helpers/ui/DRV2605Vibration.h>
#elif defined(PIN_VIBRATION)
#include <helpers/ui/GenericVibration.h>
#endif
class UITask : public AbstractUITask {
@@ -26,6 +28,8 @@ class UITask : public AbstractUITask {
#endif
#ifdef HAS_DRV2605
DRV2605Vibration vibration;
#elif defined(PIN_VIBRATION)
GenericVibration vibration;
#endif
unsigned long _next_refresh;
CompanionNodePrefs* _node_prefs;
@@ -103,6 +107,10 @@ public:
const char* channel_name = nullptr,
int queue_index = -1) override;
void notify(UIEventType t = UIEventType::none) override;
uint8_t notificationCapabilities() const override;
void notificationVibration(bool on) override;
void notificationMelody(const char* text) override;
void notificationScreen(int8_t mode) override;
void loop() override;
void shutdown(bool restart = false);
+55 -5
View File
@@ -33,6 +33,8 @@
namespace {
constexpr unsigned SCREEN_SENSOR_BUFFER_BYTES = 200;
mesh::ui::RadioProfileSystemStatus radioProfileSystemStatus(
const CompanionNodePrefs& prefs) {
mesh::ui::RadioProfileSystemStatus status;
@@ -221,7 +223,7 @@ class HomeScreen : public UIScreen {
public:
HomeScreen(UITask* task, mesh::RTCClock* rtc, SensorManager* sensors, CompanionNodePrefs* node_prefs)
: _task(task), _rtc(rtc), _sensors(sensors), _node_prefs(node_prefs), _page(0),
_shutdown_init(false), sensors_lpp(200) {
_shutdown_init(false), sensors_lpp(SCREEN_SENSOR_BUFFER_BYTES) {
resetRadioProfileDisplayPage();
}
@@ -616,6 +618,18 @@ public:
};
#endif
#if defined(MESH_COMPANION_SCREEN_STARTUP_BYTES)
// This UI allocates three small screens, one sensor buffer, and no history
// table. Check the concrete objects instead of borrowing ui-new's allowance.
static_assert(sizeof(SplashScreen) + sizeof(HomeScreen)
#if UI_SMALL_MESSAGE_FONT == 1
+ sizeof(TinyMessageScreen)
#endif
+ SCREEN_SENSOR_BUFFER_BYTES + 4 * 16
<= MESH_COMPANION_SCREEN_STARTUP_BYTES,
"Increase MESH_COMPANION_SCREEN_STARTUP_BYTES and its RAM budget");
#endif
void UITask::begin(DisplayDriver* display, SensorManager* sensors, CompanionNodePrefs* node_prefs) {
_display = display;
_sensors = sensors;
@@ -645,7 +659,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, CompanionNode
buzzer.startup();
#endif
#ifdef PIN_VIBRATION
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
vibration.begin();
#endif
@@ -667,7 +681,7 @@ void UITask::showAlert(const char* text, int duration_millis) {
void UITask::notify(UIEventType t) {
#if defined(PIN_BUZZER)
switch(t){
if (_notification_outputs & mesh::notify::Sound) switch(t){
case UIEventType::contactMessage:
// gemini's pick
buzzer.play("MsgRcv3:d=4,o=6,b=200:32e,32g,32b,16c7");
@@ -688,7 +702,7 @@ switch(t){
#ifdef PIN_VIBRATION
// Trigger vibration for all UI events except none
if (t != UIEventType::none) {
if ((_notification_outputs & mesh::notify::Vibration) && t != UIEventType::none) {
vibration.trigger();
}
#endif
@@ -729,6 +743,7 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text,
}
void UITask::userLedHandler() {
if (_notification_led_owned || !(_notification_outputs & mesh::notify::Led)) return;
#ifdef PIN_STATUS_LED
int cur_time = millis();
if (cur_time > next_led_change) {
@@ -979,7 +994,7 @@ void UITask::loop() {
#endif
}
#ifdef PIN_VIBRATION
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
vibration.loop();
#endif
@@ -1011,6 +1026,7 @@ void UITask::loop() {
}
char UITask::checkDisplayOn(char c) {
the_mesh.notificationButton();
if (_display != NULL) {
const bool was_on = _display->isOn();
_display->wake(mesh::ui::DisplayWake::Button);
@@ -1090,8 +1106,42 @@ void UITask::toggleBuzzer() {
buzzer.quiet(true);
}
_node_prefs->buzzer_quiet = buzzer.isQuiet();
the_mesh.setNotificationOutputMute(mesh::notify::Sound, _node_prefs->buzzer_quiet);
the_mesh.savePrefs();
showAlert(buzzer.isQuiet() ? "Buzzer: OFF" : "Buzzer: ON", 800);
_next_refresh = 0; // trigger refresh
#endif
}
uint8_t UITask::notificationCapabilities() const {
uint8_t bits = 0;
#ifdef PIN_BUZZER
bits |= mesh::notify::Sound;
#endif
#if defined(PIN_VIBRATION) || defined(HAS_DRV2605)
bits |= mesh::notify::Vibration;
#endif
#ifdef MESHCORE_HAS_REAL_DISPLAY
if (_display) bits |= mesh::notify::Screen;
#endif
return bits;
}
void UITask::notificationMelody(const char* text) {
#ifdef PIN_BUZZER
if (text) buzzer.playNotification(text); else buzzer.stop();
#endif
}
void UITask::notificationScreen(int8_t mode) {
if (!_display) return;
_display->notificationPower(mode);
_next_refresh = 0;
}
void UITask::notificationVibration(bool on) {
#ifdef HAS_DRV2605
vibration.pulse(on);
#elif defined(PIN_VIBRATION)
vibration.stop();
digitalWrite(PIN_VIBRATION, on ? HIGH : LOW);
#endif
}
+10 -2
View File
@@ -18,7 +18,9 @@
#ifdef PIN_BUZZER
#include <helpers/ui/buzzer.h>
#endif
#ifdef PIN_VIBRATION
#ifdef HAS_DRV2605
#include <helpers/ui/DRV2605Vibration.h>
#elif defined(PIN_VIBRATION)
#include <helpers/ui/GenericVibration.h>
#endif
@@ -32,7 +34,9 @@ class UITask : public AbstractUITask {
#ifdef PIN_BUZZER
genericBuzzer buzzer;
#endif
#ifdef PIN_VIBRATION
#ifdef HAS_DRV2605
DRV2605Vibration vibration;
#elif defined(PIN_VIBRATION)
GenericVibration vibration;
#endif
unsigned long _next_refresh;
@@ -125,6 +129,10 @@ public:
const char* channel_name = nullptr,
int queue_index = -1) override;
void notify(UIEventType t = UIEventType::none) override;
uint8_t notificationCapabilities() const override;
void notificationVibration(bool on) override;
void notificationMelody(const char* text) override;
void notificationScreen(int8_t mode) override;
void loop() override;
void shutdown(bool restart = false);