From eff0c1fe892e9b70f4bb4b889aedda31495dd627 Mon Sep 17 00:00:00 2001 From: Jm Date: Wed, 27 Jan 2021 19:18:16 -0800 Subject: [PATCH] #654 - Partial work for the LED/Speaker. Framework is done. Just need to blink a few things and update protobufs. --- src/plugins/ExternalNotificationPlugin.cpp | 108 +++++++++++++++++++++ src/plugins/ExternalNotificationPlugin.h | 43 ++++++++ src/plugins/Plugins.cpp | 5 +- 3 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 src/plugins/ExternalNotificationPlugin.cpp create mode 100644 src/plugins/ExternalNotificationPlugin.h diff --git a/src/plugins/ExternalNotificationPlugin.cpp b/src/plugins/ExternalNotificationPlugin.cpp new file mode 100644 index 00000000..f2cee7cf --- /dev/null +++ b/src/plugins/ExternalNotificationPlugin.cpp @@ -0,0 +1,108 @@ +#include "ExternalNotificationPlugin.h" +#include "MeshService.h" +#include "NodeDB.h" +#include "RTC.h" +#include "Router.h" +#include "configuration.h" +#include + +#include + +/* + + bool ext_notification_plugin_enabled = 126; + uint32 ext_notification_plugin_output_ms = 127; + uint32 ext_notification_plugin_output = 128; + bool ext_notification_plugin_active = 129; + bool ext_notification_plugin_alert_message = 130; + bool ext_notification_plugin_alert_bell = 131; + +*/ + +ExternalNotificationPlugin *externalNotificationPlugin; +ExternalNotificationPluginRadio *externalNotificationPluginRadio; + +ExternalNotificationPlugin::ExternalNotificationPlugin() : concurrency::OSThread("ExternalNotificationPlugin") {} + +int32_t ExternalNotificationPlugin::runOnce() +{ +#ifndef NO_ESP32 + + /* + Uncomment the preferences below if you want to use the plugin + without having to configure it from the PythonAPI or WebUI. + */ + + // radioConfig.preferences.externalnotificationplugin_enabled = 1; + // radioConfig.preferences.externalnotificationplugin_mode = 1; + + if (0) { + + if (firstTime) { + + DEBUG_MSG("Initializing External Notification Plugin\n"); + + externalNotificationPluginRadio = new ExternalNotificationPluginRadio(); + + firstTime = 0; + + } else { + /* + + 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. + + */ + } + + return (25); + } else { + DEBUG_MSG("External Notification Plugin Disabled\n"); + + return (INT32_MAX); + } + +#endif +} + +// -------- + +MeshPacket *ExternalNotificationPluginRadio::allocReply() +{ + + auto reply = allocDataPacket(); // Allocate a packet for sending + + return reply; +} + +bool ExternalNotificationPluginRadio::handleReceived(const MeshPacket &mp) +{ +#ifndef NO_ESP32 + + if (0) { + + auto &p = mp.decoded.data; + + if (mp.from != nodeDB.getNodeNum()) { + + /* + TODO: If ext_notification_plugin_alert_bell is true and we see a bell character, trigger an external notification. + */ + // TODO: Check p.payload.bytes to see if it contains a bell character. If it does, trigger an external notifcation. + + /* + TODO: If ext_notification_plugin_alert_message is true, trigger an external notification. + */ + // TODO: On received packet, blink the LED. + + } + + } else { + DEBUG_MSG("External Notification Plugin Disabled\n"); + } + +#endif + + return true; // Let others look at this message also if they want +} diff --git a/src/plugins/ExternalNotificationPlugin.h b/src/plugins/ExternalNotificationPlugin.h new file mode 100644 index 00000000..b8eeffe4 --- /dev/null +++ b/src/plugins/ExternalNotificationPlugin.h @@ -0,0 +1,43 @@ +#pragma once + +#include "SinglePortPlugin.h" +#include "concurrency/OSThread.h" +#include "configuration.h" +#include +#include + + +class ExternalNotificationPlugin : private concurrency::OSThread +{ + bool firstTime = 1; + + public: + ExternalNotificationPlugin(); + + protected: + virtual int32_t runOnce(); +}; + +extern ExternalNotificationPlugin *externalNotificationPlugin; + +/* + * Radio interface for ExternalNotificationPlugin + * + */ +class ExternalNotificationPluginRadio : public SinglePortPlugin +{ + + public: + ExternalNotificationPluginRadio() : SinglePortPlugin("ExternalNotificationPluginRadio", PortNum_TEXT_MESSAGE_APP) {} + + protected: + virtual MeshPacket *allocReply(); + + /** Called to handle a particular incoming message + + @return true if you've guaranteed you've handled this message and no other handlers should be considered for it + */ + virtual bool handleReceived(const MeshPacket &mp); +}; + +extern ExternalNotificationPluginRadio *externalNotificationPluginRadio; \ No newline at end of file diff --git a/src/plugins/Plugins.cpp b/src/plugins/Plugins.cpp index 096b9cf5..90a1b554 100644 --- a/src/plugins/Plugins.cpp +++ b/src/plugins/Plugins.cpp @@ -1,3 +1,4 @@ +#include "plugins/ExternalNotificationPlugin.h" #include "plugins/NodeInfoPlugin.h" #include "plugins/PositionPlugin.h" #include "plugins/RemoteHardwarePlugin.h" @@ -23,7 +24,7 @@ void setupPlugins() #ifndef NO_ESP32 // Only run on an esp32 based device. - new SerialPlugin(); // Maintained by MC Hamster (Jm Casler) jm@casler.org + new SerialPlugin(); // Maintained by MC Hamster (Jm Casler) jm@casler.org + new ExternalNotificationPlugin(); // Maintained by MC Hamster (Jm Casler) jm@casler.org #endif - } \ No newline at end of file