From 465fe18a895f9f4e6d9b0cf5654257acee077419 Mon Sep 17 00:00:00 2001 From: todd-herbert Date: Mon, 16 Jun 2025 23:09:55 +1200 Subject: [PATCH] Dismiss ExternalNotification nagging on InkHUD button press (#7056) * Expose ExternalNotification::isNagging * Dismiss external notification on button press --- src/graphics/niche/InkHUD/Events.cpp | 27 +++++++++++++++++++++- src/graphics/niche/InkHUD/Events.h | 3 +++ src/modules/ExternalNotificationModule.cpp | 6 +++++ src/modules/ExternalNotificationModule.h | 2 ++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/graphics/niche/InkHUD/Events.cpp b/src/graphics/niche/InkHUD/Events.cpp index ee6c04938..109f75df5 100644 --- a/src/graphics/niche/InkHUD/Events.cpp +++ b/src/graphics/niche/InkHUD/Events.cpp @@ -4,6 +4,7 @@ #include "RTC.h" #include "modules/AdminModule.h" +#include "modules/ExternalNotificationModule.h" #include "modules/TextMessageModule.h" #include "sleep.h" @@ -37,6 +38,10 @@ void InkHUD::Events::begin() void InkHUD::Events::onButtonShort() { + // Cancel any beeping, buzzing, blinking + // Some button handling suppressed if we are dismissing an external notification (see below) + bool dismissedExt = dismissExternalNotification(); + // Check which system applet wants to handle the button press (if any) SystemApplet *consumer = nullptr; for (SystemApplet *sa : inkhud->systemApplets) { @@ -49,7 +54,7 @@ void InkHUD::Events::onButtonShort() // If no system applet is handling input, default behavior instead is to cycle applets if (consumer) consumer->onButtonShortPress(); - else + else if (!dismissedExt) // Don't change applet if this button press silenced the external notification module inkhud->nextApplet(); } @@ -204,4 +209,24 @@ int InkHUD::Events::beforeLightSleep(void *unused) } #endif +// Silence all ongoing beeping, blinking, buzzing, coming from the external notification module +// Returns true if an external notification was active, and we dismissed it +// Button handling changes depending on our result +bool InkHUD::Events::dismissExternalNotification() +{ + // Abort if not using external notifications + if (!moduleConfig.external_notification.enabled) + return false; + + // Abort if nothing to dismiss + if (!externalNotificationModule->nagging()) + return false; + + // Stop the beep buzz blink + externalNotificationModule->stopNow(); + + // Inform that we did indeed dismiss an external notification + return true; +} + #endif \ No newline at end of file diff --git a/src/graphics/niche/InkHUD/Events.h b/src/graphics/niche/InkHUD/Events.h index 489135ea3..2a2dad5dc 100644 --- a/src/graphics/niche/InkHUD/Events.h +++ b/src/graphics/niche/InkHUD/Events.h @@ -62,6 +62,9 @@ class Events CallbackObserver lightSleepObserver = CallbackObserver(this, &Events::beforeLightSleep); #endif + // End any externalNotification beeping, buzzing, blinking etc + bool dismissExternalNotification(); + // If set, InkHUD's data will be erased during onReboot bool eraseOnReboot = false; }; diff --git a/src/modules/ExternalNotificationModule.cpp b/src/modules/ExternalNotificationModule.cpp index dc17460f6..615c3590b 100644 --- a/src/modules/ExternalNotificationModule.cpp +++ b/src/modules/ExternalNotificationModule.cpp @@ -293,6 +293,12 @@ bool ExternalNotificationModule::getExternal(uint8_t index) return externalCurrentState[index]; } +// Allow other firmware components to determine whether a notification is ongoing +bool ExternalNotificationModule::nagging() +{ + return isNagging; +} + void ExternalNotificationModule::stopNow() { rtttl::stop(); diff --git a/src/modules/ExternalNotificationModule.h b/src/modules/ExternalNotificationModule.h index 841ca6de9..85950464d 100644 --- a/src/modules/ExternalNotificationModule.h +++ b/src/modules/ExternalNotificationModule.h @@ -40,6 +40,8 @@ class ExternalNotificationModule : public SinglePortModule, private concurrency: void setMute(bool mute) { isMuted = mute; } bool getMute() { return isMuted; } + bool nagging(); + void stopNow(); void handleGetRingtone(const meshtastic_MeshPacket &req, meshtastic_AdminMessage *response);