Browse Source

Buzzer requires BEEPER_PIN

Scott Lahteine 7 years ago
parent
commit
330f82971b
5 changed files with 29 additions and 25 deletions
  1. 1
    2
      Marlin/Marlin.h
  2. 14
    13
      Marlin/Marlin_main.cpp
  3. 4
    0
      Marlin/buzzer.h
  4. 9
    9
      Marlin/ultralcd.cpp
  5. 1
    1
      Marlin/ultralcd.h

+ 1
- 2
Marlin/Marlin.h View File

@@ -384,9 +384,8 @@ extern uint8_t active_extruder;
384 384
 void calculate_volumetric_multipliers();
385 385
 
386 386
 // Buzzer
387
-#if HAS_BUZZER
387
+#if HAS_BUZZER && PIN_EXISTS(BEEPER)
388 388
   #include "buzzer.h"
389
-  extern Buzzer buzzer;
390 389
 #endif
391 390
 
392 391
 /**

+ 14
- 13
Marlin/Marlin_main.cpp View File

@@ -373,9 +373,14 @@ static millis_t stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000UL
373 373
   Stopwatch print_job_timer = Stopwatch();
374 374
 #endif
375 375
 
376
-// Buzzer
377
-#if HAS_BUZZER
378
-    Buzzer buzzer;
376
+// Buzzer - I2C on the LCD or a BEEPER_PIN
377
+#if ENABLED(LCD_USE_I2C_BUZZER)
378
+  #define BUZZ(d,f) lcd_buzz(d, f)
379
+#elif HAS_BUZZER
380
+  Buzzer buzzer;
381
+  #define BUZZ(d,f) buzzer.tone(d, f)
382
+#else
383
+  #define BUZZ(d,f) NOOP
379 384
 #endif
380 385
 
381 386
 static uint8_t target_extruder;
@@ -5657,7 +5662,7 @@ inline void gcode_M226() {
5657 5662
     // Limits the tone duration to 0-5 seconds.
5658 5663
     NOMORE(duration, 5000);
5659 5664
 
5660
-    buzzer.tone(duration, frequency);
5665
+    BUZZ(duration, frequency);
5661 5666
   }
5662 5667
 
5663 5668
 #endif // HAS_BUZZER
@@ -6129,9 +6134,7 @@ inline void gcode_M428() {
6129 6134
         SERIAL_ERROR_START;
6130 6135
         SERIAL_ERRORLNPGM(MSG_ERR_M428_TOO_FAR);
6131 6136
         LCD_ALERTMESSAGEPGM("Err: Too far!");
6132
-        #if HAS_BUZZER
6133
-          buzzer.tone(200, 40);
6134
-        #endif
6137
+        BUZZ(200, 40);
6135 6138
         err = true;
6136 6139
         break;
6137 6140
       }
@@ -6142,10 +6145,8 @@ inline void gcode_M428() {
6142 6145
     SYNC_PLAN_POSITION_KINEMATIC();
6143 6146
     report_current_position();
6144 6147
     LCD_MESSAGEPGM(MSG_HOME_OFFSETS_APPLIED);
6145
-    #if HAS_BUZZER
6146
-      buzzer.tone(200, 659);
6147
-      buzzer.tone(200, 698);
6148
-    #endif
6148
+    BUZZ(200, 659);
6149
+    BUZZ(200, 698);
6149 6150
   }
6150 6151
 }
6151 6152
 
@@ -6327,7 +6328,7 @@ inline void gcode_M503() {
6327 6328
       #if HAS_BUZZER
6328 6329
         millis_t ms = millis();
6329 6330
         if (ms >= next_tick) {
6330
-          buzzer.tone(300, 2000);
6331
+          BUZZ(300, 2000);
6331 6332
           next_tick = ms + 2500; // Beep every 2.5s while waiting
6332 6333
         }
6333 6334
       #endif
@@ -8470,7 +8471,7 @@ void idle(
8470 8471
     print_job_timer.tick();
8471 8472
   #endif
8472 8473
 
8473
-  #if HAS_BUZZER
8474
+  #if HAS_BUZZER && PIN_EXISTS(BEEPER)
8474 8475
     buzzer.tick();
8475 8476
   #endif
8476 8477
 }

+ 4
- 0
Marlin/buzzer.h View File

@@ -27,6 +27,8 @@
27 27
 #include "circularqueue.h"
28 28
 #include "temperature.h"
29 29
 
30
+#include "MarlinConfig.h"
31
+
30 32
 #define TONE_QUEUE_LENGTH 4
31 33
 
32 34
 /**
@@ -135,4 +137,6 @@ class Buzzer {
135 137
     }
136 138
 };
137 139
 
140
+extern Buzzer buzzer;
141
+
138 142
 #endif

+ 9
- 9
Marlin/ultralcd.cpp View File

@@ -1074,8 +1074,8 @@ void kill_screen(const char* lcd_msg) {
1074 1074
             lcd_return_to_status();
1075 1075
             //LCD_MESSAGEPGM(MSG_LEVEL_BED_DONE);
1076 1076
             #if HAS_BUZZER
1077
-              buzzer.tone(200, 659);
1078
-              buzzer.tone(200, 698);
1077
+              lcd_buzz(200, 659);
1078
+              lcd_buzz(200, 698);
1079 1079
             #endif
1080 1080
           }
1081 1081
           else {
@@ -2342,23 +2342,23 @@ void kill_screen(const char* lcd_msg) {
2342 2342
    * Audio feedback for controller clicks
2343 2343
    *
2344 2344
    */
2345
-
2346
-  #if ENABLED(LCD_USE_I2C_BUZZER)
2347
-    void lcd_buzz(long duration, uint16_t freq) { // called from buzz() in Marlin_main.cpp where lcd is unknown
2345
+  void lcd_buzz(long duration, uint16_t freq) {
2346
+    #if ENABLED(LCD_USE_I2C_BUZZER)
2348 2347
       lcd.buzz(duration, freq);
2349
-    }
2350
-  #endif
2348
+    #elif PIN_EXISTS(BEEPER)
2349
+      buzzer.tone(duration, freq);
2350
+    #endif
2351
+  }
2351 2352
 
2352 2353
   void lcd_quick_feedback() {
2353 2354
     lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
2354 2355
     next_button_update_ms = millis() + 500;
2355 2356
 
2356 2357
     // Buzz and wait. The delay is needed for buttons to settle!
2358
+    lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
2357 2359
     #if ENABLED(LCD_USE_I2C_BUZZER)
2358
-      lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
2359 2360
       delay(10);
2360 2361
     #elif PIN_EXISTS(BEEPER)
2361
-      buzzer.tone(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
2362 2362
       for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
2363 2363
     #endif
2364 2364
   }

+ 1
- 1
Marlin/ultralcd.h View File

@@ -43,7 +43,7 @@
43 43
   void lcd_kill_screen();
44 44
   void kill_screen(const char* lcd_msg);
45 45
 
46
-  #if ENABLED(LCD_USE_I2C_BUZZER)
46
+  #if HAS_BUZZER
47 47
     void lcd_buzz(long duration, uint16_t freq);
48 48
   #endif
49 49
 

Loading…
Cancel
Save