Skip to content

Commit

Permalink
Better outline of LCD buzzer
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jul 19, 2022
1 parent 6912e1f commit 2b477d7
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/feature/spindle_laser.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class SpindleLaser {
* 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.
Expand Down
6 changes: 5 additions & 1 deletion Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -3564,7 +3564,10 @@
#if PIN_EXISTS(BEEPER)
#define HAS_BEEPER 1
#endif
#if ANY(HAS_BEEPER, LCD_USE_I2C_BUZZER, PCA9632_BUZZER)
#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

Expand All @@ -3590,6 +3593,7 @@
#endif
#else
#undef SOUND_MENU_ITEM // No buzzer menu item without a buzzer
#undef SOUND_ON_DEFAULT
#endif

/**
Expand Down
5 changes: 3 additions & 2 deletions Marlin/src/lcd/HD44780/marlinui_HD44780.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*/) {
Expand Down
6 changes: 2 additions & 4 deletions Marlin/src/lcd/e3v2/common/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
16 changes: 7 additions & 9 deletions Marlin/src/lcd/e3v2/creality/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 7 additions & 12 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,10 @@ 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 USE_MARLINUI_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);
if (sound_on) PCA9632_buzz(duration, freq);
#endif
}
#endif
Expand Down Expand Up @@ -741,11 +735,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
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 @@ -223,12 +223,12 @@ class MarlinUI {
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)
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/libs/buzzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2b477d7

Please sign in to comment.