mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-07 21:52:05 +00:00
Wire buzzer_mode
This commit is contained in:
parent
1acdcc5a70
commit
94e0b209bc
@ -38,6 +38,11 @@ const int DURATION_1_1 = 1000; // 1/1 note
|
|||||||
|
|
||||||
void playTones(const ToneDuration *tone_durations, int size)
|
void playTones(const ToneDuration *tone_durations, int size)
|
||||||
{
|
{
|
||||||
|
if (config.device.buzzer_mode != meshtastic_Config_DeviceConfig_BuzzerMode_DISABLED &&
|
||||||
|
config.device.buzzer_mode != meshtastic_Config_DeviceConfig_BuzzerMode_NOTIFICATIONS_ONLY) {
|
||||||
|
// Buzzer is disabled or not set to system tones
|
||||||
|
return;
|
||||||
|
}
|
||||||
#ifdef PIN_BUZZER
|
#ifdef PIN_BUZZER
|
||||||
if (!config.device.buzzer_gpio)
|
if (!config.device.buzzer_gpio)
|
||||||
config.device.buzzer_gpio = PIN_BUZZER;
|
config.device.buzzer_gpio = PIN_BUZZER;
|
||||||
|
@ -188,7 +188,7 @@ int32_t ExternalNotificationModule::runOnce()
|
|||||||
|
|
||||||
// Play RTTTL over i2s audio interface if enabled as buzzer
|
// Play RTTTL over i2s audio interface if enabled as buzzer
|
||||||
#ifdef HAS_I2S
|
#ifdef HAS_I2S
|
||||||
if (moduleConfig.external_notification.use_i2s_as_buzzer) {
|
if (moduleConfig.external_notification.use_i2s_as_buzzer && canBuzz()) {
|
||||||
if (audioThread->isPlaying()) {
|
if (audioThread->isPlaying()) {
|
||||||
// Continue playing
|
// Continue playing
|
||||||
} else if (isNagging && (nagCycleCutoff >= millis())) {
|
} else if (isNagging && (nagCycleCutoff >= millis())) {
|
||||||
@ -197,7 +197,7 @@ int32_t ExternalNotificationModule::runOnce()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// now let the PWM buzzer play
|
// now let the PWM buzzer play
|
||||||
if (moduleConfig.external_notification.use_pwm && config.device.buzzer_gpio) {
|
if (moduleConfig.external_notification.use_pwm && config.device.buzzer_gpio && canBuzz()) {
|
||||||
if (rtttl::isPlaying()) {
|
if (rtttl::isPlaying()) {
|
||||||
rtttl::play();
|
rtttl::play();
|
||||||
} else if (isNagging && (nagCycleCutoff >= millis())) {
|
} else if (isNagging && (nagCycleCutoff >= millis())) {
|
||||||
@ -210,6 +210,18 @@ int32_t ExternalNotificationModule::runOnce()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Based on buzzer mode, return true if we can buzz.
|
||||||
|
*/
|
||||||
|
bool ExternalNotificationModule::canBuzz()
|
||||||
|
{
|
||||||
|
if (config.device.buzzer_mode != meshtastic_Config_DeviceConfig_BuzzerMode_DISABLED &&
|
||||||
|
config.device.buzzer_mode != meshtastic_Config_DeviceConfig_BuzzerMode_SYSTEM_ONLY) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool ExternalNotificationModule::wantPacket(const meshtastic_MeshPacket *p)
|
bool ExternalNotificationModule::wantPacket(const meshtastic_MeshPacket *p)
|
||||||
{
|
{
|
||||||
return MeshService::isTextPayload(p);
|
return MeshService::isTextPayload(p);
|
||||||
@ -364,7 +376,7 @@ ExternalNotificationModule::ExternalNotificationModule()
|
|||||||
setExternalState(1, false);
|
setExternalState(1, false);
|
||||||
externalTurnedOn[1] = 0;
|
externalTurnedOn[1] = 0;
|
||||||
}
|
}
|
||||||
if (moduleConfig.external_notification.output_buzzer) {
|
if (moduleConfig.external_notification.output_buzzer && canBuzz()) {
|
||||||
if (!moduleConfig.external_notification.use_pwm) {
|
if (!moduleConfig.external_notification.use_pwm) {
|
||||||
LOG_INFO("Use Pin %i for buzzer", moduleConfig.external_notification.output_buzzer);
|
LOG_INFO("Use Pin %i for buzzer", moduleConfig.external_notification.output_buzzer);
|
||||||
pinMode(moduleConfig.external_notification.output_buzzer, OUTPUT);
|
pinMode(moduleConfig.external_notification.output_buzzer, OUTPUT);
|
||||||
@ -454,7 +466,7 @@ ProcessMessage ExternalNotificationModule::handleReceived(const meshtastic_MeshP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (moduleConfig.external_notification.alert_bell_buzzer) {
|
if (moduleConfig.external_notification.alert_bell_buzzer && canBuzz()) {
|
||||||
if (containsBell) {
|
if (containsBell) {
|
||||||
LOG_INFO("externalNotificationModule - Notification Bell (Buzzer)");
|
LOG_INFO("externalNotificationModule - Notification Bell (Buzzer)");
|
||||||
isNagging = true;
|
isNagging = true;
|
||||||
|
@ -40,6 +40,8 @@ class ExternalNotificationModule : public SinglePortModule, private concurrency:
|
|||||||
void setMute(bool mute) { isMuted = mute; }
|
void setMute(bool mute) { isMuted = mute; }
|
||||||
bool getMute() { return isMuted; }
|
bool getMute() { return isMuted; }
|
||||||
|
|
||||||
|
bool canBuzz();
|
||||||
|
|
||||||
void stopNow();
|
void stopNow();
|
||||||
|
|
||||||
void handleGetRingtone(const meshtastic_MeshPacket &req, meshtastic_AdminMessage *response);
|
void handleGetRingtone(const meshtastic_MeshPacket &req, meshtastic_AdminMessage *response);
|
||||||
|
Loading…
Reference in New Issue
Block a user