From d4ddcdd91e7a5fc82bae82c37713410d136ea5e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 22 Oct 2022 13:35:34 +0200 Subject: [PATCH 1/3] use PWM buzzer on notification module. To activate set moduleConfig.external_notification.output equal to the PIN_BUZZER. If another value is set, the traditional digital mode is used --- src/modules/ExternalNotificationModule.cpp | 48 ++++++++++++++-------- src/modules/ExternalNotificationModule.h | 2 + 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/modules/ExternalNotificationModule.cpp b/src/modules/ExternalNotificationModule.cpp index 7e776f172..dbe8e01f4 100644 --- a/src/modules/ExternalNotificationModule.cpp +++ b/src/modules/ExternalNotificationModule.cpp @@ -3,9 +3,14 @@ #include "NodeDB.h" #include "RTC.h" #include "Router.h" +#include "buzz/buzz.h" #include "configuration.h" #include +#ifndef PIN_BUZZER +#define PIN_BUZZER false +#endif + //#include /* @@ -75,7 +80,9 @@ int32_t ExternalNotificationModule::runOnce() : EXT_NOTIFICATION_MODULE_OUTPUT_MS) < millis()) { DEBUG_MSG("Turning off external notification\n"); - setExternalOff(); + if (output != PIN_BUZZER) { + setExternalOff(); + } } } @@ -88,9 +95,7 @@ void ExternalNotificationModule::setExternalOn() externalCurrentState = 1; externalTurnedOn = millis(); - digitalWrite((moduleConfig.external_notification.output - ? moduleConfig.external_notification.output - : EXT_NOTIFICATION_MODULE_OUTPUT), + digitalWrite(output, (moduleConfig.external_notification.active ? true : false)); #endif } @@ -100,9 +105,7 @@ void ExternalNotificationModule::setExternalOff() #ifdef EXT_NOTIFY_OUT externalCurrentState = 0; - digitalWrite((moduleConfig.external_notification.output - ? moduleConfig.external_notification.output - : EXT_NOTIFICATION_MODULE_OUTPUT), + digitalWrite(output, (moduleConfig.external_notification.active ? false : true)); #endif } @@ -135,14 +138,19 @@ ExternalNotificationModule::ExternalNotificationModule() DEBUG_MSG("Initializing External Notification Module\n"); - // Set the direction of a pin - pinMode((moduleConfig.external_notification.output - ? moduleConfig.external_notification.output - : EXT_NOTIFICATION_MODULE_OUTPUT), - OUTPUT); + output = moduleConfig.external_notification.output + ? moduleConfig.external_notification.output + : EXT_NOTIFICATION_MODULE_OUTPUT; - // Turn off the pin - setExternalOff(); + if (output != PIN_BUZZER) { + // Set the direction of a pin + DEBUG_MSG("Using Pin %i in digital mode\n", output); + pinMode(output, OUTPUT); + // Turn off the pin + setExternalOff(); + } else{ + DEBUG_MSG("Using Pin %i in PWM mode\n", output); + } } else { DEBUG_MSG("External Notification Module Disabled\n"); enabled = false; @@ -165,14 +173,22 @@ ProcessMessage ExternalNotificationModule::handleReceived(const MeshPacket &mp) DEBUG_MSG("externalNotificationModule - Notification Bell\n"); for (int i = 0; i < p.payload.size; i++) { if (p.payload.bytes[i] == ASCII_BELL) { - setExternalOn(); + if (output != PIN_BUZZER) { + setExternalOn(); + } else { + playBeep(); + } } } } if (moduleConfig.external_notification.alert_message) { DEBUG_MSG("externalNotificationModule - Notification Module\n"); - setExternalOn(); + if (output != PIN_BUZZER) { + setExternalOn(); + } else { + playBeep(); + } } } diff --git a/src/modules/ExternalNotificationModule.h b/src/modules/ExternalNotificationModule.h index a671d67c2..6fb45e7e2 100644 --- a/src/modules/ExternalNotificationModule.h +++ b/src/modules/ExternalNotificationModule.h @@ -12,6 +12,8 @@ */ class ExternalNotificationModule : public SinglePortModule, private concurrency::OSThread { + uint32_t output = EXT_NOTIFY_OUT; + public: ExternalNotificationModule(); From d8178892552be507b0bd527ba5f3bc032067cbda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 22 Oct 2022 13:45:43 +0200 Subject: [PATCH 2/3] don't depend on EXT_NOTIFY_OUT being defined. --- src/modules/ExternalNotificationModule.cpp | 10 ---------- src/modules/ExternalNotificationModule.h | 4 ++-- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/modules/ExternalNotificationModule.cpp b/src/modules/ExternalNotificationModule.cpp index dbe8e01f4..90fbf28f0 100644 --- a/src/modules/ExternalNotificationModule.cpp +++ b/src/modules/ExternalNotificationModule.cpp @@ -91,23 +91,19 @@ int32_t ExternalNotificationModule::runOnce() void ExternalNotificationModule::setExternalOn() { -#ifdef EXT_NOTIFY_OUT externalCurrentState = 1; externalTurnedOn = millis(); digitalWrite(output, (moduleConfig.external_notification.active ? true : false)); -#endif } void ExternalNotificationModule::setExternalOff() { -#ifdef EXT_NOTIFY_OUT externalCurrentState = 0; digitalWrite(output, (moduleConfig.external_notification.active ? false : true)); -#endif } // -------- @@ -119,8 +115,6 @@ ExternalNotificationModule::ExternalNotificationModule() // restrict to the admin channel for rx boundChannel = Channels::gpioChannel; -#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. @@ -155,13 +149,10 @@ ExternalNotificationModule::ExternalNotificationModule() DEBUG_MSG("External Notification Module Disabled\n"); enabled = false; } -#endif } ProcessMessage ExternalNotificationModule::handleReceived(const MeshPacket &mp) { -#ifdef EXT_NOTIFY_OUT - if (moduleConfig.external_notification.enabled) { if (getFrom(&mp) != nodeDB.getNodeNum()) { @@ -195,7 +186,6 @@ ProcessMessage ExternalNotificationModule::handleReceived(const MeshPacket &mp) } else { DEBUG_MSG("External Notification Module Disabled\n"); } -#endif return ProcessMessage::CONTINUE; // Let others look at this message also if they want } diff --git a/src/modules/ExternalNotificationModule.h b/src/modules/ExternalNotificationModule.h index 6fb45e7e2..b5ab64b3c 100644 --- a/src/modules/ExternalNotificationModule.h +++ b/src/modules/ExternalNotificationModule.h @@ -12,8 +12,8 @@ */ class ExternalNotificationModule : public SinglePortModule, private concurrency::OSThread { - uint32_t output = EXT_NOTIFY_OUT; - + uint32_t output = 0; + public: ExternalNotificationModule(); From 62b350900951ac714b8c7dc0e648c7aac30f2fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 22 Oct 2022 14:13:45 +0200 Subject: [PATCH 3/3] missed one --- src/modules/ExternalNotificationModule.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/ExternalNotificationModule.cpp b/src/modules/ExternalNotificationModule.cpp index 90fbf28f0..56a0db941 100644 --- a/src/modules/ExternalNotificationModule.cpp +++ b/src/modules/ExternalNotificationModule.cpp @@ -49,7 +49,11 @@ */ // Default configurations +#ifdef EXT_NOTIFY_OUT #define EXT_NOTIFICATION_MODULE_OUTPUT EXT_NOTIFY_OUT +#else +#define EXT_NOTIFICATION_MODULE_OUTPUT 0 +#endif #define EXT_NOTIFICATION_MODULE_OUTPUT_MS 1000 #define ASCII_BELL 0x07