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,48 +67,19 @@ 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 (externalCurrentState) {
|
||||||
|
|
||||||
if (firstTime) {
|
// If the output is turned on, turn it back off after the given period of time.
|
||||||
|
if (externalTurnedOn + (radioConfig.preferences.ext_notification_plugin_output_ms
|
||||||
DEBUG_MSG("Initializing External Notification Plugin\n");
|
? radioConfig.preferences.ext_notification_plugin_output_ms
|
||||||
|
: EXT_NOTIFICATION_PLUGIN_OUTPUT_MS) <
|
||||||
// Set the direction of a pin
|
millis()) {
|
||||||
pinMode((radioConfig.preferences.ext_notification_plugin_output
|
DEBUG_MSG("Turning off external notification\n");
|
||||||
? radioConfig.preferences.ext_notification_plugin_output
|
|
||||||
: EXT_NOTIFICATION_PLUGIN_OUTPUT),
|
|
||||||
OUTPUT);
|
|
||||||
|
|
||||||
// Turn off the pin
|
|
||||||
setExternalOff();
|
setExternalOff();
|
||||||
|
|
||||||
externalNotificationPluginRadio = new ExternalNotificationPluginRadio();
|
|
||||||
|
|
||||||
firstTime = 0;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (externalCurrentState) {
|
|
||||||
|
|
||||||
// If the output is turned on, turn it back off after the given period of time.
|
|
||||||
if (externalTurnedOn + (radioConfig.preferences.ext_notification_plugin_output_ms
|
|
||||||
? radioConfig.preferences.ext_notification_plugin_output_ms
|
|
||||||
: EXT_NOTIFICATION_PLUGIN_OUTPUT_MS) <
|
|
||||||
millis()) {
|
|
||||||
DEBUG_MSG("Turning off external notification\n");
|
|
||||||
setExternalOff();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (25);
|
|
||||||
} else {
|
|
||||||
DEBUG_MSG("External Notification Plugin Disabled\n");
|
|
||||||
|
|
||||||
return (INT32_MAX);
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
return INT32_MAX;
|
return (25);
|
||||||
#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();
|
||||||
|
|
||||||
|
@ -19,29 +20,13 @@ class ExternalNotificationPlugin : private concurrency::OSThread
|
||||||
void getExternal();
|
void getExternal();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int32_t runOnce();
|
// virtual MeshPacket *allocReply();
|
||||||
};
|
|
||||||
|
|
||||||
extern ExternalNotificationPlugin *externalNotificationPlugin;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Radio interface for ExternalNotificationPlugin
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class ExternalNotificationPluginRadio : public SinglePortPlugin
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
ExternalNotificationPluginRadio();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
//virtual MeshPacket *allocReply();
|
|
||||||
|
|
||||||
/** Called to handle a particular incoming message
|
/** 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
|
@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