From 4c3cbc09619155d0c397b46755129b55933f25c8 Mon Sep 17 00:00:00 2001 From: Christian Bohn Date: Wed, 25 Mar 2015 12:23:50 +0100 Subject: [PATCH 1/3] use only one implementation for beeper feedback --- Marlin/dogm_lcd_implementation.h | 12 --------- Marlin/ultralcd.cpp | 23 +++++++++++++++- .../ultralcd_implementation_hitachi_HD44780.h | 26 ------------------- 3 files changed, 22 insertions(+), 39 deletions(-) diff --git a/Marlin/dogm_lcd_implementation.h b/Marlin/dogm_lcd_implementation.h index 7025e87bbd..e38b1d2a40 100644 --- a/Marlin/dogm_lcd_implementation.h +++ b/Marlin/dogm_lcd_implementation.h @@ -408,16 +408,4 @@ static void _drawmenu_sd(bool isSelected, uint8_t row, const char* pstr, const c #define lcd_implementation_drawmenu_gcode(sel, row, pstr, gcode) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ') #define lcd_implementation_drawmenu_function(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ') -static void lcd_implementation_quick_feedback() { - #if BEEPER > -1 - SET_OUTPUT(BEEPER); - for(int8_t i=0; i<10; i++) { - WRITE(BEEPER,HIGH); - delay(3); - WRITE(BEEPER,LOW); - delay(3); - } - #endif -} - #endif //__DOGM_LCD_IMPLEMENTATION_H diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index f6af156d53..846a5ac096 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -1137,7 +1137,28 @@ menu_edit_type(unsigned long, long5, ftostr5, 0.01) static void lcd_quick_feedback() { lcdDrawUpdate = 2; blocking_enc = millis() + 500; - lcd_implementation_quick_feedback(); + +#ifdef LCD_USE_I2C_BUZZER +#if defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS) && defined(LCD_FEEDBACK_FREQUENCY_HZ) + lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ); +#else + lcd_buzz(1000/6, 100); +#endif +#elif defined(BEEPER) && BEEPER > -1 + SET_OUTPUT(BEEPER); +#if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS) +#define LCD_FEEDBACK_FREQUENCY_HZ 500 +#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 50 +#endif + const unsigned int delay = 1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2; + int8_t i = LCD_FEEDBACK_FREQUENCY_DURATION_MS * LCD_FEEDBACK_FREQUENCY_HZ / 1000; + while (i--) { + WRITE(BEEPER,HIGH); + delayMicroseconds(delay); + WRITE(BEEPER,LOW); + delayMicroseconds(delay); +} +#endif } /** Menu action functions **/ diff --git a/Marlin/ultralcd_implementation_hitachi_HD44780.h b/Marlin/ultralcd_implementation_hitachi_HD44780.h index 044ac95eee..c303ff06a3 100644 --- a/Marlin/ultralcd_implementation_hitachi_HD44780.h +++ b/Marlin/ultralcd_implementation_hitachi_HD44780.h @@ -709,32 +709,6 @@ static void lcd_implementation_drawmenu_sddirectory(bool sel, uint8_t row, const #define lcd_implementation_drawmenu_gcode(sel, row, pstr, gcode) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ') #define lcd_implementation_drawmenu_function(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ') -static void lcd_implementation_quick_feedback() -{ - #ifdef LCD_USE_I2C_BUZZER - #if defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS) && defined(LCD_FEEDBACK_FREQUENCY_HZ) - lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ); - #else - lcd_buzz(1000/6, 100); - #endif - #elif defined(BEEPER) && BEEPER > -1 - SET_OUTPUT(BEEPER); - #if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS) - const unsigned int delay = 100; - uint8_t i = 10; - #else - const unsigned int delay = 1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2; - int8_t i = LCD_FEEDBACK_FREQUENCY_DURATION_MS * LCD_FEEDBACK_FREQUENCY_HZ / 1000; - #endif - while (i--) { - WRITE(BEEPER,HIGH); - delayMicroseconds(delay); - WRITE(BEEPER,LOW); - delayMicroseconds(delay); - } - #endif -} - #ifdef LCD_HAS_STATUS_INDICATORS static void lcd_implementation_update_indicators() { From 2dfd0e5ce73f1948494267aa9fe2f3f80c1cc3f0 Mon Sep 17 00:00:00 2001 From: chris-bo Date: Wed, 25 Mar 2015 12:44:29 +0100 Subject: [PATCH 2/3] Update Configuration.h documentation how to disable buzzer feedback --- Marlin/Configuration.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index f5a36e6b9c..cffcf40c46 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -579,8 +579,9 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o //#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking //#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store. //#define ULTIPANEL //the UltiPanel as on Thingiverse -//#define LCD_FEEDBACK_FREQUENCY_HZ 1000 // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click -//#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click +#define LCD_FEEDBACK_FREQUENCY_HZ 1000 // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click +#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click + // 0 to disable buzzer feedback // PanelOne from T3P3 (via RAMPS 1.4 AUX2/AUX3) // http://reprap.org/wiki/PanelOne From eab5fad53983b1ca39fa3e29e2d67ec8db706794 Mon Sep 17 00:00:00 2001 From: Christian Bohn Date: Thu, 26 Mar 2015 09:00:34 +0100 Subject: [PATCH 3/3] code formatting --- Marlin/Configuration.h | 4 ++-- Marlin/ultralcd.cpp | 48 +++++++++++++++++++++++------------------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index cffcf40c46..7ee90d1179 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -579,8 +579,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = false; // set to true to invert the logic o //#define ENCODER_STEPS_PER_MENU_ITEM 5 // Set according to ENCODER_PULSES_PER_STEP or your liking //#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store. //#define ULTIPANEL //the UltiPanel as on Thingiverse -#define LCD_FEEDBACK_FREQUENCY_HZ 1000 // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click -#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click +//#define LCD_FEEDBACK_FREQUENCY_HZ 1000 // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click +//#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100 // the duration the buzzer plays the UI feedback sound. ie Screen Click // 0 to disable buzzer feedback // PanelOne from T3P3 (via RAMPS 1.4 AUX2/AUX3) diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 846a5ac096..0bc49dea5f 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -1137,28 +1137,32 @@ menu_edit_type(unsigned long, long5, ftostr5, 0.01) static void lcd_quick_feedback() { lcdDrawUpdate = 2; blocking_enc = millis() + 500; - -#ifdef LCD_USE_I2C_BUZZER -#if defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS) && defined(LCD_FEEDBACK_FREQUENCY_HZ) - lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ); -#else - lcd_buzz(1000/6, 100); -#endif -#elif defined(BEEPER) && BEEPER > -1 - SET_OUTPUT(BEEPER); -#if !defined(LCD_FEEDBACK_FREQUENCY_HZ) || !defined(LCD_FEEDBACK_FREQUENCY_DURATION_MS) -#define LCD_FEEDBACK_FREQUENCY_HZ 500 -#define LCD_FEEDBACK_FREQUENCY_DURATION_MS 50 -#endif - const unsigned int delay = 1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2; - int8_t i = LCD_FEEDBACK_FREQUENCY_DURATION_MS * LCD_FEEDBACK_FREQUENCY_HZ / 1000; - while (i--) { - WRITE(BEEPER,HIGH); - delayMicroseconds(delay); - WRITE(BEEPER,LOW); - delayMicroseconds(delay); -} -#endif + + #ifdef LCD_USE_I2C_BUZZER + #ifndef LCD_FEEDBACK_FREQUENCY_HZ + #define LCD_FEEDBACK_FREQUENCY_HZ 100 + #endif + #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS + #define LCD_FEEDBACK_FREQUENCY_DURATION_MS (1000/6) + #endif + lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ); + #elif defined(BEEPER) && BEEPER > -1 + SET_OUTPUT(BEEPER); + #ifndef LCD_FEEDBACK_FREQUENCY_HZ + #define LCD_FEEDBACK_FREQUENCY_HZ 500 + #endif + #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS + #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 50 + #endif + const unsigned int delay = 1000000 / LCD_FEEDBACK_FREQUENCY_HZ / 2; + int i = LCD_FEEDBACK_FREQUENCY_DURATION_MS * LCD_FEEDBACK_FREQUENCY_HZ / 1000; + while (i--) { + WRITE(BEEPER,HIGH); + delayMicroseconds(delay); + WRITE(BEEPER,LOW); + delayMicroseconds(delay); + } + #endif } /** Menu action functions **/