Browse Source

Rework buzzing (PR#2296)

by:
Moving HAS_LCD_BUZZ macro to Coditionals.h
Renaming HAS_LCD_BUZZ to HAS_BUZZER to make clear is has nothing to do with the lcd.
Removing the ULTRALCD condition.

Moving declaration of lcd_buzz() out of the ULTRA_LCD block in ultralcd.h
Moving definition of lcd_buzz() out of the ULTIPANEL block in ultralcd.cpp
Renaming lcd_buzz() to buzz() to make clear is has nothing to do with the lcd.

All buzzing code is now only dependent on the existence of a BEEPER-pin or the definition of a LCD_USE_I2C_BUZZER.

To do: Check the conditions for the BEEPER-pin in all pin-files.
AnHardt 10 years ago
parent
commit
6ab7b560af
4 changed files with 22 additions and 18 deletions
  1. 2
    0
      Marlin/Conditionals.h
  2. 7
    8
      Marlin/Marlin_main.cpp
  3. 9
    7
      Marlin/ultralcd.cpp
  4. 4
    3
      Marlin/ultralcd.h

+ 2
- 0
Marlin/Conditionals.h View File

@@ -504,5 +504,7 @@
504 504
     #define WRITE_FAN(v) WRITE(FAN_PIN, v)
505 505
   #endif
506 506
 
507
+  #define HAS_BUZZER ((defined(BEEPER) && BEEPER >= 0) || defined(LCD_USE_I2C_BUZZER))
508
+
507 509
 #endif //CONFIGURATION_LCD
508 510
 #endif //CONDITIONALS_H

+ 7
- 8
Marlin/Marlin_main.cpp View File

@@ -36,7 +36,6 @@
36 36
   #endif
37 37
 #endif // ENABLE_AUTO_BED_LEVELING
38 38
 
39
-#define HAS_LCD_BUZZ (defined(ULTRA_LCD) || (defined(BEEPER) && BEEPER >= 0) || defined(LCD_USE_I2C_BUZZER))
40 39
 #define SERVO_LEVELING (defined(ENABLE_AUTO_BED_LEVELING) && PROBE_SERVO_DEACTIVATION_DELAY > 0)
41 40
 
42 41
 #ifdef MESH_BED_LEVELING
@@ -4349,7 +4348,7 @@ inline void gcode_M226() {
4349 4348
 
4350 4349
 #endif // NUM_SERVOS > 0
4351 4350
 
4352
-#if HAS_LCD_BUZZ
4351
+#if HAS_BUZZER
4353 4352
 
4354 4353
   /**
4355 4354
    * M300: Play beep sound S<frequency Hz> P<duration ms>
@@ -4358,10 +4357,10 @@ inline void gcode_M226() {
4358 4357
     uint16_t beepS = code_seen('S') ? code_value_short() : 110;
4359 4358
     uint32_t beepP = code_seen('P') ? code_value_long() : 1000;
4360 4359
     if (beepP > 5000) beepP = 5000; // limit to 5 seconds
4361
-    lcd_buzz(beepP, beepS);
4360
+    buzz(beepP, beepS);
4362 4361
   }
4363 4362
 
4364
-#endif // HAS_LCD_BUZZ
4363
+#endif // HAS_BUZZER
4365 4364
 
4366 4365
 #ifdef PIDTEMP
4367 4366
 
@@ -4791,7 +4790,7 @@ inline void gcode_M428() {
4791 4790
         SERIAL_ERROR_START;
4792 4791
         SERIAL_ERRORLNPGM(MSG_ERR_M428_TOO_FAR);
4793 4792
         LCD_ALERTMESSAGEPGM("Err: Too far!");
4794
-        #if HAS_LCD_BUZZ
4793
+        #if HAS_BUZZER
4795 4794
           enqueuecommands_P(PSTR("M300 S40 P200"));
4796 4795
         #endif
4797 4796
         err = true;
@@ -4805,7 +4804,7 @@ inline void gcode_M428() {
4805 4804
     memcpy(home_offset, new_offs, sizeof(new_offs));
4806 4805
     sync_plan_position();
4807 4806
     LCD_ALERTMESSAGEPGM("Offset applied.");
4808
-    #if HAS_LCD_BUZZ
4807
+    #if HAS_BUZZER
4809 4808
       enqueuecommands_P(PSTR("M300 S659 P200\nM300 S698 P200"));
4810 4809
     #endif
4811 4810
   }
@@ -5607,11 +5606,11 @@ void process_next_command() {
5607 5606
           break;
5608 5607
       #endif // NUM_SERVOS > 0
5609 5608
 
5610
-      #if HAS_LCD_BUZZ
5609
+      #if HAS_BUZZER
5611 5610
         case 300: // M300 - Play beep tone
5612 5611
           gcode_M300();
5613 5612
           break;
5614
-      #endif // HAS_LCD_BUZZ
5613
+      #endif // HAS_BUZZER
5615 5614
 
5616 5615
       #ifdef PIDTEMP
5617 5616
         case 301: // M301

+ 9
- 7
Marlin/ultralcd.cpp View File

@@ -1313,7 +1313,7 @@ void lcd_quick_feedback() {
1313 1313
     #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
1314 1314
       #define LCD_FEEDBACK_FREQUENCY_DURATION_MS (1000/6)
1315 1315
     #endif    
1316
-    lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
1316
+    buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
1317 1317
   #elif defined(BEEPER) && BEEPER >= 0
1318 1318
     #ifndef LCD_FEEDBACK_FREQUENCY_HZ
1319 1319
       #define LCD_FEEDBACK_FREQUENCY_HZ 5000
@@ -1321,7 +1321,7 @@ void lcd_quick_feedback() {
1321 1321
     #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
1322 1322
       #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2
1323 1323
     #endif
1324
-    lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
1324
+    buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
1325 1325
   #else
1326 1326
     #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
1327 1327
       #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2
@@ -1745,7 +1745,12 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
1745 1745
     #endif
1746 1746
   }
1747 1747
 
1748
-  void lcd_buzz(long duration, uint16_t freq) {
1748
+  bool lcd_clicked() { return LCD_CLICKED; }
1749
+
1750
+#endif // ULTIPANEL
1751
+
1752
+#if HAS_BUZZER
1753
+  void buzz(long duration, uint16_t freq) {
1749 1754
     if (freq > 0) {
1750 1755
       #ifdef LCD_USE_I2C_BUZZER
1751 1756
         lcd.buzz(duration, freq);
@@ -1761,10 +1766,7 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
1761 1766
       delay(duration);
1762 1767
     }
1763 1768
   }
1764
-
1765
-  bool lcd_clicked() { return LCD_CLICKED; }
1766
-
1767
-#endif // ULTIPANEL
1769
+#endif
1768 1770
 
1769 1771
 /*********************************/
1770 1772
 /** Number to string conversion **/

+ 4
- 3
Marlin/ultralcd.h View File

@@ -52,8 +52,6 @@
52 52
   #ifdef FILAMENT_LCD_DISPLAY
53 53
     extern millis_t previous_lcd_status_ms;
54 54
   #endif
55
-
56
-  void lcd_buzz(long duration,uint16_t freq);
57 55
   void lcd_quick_feedback(); // Audible feedback for a button click - could also be visual
58 56
   bool lcd_clicked();
59 57
 
@@ -106,7 +104,6 @@
106 104
   FORCE_INLINE void lcd_setstatuspgm(const char* message, const uint8_t level=0) {}
107 105
   FORCE_INLINE void lcd_buttons_update() {}
108 106
   FORCE_INLINE void lcd_reset_alert_level() {}
109
-  FORCE_INLINE void lcd_buzz(long duration, uint16_t freq) {}
110 107
   FORCE_INLINE bool lcd_detected(void) { return true; }
111 108
 
112 109
   #define LCD_MESSAGEPGM(x) do{}while(0)
@@ -114,6 +111,10 @@
114 111
 
115 112
 #endif //ULTRA_LCD
116 113
 
114
+#if HAS_BUZZER
115
+  void buzz(long duration,uint16_t freq);
116
+#endif
117
+
117 118
 char *itostr2(const uint8_t &x);
118 119
 char *itostr31(const int &xx);
119 120
 char *itostr3(const int &xx);

Loading…
Cancel
Save