feat: lower volume curve (duty=2 min) and add non-blocking Casio double-chirp alarm sound
This commit is contained in:
parent
3b868f38dc
commit
88503b0313
2 changed files with 53 additions and 1 deletions
|
|
@ -1365,6 +1365,53 @@ void updateMeter(uint8_t pidNo, String response) { // update parameter on screen
|
|||
}
|
||||
/*-------------------------------*/
|
||||
|
||||
// Non-blocking alarm sound generator: classic Casio double-chirp [bip-bip] every 1 second
|
||||
uint32_t lastAlarmSoundCycle = 0;
|
||||
uint8_t alarmSoundStep = 0;
|
||||
uint32_t alarmSoundStepTime = 0;
|
||||
|
||||
void handleAlarmSound(bool anyAlarmActive) {
|
||||
if (!anyAlarmActive || buzzerVolumeLevel == 0) {
|
||||
if (alarmSoundStep != 0) {
|
||||
ledcWrite(buzzerChannel, 0);
|
||||
alarmSoundStep = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t now = millis();
|
||||
uint16_t duty = VOL_DUTY_TABLE[buzzerVolumeLevel > 5 ? 3 : buzzerVolumeLevel];
|
||||
|
||||
// Pattern: [25ms chirp] -> 35ms pause -> [25ms chirp] -> pause until 1000ms
|
||||
if (alarmSoundStep == 0) {
|
||||
if (now - lastAlarmSoundCycle >= 1000) {
|
||||
lastAlarmSoundCycle = now;
|
||||
alarmSoundStep = 1;
|
||||
alarmSoundStepTime = now;
|
||||
ledcSetup(buzzerChannel, 4096, 10);
|
||||
ledcWrite(buzzerChannel, duty);
|
||||
}
|
||||
} else if (alarmSoundStep == 1) { // 25ms first chirp
|
||||
if (now - alarmSoundStepTime >= 25) {
|
||||
ledcWrite(buzzerChannel, 0);
|
||||
alarmSoundStep = 2;
|
||||
alarmSoundStepTime = now;
|
||||
}
|
||||
} else if (alarmSoundStep == 2) { // 35ms gap
|
||||
if (now - alarmSoundStepTime >= 35) {
|
||||
ledcSetup(buzzerChannel, 4096, 10);
|
||||
ledcWrite(buzzerChannel, duty);
|
||||
alarmSoundStep = 3;
|
||||
alarmSoundStepTime = now;
|
||||
}
|
||||
} else if (alarmSoundStep == 3) { // 25ms second chirp
|
||||
if (now - alarmSoundStepTime >= 25) {
|
||||
ledcWrite(buzzerChannel, 0);
|
||||
alarmSoundStep = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Non-blocking handler to blink/flash arcs and numerical values on alarm (when in TFT_RED)
|
||||
void handleArcAlarmFlash() {
|
||||
uint32_t now = millis();
|
||||
|
|
@ -1375,6 +1422,8 @@ void handleArcAlarmFlash() {
|
|||
toggleTick = true;
|
||||
}
|
||||
|
||||
bool anyInRedAlarm = false;
|
||||
|
||||
if (fullScreenCell >= 0 && fullScreenCell < 4) {
|
||||
uint8_t cell = fullScreenCell;
|
||||
if (last_valid_data[cell] != -999) {
|
||||
|
|
@ -1383,6 +1432,7 @@ void handleArcAlarmFlash() {
|
|||
float data = last_valid_data[cell];
|
||||
uint16_t col = getMeterColor(pidIdx, data, warn);
|
||||
bool inRed = (col == TFT_RED);
|
||||
if (inRed) anyInRedAlarm = true;
|
||||
bool digit = pidConfig[pidIdx][7].toInt();
|
||||
String numStr = String(data, digit);
|
||||
|
||||
|
|
@ -1466,6 +1516,7 @@ void handleArcAlarmFlash() {
|
|||
float data = last_valid_data[cell];
|
||||
uint16_t col = getMeterColor(pidIdx, data, warn);
|
||||
bool inRed = (col == TFT_RED);
|
||||
if (inRed) anyInRedAlarm = true;
|
||||
bool digit = pidConfig[pidIdx][7].toInt();
|
||||
String numStr = String(data, digit);
|
||||
int x = cell4_x[cell];
|
||||
|
|
@ -1544,6 +1595,7 @@ void handleArcAlarmFlash() {
|
|||
}
|
||||
}
|
||||
}
|
||||
handleAlarmSound(anyInRedAlarm);
|
||||
}
|
||||
|
||||
// Target and current brightness variables for smooth fade
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ String warningValue[4] = { "106", "5000", "15.0", "130" };
|
|||
bool alarmEnabled[4] = { true, true, true, true };
|
||||
|
||||
// Buzzer volume control table (0: Silencio, 1: Ultra Bajo, 2: Muy Bajo, 3: Bajo/Casio, 4: Medio, 5: Alto)
|
||||
const uint16_t VOL_DUTY_TABLE[6] = { 0, 5, 18, 50, 140, 380 };
|
||||
const uint16_t VOL_DUTY_TABLE[6] = { 0, 2, 8, 25, 80, 250 };
|
||||
const char* const VOL_NAME_TABLE[6] = { "SILENCIO", "ULTRA BAJO", "MUY BAJO", "BAJO (CASIO)", "MEDIO", "ALTO" };
|
||||
uint8_t buzzerVolumeLevel = 3; // Default 3: Bajo (Casio suave)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue