Enhance buzzer detection logic to group intermittent matches with a 500 ms quiet tail, updating relevant configurations and documentation.

This commit is contained in:
2026-10-19 15:28:21 -05:00
parent 7862a09858
commit 63d9995f59
10 changed files with 131 additions and 50 deletions
+15 -6
View File
@@ -92,11 +92,12 @@ static void processing_task(void *arg)
const app_mode_t mode = calibration_get_mode();
const bool match = has_tpl && detector_is_match(rms, score, cfg.min_rms, cfg.threshold);
bool trig = false;
bool buzz_ended = false;
uint32_t buzz_duration_ms = 0;
if (mode == MODE_NORMAL) {
if (has_tpl) {
detector_cfg_t dc = { cfg.win_n, cfg.win_m, cfg.cooldown_ms };
trig = detector_update(&det, match, now_ms, &dc);
buzz_ended = detector_update(&det, match, now_ms, &dc, &buzz_duration_ms);
} else {
detector_reset(&det);
}
@@ -104,9 +105,13 @@ static void processing_task(void *arg)
calibration_on_frame(fp, valid, rms, score); // detector paused: no alerts
detector_reset(&det);
}
if (trig) {
ESP_LOGW(TAG, "BUZZER DETECTED (rms %.0f, score %.3f)", rms, score);
notifier_send(NOTIF_ALERT, "Buzzer detected");
if (buzz_ended) {
char message[96];
snprintf(message, sizeof(message), "Buzzer detected: %lu ms",
(unsigned long)buzz_duration_ms);
ESP_LOGW(TAG, "BUZZER EVENT ended, detected duration %lu ms",
(unsigned long)buzz_duration_ms);
notifier_send(NOTIF_ALERT, message);
}
portENTER_CRITICAL(&s_lock);
@@ -118,7 +123,11 @@ static void processing_task(void *arg)
s_stats.last_match = match;
s_stats.state = det.state;
s_stats.triggers = det.triggers;
if (trig) s_stats.last_trigger_s = now_ms / 1000 ? now_ms / 1000 : 1;
if (buzz_ended) {
s_stats.last_trigger_s = det.last_completed_start_ms / 1000;
if (s_stats.last_trigger_s == 0) s_stats.last_trigger_s = 1;
s_stats.last_buzz_ms = buzz_duration_ms;
}
memcpy(s_last_fp, fp, sizeof(s_last_fp));
portEXIT_CRITICAL(&s_lock);