From 5f2908a117ab45cf9e5a03a39e499979a40bf0f3 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 18 Jul 2022 19:53:36 -0500 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Small=20sound=20/=20buzz?= =?UTF-8?q?=20refactor=20(#24520)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/feature/pause.cpp | 4 ++-- Marlin/src/feature/spindle_laser.h | 2 +- Marlin/src/gcode/gcode.cpp | 2 +- Marlin/src/gcode/gcode.h | 2 +- Marlin/src/gcode/lcd/M300.cpp | 4 ++-- Marlin/src/inc/Conditionals_post.h | 12 +++++++---- Marlin/src/lcd/HD44780/marlinui_HD44780.cpp | 5 +++-- Marlin/src/lcd/e3v2/common/encoder.cpp | 8 +++---- Marlin/src/lcd/e3v2/creality/dwin.cpp | 16 +++++++------- Marlin/src/lcd/marlinui.cpp | 23 +++++++-------------- Marlin/src/lcd/marlinui.h | 8 +++---- Marlin/src/lcd/menu/game/game.h | 2 +- Marlin/src/lcd/menu/menu.cpp | 4 ++-- Marlin/src/libs/buzzer.h | 6 +++--- Marlin/src/module/printcounter.cpp | 4 ++-- ini/features.ini | 2 +- 16 files changed, 49 insertions(+), 55 deletions(-) diff --git a/Marlin/src/feature/pause.cpp b/Marlin/src/feature/pause.cpp index e9cb2df594..78572b0795 100644 --- a/Marlin/src/feature/pause.cpp +++ b/Marlin/src/feature/pause.cpp @@ -63,7 +63,7 @@ #include "../lcd/marlinui.h" -#if HAS_BUZZER +#if HAS_SOUND #include "../libs/buzzer.h" #endif @@ -98,7 +98,7 @@ fil_change_settings_t fc_settings[EXTRUDERS]; #define _PMSG(L) L##_LCD #endif -#if HAS_BUZZER +#if HAS_SOUND 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; diff --git a/Marlin/src/feature/spindle_laser.h b/Marlin/src/feature/spindle_laser.h index b945032d8e..8c73394c9b 100644 --- a/Marlin/src/feature/spindle_laser.h +++ b/Marlin/src/feature/spindle_laser.h @@ -294,7 +294,7 @@ public: * If not set defaults to 80% power */ static void test_fire_pulse() { - TERN_(HAS_BEEPER, buzzer.tone(30, 3000)); + BUZZ(30, 3000); cutter_mode = CUTTER_MODE_STANDARD;// Menu needs standard mode. laser_menu_toggle(true); // Laser On delay(testPulse); // Delay for time set by user in pulse ms menu screen. diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 1cbd3019c8..0cae1573bc 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -765,7 +765,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { case 290: M290(); break; // M290: Babystepping #endif - #if HAS_BUZZER + #if HAS_SOUND case 300: M300(); break; // M300: Play beep tone #endif diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 3657ab2b12..135cfc7f43 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -914,7 +914,7 @@ private: static void M290(); #endif - #if HAS_BUZZER + #if HAS_SOUND static void M300(); #endif diff --git a/Marlin/src/gcode/lcd/M300.cpp b/Marlin/src/gcode/lcd/M300.cpp index 5250774955..76d4b96b24 100644 --- a/Marlin/src/gcode/lcd/M300.cpp +++ b/Marlin/src/gcode/lcd/M300.cpp @@ -22,7 +22,7 @@ #include "../../inc/MarlinConfig.h" -#if HAS_BUZZER +#if HAS_SOUND #include "../gcode.h" @@ -42,4 +42,4 @@ void GcodeSuite::M300() { BUZZ(duration, frequency); } -#endif // HAS_BUZZER +#endif // HAS_SOUND diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 517e95c83e..7d2009dc8f 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -3564,8 +3564,11 @@ #if PIN_EXISTS(BEEPER) #define HAS_BEEPER 1 #endif -#if ANY(HAS_BEEPER, LCD_USE_I2C_BUZZER, PCA9632_BUZZER) - #define HAS_BUZZER 1 +#if ANY(IS_TFTGLCD_PANEL, PCA9632_BUZZER, LCD_USE_I2C_BUZZER) + #define USE_MARLINUI_BUZZER 1 +#endif +#if EITHER(HAS_BEEPER, USE_MARLINUI_BUZZER) + #define HAS_SOUND 1 #endif #if ENABLED(LCD_USE_I2C_BUZZER) @@ -3575,7 +3578,7 @@ #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 #endif -#elif HAS_BUZZER +#elif HAS_SOUND #ifndef LCD_FEEDBACK_FREQUENCY_HZ #define LCD_FEEDBACK_FREQUENCY_HZ 5000 #endif @@ -3584,12 +3587,13 @@ #endif #endif -#if HAS_BUZZER +#if HAS_SOUND #if LCD_FEEDBACK_FREQUENCY_DURATION_MS && LCD_FEEDBACK_FREQUENCY_HZ #define HAS_CHIRP 1 #endif #else #undef SOUND_MENU_ITEM // No buzzer menu item without a buzzer + #undef SOUND_ON_DEFAULT #endif /** diff --git a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp index d8306dbf94..b8dc8db817 100644 --- a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp +++ b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp @@ -120,10 +120,11 @@ static void createChar_P(const char c, const byte * const ptr) { #endif #if ENABLED(LCD_USE_I2C_BUZZER) + void MarlinUI::buzz(const long duration, const uint16_t freq) { - if (!sound_on) return; - lcd.buzz(duration, freq); + if (sound_on) lcd.buzz(duration, freq); } + #endif void MarlinUI::set_custom_characters(const HD44780CharSet screen_charset/*=CHARSET_INFO*/) { diff --git a/Marlin/src/lcd/e3v2/common/encoder.cpp b/Marlin/src/lcd/e3v2/common/encoder.cpp index 9922b70b29..f14d63e7b5 100644 --- a/Marlin/src/lcd/e3v2/common/encoder.cpp +++ b/Marlin/src/lcd/e3v2/common/encoder.cpp @@ -36,7 +36,7 @@ #include "../../marlinui.h" #include "../../../HAL/shared/Delay.h" -#if HAS_BUZZER +#if HAS_SOUND #include "../../../libs/buzzer.h" #endif @@ -50,9 +50,7 @@ ENCODER_Rate EncoderRate; // TODO: Replace with ui.quick_feedback void Encoder_tick() { - #if PIN_EXISTS(BEEPER) - if (ui.sound_on) buzzer.click(10); - #endif + TERN_(HAS_BEEPER, if (ui.sound_on) buzzer.click(10)); } // Encoder initialization @@ -66,7 +64,7 @@ void Encoder_Configuration() { #if BUTTON_EXISTS(ENC) SET_INPUT_PULLUP(BTN_ENC); #endif - #if PIN_EXISTS(BEEPER) + #if HAS_BEEPER SET_OUTPUT(BEEPER_PIN); // TODO: Use buzzer.h which already inits this #endif } diff --git a/Marlin/src/lcd/e3v2/creality/dwin.cpp b/Marlin/src/lcd/e3v2/creality/dwin.cpp index 3ca7627db0..1232c8e0c9 100644 --- a/Marlin/src/lcd/e3v2/creality/dwin.cpp +++ b/Marlin/src/lcd/e3v2/creality/dwin.cpp @@ -2625,15 +2625,13 @@ void Draw_HomeOff_Menu() { #include "../../../libs/buzzer.h" void HMI_AudioFeedback(const bool success=true) { - #if HAS_BUZZER - if (success) { - buzzer.tone(100, 659); - buzzer.tone(10, 0); - buzzer.tone(100, 698); - } - else - buzzer.tone(40, 440); - #endif + if (success) { + BUZZ(100, 659); + BUZZ(10, 0); + BUZZ(100, 698); + } + else + BUZZ(40, 440); } // Prepare diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index 7707cbb052..5b17b0b975 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -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 diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h index 9d2fba446a..a4166c4100 100644 --- a/Marlin/src/lcd/marlinui.h +++ b/Marlin/src/lcd/marlinui.h @@ -225,12 +225,12 @@ public: static constexpr bool sound_on = true; #endif - #if HAS_BUZZER + #if USE_MARLINUI_BUZZER static void buzz(const long duration, const uint16_t freq); #endif - FORCE_INLINE static void chirp() { - TERN_(HAS_CHIRP, TERN(HAS_BUZZER, buzz, BUZZ)(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ)); + static void chirp() { + TERN_(HAS_CHIRP, TERN(USE_MARLINUI_BUZZER, buzz, BUZZ)(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ)); } #if ENABLED(LCD_HAS_STATUS_INDICATORS) @@ -453,7 +453,7 @@ public: #endif static void quick_feedback(const bool clear_buttons=true); - #if HAS_BUZZER + #if HAS_SOUND static void completion_feedback(const bool good=true); #else static void completion_feedback(const bool=true) { TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); } diff --git a/Marlin/src/lcd/menu/game/game.h b/Marlin/src/lcd/menu/game/game.h index 999aa78100..ba123cb98b 100644 --- a/Marlin/src/lcd/menu/game/game.h +++ b/Marlin/src/lcd/menu/game/game.h @@ -28,7 +28,7 @@ //#define MUTE_GAMES -#if ENABLED(MUTE_GAMES) || !HAS_BUZZER +#if ENABLED(MUTE_GAMES) || !HAS_SOUND #define _BUZZ(D,F) NOOP #else #define _BUZZ(D,F) BUZZ(D,F) diff --git a/Marlin/src/lcd/menu/menu.cpp b/Marlin/src/lcd/menu/menu.cpp index c11f389276..9dd74988f3 100644 --- a/Marlin/src/lcd/menu/menu.cpp +++ b/Marlin/src/lcd/menu/menu.cpp @@ -31,7 +31,7 @@ #include "../../module/temperature.h" #include "../../gcode/queue.h" -#if HAS_BUZZER +#if HAS_SOUND #include "../../libs/buzzer.h" #endif @@ -272,7 +272,7 @@ void scroll_screen(const uint8_t limit, const bool is_menu) { encoderTopLine = encoderLine; } -#if HAS_BUZZER +#if HAS_SOUND void MarlinUI::completion_feedback(const bool good/*=true*/) { TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); // Wake up on rotary encoder click... if (good) OKAY_BUZZ(); else ERR_BUZZ(); diff --git a/Marlin/src/libs/buzzer.h b/Marlin/src/libs/buzzer.h index b1c286a662..cd8e17d004 100644 --- a/Marlin/src/libs/buzzer.h +++ b/Marlin/src/libs/buzzer.h @@ -117,11 +117,11 @@ // Buzz directly via the BEEPER pin tone queue #define BUZZ(d,f) buzzer.tone(d, f) -#elif HAS_BUZZER +#elif USE_MARLINUI_BUZZER - // Buzz indirectly via the MarlinUI instance - #define BUZZ(d,f) ui.buzz(d,f) + // Use MarlinUI for a buzzer on the LCD #include "../lcd/marlinui.h" + #define BUZZ(d,f) ui.buzz(d,f) #else diff --git a/Marlin/src/module/printcounter.cpp b/Marlin/src/module/printcounter.cpp index 619fbc137c..ad6f4eff68 100644 --- a/Marlin/src/module/printcounter.cpp +++ b/Marlin/src/module/printcounter.cpp @@ -37,7 +37,7 @@ Stopwatch print_job_timer; // Global Print Job Timer instance #include "../MarlinCore.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" #endif @@ -156,7 +156,7 @@ void PrintCounter::loadStats() { #if SERVICE_INTERVAL_3 > 0 if (data.nextService3 == 0) doBuzz = _service_warn(PSTR(" " SERVICE_NAME_3)); #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); } #else UNUSED(doBuzz); diff --git a/ini/features.ini b/ini/features.ini index 6eebbe8fd2..a763213299 100644 --- a/ini/features.ini +++ b/ini/features.ini @@ -202,7 +202,7 @@ HAS_STATUS_MESSAGE = src_filter=+ HAS_LCD_CONTRAST = src_filter=+ HAS_GCODE_M255 = src_filter=+ HAS_LCD_BRIGHTNESS = src_filter=+ -HAS_BUZZER = src_filter=+ +HAS_SOUND = src_filter=+ TOUCH_SCREEN_CALIBRATION = src_filter=+ ARC_SUPPORT = src_filter=+ GCODE_MOTION_MODES = src_filter=+