From c524732849305ea3fe9c163f953600ce1fdd2e45 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Wed, 27 Jan 2021 21:35:07 -0800 Subject: [PATCH] #654 - Non blocking call to toggle the output. --- src/plugins/ExternalNotificationPlugin.cpp | 23 ++++++++-------------- src/plugins/ExternalNotificationPlugin.h | 1 + 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/plugins/ExternalNotificationPlugin.cpp b/src/plugins/ExternalNotificationPlugin.cpp index 95164d42a..74334d01e 100644 --- a/src/plugins/ExternalNotificationPlugin.cpp +++ b/src/plugins/ExternalNotificationPlugin.cpp @@ -12,7 +12,7 @@ This plugin supports: https://github.com/meshtastic/Meshtastic-device/issues/654 - + bool ext_notification_plugin_enabled = 126; bool ext_notification_plugin_active = 129; @@ -72,13 +72,13 @@ int32_t ExternalNotificationPlugin::runOnce() } } else { - /* + if (externalCurrentState) { - 1) If GPIO is turned on ... - 2) Check the timer. If the timer has elapsed more time than - our set limit, turn the GPIO off. - - */ + // TODO: Test this part. Don't know if this should be greater than or less than. + if (externalTurnedOn + EXT_NOTIFICATION_PLUGIN_OUTPUT_MS < millis()) { + setExternalOff(); + } + } } return (25); @@ -94,6 +94,7 @@ int32_t ExternalNotificationPlugin::runOnce() void ExternalNotificationPlugin::setExternalOn() { externalCurrentState = 1; + externalTurnedOn = millis(); // if ext_notification_plugin_active if (EXT_NOTIFICATION_PLUGIN_ACTIVE) { @@ -140,20 +141,12 @@ bool ExternalNotificationPluginRadio::handleReceived(const MeshPacket &mp) for (int i = 0; i < p.payload.size; i++) { if (p.payload.bytes[i] == ASCII_BELL) { externalNotificationPlugin->setExternalOn(); - - // TODO: Make this non-blocking. - delay(EXT_NOTIFICATION_PLUGIN_OUTPUT_MS); - externalNotificationPlugin->setExternalOff(); } } } if (EXT_NOTIFICATION_PLUGIN_ALERT_MESSAGE) { externalNotificationPlugin->setExternalOn(); - - // TODO: Make this non-blocking. - delay(EXT_NOTIFICATION_PLUGIN_OUTPUT_MS); - externalNotificationPlugin->setExternalOff(); } } diff --git a/src/plugins/ExternalNotificationPlugin.h b/src/plugins/ExternalNotificationPlugin.h index ff36c2a77..6de72fda6 100644 --- a/src/plugins/ExternalNotificationPlugin.h +++ b/src/plugins/ExternalNotificationPlugin.h @@ -11,6 +11,7 @@ class ExternalNotificationPlugin : private concurrency::OSThread { bool firstTime = 1; bool externalCurrentState = 0; + uint32_t externalTurnedOn = 0; public: ExternalNotificationPlugin();