diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 6c7c38e94..24eb89115 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -52,6 +52,7 @@ #include "language.h" #include "pins_arduino.h" #include "math.h" +#include "buzzer.h" #ifdef BLINKM #include "blinkm.h" diff --git a/Marlin/buzzer.cpp b/Marlin/buzzer.cpp new file mode 100644 index 000000000..e52f2fb41 --- /dev/null +++ b/Marlin/buzzer.cpp @@ -0,0 +1,22 @@ +#include "Marlin.h" +#include "buzzer.h" +#include "ultralcd.h" + +#if HAS_BUZZER + void buzz(long duration, uint16_t freq) { + if (freq > 0) { + #ifdef LCD_USE_I2C_BUZZER + lcd_buzz(duration, freq); + #elif defined(BEEPER) && BEEPER >= 0 // on-board buzzers have no further condition + SET_OUTPUT(BEEPER); + tone(BEEPER, freq, duration); + delay(duration); + #else + delay(duration); + #endif + } + else { + delay(duration); + } + } +#endif diff --git a/Marlin/buzzer.h b/Marlin/buzzer.h new file mode 100644 index 000000000..7d627fc93 --- /dev/null +++ b/Marlin/buzzer.h @@ -0,0 +1,8 @@ +#ifndef BUZZER_H + #define BUZZER_H + + #if HAS_BUZZER + void buzz(long duration,uint16_t freq); + #endif + +#endif BUZZER_H \ No newline at end of file diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 5ecb90705..e573f8561 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -1302,6 +1302,13 @@ menu_edit_type(unsigned long, long5, ftostr5, 0.01) * Audio feedback for controller clicks * */ + +#ifdef LCD_USE_I2C_BUZZER + void lcd_buzz(long duration, uint16_t freq) { // called from buzz() in Marlin_main.cpp where lcd is unknown + lcd.buzz(duration, freq); + } +#endif + void lcd_quick_feedback() { lcdDrawUpdate = 2; next_button_update_ms = millis() + 500; @@ -1313,7 +1320,7 @@ void lcd_quick_feedback() { #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS #define LCD_FEEDBACK_FREQUENCY_DURATION_MS (1000/6) #endif - buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ); + lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ); #elif defined(BEEPER) && BEEPER >= 0 #ifndef LCD_FEEDBACK_FREQUENCY_HZ #define LCD_FEEDBACK_FREQUENCY_HZ 5000 @@ -1749,25 +1756,6 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; } #endif // ULTIPANEL -#if HAS_BUZZER - void buzz(long duration, uint16_t freq) { - if (freq > 0) { - #ifdef LCD_USE_I2C_BUZZER - lcd.buzz(duration, freq); - #elif defined(BEEPER) && BEEPER >= 0 - SET_OUTPUT(BEEPER); - tone(BEEPER, freq, duration); - delay(duration); - #else - delay(duration); - #endif - } - else { - delay(duration); - } - } -#endif - /*********************************/ /** Number to string conversion **/ /*********************************/ diff --git a/Marlin/ultralcd.h b/Marlin/ultralcd.h index 8560d1179..0eb94db4f 100644 --- a/Marlin/ultralcd.h +++ b/Marlin/ultralcd.h @@ -2,6 +2,7 @@ #define ULTRALCD_H #include "Marlin.h" +#include "buzzer.h" #ifdef ULTRA_LCD int lcd_strlen(char *s); @@ -15,6 +16,10 @@ void lcd_reset_alert_level(); bool lcd_detected(void); + #ifdef LCD_USE_I2C_BUZZER + void lcd_buzz(long duration, uint16_t freq); + #endif + #if defined(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0 void dontExpireStatus(); #endif @@ -111,10 +116,6 @@ #endif //ULTRA_LCD -#if HAS_BUZZER - void buzz(long duration,uint16_t freq); -#endif - char *itostr2(const uint8_t &x); char *itostr31(const int &xx); char *itostr3(const int &xx);