♻️ Small sound / buzz refactor (#24520)

This commit is contained in:
Scott Lahteine
2022-07-18 19:53:36 -05:00
parent 97a73147fa
commit f752fe75ee
16 changed files with 49 additions and 55 deletions

View File

@@ -119,17 +119,9 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
bool MarlinUI::sound_on = ENABLED(SOUND_ON_DEFAULT);
#endif
#if EITHER(PCA9632_BUZZER, HAS_BEEPER)
#if ENABLED(PCA9632_BUZZER)
#include "../feature/leds/pca9632.h"
#endif
#if ENABLED(PCA9632_BUZZER)
void MarlinUI::buzz(const long duration, const uint16_t freq) {
if (!sound_on) return;
#if ENABLED(PCA9632_BUZZER)
PCA9632_buzz(duration, freq);
#elif HAS_BEEPER
buzzer.tone(duration, freq);
#endif
if (sound_on) PCA9632_buzz(duration, freq);
}
#endif
@@ -683,7 +675,7 @@ void MarlinUI::init() {
if (old_frm != new_frm) {
feedrate_percentage = new_frm;
encoderPosition = 0;
#if BOTH(HAS_BUZZER, BEEP_ON_FEEDRATE_CHANGE)
#if BOTH(HAS_SOUND, BEEP_ON_FEEDRATE_CHANGE)
static millis_t next_beep;
#ifndef GOT_MS
const millis_t ms = millis();
@@ -741,11 +733,12 @@ void MarlinUI::init() {
UNUSED(clear_buttons);
#endif
#if HAS_CHIRP
chirp(); // Buzz and wait. Is the delay needed for buttons to settle?
#if BOTH(HAS_MARLINUI_MENU, HAS_BEEPER)
chirp(); // Buzz and wait. Is the delay needed for buttons to settle?
#if HAS_CHIRP && HAS_MARLINUI_MENU
#if HAS_BEEPER
for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
#elif HAS_MARLINUI_MENU
#else
delay(10);
#endif
#endif