Update External Notifications with a full redo of logic gates (#10006)
* Update External Notifications with a full redo of pathways * Correct comments. * Fix TWatch S3 and use HAS_DRV2605
This commit is contained in:
@@ -350,12 +350,6 @@ ProcessMessage ExternalNotificationModule::handleReceived(const meshtastic_MeshP
|
|||||||
{
|
{
|
||||||
// Trigger external notification if enabled and not muted; isSilenced is from temporary mute toggles
|
// Trigger external notification if enabled and not muted; isSilenced is from temporary mute toggles
|
||||||
if (moduleConfig.external_notification.enabled && !isSilenced) {
|
if (moduleConfig.external_notification.enabled && !isSilenced) {
|
||||||
#ifdef T_WATCH_S3
|
|
||||||
drv.setWaveform(0, 75);
|
|
||||||
drv.setWaveform(1, 56);
|
|
||||||
drv.setWaveform(2, 0);
|
|
||||||
drv.go();
|
|
||||||
#endif
|
|
||||||
if (!isFromUs(&mp)) {
|
if (!isFromUs(&mp)) {
|
||||||
// Check if the message contains a bell character. Don't do this loop for every pin, just once.
|
// Check if the message contains a bell character. Don't do this loop for every pin, just once.
|
||||||
auto &p = mp.decoded;
|
auto &p = mp.decoded;
|
||||||
@@ -380,60 +374,69 @@ ProcessMessage ExternalNotificationModule::handleReceived(const meshtastic_MeshP
|
|||||||
const bool buzzerModeIsDirectOnly =
|
const bool buzzerModeIsDirectOnly =
|
||||||
(config.device.buzzer_mode == meshtastic_Config_DeviceConfig_BuzzerMode_DIRECT_MSG_ONLY);
|
(config.device.buzzer_mode == meshtastic_Config_DeviceConfig_BuzzerMode_DIRECT_MSG_ONLY);
|
||||||
|
|
||||||
if (containsBell || !is_muted) {
|
// Each output evaluates its own alert condition independently:
|
||||||
if (moduleConfig.external_notification.alert_bell || moduleConfig.external_notification.alert_message ||
|
// alert_bell_* fires only when a bell character is present.
|
||||||
moduleConfig.external_notification.alert_bell_vibra ||
|
// alert_message_* fires on any non-muted message.
|
||||||
moduleConfig.external_notification.alert_message_vibra ||
|
|
||||||
((moduleConfig.external_notification.alert_bell_buzzer ||
|
|
||||||
moduleConfig.external_notification.alert_message_buzzer) &&
|
|
||||||
canBuzz())) {
|
|
||||||
nagCycleCutoff = millis() + (moduleConfig.external_notification.nag_timeout
|
|
||||||
? (moduleConfig.external_notification.nag_timeout * 1000)
|
|
||||||
: moduleConfig.external_notification.output_ms);
|
|
||||||
LOG_INFO("Toggling nagCycleCutoff to %lu", nagCycleCutoff);
|
|
||||||
isNagging = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (moduleConfig.external_notification.alert_bell || moduleConfig.external_notification.alert_message) {
|
// Alert when receiving a bell = alertBell: true
|
||||||
LOG_INFO("externalNotificationModule - Notification Module or Bell");
|
// Alert when receiving a message = alertMessage: true
|
||||||
setExternalState(0, true);
|
const bool genericShouldAlert = (moduleConfig.external_notification.alert_bell && containsBell) ||
|
||||||
}
|
(moduleConfig.external_notification.alert_message && !is_muted);
|
||||||
|
|
||||||
if (moduleConfig.external_notification.alert_bell_vibra ||
|
// Alert GPIO Vibra when receiving a bell = alertBellVibra: true
|
||||||
moduleConfig.external_notification.alert_message_vibra) {
|
// Alert GPIO Vibra when receiving a message = alertMessageVibra: true
|
||||||
LOG_INFO("externalNotificationModule - Notification Module or Bell (Vibra)");
|
const bool vibraShouldAlert = (moduleConfig.external_notification.alert_bell_vibra && containsBell) ||
|
||||||
setExternalState(1, true);
|
(moduleConfig.external_notification.alert_message_vibra && !is_muted);
|
||||||
}
|
|
||||||
|
|
||||||
if ((moduleConfig.external_notification.alert_bell_buzzer ||
|
// Alert GPIO Buzzer when receiving a bell = alertBellBuzzer: true
|
||||||
moduleConfig.external_notification.alert_message_buzzer) &&
|
// Alert GPIO Buzzer when receiving a message = alertMessageBuzzer: true
|
||||||
canBuzz()) {
|
const bool buzzerShouldAlert = canBuzz() && ((moduleConfig.external_notification.alert_bell_buzzer && containsBell) ||
|
||||||
LOG_INFO("externalNotificationModule - Notification Module or Bell (Buzzer)");
|
(moduleConfig.external_notification.alert_message_buzzer && !is_muted));
|
||||||
if (buzzerModeIsDirectOnly && !isDmToUs && !containsBell) {
|
|
||||||
LOG_INFO("Message buzzer was suppressed because buzzer mode DIRECT_MSG_ONLY");
|
if (genericShouldAlert || vibraShouldAlert || buzzerShouldAlert) {
|
||||||
} else {
|
nagCycleCutoff = millis() + (moduleConfig.external_notification.nag_timeout
|
||||||
// Buzz if buzzer mode is not in DIRECT_MSG_ONLY or is DM to us
|
? (moduleConfig.external_notification.nag_timeout * 1000)
|
||||||
#ifdef T_LORA_PAGER
|
: moduleConfig.external_notification.output_ms);
|
||||||
drv.setWaveform(0, 16); // Long buzzer 100%
|
LOG_INFO("Toggling nagCycleCutoff to %lu", nagCycleCutoff);
|
||||||
drv.setWaveform(1, 0); // Pause
|
isNagging = true;
|
||||||
drv.setWaveform(2, 16);
|
}
|
||||||
drv.setWaveform(3, 0);
|
|
||||||
drv.setWaveform(4, 16);
|
if (genericShouldAlert) {
|
||||||
drv.setWaveform(5, 0);
|
LOG_INFO("externalNotificationModule - Generic alert");
|
||||||
drv.setWaveform(6, 16);
|
setExternalState(0, true);
|
||||||
drv.setWaveform(7, 0);
|
}
|
||||||
drv.go();
|
|
||||||
|
if (vibraShouldAlert) {
|
||||||
|
LOG_INFO("externalNotificationModule - Vibra alert");
|
||||||
|
setExternalState(1, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buzzerShouldAlert) {
|
||||||
|
LOG_INFO("externalNotificationModule - Buzzer alert");
|
||||||
|
if (buzzerModeIsDirectOnly && !isDmToUs && !containsBell) {
|
||||||
|
LOG_INFO("Message buzzer was suppressed because buzzer mode DIRECT_MSG_ONLY");
|
||||||
|
} else {
|
||||||
|
// Buzz if buzzer mode is not in DIRECT_MSG_ONLY or is DM to us
|
||||||
|
#ifdef HAS_DRV2605
|
||||||
|
drv.setWaveform(0, 16); // Long buzzer 100%
|
||||||
|
drv.setWaveform(1, 0); // Pause
|
||||||
|
drv.setWaveform(2, 16);
|
||||||
|
drv.setWaveform(3, 0);
|
||||||
|
drv.setWaveform(4, 16);
|
||||||
|
drv.setWaveform(5, 0);
|
||||||
|
drv.setWaveform(6, 16);
|
||||||
|
drv.setWaveform(7, 0);
|
||||||
|
drv.go();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (moduleConfig.external_notification.use_i2s_as_buzzer) {
|
||||||
#ifdef HAS_I2S
|
#ifdef HAS_I2S
|
||||||
if (moduleConfig.external_notification.use_i2s_as_buzzer) {
|
audioThread->beginRttl(rtttlConfig.ringtone, strlen_P(rtttlConfig.ringtone));
|
||||||
audioThread->beginRttl(rtttlConfig.ringtone, strlen_P(rtttlConfig.ringtone));
|
|
||||||
} else
|
|
||||||
#endif
|
#endif
|
||||||
if (moduleConfig.external_notification.use_pwm) {
|
} else if (moduleConfig.external_notification.use_pwm) {
|
||||||
rtttl::begin(config.device.buzzer_gpio, rtttlConfig.ringtone);
|
rtttl::begin(config.device.buzzer_gpio, rtttlConfig.ringtone);
|
||||||
} else {
|
} else {
|
||||||
setExternalState(2, true);
|
setExternalState(2, true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -513,4 +516,4 @@ int ExternalNotificationModule::handleInputEvent(const InputEvent *event)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user