mirror of
https://github.com/meshtastic/firmware.git
synced 2025-05-11 15:40:48 +00:00
Update comments and use radioConfig
This commit is contained in:
parent
aee81c8dcd
commit
6cef3e41e7
@ -14,21 +14,32 @@ This plugin supports:
|
|||||||
https://github.com/meshtastic/Meshtastic-device/issues/654
|
https://github.com/meshtastic/Meshtastic-device/issues/654
|
||||||
|
|
||||||
|
|
||||||
bool ext_notification_plugin_enabled = 126;
|
radioConfig.preferences.ext_notification_plugin_enabled
|
||||||
bool ext_notification_plugin_active = 129;
|
0 = Disabled (Default)
|
||||||
bool ext_notification_plugin_alert_message = 130;
|
1 = Enabled
|
||||||
bool ext_notification_plugin_alert_bell = 131;
|
|
||||||
uint32 ext_notification_plugin_output = 128;
|
|
||||||
|
|
||||||
|
radioConfig.preferences.ext_notification_plugin_active
|
||||||
|
0 = Active Low (Default)
|
||||||
|
1 = Active High
|
||||||
|
|
||||||
uint32 ext_notification_plugin_output_ms = 127;
|
radioConfig.preferences.ext_notification_plugin_alert_message
|
||||||
|
0 = Disabled (Default)
|
||||||
|
1 = Alert when a text message comes
|
||||||
|
|
||||||
|
radioConfig.preferences.ext_notification_plugin_alert_bell
|
||||||
|
0 = Disabled (Default)
|
||||||
|
1 = Alert when the bell character is received
|
||||||
|
|
||||||
|
radioConfig.preferences.ext_notification_plugin_output
|
||||||
|
GPIO of the output. (Default = 13)
|
||||||
|
|
||||||
|
radioConfig.preferences.ext_notification_plugin_output_ms
|
||||||
|
Amount of time in ms for the alert. Default is 1000.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define EXT_NOTIFICATION_PLUGIN_ENABLED 0
|
|
||||||
#define EXT_NOTIFICATION_PLUGIN_ACTIVE 0
|
// Default configurations
|
||||||
#define EXT_NOTIFICATION_PLUGIN_ALERT_MESSAGE 0
|
|
||||||
#define EXT_NOTIFICATION_PLUGIN_ALERT_BELL 0
|
|
||||||
#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
|
||||||
|
|
||||||
@ -49,40 +60,27 @@ int32_t ExternalNotificationPlugin::runOnce()
|
|||||||
/*
|
/*
|
||||||
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.
|
||||||
|
|
||||||
EXT_NOTIFICATION_PLUGIN_ENABLED
|
|
||||||
0 = Disabled (Default)
|
|
||||||
1 = Enabled
|
|
||||||
|
|
||||||
EXT_NOTIFICATION_PLUGIN_ACTIVE
|
|
||||||
0 = Active Low (Default)
|
|
||||||
1 = Active High
|
|
||||||
|
|
||||||
EXT_NOTIFICATION_PLUGIN_ALERT_MESSAGE
|
|
||||||
0 = Disabled (Default)
|
|
||||||
1 = Alert when a text message comes
|
|
||||||
|
|
||||||
EXT_NOTIFICATION_PLUGIN_ALERT_BELL
|
|
||||||
0 = Disabled (Default)
|
|
||||||
1 = Alert when the bell character is received
|
|
||||||
|
|
||||||
EXT_NOTIFICATION_PLUGIN_OUTPUT
|
|
||||||
GPIO of the output. (Default = 13)
|
|
||||||
|
|
||||||
EXT_NOTIFICATION_PLUGIN_OUTPUT_MS
|
|
||||||
Amount of time in ms for the alert. Default is 1000.
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (EXT_NOTIFICATION_PLUGIN_ENABLED) {
|
// 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) {
|
||||||
|
|
||||||
if (firstTime) {
|
if (firstTime) {
|
||||||
|
|
||||||
DEBUG_MSG("Initializing External Notification Plugin\n");
|
DEBUG_MSG("Initializing External Notification Plugin\n");
|
||||||
|
|
||||||
// Set the direction of a pin
|
// Set the direction of a pin
|
||||||
pinMode(EXT_NOTIFICATION_PLUGIN_OUTPUT, OUTPUT);
|
pinMode((radioConfig.preferences.ext_notification_plugin_output
|
||||||
|
? radioConfig.preferences.ext_notification_plugin_output
|
||||||
|
: EXT_NOTIFICATION_PLUGIN_OUTPUT),
|
||||||
|
OUTPUT);
|
||||||
|
|
||||||
// Turn off the pin
|
// Turn off the pin
|
||||||
setExternalOff();
|
setExternalOff();
|
||||||
@ -95,7 +93,10 @@ int32_t ExternalNotificationPlugin::runOnce()
|
|||||||
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.
|
||||||
if (externalTurnedOn + EXT_NOTIFICATION_PLUGIN_OUTPUT_MS < millis()) {
|
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");
|
DEBUG_MSG("Turning off external notification\n");
|
||||||
setExternalOff();
|
setExternalOff();
|
||||||
}
|
}
|
||||||
@ -117,16 +118,18 @@ void ExternalNotificationPlugin::setExternalOn()
|
|||||||
externalCurrentState = 1;
|
externalCurrentState = 1;
|
||||||
externalTurnedOn = millis();
|
externalTurnedOn = millis();
|
||||||
|
|
||||||
// if ext_notification_plugin_active
|
digitalWrite((radioConfig.preferences.ext_notification_plugin_output ? radioConfig.preferences.ext_notification_plugin_output
|
||||||
digitalWrite(EXT_NOTIFICATION_PLUGIN_OUTPUT, (EXT_NOTIFICATION_PLUGIN_ACTIVE ? true : false));
|
: EXT_NOTIFICATION_PLUGIN_OUTPUT),
|
||||||
|
(radioConfig.preferences.ext_notification_plugin_active ? true : false));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExternalNotificationPlugin::setExternalOff()
|
void ExternalNotificationPlugin::setExternalOff()
|
||||||
{
|
{
|
||||||
externalCurrentState = 0;
|
externalCurrentState = 0;
|
||||||
|
|
||||||
// if ext_notification_plugin_active
|
digitalWrite((radioConfig.preferences.ext_notification_plugin_output ? radioConfig.preferences.ext_notification_plugin_output
|
||||||
digitalWrite(EXT_NOTIFICATION_PLUGIN_OUTPUT, (EXT_NOTIFICATION_PLUGIN_ACTIVE ? false : true));
|
: EXT_NOTIFICATION_PLUGIN_OUTPUT),
|
||||||
|
(radioConfig.preferences.ext_notification_plugin_active ? false : true));
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------
|
// --------
|
||||||
@ -135,15 +138,16 @@ bool ExternalNotificationPluginRadio::handleReceived(const MeshPacket &mp)
|
|||||||
{
|
{
|
||||||
#ifndef NO_ESP32
|
#ifndef NO_ESP32
|
||||||
|
|
||||||
if (EXT_NOTIFICATION_PLUGIN_ENABLED) {
|
if (radioConfig.preferences.ext_notification_plugin_enabled) {
|
||||||
|
|
||||||
auto &p = mp.decoded.data;
|
auto &p = mp.decoded.data;
|
||||||
// DEBUG_MSG("Processing handleReceived\n");
|
|
||||||
|
|
||||||
if (mp.from != nodeDB.getNodeNum()) {
|
if (mp.from != nodeDB.getNodeNum()) {
|
||||||
DEBUG_MSG("handleReceived from some other device\n");
|
|
||||||
|
|
||||||
if (EXT_NOTIFICATION_PLUGIN_ALERT_BELL) {
|
// TODO: This may be a problem if messages are sent in unicide, but I'm not sure if it will.
|
||||||
|
// Need to know if and how this could be a problem.
|
||||||
|
if (radioConfig.preferences.ext_notification_plugin_alert_bell) {
|
||||||
|
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();
|
externalNotificationPlugin->setExternalOn();
|
||||||
@ -151,8 +155,8 @@ bool ExternalNotificationPluginRadio::handleReceived(const MeshPacket &mp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EXT_NOTIFICATION_PLUGIN_ALERT_MESSAGE) {
|
if (radioConfig.preferences.ext_notification_plugin_alert_message) {
|
||||||
// DEBUG_MSG("Turning on alert\n");
|
DEBUG_MSG("externalNotificationPlugin - Notification Plugin\n");
|
||||||
externalNotificationPlugin->setExternalOn();
|
externalNotificationPlugin->setExternalOn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user