Skip to content

Commit

Permalink
prefer BUZZ macro
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Apr 30, 2022
1 parent 3e2ec6d commit 043dd09
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 30 deletions.
4 changes: 2 additions & 2 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1346,8 +1346,8 @@
#endif // HAS_MARLINUI_MENU

#if ANY(HAS_DISPLAY, DWIN_LCD_PROUI, DWIN_CREALITY_LCD_JYERSUI)
//#define SOUND_MENU_ITEM // Add a mute option to the LCD menu
//#define BUZZER_ENABLED_DEFAULT // Buzzer/speaker default enabled state
//#define SOUND_MENU_ITEM // Add a mute option to the LCD menu
//#define SOUND_ON_DEFAULT // Buzzer/speaker default enabled state
#endif

#if EITHER(HAS_DISPLAY, DWIN_LCD_PROUI)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/HD44780/marlinui_HD44780.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,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;
if (!sound_on) return;
lcd.buzz(duration, freq);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ uint8_t MarlinUI::read_slow_buttons() {
// Duration in ms, freq in Hz
void MarlinUI::buzz(const long duration, const uint16_t freq) {
if (!PanelDetected) return;
if (!buzzer_enabled) return;
if (!sound_on) return;
#if ENABLED(TFTGLCD_PANEL_SPI)
WRITE(TFTGLCD_CS, LOW);
SPI_SEND_ONE(BUZZER);
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/e3v2/common/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ENCODER_Rate EncoderRate;
// TODO: Replace with ui.quick_feedback
void Encoder_tick() {
#if PIN_EXISTS(BEEPER)
if (ui.buzzer_enabled) {
if (ui.sound_on) {
WRITE(BEEPER_PIN, HIGH);
delay(10);
WRITE(BEEPER_PIN, LOW);
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/lcd/e3v2/jyersui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2587,11 +2587,11 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
case ADVANCED_BEEPER:
if (draw) {
Draw_Menu_Item(row, ICON_Version, F("LCD Beeper"));
Draw_Checkbox(row, ui.buzzer_enabled);
Draw_Checkbox(row, ui.sound_on);
}
else {
ui.buzzer_enabled = !ui.buzzer_enabled;
Draw_Checkbox(row, ui.buzzer_enabled);
ui.sound_on = !ui.sound_on;
Draw_Checkbox(row, ui.sound_on);
}
break;
#endif
Expand Down Expand Up @@ -4611,7 +4611,7 @@ void CrealityDWINClass::Screen_Update() {
}

void CrealityDWINClass::AudioFeedback(const bool success/*=true*/) {
if (ui.buzzer_enabled)
if (ui.sound_on)
DONE_BUZZ(success);
else
Update_Status(success ? "Success" : "Failed");
Expand Down Expand Up @@ -4655,7 +4655,7 @@ void CrealityDWINClass::Reset_Settings() {
eeprom_settings.coordinates_split_line = 0;
TERN_(AUTO_BED_LEVELING_UBL, mesh_conf.tilt_grid = eeprom_settings.tilt_grid_size + 1);
corner_pos = eeprom_settings.corner_pos / 10.0f;
TERN_(SOUND_MENU_ITEM, ui.buzzer_enabled = ENABLED(BUZZER_ENABLED_DEFAULT));
TERN_(SOUND_MENU_ITEM, ui.sound_on = ENABLED(SOUND_ON_DEFAULT));
Redraw_Screen();
}

Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/e3v2/proui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2106,8 +2106,8 @@ void SetPID(celsius_t t, heater_id_t h) {

#if ENABLED(SOUND_MENU_ITEM)
void SetEnableSound() {
ui.buzzer_enabled = !ui.buzzer_enabled;
Draw_Chkb_Line(CurrentMenu->line(), ui.buzzer_enabled);
ui.sound_on = !ui.sound_on;
Draw_Chkb_Line(CurrentMenu->line(), ui.sound_on);
DWIN_UpdateLCD();
}
#endif
Expand Down Expand Up @@ -2638,7 +2638,7 @@ void onDrawLanguage(MenuItemClass* menuitem, int8_t line) {
#endif

#if ENABLED(SOUND_MENU_ITEM)
void onDrawEnableSound(MenuItemClass* menuitem, int8_t line) { onDrawChkbMenu(menuitem, line, ui.buzzer_enabled); }
void onDrawEnableSound(MenuItemClass* menuitem, int8_t line) { onDrawChkbMenu(menuitem, line, ui.sound_on); }
#endif

#ifdef BLTOUCH_HS_MODE
Expand Down
11 changes: 6 additions & 5 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,17 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
#endif

#if ENABLED(SOUND_MENU_ITEM)
bool MarlinUI::buzzer_enabled = ENABLED(BUZZER_ENABLED_DEFAULT);
bool MarlinUI::sound_on = ENABLED(SOUND_ON_DEFAULT);
#endif

#include "../libs/buzzer.h" // for BUZZ() macro

#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 (!sound_on) return;
#if ENABLED(PCA9632_BUZZER)
PCA9632_buzz(duration, freq);
#elif USE_BEEPER
Expand Down Expand Up @@ -694,7 +695,7 @@ void MarlinUI::init() {
const millis_t ms = millis();
#endif
if (ELAPSED(ms, next_beep)) {
buzz(FEEDRATE_CHANGE_BEEP_DURATION, FEEDRATE_CHANGE_BEEP_FREQUENCY);
BUZZ(FEEDRATE_CHANGE_BEEP_DURATION, FEEDRATE_CHANGE_BEEP_FREQUENCY);
next_beep = ms + 500UL;
}
#endif
Expand Down Expand Up @@ -1646,7 +1647,7 @@ void MarlinUI::init() {

void MarlinUI::flow_fault() {
LCD_ALERTMESSAGE(MSG_FLOWMETER_FAULT);
TERN_(HAS_BUZZER, buzz(1000, 440));
BUZZ(1000, 440);
TERN_(HAS_MARLINUI_MENU, return_to_status());
}

Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/marlinui.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,17 @@ class MarlinUI {
#endif

#if ENABLED(SOUND_MENU_ITEM)
static bool buzzer_enabled; // Initialized by settings.load()
static bool sound_on; // Initialized by settings.load()
#else
static constexpr bool buzzer_enabled = ENABLED(BUZZER_ENABLED_DEFAULT);
static constexpr bool sound_on = ENABLED(SOUND_ON_DEFAULT);
#endif

#if HAS_BUZZER
static void buzz(const long duration, const uint16_t freq);
#endif

FORCE_INLINE static void chirp() {
TERN_(HAS_CHIRP, buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ));
TERN_(HAS_CHIRP, BUZZ(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ));
}

#if ENABLED(LCD_HAS_STATUS_INDICATORS)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_bed_corners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ static void _lcd_level_bed_corners_get_next_position() {
probe_triggered = PROBE_TRIGGERED();
if (probe_triggered) {
endstops.hit_on_purpose();
TERN_(LEVEL_CORNERS_AUDIO_FEEDBACK, ui.buzz(200, 600));
TERN_(LEVEL_CORNERS_AUDIO_FEEDBACK, BUZZ(200, 600));
}
idle();
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ void menu_configuration() {
#endif

#if ENABLED(SOUND_MENU_ITEM)
EDIT_ITEM(bool, MSG_SOUND, &ui.buzzer_enabled, []{ ui.chirp(); });
EDIT_ITEM(bool, MSG_SOUND, &ui.sound_on, []{ ui.chirp(); });
#endif

#if ENABLED(EEPROM_SETTINGS)
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/libs/buzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +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;
if (!ui.sound_on) return;
while (buffer.isFull()) {
tick();
thermalManager.manage_heater();
Expand All @@ -55,7 +55,7 @@ void Buzzer::tone(const uint16_t duration, const uint16_t frequency/*=0*/) {
}

void Buzzer::tick() {
if (!ui.buzzer_enabled) return;
if (!ui.sound_on) return;
const millis_t now = millis();

if (!state.endtime) {
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/module/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ typedef struct SettingsDataStruct {
// Buzzer enable/disable
//
#if ENABLED(SOUND_MENU_ITEM)
bool buzzer_enabled;
bool sound_on;
#endif

//
Expand Down Expand Up @@ -1576,7 +1576,7 @@ void MarlinSettings::postprocess() {
// Buzzer enable/disable
//
#if ENABLED(SOUND_MENU_ITEM)
EEPROM_WRITE(ui.buzzer_enabled);
EEPROM_WRITE(ui.sound_on);
#endif

//
Expand Down Expand Up @@ -2546,8 +2546,8 @@ void MarlinSettings::postprocess() {
// Buzzer enable/disable
//
#if ENABLED(SOUND_MENU_ITEM)
_FIELD_TEST(buzzer_enabled);
EEPROM_READ(ui.buzzer_enabled);
_FIELD_TEST(sound_on);
EEPROM_READ(ui.sound_on);
#endif

//
Expand Down Expand Up @@ -2946,7 +2946,7 @@ void MarlinSettings::reset() {
// Buzzer enable/disable
//
#if ENABLED(SOUND_MENU_ITEM)
ui.buzzer_enabled = ENABLED(BUZZER_ENABLED_DEFAULT);
ui.sound_on = ENABLED(SOUND_ON_DEFAULT);
#endif

//
Expand Down

0 comments on commit 043dd09

Please sign in to comment.