mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-25 22:20:27 +00:00
Merge pull request #1839 from meshtastic/pwm-notify
use PWM buzzer on notification module.
This commit is contained in:
commit
05147c016c
@ -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>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -44,7 +49,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Default configurations
|
// Default configurations
|
||||||
|
#ifdef EXT_NOTIFY_OUT
|
||||||
#define EXT_NOTIFICATION_MODULE_OUTPUT 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 EXT_NOTIFICATION_MODULE_OUTPUT_MS 1000
|
||||||
|
|
||||||
#define ASCII_BELL 0x07
|
#define ASCII_BELL 0x07
|
||||||
@ -75,7 +84,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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,27 +95,19 @@ int32_t ExternalNotificationModule::runOnce()
|
|||||||
|
|
||||||
void ExternalNotificationModule::setExternalOn()
|
void ExternalNotificationModule::setExternalOn()
|
||||||
{
|
{
|
||||||
#ifdef EXT_NOTIFY_OUT
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExternalNotificationModule::setExternalOff()
|
void ExternalNotificationModule::setExternalOff()
|
||||||
{
|
{
|
||||||
#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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------
|
// --------
|
||||||
@ -116,8 +119,6 @@ ExternalNotificationModule::ExternalNotificationModule()
|
|||||||
// restrict to the admin channel for rx
|
// restrict to the admin channel for rx
|
||||||
boundChannel = Channels::gpioChannel;
|
boundChannel = Channels::gpioChannel;
|
||||||
|
|
||||||
#ifdef EXT_NOTIFY_OUT
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Uncomment the preferences below if you want to use the module
|
Uncomment the preferences below if you want to use the module
|
||||||
without having to configure it from the PythonAPI or WebUI.
|
without having to configure it from the PythonAPI or WebUI.
|
||||||
@ -135,25 +136,27 @@ 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;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessMessage ExternalNotificationModule::handleReceived(const MeshPacket &mp)
|
ProcessMessage ExternalNotificationModule::handleReceived(const MeshPacket &mp)
|
||||||
{
|
{
|
||||||
#ifdef EXT_NOTIFY_OUT
|
|
||||||
|
|
||||||
if (moduleConfig.external_notification.enabled) {
|
if (moduleConfig.external_notification.enabled) {
|
||||||
|
|
||||||
if (getFrom(&mp) != nodeDB.getNodeNum()) {
|
if (getFrom(&mp) != nodeDB.getNodeNum()) {
|
||||||
@ -165,21 +168,28 @@ 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
DEBUG_MSG("External Notification Module Disabled\n");
|
DEBUG_MSG("External Notification Module Disabled\n");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
return ProcessMessage::CONTINUE; // Let others look at this message also if they want
|
return ProcessMessage::CONTINUE; // Let others look at this message also if they want
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
*/
|
*/
|
||||||
class ExternalNotificationModule : public SinglePortModule, private concurrency::OSThread
|
class ExternalNotificationModule : public SinglePortModule, private concurrency::OSThread
|
||||||
{
|
{
|
||||||
|
uint32_t output = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ExternalNotificationModule();
|
ExternalNotificationModule();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user