From 6f6ca64cfd7acda9fd23bcdfcd6ba7073907ef19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Tue, 27 Dec 2022 21:51:35 +0100 Subject: [PATCH] potential bugfix for nag cutoff --- src/ButtonThread.h | 5 ---- src/graphics/Screen.cpp | 5 ++++ src/modules/ExternalNotificationModule.cpp | 28 +++++++++++----------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/ButtonThread.h b/src/ButtonThread.h index f9131c84a..0e9830f3f 100644 --- a/src/ButtonThread.h +++ b/src/ButtonThread.h @@ -4,7 +4,6 @@ #include "concurrency/OSThread.h" #include "configuration.h" #include "graphics/Screen.h" -#include "modules/ExternalNotificationModule.h" #include "power.h" #include @@ -116,10 +115,6 @@ class ButtonThread : public concurrency::OSThread { // DEBUG_MSG("press!\n"); #ifdef BUTTON_PIN - // If a nag notification is running, stop it - if (externalNotificationModule->nagCycleCutoff != UINT32_MAX) { - externalNotificationModule->nagCycleCutoff = 0; - } if ((BUTTON_PIN != moduleConfig.canned_message.inputbroker_pin_press) || !moduleConfig.canned_message.enabled) { powerFSM.trigger(EVENT_PRESS); diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 394006622..4f1c9a5e3 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -35,6 +35,7 @@ along with this program. If not, see . #include "mesh/Channels.h" #include "mesh/generated/deviceonly.pb.h" #include "modules/TextMessageModule.h" +#include "modules/ExternalNotificationModule.h" #include "sleep.h" #include "target_specific.h" #include "utils.h" @@ -1070,6 +1071,10 @@ int32_t Screen::runOnce() handleSetOn(false); break; case Cmd::ON_PRESS: + // If a nag notification is running, stop it + if (externalNotificationModule->nagCycleCutoff != UINT32_MAX) { + externalNotificationModule->nagCycleCutoff = 0; + } handleOnPress(); break; case Cmd::START_BLUETOOTH_PIN_SCREEN: diff --git a/src/modules/ExternalNotificationModule.cpp b/src/modules/ExternalNotificationModule.cpp index b77f3a887..e0f4282ab 100644 --- a/src/modules/ExternalNotificationModule.cpp +++ b/src/modules/ExternalNotificationModule.cpp @@ -38,6 +38,20 @@ int32_t ExternalNotificationModule::runOnce() return INT32_MAX; // we don't need this thread here... } else { + if (nagCycleCutoff < millis()) { + nagCycleCutoff = UINT32_MAX; + DEBUG_MSG("Turning off external notification: "); + for (int i = 0; i < 2; i++) { + if (getExternal(i)) { + setExternalOff(i); + externalTurnedOn[i] = 0; + DEBUG_MSG("%d ", i); + } + } + DEBUG_MSG("\n"); + return INT32_MAX; // save cycles till we're needed again + } + // If the output is turned on, turn it back off after the given period of time. if (nagCycleCutoff != UINT32_MAX) { if (externalTurnedOn[0] + (moduleConfig.external_notification.output_ms @@ -56,20 +70,6 @@ int32_t ExternalNotificationModule::runOnce() getExternal(2) ? setExternalOff(2) : setExternalOn(2); } } - - if (nagCycleCutoff < millis()) { - nagCycleCutoff = UINT32_MAX; - DEBUG_MSG("Turning off external notification: "); - for (int i = 0; i < 2; i++) { - if (getExternal(i)) { - setExternalOff(i); - externalTurnedOn[i] = 0; - DEBUG_MSG("%d ", i); - } - } - DEBUG_MSG("\n"); - return INT32_MAX; // save cycles till we're needed again - } return 25; } }