🩹 Advance tone queue when muted, tuning (#26278)

This commit is contained in:
MageDelfador 2024-12-08 12:50:41 +08:00 committed by GitHub
parent 71ce7803e7
commit 7e45d56e66
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 23 deletions

View file

@ -55,30 +55,29 @@ void Buzzer::tone(const uint16_t duration, const uint16_t frequency/*=0*/) {
}
void Buzzer::tick() {
if (!ui.sound_on) return;
const millis_t now = millis();
if (!state.endtime) {
if (buffer.isEmpty()) return;
state.tone = buffer.dequeue();
state.endtime = now + state.tone.duration;
if (state.tone.frequency > 0) {
#if ENABLED(EXTENSIBLE_UI) && DISABLED(EXTUI_LOCAL_BEEPER)
CRITICAL_SECTION_START();
ExtUI::onPlayTone(state.tone.frequency, state.tone.duration);
CRITICAL_SECTION_END();
#elif ENABLED(SPEAKER)
CRITICAL_SECTION_START();
::tone(BEEPER_PIN, state.tone.frequency, state.tone.duration);
CRITICAL_SECTION_END();
#else
on();
#endif
}
if (state.endtime) {
if (ELAPSED(millis(), state.endtime)) reset();
return;
}
if (buffer.isEmpty()) return;
state.tone = buffer.dequeue();
state.endtime = millis() + state.tone.duration;
if (state.tone.frequency > 0) {
#if ENABLED(EXTENSIBLE_UI) && DISABLED(EXTUI_LOCAL_BEEPER)
CRITICAL_SECTION_START();
ExtUI::onPlayTone(state.tone.frequency, state.tone.duration);
CRITICAL_SECTION_END();
#elif ENABLED(SPEAKER)
CRITICAL_SECTION_START();
::tone(BEEPER_PIN, state.tone.frequency, state.tone.duration);
CRITICAL_SECTION_END();
#else
on();
#endif
}
else if (ELAPSED(now, state.endtime)) reset();
}
#endif // HAS_BEEPER

View file

@ -703,6 +703,9 @@ volatile bool Temperature::raw_temps_ready = false;
ui.update();
#endif
// Update beeper queue
TERN_(HAS_BEEPER, buzzer.tick());
return temp_ready;
}