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

This commit is contained in:
Thomas Göttgens 2022-10-22 13:35:34 +02:00
parent 0bda4c2f76
commit d4ddcdd91e
2 changed files with 34 additions and 16 deletions

View File

@ -3,9 +3,14 @@
#include "NodeDB.h" #include "NodeDB.h"
#include "RTC.h" #include "RTC.h"
#include "Router.h" #include "Router.h"
#include "buzz/buzz.h"
#include "configuration.h" #include "configuration.h"
#include <Arduino.h> #include <Arduino.h>
#ifndef PIN_BUZZER
#define PIN_BUZZER false
#endif
//#include <assert.h> //#include <assert.h>
/* /*
@ -75,7 +80,9 @@ int32_t ExternalNotificationModule::runOnce()
: EXT_NOTIFICATION_MODULE_OUTPUT_MS) < : EXT_NOTIFICATION_MODULE_OUTPUT_MS) <
millis()) { millis()) {
DEBUG_MSG("Turning off external notification\n"); DEBUG_MSG("Turning off external notification\n");
setExternalOff(); if (output != PIN_BUZZER) {
setExternalOff();
}
} }
} }
@ -88,9 +95,7 @@ void ExternalNotificationModule::setExternalOn()
externalCurrentState = 1; externalCurrentState = 1;
externalTurnedOn = millis(); externalTurnedOn = millis();
digitalWrite((moduleConfig.external_notification.output digitalWrite(output,
? moduleConfig.external_notification.output
: EXT_NOTIFICATION_MODULE_OUTPUT),
(moduleConfig.external_notification.active ? true : false)); (moduleConfig.external_notification.active ? true : false));
#endif #endif
} }
@ -100,9 +105,7 @@ void ExternalNotificationModule::setExternalOff()
#ifdef EXT_NOTIFY_OUT #ifdef EXT_NOTIFY_OUT
externalCurrentState = 0; externalCurrentState = 0;
digitalWrite((moduleConfig.external_notification.output digitalWrite(output,
? moduleConfig.external_notification.output
: EXT_NOTIFICATION_MODULE_OUTPUT),
(moduleConfig.external_notification.active ? false : true)); (moduleConfig.external_notification.active ? false : true));
#endif #endif
} }
@ -135,14 +138,19 @@ ExternalNotificationModule::ExternalNotificationModule()
DEBUG_MSG("Initializing External Notification Module\n"); DEBUG_MSG("Initializing External Notification Module\n");
// Set the direction of a pin output = moduleConfig.external_notification.output
pinMode((moduleConfig.external_notification.output ? moduleConfig.external_notification.output
? moduleConfig.external_notification.output : EXT_NOTIFICATION_MODULE_OUTPUT;
: EXT_NOTIFICATION_MODULE_OUTPUT),
OUTPUT);
// Turn off the pin if (output != PIN_BUZZER) {
setExternalOff(); // 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 { } else {
DEBUG_MSG("External Notification Module Disabled\n"); DEBUG_MSG("External Notification Module Disabled\n");
enabled = false; enabled = false;
@ -165,14 +173,22 @@ ProcessMessage ExternalNotificationModule::handleReceived(const MeshPacket &mp)
DEBUG_MSG("externalNotificationModule - Notification Bell\n"); DEBUG_MSG("externalNotificationModule - 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) {
setExternalOn(); if (output != PIN_BUZZER) {
setExternalOn();
} else {
playBeep();
}
} }
} }
} }
if (moduleConfig.external_notification.alert_message) { if (moduleConfig.external_notification.alert_message) {
DEBUG_MSG("externalNotificationModule - Notification Module\n"); DEBUG_MSG("externalNotificationModule - Notification Module\n");
setExternalOn(); if (output != PIN_BUZZER) {
setExternalOn();
} else {
playBeep();
}
} }
} }

View File

@ -12,6 +12,8 @@
*/ */
class ExternalNotificationModule : public SinglePortModule, private concurrency::OSThread class ExternalNotificationModule : public SinglePortModule, private concurrency::OSThread
{ {
uint32_t output = EXT_NOTIFY_OUT;
public: public:
ExternalNotificationModule(); ExternalNotificationModule();