BUZZ cleanup (#14760)

This commit is contained in:
Ludy 2019-07-29 02:14:50 +02:00 committed by Scott Lahteine
parent 6b02b89ab4
commit c4bb458763
12 changed files with 74 additions and 34 deletions

View file

@ -54,7 +54,11 @@
#endif
#include "../lcd/ultralcd.h"
#include "../libs/buzzer.h"
#if HAS_BUZZER
#include "../libs/buzzer.h"
#endif
#include "../libs/nozzle.h"
#include "pause.h"

View file

@ -79,7 +79,7 @@ void BrickoutGame::game_screen() {
}
// Did the ball go below the bottom?
else if (newy > BTOF(LCD_PIXEL_HEIGHT)) {
BUZZ(500, 75);
_BUZZ(500, 75);
if (--bdat.balls_left) reset_ball(); else game_state = 0;
break; // done
}

View file

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

View file

@ -31,7 +31,9 @@
#include "../../module/printcounter.h"
#include "../../gcode/queue.h"
#include "../../sd/cardreader.h"
#include "../../libs/buzzer.h"
#if HAS_BUZZER
#include "../../libs/buzzer.h"
#endif
#if ENABLED(EEPROM_SETTINGS)
#include "../../module/configuration_store.h"
@ -346,13 +348,15 @@ void scroll_screen(const uint8_t limit, const bool is_menu) {
encoderTopLine = encoderLine;
}
void MarlinUI::completion_feedback(const bool good/*=true*/) {
if (good) {
BUZZ(100, 659);
BUZZ(100, 698);
#if HAS_BUZZER
void MarlinUI::completion_feedback(const bool good/*=true*/) {
if (good) {
BUZZ(100, 659);
BUZZ(100, 698);
}
else BUZZ(20, 440);
}
else BUZZ(20, 440);
}
#endif
#if HAS_LINE_TO_Z
@ -433,8 +437,18 @@ void MarlinUI::completion_feedback(const bool good/*=true*/) {
#endif
#if ENABLED(EEPROM_SETTINGS)
void lcd_store_settings() { ui.completion_feedback(settings.save()); }
void lcd_load_settings() { ui.completion_feedback(settings.load()); }
void lcd_store_settings() {
const bool saved = settings.save();
#if HAS_BUZZER
ui.completion_feedback(saved);
#endif
}
void lcd_load_settings() {
const bool loaded = settings.load();
#if HAS_BUZZER
ui.completion_feedback(loaded);
#endif
}
#endif
void _lcd_draw_homing() {

View file

@ -603,7 +603,12 @@ void menu_backlash();
static void lcd_init_eeprom_confirm() {
do_select_screen(
PSTR(MSG_BUTTON_INIT), PSTR(MSG_BUTTON_CANCEL),
[]{ ui.completion_feedback(settings.init_eeprom()); },
[]{
const bool inited = settings.init_eeprom();
#if HAS_BUZZER
ui.completion_feedback(inited);
#endif
},
ui.goto_previous_screen,
PSTR(MSG_INIT_EEPROM), nullptr, PSTR("?")
);
@ -698,8 +703,11 @@ void menu_advanced_settings() {
//
// Toggle the SD Firmware Update state in EEPROM
//
const bool new_state = !settings.sd_update_status();
ui.completion_feedback(settings.set_sd_update_status(new_state));
const bool new_state = !settings.sd_update_status(),
didset = settings.set_sd_update_status(new_state);
#if HAS_BUZZER
ui.completion_feedback(didset);
#endif
ui.return_to_status();
if (new_state) LCD_MESSAGEPGM(MSG_RESET_PRINTER); else ui.reset_status();
});

View file

@ -77,7 +77,9 @@
ui.synchronize(PSTR(MSG_LEVEL_BED_DONE));
#endif
ui.goto_previous_screen_no_defer();
ui.completion_feedback();
#if HAS_BUZZER
ui.completion_feedback();
#endif
}
if (ui.should_draw()) draw_menu_item_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_LEVEL_BED_DONE));
ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);

View file

@ -56,7 +56,9 @@ void menu_advanced_settings();
static void lcd_factory_settings() {
settings.reset();
ui.completion_feedback();
#if HAS_BUZZER
ui.completion_feedback();
#endif
}
#if ENABLED(LCD_PROGRESS_BAR_TEST)

View file

@ -39,7 +39,7 @@
void _lcd_user_gcode(PGM_P const cmd) {
queue.inject_P(cmd);
#if ENABLED(USER_SCRIPT_AUDIBLE_FEEDBACK)
#if ENABLED(USER_SCRIPT_AUDIBLE_FEEDBACK) && HAS_BUZZER
ui.completion_feedback();
#endif
#if ENABLED(USER_SCRIPT_RETURN)

View file

@ -38,7 +38,9 @@ inline void _menu_service(const int index, PGM_P const name) {
PSTR(MSG_BUTTON_RESET), PSTR(MSG_BUTTON_CANCEL),
[]{
print_job_timer.resetServiceInterval(index);
ui.completion_feedback(true);
#if HAS_BUZZER
ui.completion_feedback();
#endif
ui.reset_status();
ui.return_to_status();
},

View file

@ -562,7 +562,7 @@ void MarlinUI::status_screen() {
if (old_frm != new_frm) {
feedrate_percentage = new_frm;
encoderPosition = 0;
#if ENABLED(BEEP_ON_FEEDRATE_CHANGE)
#if HAS_BUZZER && ENABLED(BEEP_ON_FEEDRATE_CHANGE)
static millis_t next_beep;
#ifndef GOT_MS
const millis_t ms = millis();
@ -608,8 +608,10 @@ void MarlinUI::quick_feedback(const bool clear_buttons/*=true*/) {
UNUSED(clear_buttons);
#endif
// Buzz and wait. The delay is needed for buttons to settle!
buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
#if HAS_BUZZER
// Buzz and wait. Is the delay needed for buttons to settle?
buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
#endif
#if HAS_LCD_MENU
#if ENABLED(LCD_USE_I2C_BUZZER)

View file

@ -258,15 +258,15 @@ public:
#endif
}
static inline void buzz(const long duration, const uint16_t freq) {
#if ENABLED(LCD_USE_I2C_BUZZER)
lcd.buzz(duration, freq);
#elif PIN_EXISTS(BEEPER)
buzzer.tone(duration, freq);
#else
UNUSED(duration); UNUSED(freq);
#endif
}
#if HAS_BUZZER
static inline void buzz(const long duration, const uint16_t freq) {
#if ENABLED(LCD_USE_I2C_BUZZER)
lcd.buzz(duration, freq);
#elif PIN_EXISTS(BEEPER)
buzzer.tone(duration, freq);
#endif
}
#endif
// LCD implementations
static void clear_lcd();
@ -355,7 +355,9 @@ public:
#endif
static void quick_feedback(const bool clear_buttons=true);
static void completion_feedback(const bool good=true);
#if HAS_BUZZER
static void completion_feedback(const bool good=true);
#endif
#if DISABLED(LIGHTWEIGHT_UI)
static void draw_status_message(const bool blink);
@ -466,7 +468,11 @@ public:
#endif
#if ENABLED(G26_MESH_VALIDATION)
static inline void chirp() { buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ); }
static inline void chirp() {
#if HAS_BUZZER
buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
#endif
}
#endif
#if ENABLED(AUTO_BED_LEVELING_UBL)

View file

@ -68,7 +68,7 @@
#include "tool_change.h"
#endif
#if HAS_BUZZER
#if HAS_BUZZER && PIN_EXISTS(BEEPER)
#include "../libs/buzzer.h"
#endif