Browse Source

BUZZ cleanup (#14760)

Ludy 6 years ago
parent
commit
c4bb458763

+ 5
- 1
Marlin/src/feature/pause.cpp View File

54
 #endif
54
 #endif
55
 
55
 
56
 #include "../lcd/ultralcd.h"
56
 #include "../lcd/ultralcd.h"
57
-#include "../libs/buzzer.h"
57
+
58
+#if HAS_BUZZER
59
+  #include "../libs/buzzer.h"
60
+#endif
61
+
58
 #include "../libs/nozzle.h"
62
 #include "../libs/nozzle.h"
59
 #include "pause.h"
63
 #include "pause.h"
60
 
64
 

+ 1
- 1
Marlin/src/lcd/menu/game/brickout.cpp View File

79
       }
79
       }
80
       // Did the ball go below the bottom?
80
       // Did the ball go below the bottom?
81
       else if (newy > BTOF(LCD_PIXEL_HEIGHT)) {
81
       else if (newy > BTOF(LCD_PIXEL_HEIGHT)) {
82
-        BUZZ(500, 75);
82
+        _BUZZ(500, 75);
83
         if (--bdat.balls_left) reset_ball(); else game_state = 0;
83
         if (--bdat.balls_left) reset_ball(); else game_state = 0;
84
         break; // done
84
         break; // done
85
       }
85
       }

+ 1
- 1
Marlin/src/lcd/menu/game/game.h View File

28
 
28
 
29
 //#define MUTE_GAMES
29
 //#define MUTE_GAMES
30
 
30
 
31
-#ifdef MUTE_GAMES
31
+#if ENABLED(MUTE_GAMES) || !HAS_BUZZER
32
   #define _BUZZ(D,F) NOOP
32
   #define _BUZZ(D,F) NOOP
33
 #else
33
 #else
34
   #define _BUZZ(D,F) BUZZ(D,F)
34
   #define _BUZZ(D,F) BUZZ(D,F)

+ 23
- 9
Marlin/src/lcd/menu/menu.cpp View File

31
 #include "../../module/printcounter.h"
31
 #include "../../module/printcounter.h"
32
 #include "../../gcode/queue.h"
32
 #include "../../gcode/queue.h"
33
 #include "../../sd/cardreader.h"
33
 #include "../../sd/cardreader.h"
34
-#include "../../libs/buzzer.h"
34
+#if HAS_BUZZER
35
+  #include "../../libs/buzzer.h"
36
+#endif
35
 
37
 
36
 #if ENABLED(EEPROM_SETTINGS)
38
 #if ENABLED(EEPROM_SETTINGS)
37
   #include "../../module/configuration_store.h"
39
   #include "../../module/configuration_store.h"
346
     encoderTopLine = encoderLine;
348
     encoderTopLine = encoderLine;
347
 }
349
 }
348
 
350
 
349
-void MarlinUI::completion_feedback(const bool good/*=true*/) {
350
-  if (good) {
351
-    BUZZ(100, 659);
352
-    BUZZ(100, 698);
351
+#if HAS_BUZZER
352
+  void MarlinUI::completion_feedback(const bool good/*=true*/) {
353
+    if (good) {
354
+      BUZZ(100, 659);
355
+      BUZZ(100, 698);
356
+    }
357
+    else BUZZ(20, 440);
353
   }
358
   }
354
-  else BUZZ(20, 440);
355
-}
359
+#endif
356
 
360
 
357
 #if HAS_LINE_TO_Z
361
 #if HAS_LINE_TO_Z
358
 
362
 
433
 #endif
437
 #endif
434
 
438
 
435
 #if ENABLED(EEPROM_SETTINGS)
439
 #if ENABLED(EEPROM_SETTINGS)
436
-  void lcd_store_settings()   { ui.completion_feedback(settings.save()); }
437
-  void lcd_load_settings()    { ui.completion_feedback(settings.load()); }
440
+  void lcd_store_settings() {
441
+    const bool saved = settings.save();
442
+    #if HAS_BUZZER
443
+      ui.completion_feedback(saved);
444
+    #endif
445
+  }
446
+  void lcd_load_settings() {
447
+    const bool loaded = settings.load();
448
+    #if HAS_BUZZER
449
+      ui.completion_feedback(loaded);
450
+    #endif
451
+  }
438
 #endif
452
 #endif
439
 
453
 
440
 void _lcd_draw_homing() {
454
 void _lcd_draw_homing() {

+ 11
- 3
Marlin/src/lcd/menu/menu_advanced.cpp View File

603
     static void lcd_init_eeprom_confirm() {
603
     static void lcd_init_eeprom_confirm() {
604
       do_select_screen(
604
       do_select_screen(
605
         PSTR(MSG_BUTTON_INIT), PSTR(MSG_BUTTON_CANCEL),
605
         PSTR(MSG_BUTTON_INIT), PSTR(MSG_BUTTON_CANCEL),
606
-        []{ ui.completion_feedback(settings.init_eeprom()); },
606
+        []{
607
+          const bool inited = settings.init_eeprom();
608
+          #if HAS_BUZZER
609
+            ui.completion_feedback(inited);
610
+          #endif
611
+        },
607
         ui.goto_previous_screen,
612
         ui.goto_previous_screen,
608
         PSTR(MSG_INIT_EEPROM), nullptr, PSTR("?")
613
         PSTR(MSG_INIT_EEPROM), nullptr, PSTR("?")
609
       );
614
       );
698
       //
703
       //
699
       // Toggle the SD Firmware Update state in EEPROM
704
       // Toggle the SD Firmware Update state in EEPROM
700
       //
705
       //
701
-      const bool new_state = !settings.sd_update_status();
702
-      ui.completion_feedback(settings.set_sd_update_status(new_state));
706
+      const bool new_state = !settings.sd_update_status(),
707
+                 didset = settings.set_sd_update_status(new_state);
708
+      #if HAS_BUZZER
709
+        ui.completion_feedback(didset);
710
+      #endif
703
       ui.return_to_status();
711
       ui.return_to_status();
704
       if (new_state) LCD_MESSAGEPGM(MSG_RESET_PRINTER); else ui.reset_status();
712
       if (new_state) LCD_MESSAGEPGM(MSG_RESET_PRINTER); else ui.reset_status();
705
     });
713
     });

+ 3
- 1
Marlin/src/lcd/menu/menu_bed_leveling.cpp View File

77
         ui.synchronize(PSTR(MSG_LEVEL_BED_DONE));
77
         ui.synchronize(PSTR(MSG_LEVEL_BED_DONE));
78
       #endif
78
       #endif
79
       ui.goto_previous_screen_no_defer();
79
       ui.goto_previous_screen_no_defer();
80
-      ui.completion_feedback();
80
+      #if HAS_BUZZER
81
+        ui.completion_feedback();
82
+      #endif
81
     }
83
     }
82
     if (ui.should_draw()) draw_menu_item_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_LEVEL_BED_DONE));
84
     if (ui.should_draw()) draw_menu_item_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_LEVEL_BED_DONE));
83
     ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
85
     ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);

+ 3
- 1
Marlin/src/lcd/menu/menu_configuration.cpp View File

56
 
56
 
57
 static void lcd_factory_settings() {
57
 static void lcd_factory_settings() {
58
   settings.reset();
58
   settings.reset();
59
-  ui.completion_feedback();
59
+  #if HAS_BUZZER
60
+    ui.completion_feedback();
61
+  #endif
60
 }
62
 }
61
 
63
 
62
 #if ENABLED(LCD_PROGRESS_BAR_TEST)
64
 #if ENABLED(LCD_PROGRESS_BAR_TEST)

+ 1
- 1
Marlin/src/lcd/menu/menu_custom.cpp View File

39
 
39
 
40
 void _lcd_user_gcode(PGM_P const cmd) {
40
 void _lcd_user_gcode(PGM_P const cmd) {
41
   queue.inject_P(cmd);
41
   queue.inject_P(cmd);
42
-  #if ENABLED(USER_SCRIPT_AUDIBLE_FEEDBACK)
42
+  #if ENABLED(USER_SCRIPT_AUDIBLE_FEEDBACK) && HAS_BUZZER
43
     ui.completion_feedback();
43
     ui.completion_feedback();
44
   #endif
44
   #endif
45
   #if ENABLED(USER_SCRIPT_RETURN)
45
   #if ENABLED(USER_SCRIPT_RETURN)

+ 3
- 1
Marlin/src/lcd/menu/menu_service.cpp View File

38
     PSTR(MSG_BUTTON_RESET), PSTR(MSG_BUTTON_CANCEL),
38
     PSTR(MSG_BUTTON_RESET), PSTR(MSG_BUTTON_CANCEL),
39
     []{
39
     []{
40
       print_job_timer.resetServiceInterval(index);
40
       print_job_timer.resetServiceInterval(index);
41
-      ui.completion_feedback(true);
41
+      #if HAS_BUZZER
42
+        ui.completion_feedback();
43
+      #endif
42
       ui.reset_status();
44
       ui.reset_status();
43
       ui.return_to_status();
45
       ui.return_to_status();
44
     },
46
     },

+ 5
- 3
Marlin/src/lcd/ultralcd.cpp View File

562
     if (old_frm != new_frm) {
562
     if (old_frm != new_frm) {
563
       feedrate_percentage = new_frm;
563
       feedrate_percentage = new_frm;
564
       encoderPosition = 0;
564
       encoderPosition = 0;
565
-      #if ENABLED(BEEP_ON_FEEDRATE_CHANGE)
565
+      #if HAS_BUZZER && ENABLED(BEEP_ON_FEEDRATE_CHANGE)
566
         static millis_t next_beep;
566
         static millis_t next_beep;
567
         #ifndef GOT_MS
567
         #ifndef GOT_MS
568
           const millis_t ms = millis();
568
           const millis_t ms = millis();
608
     UNUSED(clear_buttons);
608
     UNUSED(clear_buttons);
609
   #endif
609
   #endif
610
 
610
 
611
-  // Buzz and wait. The delay is needed for buttons to settle!
612
-  buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
611
+  #if HAS_BUZZER
612
+    // Buzz and wait. Is the delay needed for buttons to settle?
613
+    buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
614
+  #endif
613
 
615
 
614
   #if HAS_LCD_MENU
616
   #if HAS_LCD_MENU
615
     #if ENABLED(LCD_USE_I2C_BUZZER)
617
     #if ENABLED(LCD_USE_I2C_BUZZER)

+ 17
- 11
Marlin/src/lcd/ultralcd.h View File

258
     #endif
258
     #endif
259
   }
259
   }
260
 
260
 
261
-  static inline void buzz(const long duration, const uint16_t freq) {
262
-    #if ENABLED(LCD_USE_I2C_BUZZER)
263
-      lcd.buzz(duration, freq);
264
-    #elif PIN_EXISTS(BEEPER)
265
-      buzzer.tone(duration, freq);
266
-    #else
267
-      UNUSED(duration); UNUSED(freq);
268
-    #endif
269
-  }
261
+  #if HAS_BUZZER
262
+    static inline void buzz(const long duration, const uint16_t freq) {
263
+      #if ENABLED(LCD_USE_I2C_BUZZER)
264
+        lcd.buzz(duration, freq);
265
+      #elif PIN_EXISTS(BEEPER)
266
+        buzzer.tone(duration, freq);
267
+      #endif
268
+    }
269
+  #endif
270
 
270
 
271
   // LCD implementations
271
   // LCD implementations
272
   static void clear_lcd();
272
   static void clear_lcd();
355
       #endif
355
       #endif
356
 
356
 
357
       static void quick_feedback(const bool clear_buttons=true);
357
       static void quick_feedback(const bool clear_buttons=true);
358
-      static void completion_feedback(const bool good=true);
358
+      #if HAS_BUZZER
359
+        static void completion_feedback(const bool good=true);
360
+      #endif
359
 
361
 
360
       #if DISABLED(LIGHTWEIGHT_UI)
362
       #if DISABLED(LIGHTWEIGHT_UI)
361
         static void draw_status_message(const bool blink);
363
         static void draw_status_message(const bool blink);
466
     #endif
468
     #endif
467
 
469
 
468
     #if ENABLED(G26_MESH_VALIDATION)
470
     #if ENABLED(G26_MESH_VALIDATION)
469
-      static inline void chirp() { buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ); }
471
+      static inline void chirp() {
472
+        #if HAS_BUZZER
473
+          buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
474
+        #endif
475
+      }
470
     #endif
476
     #endif
471
 
477
 
472
     #if ENABLED(AUTO_BED_LEVELING_UBL)
478
     #if ENABLED(AUTO_BED_LEVELING_UBL)

+ 1
- 1
Marlin/src/module/temperature.cpp View File

68
   #include "tool_change.h"
68
   #include "tool_change.h"
69
 #endif
69
 #endif
70
 
70
 
71
-#if HAS_BUZZER
71
+#if HAS_BUZZER && PIN_EXISTS(BEEPER)
72
   #include "../libs/buzzer.h"
72
   #include "../libs/buzzer.h"
73
 #endif
73
 #endif
74
 
74
 

Loading…
Cancel
Save