kopia lustrzana https://github.com/meshtastic/firmware
cleanup external notification plugin
rodzic
c0ac457cad
commit
a07291d904
|
@ -43,25 +43,17 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Default configurations
|
// Default configurations
|
||||||
#define EXT_NOTIFICATION_PLUGIN_OUTPUT 13
|
#define EXT_NOTIFICATION_PLUGIN_OUTPUT 13
|
||||||
#define EXT_NOTIFICATION_PLUGIN_OUTPUT_MS 1000
|
#define EXT_NOTIFICATION_PLUGIN_OUTPUT_MS 1000
|
||||||
|
|
||||||
#define ASCII_BELL 0x07
|
#define ASCII_BELL 0x07
|
||||||
|
|
||||||
ExternalNotificationPlugin *externalNotificationPlugin;
|
|
||||||
ExternalNotificationPluginRadio *externalNotificationPluginRadio;
|
|
||||||
|
|
||||||
ExternalNotificationPlugin::ExternalNotificationPlugin() : concurrency::OSThread("ExternalNotificationPlugin") {}
|
|
||||||
|
|
||||||
bool externalCurrentState = 0;
|
bool externalCurrentState = 0;
|
||||||
uint32_t externalTurnedOn = 0;
|
uint32_t externalTurnedOn = 0;
|
||||||
|
|
||||||
int32_t ExternalNotificationPlugin::runOnce()
|
int32_t ExternalNotificationPlugin::runOnce()
|
||||||
{
|
{
|
||||||
#ifndef NO_ESP32
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Uncomment the preferences below if you want to use the plugin
|
Uncomment the preferences below if you want to use the plugin
|
||||||
without having to configure it from the PythonAPI or WebUI.
|
without having to configure it from the PythonAPI or WebUI.
|
||||||
|
@ -75,26 +67,6 @@ int32_t ExternalNotificationPlugin::runOnce()
|
||||||
// radioConfig.preferences.ext_notification_plugin_output_ms = 1000;
|
// radioConfig.preferences.ext_notification_plugin_output_ms = 1000;
|
||||||
// radioConfig.preferences.ext_notification_plugin_output = 13;
|
// radioConfig.preferences.ext_notification_plugin_output = 13;
|
||||||
|
|
||||||
if (radioConfig.preferences.ext_notification_plugin_enabled) {
|
|
||||||
|
|
||||||
if (firstTime) {
|
|
||||||
|
|
||||||
DEBUG_MSG("Initializing External Notification Plugin\n");
|
|
||||||
|
|
||||||
// Set the direction of a pin
|
|
||||||
pinMode((radioConfig.preferences.ext_notification_plugin_output
|
|
||||||
? radioConfig.preferences.ext_notification_plugin_output
|
|
||||||
: EXT_NOTIFICATION_PLUGIN_OUTPUT),
|
|
||||||
OUTPUT);
|
|
||||||
|
|
||||||
// Turn off the pin
|
|
||||||
setExternalOff();
|
|
||||||
|
|
||||||
externalNotificationPluginRadio = new ExternalNotificationPluginRadio();
|
|
||||||
|
|
||||||
firstTime = 0;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (externalCurrentState) {
|
if (externalCurrentState) {
|
||||||
|
|
||||||
// If the output is turned on, turn it back off after the given period of time.
|
// If the output is turned on, turn it back off after the given period of time.
|
||||||
|
@ -106,17 +78,8 @@ int32_t ExternalNotificationPlugin::runOnce()
|
||||||
setExternalOff();
|
setExternalOff();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return (25);
|
return (25);
|
||||||
} else {
|
|
||||||
DEBUG_MSG("External Notification Plugin Disabled\n");
|
|
||||||
|
|
||||||
return (INT32_MAX);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
return INT32_MAX;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExternalNotificationPlugin::setExternalOn()
|
void ExternalNotificationPlugin::setExternalOn()
|
||||||
|
@ -140,12 +103,47 @@ void ExternalNotificationPlugin::setExternalOff()
|
||||||
|
|
||||||
// --------
|
// --------
|
||||||
|
|
||||||
ExternalNotificationPluginRadio::ExternalNotificationPluginRadio() : SinglePortPlugin("ExternalNotificationPluginRadio", PortNum_TEXT_MESSAGE_APP) {
|
ExternalNotificationPlugin::ExternalNotificationPlugin()
|
||||||
|
: SinglePortPlugin("ExternalNotificationPlugin", PortNum_TEXT_MESSAGE_APP), concurrency::OSThread(
|
||||||
|
"ExternalNotificationPlugin")
|
||||||
|
{
|
||||||
// restrict to the admin channel for rx
|
// restrict to the admin channel for rx
|
||||||
boundChannel = Channels::gpioChannel;
|
boundChannel = Channels::gpioChannel;
|
||||||
|
|
||||||
|
#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.ext_notification_plugin_enabled = 1;
|
||||||
|
// radioConfig.preferences.ext_notification_plugin_alert_message = 1;
|
||||||
|
|
||||||
|
// radioConfig.preferences.ext_notification_plugin_active = 1;
|
||||||
|
// radioConfig.preferences.ext_notification_plugin_alert_bell = 1;
|
||||||
|
// radioConfig.preferences.ext_notification_plugin_output_ms = 1000;
|
||||||
|
// radioConfig.preferences.ext_notification_plugin_output = 13;
|
||||||
|
|
||||||
|
if (radioConfig.preferences.ext_notification_plugin_enabled) {
|
||||||
|
|
||||||
|
DEBUG_MSG("Initializing External Notification Plugin\n");
|
||||||
|
|
||||||
|
// Set the direction of a pin
|
||||||
|
pinMode((radioConfig.preferences.ext_notification_plugin_output ? radioConfig.preferences.ext_notification_plugin_output
|
||||||
|
: EXT_NOTIFICATION_PLUGIN_OUTPUT),
|
||||||
|
OUTPUT);
|
||||||
|
|
||||||
|
// Turn off the pin
|
||||||
|
setExternalOff();
|
||||||
|
} else {
|
||||||
|
DEBUG_MSG("External Notification Plugin Disabled\n");
|
||||||
|
enabled = false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ExternalNotificationPluginRadio::handleReceived(const MeshPacket &mp)
|
bool ExternalNotificationPlugin::handleReceived(const MeshPacket &mp)
|
||||||
{
|
{
|
||||||
#ifndef NO_ESP32
|
#ifndef NO_ESP32
|
||||||
|
|
||||||
|
@ -161,14 +159,14 @@ bool ExternalNotificationPluginRadio::handleReceived(const MeshPacket &mp)
|
||||||
DEBUG_MSG("externalNotificationPlugin - Notification Bell\n");
|
DEBUG_MSG("externalNotificationPlugin - Notification Bell\n");
|
||||||
for (int i = 0; i < p.payload.size; i++) {
|
for (int i = 0; i < p.payload.size; i++) {
|
||||||
if (p.payload.bytes[i] == ASCII_BELL) {
|
if (p.payload.bytes[i] == ASCII_BELL) {
|
||||||
externalNotificationPlugin->setExternalOn();
|
setExternalOn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (radioConfig.preferences.ext_notification_plugin_alert_message) {
|
if (radioConfig.preferences.ext_notification_plugin_alert_message) {
|
||||||
DEBUG_MSG("externalNotificationPlugin - Notification Plugin\n");
|
DEBUG_MSG("externalNotificationPlugin - Notification Plugin\n");
|
||||||
externalNotificationPlugin->setExternalOn();
|
setExternalOn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,12 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
/*
|
||||||
class ExternalNotificationPlugin : private concurrency::OSThread
|
* Radio interface for ExternalNotificationPlugin
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class ExternalNotificationPlugin : public SinglePortPlugin, private concurrency::OSThread
|
||||||
{
|
{
|
||||||
bool firstTime = 1;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ExternalNotificationPlugin();
|
ExternalNotificationPlugin();
|
||||||
|
|
||||||
|
@ -18,22 +19,6 @@ class ExternalNotificationPlugin : private concurrency::OSThread
|
||||||
void setExternalOff();
|
void setExternalOff();
|
||||||
void getExternal();
|
void getExternal();
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual int32_t runOnce();
|
|
||||||
};
|
|
||||||
|
|
||||||
extern ExternalNotificationPlugin *externalNotificationPlugin;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Radio interface for ExternalNotificationPlugin
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class ExternalNotificationPluginRadio : public SinglePortPlugin
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
ExternalNotificationPluginRadio();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// virtual MeshPacket *allocReply();
|
// virtual MeshPacket *allocReply();
|
||||||
|
|
||||||
|
@ -42,6 +27,6 @@ class ExternalNotificationPluginRadio : public SinglePortPlugin
|
||||||
@return true if you've guaranteed you've handled this message and no other handlers should be considered for it
|
@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);
|
virtual bool handleReceived(const MeshPacket &mp);
|
||||||
};
|
|
||||||
|
|
||||||
extern ExternalNotificationPluginRadio *externalNotificationPluginRadio;
|
virtual int32_t runOnce();
|
||||||
|
};
|
||||||
|
|
Ładowanie…
Reference in New Issue