From d7d1ef82284eec8fa961b4f67447de59dc53b5d2 Mon Sep 17 00:00:00 2001 From: Lucas Seiki Oshiro Date: Tue, 27 Oct 2020 22:41:12 -0300 Subject: [PATCH] "Sound: ON/OFF" menu item (#19901) Co-authored-by: Scott Lahteine --- Marlin/Configuration_adv.h | 3 +++ Marlin/src/inc/Conditionals_post.h | 16 ++++++----- Marlin/src/lcd/HD44780/marlinui_HD44780.cpp | 1 + Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp | 1 + Marlin/src/lcd/language/language_en.h | 1 + Marlin/src/lcd/marlinui.cpp | 5 ++++ Marlin/src/lcd/marlinui.h | 6 +++++ Marlin/src/lcd/menu/menu_configuration.cpp | 8 ++++++ Marlin/src/libs/buzzer.cpp | 8 +++--- Marlin/src/module/settings.cpp | 30 +++++++++++++++++++++ buildroot/tests/LPC1768-tests | 2 +- buildroot/tests/mega2560-tests | 4 +-- buildroot/tests/teensy35-tests | 2 +- 13 files changed, 74 insertions(+), 13 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 31661a582e..951aab7804 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1090,6 +1090,9 @@ // BACK menu items keep the highlight at the top //#define TURBO_BACK_MENU_ITEM + // Add a mute option to the LCD menu + //#define SOUND_MENU_ITEM + /** * LED Control Menu * Add LED Control to the LCD menu diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index bb717ba097..bbbcf6fb2f 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -2505,11 +2505,11 @@ /** * Buzzer/Speaker */ -#if PIN_EXISTS(BEEPER) || ANY(LCD_USE_I2C_BUZZER, PCA9632_BUZZER) +#if PIN_EXISTS(BEEPER) + #define USE_BEEPER 1 +#endif +#if USE_BEEPER || ANY(LCD_USE_I2C_BUZZER, PCA9632_BUZZER) #define HAS_BUZZER 1 - #if PIN_EXISTS(BEEPER) - #define USE_BEEPER 1 - #endif #endif #if ENABLED(LCD_USE_I2C_BUZZER) @@ -2528,8 +2528,12 @@ #endif #endif -#if HAS_BUZZER && LCD_FEEDBACK_FREQUENCY_DURATION_MS && LCD_FEEDBACK_FREQUENCY_HZ - #define HAS_CHIRP 1 +#if HAS_BUZZER + #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 #endif /** diff --git a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp index 4b82458398..81862e1ddf 100644 --- a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp +++ b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp @@ -113,6 +113,7 @@ static void createChar_P(const char c, const byte * const ptr) { #if ENABLED(LCD_USE_I2C_BUZZER) void MarlinUI::buzz(const long duration, const uint16_t freq) { + if (!buzzer_enabled) return; lcd.buzz(duration, freq); } #endif diff --git a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp index c21c2ceb58..571d576bbc 100644 --- a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp +++ b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp @@ -289,6 +289,7 @@ uint8_t MarlinUI::read_slow_buttons(void) { // Duration in ms, freq in Hz void MarlinUI::buzz(const long duration, const uint16_t freq) { if (!PanelDetected) return; + if (!buzzer_enabled) return; #if ENABLED(TFTGLCD_PANEL_SPI) WRITE(TFTGLCD_CS, LOW); SPI_SEND_ONE(BUZZER); diff --git a/Marlin/src/lcd/language/language_en.h b/Marlin/src/lcd/language/language_en.h index e8b4769cc2..8bf4fa6b7e 100644 --- a/Marlin/src/lcd/language/language_en.h +++ b/Marlin/src/lcd/language/language_en.h @@ -659,6 +659,7 @@ namespace Language_en { PROGMEM Language_Str MSG_REHEATING = _UxGT("Reheating..."); PROGMEM Language_Str MSG_PROBE_WIZARD = _UxGT("Z Probe Wizard"); + PROGMEM Language_Str MSG_SOUND = _UxGT("Sound"); } #if FAN_COUNT == 1 diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index 0a87965721..1994e4094b 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -74,12 +74,17 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP; #endif #endif +#if ENABLED(SOUND_MENU_ITEM) + bool MarlinUI::buzzer_enabled = true; +#endif + #if EITHER(PCA9632_BUZZER, USE_BEEPER) #include "../libs/buzzer.h" // for BUZZ() macro #if ENABLED(PCA9632_BUZZER) #include "../feature/leds/pca9632.h" #endif void MarlinUI::buzz(const long duration, const uint16_t freq) { + if (!buzzer_enabled) return; #if ENABLED(PCA9632_BUZZER) PCA9632_buzz(duration, freq); #elif USE_BEEPER diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h index bf9e47e0c8..d0b66aee45 100644 --- a/Marlin/src/lcd/marlinui.h +++ b/Marlin/src/lcd/marlinui.h @@ -292,6 +292,12 @@ public: TERN_(HAS_LCD_MENU, currentScreen = status_screen); } + #if ENABLED(SOUND_MENU_ITEM) + static bool buzzer_enabled; // Initialized by settings.load() + #else + static constexpr bool buzzer_enabled = true; + #endif + #if HAS_BUZZER static void buzz(const long duration, const uint16_t freq); #endif diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index 22947ee514..f667242bc1 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -45,6 +45,10 @@ #endif #endif +#if ENABLED(SOUND_MENU_ITEM) + #include "../../libs/buzzer.h" +#endif + #define HAS_DEBUG_MENU ENABLED(LCD_PROGRESS_BAR_TEST) void menu_advanced_settings(); @@ -412,6 +416,10 @@ void menu_configuration() { SUBMENU_N_S(m, ui.get_preheat_label(m), MSG_PREHEAT_M_SETTINGS, _menu_configuration_preheat_settings); #endif + #if ENABLED(SOUND_MENU_ITEM) + EDIT_ITEM(bool, MSG_SOUND, &ui.buzzer_enabled, []{ ui.chirp(); }); + #endif + #if ENABLED(EEPROM_SETTINGS) ACTION_ITEM(MSG_STORE_EEPROM, ui.store_settings); if (!busy) ACTION_ITEM(MSG_LOAD_EEPROM, ui.load_settings); diff --git a/Marlin/src/libs/buzzer.cpp b/Marlin/src/libs/buzzer.cpp index 8459695359..57ed5fb419 100644 --- a/Marlin/src/libs/buzzer.cpp +++ b/Marlin/src/libs/buzzer.cpp @@ -26,6 +26,7 @@ #include "buzzer.h" #include "../module/temperature.h" +#include "../lcd/marlinui.h" #if ENABLED(EXTENSIBLE_UI) #include "../lcd/extui/ui_api.h" @@ -44,6 +45,7 @@ Buzzer buzzer; * @param frequency Frequency of the tone in hertz */ void Buzzer::tone(const uint16_t duration, const uint16_t frequency/*=0*/) { + if (!ui.buzzer_enabled) return; while (buffer.isFull()) { tick(); thermalManager.manage_heater(); @@ -53,6 +55,7 @@ void Buzzer::tone(const uint16_t duration, const uint16_t frequency/*=0*/) { } void Buzzer::tick() { + if (!ui.buzzer_enabled) return; const millis_t now = millis(); if (!state.endtime) { @@ -62,12 +65,11 @@ void Buzzer::tick() { state.endtime = now + state.tone.duration; if (state.tone.frequency > 0) { - #if ENABLED(EXTENSIBLE_UI) + #if ENABLED(EXTENSIBLE_UI) && DISABLED(EXTUI_LOCAL_BEEPER) CRITICAL_SECTION_START(); ExtUI::onPlayTone(state.tone.frequency, state.tone.duration); CRITICAL_SECTION_END(); - #endif - #if ENABLED(SPEAKER) && (DISABLED(EXTENSIBLE_UI) || ENABLED(EXTUI_LOCAL_BEEPER)) + #elif ENABLED(SPEAKER) CRITICAL_SECTION_START(); ::tone(BEEPER_PIN, state.tone.frequency, state.tone.duration); CRITICAL_SECTION_END(); diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index d01486a80d..5c646c85dd 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -153,6 +153,10 @@ #include "../feature/ethernet.h" #endif +#if ENABLED(SOUND_MENU_ITEM) + #include "../libs/buzzer.h" +#endif + #pragma pack(push, 1) // No padding between variables #if HAS_ETHERNET @@ -451,6 +455,12 @@ typedef struct SettingsDataStruct { ethernet_subnet; // M554 P #endif + // + // Buzzer enable/disable + // + #if ENABLED(SOUND_MENU_ITEM) + bool buzzer_enabled; + #endif } SettingsData; //static_assert(sizeof(SettingsData) <= MARLIN_EEPROM_SIZE, "EEPROM too small to contain SettingsData!"); @@ -1422,6 +1432,13 @@ void MarlinSettings::postprocess() { } #endif + // + // Buzzer enable/disable + // + #if ENABLED(SOUND_MENU_ITEM) + EEPROM_WRITE(ui.buzzer_enabled); + #endif + // // Report final CRC and Data Size // @@ -2293,6 +2310,14 @@ void MarlinSettings::postprocess() { EEPROM_READ(ethernet_subnet); ethernet.subnet = ethernet_subnet; #endif + // + // Buzzer enable/disable + // + #if ENABLED(SOUND_MENU_ITEM) + _FIELD_TEST(buzzer_enabled); + EEPROM_READ(ui.buzzer_enabled); + #endif + // // Validate Final Size and CRC // @@ -2603,6 +2628,11 @@ void MarlinSettings::reset() { // TERN_(TOUCH_SCREEN_CALIBRATION, touch.calibration_reset()); + // + // Buzzer enable/disable + // + TERN_(SOUND_MENU_ITEM, ui.buzzer_enabled = true); + // // Magnetic Parking Extruder // diff --git a/buildroot/tests/LPC1768-tests b/buildroot/tests/LPC1768-tests index 2f206f02f2..7877b60721 100755 --- a/buildroot/tests/LPC1768-tests +++ b/buildroot/tests/LPC1768-tests @@ -38,7 +38,7 @@ opt_set EXTRUDERS 2 opt_set TEMP_SENSOR_1 -1 opt_set TEMP_SENSOR_BED 5 opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER SDSUPPORT ADAPTIVE_FAN_SLOWING NO_FAN_SLOWING_IN_PID_TUNING \ - FILAMENT_WIDTH_SENSOR FILAMENT_LCD_DISPLAY PID_EXTRUSION_SCALING \ + FILAMENT_WIDTH_SENSOR FILAMENT_LCD_DISPLAY PID_EXTRUSION_SCALING SOUND_MENU_ITEM \ NOZZLE_AS_PROBE AUTO_BED_LEVELING_BILINEAR G29_RETRY_AND_RECOVER Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE \ BABYSTEPPING BABYSTEP_XY BABYSTEP_ZPROBE_OFFSET BABYSTEP_ZPROBE_GFX_OVERLAY \ PRINTCOUNTER NOZZLE_PARK_FEATURE NOZZLE_CLEAN_FEATURE SLOW_PWM_HEATERS PIDTEMPBED EEPROM_SETTINGS INCH_MODE_SUPPORT TEMPERATURE_UNITS_SUPPORT \ diff --git a/buildroot/tests/mega2560-tests b/buildroot/tests/mega2560-tests index d3fd5c0192..a6902b9d14 100755 --- a/buildroot/tests/mega2560-tests +++ b/buildroot/tests/mega2560-tests @@ -27,7 +27,7 @@ opt_set TEMP_SENSOR_4 1000 opt_set TEMP_SENSOR_BED 1 opt_enable AUTO_BED_LEVELING_UBL RESTORE_LEVELING_AFTER_G28 DEBUG_LEVELING_FEATURE G26_MESH_VALIDATION ENABLE_LEVELING_FADE_HEIGHT SKEW_CORRECTION \ REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER LIGHTWEIGHT_UI STATUS_MESSAGE_SCROLLING BOOT_MARLIN_LOGO_SMALL \ - SDSUPPORT SDCARD_SORT_ALPHA USB_FLASH_DRIVE_SUPPORT SCROLL_LONG_FILENAMES CANCEL_OBJECTS \ + SDSUPPORT SDCARD_SORT_ALPHA USB_FLASH_DRIVE_SUPPORT SCROLL_LONG_FILENAMES CANCEL_OBJECTS SOUND_MENU_ITEM \ EEPROM_SETTINGS EEPROM_CHITCHAT GCODE_MACROS CUSTOM_USER_MENUS \ MULTI_NOZZLE_DUPLICATION CLASSIC_JERK LIN_ADVANCE EXTRA_LIN_ADVANCE_K QUICK_HOME \ LCD_SET_PROGRESS_MANUALLY PRINT_PROGRESS_SHOW_DECIMALS SHOW_REMAINING_TIME \ @@ -82,7 +82,7 @@ restore_configs opt_set MOTHERBOARD BOARD_MEGACONTROLLER opt_set LCD_LANGUAGE de opt_enable EEPROM_SETTINGS EEPROM_CHITCHAT \ - MINIPANEL SDSUPPORT PCA9632 LCD_INFO_MENU \ + MINIPANEL SDSUPPORT PCA9632 LCD_INFO_MENU SOUND_MENU_ITEM \ AUTO_BED_LEVELING_BILINEAR PROBE_MANUALLY LCD_BED_LEVELING G26_MESH_VALIDATION MESH_EDIT_MENU \ LIN_ADVANCE EXTRA_LIN_ADVANCE_K \ INCH_MODE_SUPPORT TEMPERATURE_UNITS_SUPPORT EXPERIMENTAL_I2CBUS M100_FREE_MEMORY_WATCHER \ diff --git a/buildroot/tests/teensy35-tests b/buildroot/tests/teensy35-tests index 20a0c19726..39ee4faf49 100755 --- a/buildroot/tests/teensy35-tests +++ b/buildroot/tests/teensy35-tests @@ -20,7 +20,7 @@ opt_set TEMP_SENSOR_0 1 opt_set TEMP_SENSOR_1 5 opt_set TEMP_SENSOR_BED 1 opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER LCD_INFO_MENU SDSUPPORT SDCARD_SORT_ALPHA \ - FILAMENT_WIDTH_SENSOR FILAMENT_LCD_DISPLAY CALIBRATION_GCODE BAUD_RATE_GCODE \ + FILAMENT_WIDTH_SENSOR FILAMENT_LCD_DISPLAY CALIBRATION_GCODE BAUD_RATE_GCODE SOUND_MENU_ITEM \ FIX_MOUNTED_PROBE Z_SAFE_HOMING AUTO_BED_LEVELING_BILINEAR Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE \ BABYSTEPPING BABYSTEP_XY BABYSTEP_ZPROBE_OFFSET BABYSTEP_ZPROBE_GFX_OVERLAY \ PRINTCOUNTER NOZZLE_PARK_FEATURE NOZZLE_CLEAN_FEATURE SLOW_PWM_HEATERS PIDTEMPBED EEPROM_SETTINGS INCH_MODE_SUPPORT TEMPERATURE_UNITS_SUPPORT M100_FREE_MEMORY_WATCHER \