♻️ Small sound / buzz refactor (#24520)

This commit is contained in:
Scott Lahteine 2022-07-18 19:53:36 -05:00
parent 2952f0be5d
commit 593b734d18
15 changed files with 46 additions and 53 deletions

View file

@ -66,7 +66,7 @@
#include "../lcd/marlinui.h" #include "../lcd/marlinui.h"
#if HAS_BUZZER #if HAS_SOUND
#include "../libs/buzzer.h" #include "../libs/buzzer.h"
#endif #endif
@ -101,7 +101,7 @@ fil_change_settings_t fc_settings[EXTRUDERS];
#define _PMSG(L) L##_LCD #define _PMSG(L) L##_LCD
#endif #endif
#if HAS_BUZZER #if HAS_SOUND
static void impatient_beep(const int8_t max_beep_count, const bool restart=false) { static void impatient_beep(const int8_t max_beep_count, const bool restart=false) {
if (TERN0(HAS_MARLINUI_MENU, pause_mode == PAUSE_MODE_PAUSE_PRINT)) return; if (TERN0(HAS_MARLINUI_MENU, pause_mode == PAUSE_MODE_PAUSE_PRINT)) return;

View file

@ -293,7 +293,7 @@ public:
* If not set defaults to 80% power * If not set defaults to 80% power
*/ */
static void test_fire_pulse() { static void test_fire_pulse() {
TERN_(HAS_BEEPER, buzzer.tone(30, 3000)); BUZZ(30, 3000);
cutter_mode = CUTTER_MODE_STANDARD;// Menu needs standard mode. cutter_mode = CUTTER_MODE_STANDARD;// Menu needs standard mode.
laser_menu_toggle(true); // Laser On laser_menu_toggle(true); // Laser On
delay(testPulse); // Delay for time set by user in pulse ms menu screen. delay(testPulse); // Delay for time set by user in pulse ms menu screen.

View file

@ -762,7 +762,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
case 290: M290(); break; // M290: Babystepping case 290: M290(); break; // M290: Babystepping
#endif #endif
#if HAS_BUZZER #if HAS_SOUND
case 300: M300(); break; // M300: Play beep tone case 300: M300(); break; // M300: Play beep tone
#endif #endif

View file

@ -916,7 +916,7 @@ private:
static void M290(); static void M290();
#endif #endif
#if HAS_BUZZER #if HAS_SOUND
static void M300(); static void M300();
#endif #endif

View file

@ -22,7 +22,7 @@
#include "../../inc/MarlinConfig.h" #include "../../inc/MarlinConfig.h"
#if HAS_BUZZER #if HAS_SOUND
#include "../gcode.h" #include "../gcode.h"
@ -42,4 +42,4 @@ void GcodeSuite::M300() {
BUZZ(duration, frequency); BUZZ(duration, frequency);
} }
#endif // HAS_BUZZER #endif // HAS_SOUND

View file

@ -3313,8 +3313,11 @@
#if PIN_EXISTS(BEEPER) #if PIN_EXISTS(BEEPER)
#define HAS_BEEPER 1 #define HAS_BEEPER 1
#endif #endif
#if ANY(HAS_BEEPER, LCD_USE_I2C_BUZZER, PCA9632_BUZZER) #if ANY(IS_TFTGLCD_PANEL, PCA9632_BUZZER, LCD_USE_I2C_BUZZER)
#define HAS_BUZZER 1 #define USE_MARLINUI_BUZZER 1
#endif
#if EITHER(HAS_BEEPER, USE_MARLINUI_BUZZER)
#define HAS_SOUND 1
#endif #endif
#if ENABLED(LCD_USE_I2C_BUZZER) #if ENABLED(LCD_USE_I2C_BUZZER)
@ -3324,7 +3327,7 @@
#ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100
#endif #endif
#elif HAS_BUZZER #elif HAS_SOUND
#ifndef LCD_FEEDBACK_FREQUENCY_HZ #ifndef LCD_FEEDBACK_FREQUENCY_HZ
#define LCD_FEEDBACK_FREQUENCY_HZ 5000 #define LCD_FEEDBACK_FREQUENCY_HZ 5000
#endif #endif
@ -3333,12 +3336,13 @@
#endif #endif
#endif #endif
#if HAS_BUZZER #if HAS_SOUND
#if LCD_FEEDBACK_FREQUENCY_DURATION_MS && LCD_FEEDBACK_FREQUENCY_HZ #if LCD_FEEDBACK_FREQUENCY_DURATION_MS && LCD_FEEDBACK_FREQUENCY_HZ
#define HAS_CHIRP 1 #define HAS_CHIRP 1
#endif #endif
#else #else
#undef SOUND_MENU_ITEM // No buzzer menu item without a buzzer #undef SOUND_MENU_ITEM // No buzzer menu item without a buzzer
#undef SOUND_ON_DEFAULT
#endif #endif
/** /**

View file

@ -36,7 +36,7 @@
#include "../../marlinui.h" #include "../../marlinui.h"
#include "../../../HAL/shared/Delay.h" #include "../../../HAL/shared/Delay.h"
#if HAS_BUZZER #if HAS_SOUND
#include "../../../libs/buzzer.h" #include "../../../libs/buzzer.h"
#endif #endif
@ -50,9 +50,7 @@ ENCODER_Rate EncoderRate;
// TODO: Replace with ui.quick_feedback // TODO: Replace with ui.quick_feedback
void Encoder_tick() { void Encoder_tick() {
#if PIN_EXISTS(BEEPER) TERN_(HAS_BEEPER, if (ui.sound_on) buzzer.click(10));
if (ui.sound_on) buzzer.click(10);
#endif
} }
// Encoder initialization // Encoder initialization
@ -66,7 +64,7 @@ void Encoder_Configuration() {
#if BUTTON_EXISTS(ENC) #if BUTTON_EXISTS(ENC)
SET_INPUT_PULLUP(BTN_ENC); SET_INPUT_PULLUP(BTN_ENC);
#endif #endif
#if PIN_EXISTS(BEEPER) #if HAS_BEEPER
SET_OUTPUT(BEEPER_PIN); // TODO: Use buzzer.h which already inits this SET_OUTPUT(BEEPER_PIN); // TODO: Use buzzer.h which already inits this
#endif #endif
} }

View file

@ -2625,15 +2625,13 @@ void Draw_HomeOff_Menu() {
#include "../../../libs/buzzer.h" #include "../../../libs/buzzer.h"
void HMI_AudioFeedback(const bool success=true) { void HMI_AudioFeedback(const bool success=true) {
#if HAS_BUZZER
if (success) { if (success) {
buzzer.tone(100, 659); BUZZ(100, 659);
buzzer.tone(10, 0); BUZZ(10, 0);
buzzer.tone(100, 698); BUZZ(100, 698);
} }
else else
buzzer.tone(40, 440); BUZZ(40, 440);
#endif
} }
// Prepare // Prepare

View file

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

View file

@ -227,12 +227,12 @@ public:
static constexpr bool sound_on = true; static constexpr bool sound_on = true;
#endif #endif
#if HAS_BUZZER #if USE_MARLINUI_BUZZER
static void buzz(const long duration, const uint16_t freq); static void buzz(const long duration, const uint16_t freq);
#endif #endif
FORCE_INLINE static void chirp() { static void chirp() {
TERN_(HAS_CHIRP, TERN(HAS_BUZZER, buzz, BUZZ)(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ)); TERN_(HAS_CHIRP, TERN(USE_MARLINUI_BUZZER, buzz, BUZZ)(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ));
} }
#if ENABLED(LCD_HAS_STATUS_INDICATORS) #if ENABLED(LCD_HAS_STATUS_INDICATORS)
@ -455,7 +455,7 @@ public:
#endif #endif
static void quick_feedback(const bool clear_buttons=true); static void quick_feedback(const bool clear_buttons=true);
#if HAS_BUZZER #if HAS_SOUND
static void completion_feedback(const bool good=true); static void completion_feedback(const bool good=true);
#else #else
static void completion_feedback(const bool=true) { TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); } static void completion_feedback(const bool=true) { TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); }

View file

@ -28,7 +28,7 @@
//#define MUTE_GAMES //#define MUTE_GAMES
#if ENABLED(MUTE_GAMES) || !HAS_BUZZER #if ENABLED(MUTE_GAMES) || !HAS_SOUND
#define _BUZZ(D,F) NOOP #define _BUZZ(D,F) NOOP
#else #else
#define _BUZZ(D,F) BUZZ(D,F) #define _BUZZ(D,F) BUZZ(D,F)

View file

@ -31,7 +31,7 @@
#include "../../module/temperature.h" #include "../../module/temperature.h"
#include "../../gcode/queue.h" #include "../../gcode/queue.h"
#if HAS_BUZZER #if HAS_SOUND
#include "../../libs/buzzer.h" #include "../../libs/buzzer.h"
#endif #endif
@ -272,7 +272,7 @@ void scroll_screen(const uint8_t limit, const bool is_menu) {
encoderTopLine = encoderLine; encoderTopLine = encoderLine;
} }
#if HAS_BUZZER #if HAS_SOUND
void MarlinUI::completion_feedback(const bool good/*=true*/) { void MarlinUI::completion_feedback(const bool good/*=true*/) {
TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); // Wake up on rotary encoder click... TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); // Wake up on rotary encoder click...
if (good) OKAY_BUZZ(); else ERR_BUZZ(); if (good) OKAY_BUZZ(); else ERR_BUZZ();

View file

@ -117,11 +117,11 @@
// Buzz directly via the BEEPER pin tone queue // Buzz directly via the BEEPER pin tone queue
#define BUZZ(d,f) buzzer.tone(d, f) #define BUZZ(d,f) buzzer.tone(d, f)
#elif HAS_BUZZER #elif USE_MARLINUI_BUZZER
// Buzz indirectly via the MarlinUI instance // Use MarlinUI for a buzzer on the LCD
#define BUZZ(d,f) ui.buzz(d,f)
#include "../lcd/marlinui.h" #include "../lcd/marlinui.h"
#define BUZZ(d,f) ui.buzz(d,f)
#else #else

View file

@ -37,7 +37,7 @@ Stopwatch print_job_timer; // Global Print Job Timer instance
#include "../MarlinCore.h" #include "../MarlinCore.h"
#include "../HAL/shared/eeprom_api.h" #include "../HAL/shared/eeprom_api.h"
#if HAS_BUZZER && SERVICE_WARNING_BUZZES > 0 #if HAS_SOUND && SERVICE_WARNING_BUZZES > 0
#include "../libs/buzzer.h" #include "../libs/buzzer.h"
#endif #endif
@ -156,7 +156,7 @@ void PrintCounter::loadStats() {
#if SERVICE_INTERVAL_3 > 0 #if SERVICE_INTERVAL_3 > 0
if (data.nextService3 == 0) doBuzz = _service_warn(PSTR(" " SERVICE_NAME_3)); if (data.nextService3 == 0) doBuzz = _service_warn(PSTR(" " SERVICE_NAME_3));
#endif #endif
#if HAS_BUZZER && SERVICE_WARNING_BUZZES > 0 #if HAS_SOUND && SERVICE_WARNING_BUZZES > 0
if (doBuzz) for (int i = 0; i < SERVICE_WARNING_BUZZES; i++) { BUZZ(200, 404); BUZZ(10, 0); } if (doBuzz) for (int i = 0; i < SERVICE_WARNING_BUZZES; i++) { BUZZ(200, 404); BUZZ(10, 0); }
#else #else
UNUSED(doBuzz); UNUSED(doBuzz);

View file

@ -205,7 +205,7 @@ HAS_STATUS_MESSAGE = src_filter=+<src/gcode/lcd/M117.cpp>
HAS_LCD_CONTRAST = src_filter=+<src/gcode/lcd/M250.cpp> HAS_LCD_CONTRAST = src_filter=+<src/gcode/lcd/M250.cpp>
HAS_GCODE_M255 = src_filter=+<src/gcode/lcd/M255.cpp> HAS_GCODE_M255 = src_filter=+<src/gcode/lcd/M255.cpp>
HAS_LCD_BRIGHTNESS = src_filter=+<src/gcode/lcd/M256.cpp> HAS_LCD_BRIGHTNESS = src_filter=+<src/gcode/lcd/M256.cpp>
HAS_BUZZER = src_filter=+<src/gcode/lcd/M300.cpp> HAS_SOUND = src_filter=+<src/gcode/lcd/M300.cpp>
TOUCH_SCREEN_CALIBRATION = src_filter=+<src/gcode/lcd/M995.cpp> TOUCH_SCREEN_CALIBRATION = src_filter=+<src/gcode/lcd/M995.cpp>
ARC_SUPPORT = src_filter=+<src/gcode/motion/G2_G3.cpp> ARC_SUPPORT = src_filter=+<src/gcode/motion/G2_G3.cpp>
GCODE_MOTION_MODES = src_filter=+<src/gcode/motion/G80.cpp> GCODE_MOTION_MODES = src_filter=+<src/gcode/motion/G80.cpp>