Browse Source

Move buzzing code to buzzr.h & buzzer.cpp (PR#2307)

at least the lcd independent part from Marlin_main.cpp.
AnHardt 9 years ago
parent
commit
722829b058
5 changed files with 44 additions and 24 deletions
  1. 1
    0
      Marlin/Marlin_main.cpp
  2. 22
    0
      Marlin/buzzer.cpp
  3. 8
    0
      Marlin/buzzer.h
  4. 8
    20
      Marlin/ultralcd.cpp
  5. 5
    4
      Marlin/ultralcd.h

+ 1
- 0
Marlin/Marlin_main.cpp View File

@@ -52,6 +52,7 @@
52 52
 #include "language.h"
53 53
 #include "pins_arduino.h"
54 54
 #include "math.h"
55
+#include "buzzer.h"
55 56
 
56 57
 #ifdef BLINKM
57 58
   #include "blinkm.h"

+ 22
- 0
Marlin/buzzer.cpp View File

@@ -0,0 +1,22 @@
1
+#include "Marlin.h"
2
+#include "buzzer.h"
3
+#include "ultralcd.h"
4
+
5
+#if HAS_BUZZER
6
+  void buzz(long duration, uint16_t freq) {
7
+    if (freq > 0) {
8
+      #ifdef LCD_USE_I2C_BUZZER
9
+        lcd_buzz(duration, freq);
10
+      #elif defined(BEEPER) && BEEPER >= 0 // on-board buzzers have no further condition
11
+        SET_OUTPUT(BEEPER);
12
+        tone(BEEPER, freq, duration);
13
+        delay(duration);
14
+      #else
15
+        delay(duration);
16
+      #endif
17
+    }
18
+    else {
19
+      delay(duration);
20
+    }
21
+  }
22
+#endif

+ 8
- 0
Marlin/buzzer.h View File

@@ -0,0 +1,8 @@
1
+#ifndef BUZZER_H
2
+  #define BUZZER_H
3
+
4
+  #if HAS_BUZZER
5
+    void buzz(long duration,uint16_t freq);
6
+  #endif
7
+
8
+#endif BUZZER_H

+ 8
- 20
Marlin/ultralcd.cpp View File

@@ -1302,6 +1302,13 @@ menu_edit_type(unsigned long, long5, ftostr5, 0.01)
1302 1302
  * Audio feedback for controller clicks
1303 1303
  *
1304 1304
  */
1305
+
1306
+#ifdef LCD_USE_I2C_BUZZER
1307
+  void lcd_buzz(long duration, uint16_t freq) { // called from buzz() in Marlin_main.cpp where lcd is unknown
1308
+    lcd.buzz(duration, freq);
1309
+  }
1310
+#endif
1311
+
1305 1312
 void lcd_quick_feedback() {
1306 1313
   lcdDrawUpdate = 2;
1307 1314
   next_button_update_ms = millis() + 500;
@@ -1313,7 +1320,7 @@ void lcd_quick_feedback() {
1313 1320
     #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
1314 1321
       #define LCD_FEEDBACK_FREQUENCY_DURATION_MS (1000/6)
1315 1322
     #endif    
1316
-    buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
1323
+    lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
1317 1324
   #elif defined(BEEPER) && BEEPER >= 0
1318 1325
     #ifndef LCD_FEEDBACK_FREQUENCY_HZ
1319 1326
       #define LCD_FEEDBACK_FREQUENCY_HZ 5000
@@ -1749,25 +1756,6 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
1749 1756
 
1750 1757
 #endif // ULTIPANEL
1751 1758
 
1752
-#if HAS_BUZZER
1753
-  void buzz(long duration, uint16_t freq) {
1754
-    if (freq > 0) {
1755
-      #ifdef LCD_USE_I2C_BUZZER
1756
-        lcd.buzz(duration, freq);
1757
-      #elif defined(BEEPER) && BEEPER >= 0
1758
-        SET_OUTPUT(BEEPER);
1759
-        tone(BEEPER, freq, duration);
1760
-        delay(duration);
1761
-      #else
1762
-        delay(duration);
1763
-      #endif
1764
-    }
1765
-    else {
1766
-      delay(duration);
1767
-    }
1768
-  }
1769
-#endif
1770
-
1771 1759
 /*********************************/
1772 1760
 /** Number to string conversion **/
1773 1761
 /*********************************/

+ 5
- 4
Marlin/ultralcd.h View File

@@ -2,6 +2,7 @@
2 2
 #define ULTRALCD_H
3 3
 
4 4
 #include "Marlin.h"
5
+#include "buzzer.h"
5 6
 
6 7
 #ifdef ULTRA_LCD
7 8
   int lcd_strlen(char *s);
@@ -15,6 +16,10 @@
15 16
   void lcd_reset_alert_level();
16 17
   bool lcd_detected(void);
17 18
 
19
+  #ifdef LCD_USE_I2C_BUZZER
20
+    void lcd_buzz(long duration, uint16_t freq);
21
+  #endif
22
+
18 23
   #if defined(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
19 24
     void dontExpireStatus();
20 25
   #endif
@@ -111,10 +116,6 @@
111 116
 
112 117
 #endif //ULTRA_LCD
113 118
 
114
-#if HAS_BUZZER
115
-  void buzz(long duration,uint16_t freq);
116
-#endif
117
-
118 119
 char *itostr2(const uint8_t &x);
119 120
 char *itostr31(const int &xx);
120 121
 char *itostr3(const int &xx);

Loading…
Cancel
Save