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 "RTC.h"
#include "Router.h"
#include "buzz/buzz.h"
#include "configuration.h"
#include <Arduino.h>
#ifndef PIN_BUZZER
#define PIN_BUZZER false
#endif
//#include <assert.h>
/*
@ -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();
}
}
}

View File

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