mirror of
https://github.com/meshtastic/firmware.git
synced 2026-02-01 11:11:11 -05:00
Finish config transition
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#include "configuration.h"
|
||||
#include "ExternalNotificationModule.h"
|
||||
#include "MeshService.h"
|
||||
#include "NodeDB.h"
|
||||
#include "RTC.h"
|
||||
#include "Router.h"
|
||||
#include "configuration.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
//#include <assert.h>
|
||||
@@ -19,26 +19,26 @@
|
||||
|
||||
Quick reference:
|
||||
|
||||
radioConfig.preferences.ext_notification_module_enabled
|
||||
moduleConfig.payloadVariant.external_notification.enabled
|
||||
0 = Disabled (Default)
|
||||
1 = Enabled
|
||||
|
||||
radioConfig.preferences.ext_notification_module_active
|
||||
moduleConfig.payloadVariant.external_notification.active
|
||||
0 = Active Low (Default)
|
||||
1 = Active High
|
||||
|
||||
radioConfig.preferences.ext_notification_module_alert_message
|
||||
moduleConfig.payloadVariant.external_notification.alert_message
|
||||
0 = Disabled (Default)
|
||||
1 = Alert when a text message comes
|
||||
|
||||
radioConfig.preferences.ext_notification_module_alert_bell
|
||||
moduleConfig.payloadVariant.external_notification.alert_bell
|
||||
0 = Disabled (Default)
|
||||
1 = Alert when the bell character is received
|
||||
|
||||
radioConfig.preferences.ext_notification_module_output
|
||||
moduleConfig.payloadVariant.external_notification.output
|
||||
GPIO of the output. (Default = 13)
|
||||
|
||||
radioConfig.preferences.ext_notification_module_output_ms
|
||||
moduleConfig.payloadVariant.external_notification.output_ms
|
||||
Amount of time in ms for the alert. Default is 1000.
|
||||
|
||||
*/
|
||||
@@ -59,19 +59,19 @@ int32_t ExternalNotificationModule::runOnce()
|
||||
without having to configure it from the PythonAPI or WebUI.
|
||||
*/
|
||||
|
||||
// radioConfig.preferences.ext_notification_module_enabled = 1;
|
||||
// radioConfig.preferences.ext_notification_module_alert_message = 1;
|
||||
// moduleConfig.payloadVariant.external_notification.enabled = 1;
|
||||
// moduleConfig.payloadVariant.external_notification.alert_message = 1;
|
||||
|
||||
// radioConfig.preferences.ext_notification_module_active = 1;
|
||||
// radioConfig.preferences.ext_notification_module_alert_bell = 1;
|
||||
// radioConfig.preferences.ext_notification_module_output_ms = 1000;
|
||||
// radioConfig.preferences.ext_notification_module_output = 13;
|
||||
// moduleConfig.payloadVariant.external_notification.active = 1;
|
||||
// moduleConfig.payloadVariant.external_notification.alert_bell = 1;
|
||||
// moduleConfig.payloadVariant.external_notification.output_ms = 1000;
|
||||
// moduleConfig.payloadVariant.external_notification.output = 13;
|
||||
|
||||
if (externalCurrentState) {
|
||||
|
||||
// If the output is turned on, turn it back off after the given period of time.
|
||||
if (externalTurnedOn + (radioConfig.preferences.ext_notification_module_output_ms
|
||||
? radioConfig.preferences.ext_notification_module_output_ms
|
||||
if (externalTurnedOn + (moduleConfig.payloadVariant.external_notification.output_ms
|
||||
? moduleConfig.payloadVariant.external_notification.output_ms
|
||||
: EXT_NOTIFICATION_MODULE_OUTPUT_MS) <
|
||||
millis()) {
|
||||
DEBUG_MSG("Turning off external notification\n");
|
||||
@@ -84,59 +84,62 @@ int32_t ExternalNotificationModule::runOnce()
|
||||
|
||||
void ExternalNotificationModule::setExternalOn()
|
||||
{
|
||||
#ifdef EXT_NOTIFY_OUT
|
||||
#ifdef EXT_NOTIFY_OUT
|
||||
externalCurrentState = 1;
|
||||
externalTurnedOn = millis();
|
||||
|
||||
digitalWrite((radioConfig.preferences.ext_notification_module_output ? radioConfig.preferences.ext_notification_module_output
|
||||
: EXT_NOTIFICATION_MODULE_OUTPUT),
|
||||
(radioConfig.preferences.ext_notification_module_active ? true : false));
|
||||
#endif
|
||||
digitalWrite((moduleConfig.payloadVariant.external_notification.output
|
||||
? moduleConfig.payloadVariant.external_notification.output
|
||||
: EXT_NOTIFICATION_MODULE_OUTPUT),
|
||||
(moduleConfig.payloadVariant.external_notification.active ? true : false));
|
||||
#endif
|
||||
}
|
||||
|
||||
void ExternalNotificationModule::setExternalOff()
|
||||
{
|
||||
#ifdef EXT_NOTIFY_OUT
|
||||
#ifdef EXT_NOTIFY_OUT
|
||||
externalCurrentState = 0;
|
||||
|
||||
digitalWrite((radioConfig.preferences.ext_notification_module_output ? radioConfig.preferences.ext_notification_module_output
|
||||
: EXT_NOTIFICATION_MODULE_OUTPUT),
|
||||
(radioConfig.preferences.ext_notification_module_active ? false : true));
|
||||
#endif
|
||||
digitalWrite((moduleConfig.payloadVariant.external_notification.output
|
||||
? moduleConfig.payloadVariant.external_notification.output
|
||||
: EXT_NOTIFICATION_MODULE_OUTPUT),
|
||||
(moduleConfig.payloadVariant.external_notification.active ? false : true));
|
||||
#endif
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
ExternalNotificationModule::ExternalNotificationModule()
|
||||
: SinglePortModule("ExternalNotificationModule", PortNum_TEXT_MESSAGE_APP), concurrency::OSThread(
|
||||
"ExternalNotificationModule")
|
||||
"ExternalNotificationModule")
|
||||
{
|
||||
// restrict to the admin channel for rx
|
||||
boundChannel = Channels::gpioChannel;
|
||||
|
||||
#ifndef NO_ESP32
|
||||
#ifdef EXT_NOTIFY_OUT
|
||||
#ifdef EXT_NOTIFY_OUT
|
||||
|
||||
/*
|
||||
Uncomment the preferences below if you want to use the module
|
||||
without having to configure it from the PythonAPI or WebUI.
|
||||
*/
|
||||
|
||||
// radioConfig.preferences.ext_notification_module_enabled = 1;
|
||||
// radioConfig.preferences.ext_notification_module_alert_message = 1;
|
||||
// moduleConfig.payloadVariant.external_notification.enabled = 1;
|
||||
// moduleConfig.payloadVariant.external_notification.alert_message = 1;
|
||||
|
||||
// radioConfig.preferences.ext_notification_module_active = 1;
|
||||
// radioConfig.preferences.ext_notification_module_alert_bell = 1;
|
||||
// radioConfig.preferences.ext_notification_module_output_ms = 1000;
|
||||
// radioConfig.preferences.ext_notification_module_output = 13;
|
||||
// moduleConfig.payloadVariant.external_notification.active = 1;
|
||||
// moduleConfig.payloadVariant.external_notification.alert_bell = 1;
|
||||
// moduleConfig.payloadVariant.external_notification.output_ms = 1000;
|
||||
// moduleConfig.payloadVariant.external_notification.output = 13;
|
||||
|
||||
if (radioConfig.preferences.ext_notification_module_enabled) {
|
||||
if (moduleConfig.payloadVariant.external_notification.enabled) {
|
||||
|
||||
DEBUG_MSG("Initializing External Notification Module\n");
|
||||
|
||||
// Set the direction of a pin
|
||||
pinMode((radioConfig.preferences.ext_notification_module_output ? radioConfig.preferences.ext_notification_module_output
|
||||
: EXT_NOTIFICATION_MODULE_OUTPUT),
|
||||
pinMode((moduleConfig.payloadVariant.external_notification.output
|
||||
? moduleConfig.payloadVariant.external_notification.output
|
||||
: EXT_NOTIFICATION_MODULE_OUTPUT),
|
||||
OUTPUT);
|
||||
|
||||
// Turn off the pin
|
||||
@@ -145,22 +148,22 @@ ExternalNotificationModule::ExternalNotificationModule()
|
||||
DEBUG_MSG("External Notification Module Disabled\n");
|
||||
enabled = false;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
ProcessMessage ExternalNotificationModule::handleReceived(const MeshPacket &mp)
|
||||
{
|
||||
#ifndef NO_ESP32
|
||||
#ifdef EXT_NOTIFY_OUT
|
||||
#ifdef EXT_NOTIFY_OUT
|
||||
|
||||
if (radioConfig.preferences.ext_notification_module_enabled) {
|
||||
if (moduleConfig.payloadVariant.external_notification.enabled) {
|
||||
|
||||
if (getFrom(&mp) != nodeDB.getNodeNum()) {
|
||||
|
||||
// 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_module_alert_bell) {
|
||||
if (moduleConfig.payloadVariant.external_notification.alert_bell) {
|
||||
auto &p = mp.decoded;
|
||||
DEBUG_MSG("externalNotificationModule - Notification Bell\n");
|
||||
for (int i = 0; i < p.payload.size; i++) {
|
||||
@@ -170,7 +173,7 @@ ProcessMessage ExternalNotificationModule::handleReceived(const MeshPacket &mp)
|
||||
}
|
||||
}
|
||||
|
||||
if (radioConfig.preferences.ext_notification_module_alert_message) {
|
||||
if (moduleConfig.payloadVariant.external_notification.alert_message) {
|
||||
DEBUG_MSG("externalNotificationModule - Notification Module\n");
|
||||
setExternalOn();
|
||||
}
|
||||
@@ -179,7 +182,7 @@ ProcessMessage ExternalNotificationModule::handleReceived(const MeshPacket &mp)
|
||||
} else {
|
||||
DEBUG_MSG("External Notification Module Disabled\n");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user