mirror of
https://github.com/meshtastic/firmware.git
synced 2025-05-06 21:58:24 +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
|
||||
|
||||
|
||||
bool ext_notification_plugin_enabled = 126;
|
||||
bool ext_notification_plugin_active = 129;
|
||||
bool ext_notification_plugin_alert_message = 130;
|
||||
bool ext_notification_plugin_alert_bell = 131;
|
||||
uint32 ext_notification_plugin_output = 128;
|
||||
radioConfig.preferences.ext_notification_plugin_enabled
|
||||
0 = Disabled (Default)
|
||||
1 = Enabled
|
||||
|
||||
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
|
||||
#define EXT_NOTIFICATION_PLUGIN_ALERT_MESSAGE 0
|
||||
#define EXT_NOTIFICATION_PLUGIN_ALERT_BELL 0
|
||||
|
||||
// Default configurations
|
||||
#define EXT_NOTIFICATION_PLUGIN_OUTPUT 13
|
||||
#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
|
||||
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) {
|
||||
|
||||
DEBUG_MSG("Initializing External Notification Plugin\n");
|
||||
|
||||
// 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
|
||||
setExternalOff();
|
||||
@ -95,7 +93,10 @@ int32_t ExternalNotificationPlugin::runOnce()
|
||||
if (externalCurrentState) {
|
||||
|
||||
// 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");
|
||||
setExternalOff();
|
||||
}
|
||||
@ -117,16 +118,18 @@ void ExternalNotificationPlugin::setExternalOn()
|
||||
externalCurrentState = 1;
|
||||
externalTurnedOn = millis();
|
||||
|
||||
// if ext_notification_plugin_active
|
||||
digitalWrite(EXT_NOTIFICATION_PLUGIN_OUTPUT, (EXT_NOTIFICATION_PLUGIN_ACTIVE ? true : false));
|
||||
digitalWrite((radioConfig.preferences.ext_notification_plugin_output ? radioConfig.preferences.ext_notification_plugin_output
|
||||
: EXT_NOTIFICATION_PLUGIN_OUTPUT),
|
||||
(radioConfig.preferences.ext_notification_plugin_active ? true : false));
|
||||
}
|
||||
|
||||
void ExternalNotificationPlugin::setExternalOff()
|
||||
{
|
||||
externalCurrentState = 0;
|
||||
|
||||
// if ext_notification_plugin_active
|
||||
digitalWrite(EXT_NOTIFICATION_PLUGIN_OUTPUT, (EXT_NOTIFICATION_PLUGIN_ACTIVE ? false : true));
|
||||
digitalWrite((radioConfig.preferences.ext_notification_plugin_output ? radioConfig.preferences.ext_notification_plugin_output
|
||||
: 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
|
||||
|
||||
if (EXT_NOTIFICATION_PLUGIN_ENABLED) {
|
||||
if (radioConfig.preferences.ext_notification_plugin_enabled) {
|
||||
|
||||
auto &p = mp.decoded.data;
|
||||
// DEBUG_MSG("Processing handleReceived\n");
|
||||
|
||||
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++) {
|
||||
if (p.payload.bytes[i] == ASCII_BELL) {
|
||||
externalNotificationPlugin->setExternalOn();
|
||||
@ -151,8 +155,8 @@ bool ExternalNotificationPluginRadio::handleReceived(const MeshPacket &mp)
|
||||
}
|
||||
}
|
||||
|
||||
if (EXT_NOTIFICATION_PLUGIN_ALERT_MESSAGE) {
|
||||
// DEBUG_MSG("Turning on alert\n");
|
||||
if (radioConfig.preferences.ext_notification_plugin_alert_message) {
|
||||
DEBUG_MSG("externalNotificationPlugin - Notification Plugin\n");
|
||||
externalNotificationPlugin->setExternalOn();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user