Browse Source

♻️ Small sound / buzz refactor (#24520)

Scott Lahteine 2 years ago
parent
commit
5f2908a117
No account linked to committer's email address

+ 2
- 2
Marlin/src/feature/pause.cpp View File

63
 
63
 
64
 #include "../lcd/marlinui.h"
64
 #include "../lcd/marlinui.h"
65
 
65
 
66
-#if HAS_BUZZER
66
+#if HAS_SOUND
67
   #include "../libs/buzzer.h"
67
   #include "../libs/buzzer.h"
68
 #endif
68
 #endif
69
 
69
 
98
   #define _PMSG(L) L##_LCD
98
   #define _PMSG(L) L##_LCD
99
 #endif
99
 #endif
100
 
100
 
101
-#if HAS_BUZZER
101
+#if HAS_SOUND
102
   static void impatient_beep(const int8_t max_beep_count, const bool restart=false) {
102
   static void impatient_beep(const int8_t max_beep_count, const bool restart=false) {
103
 
103
 
104
     if (TERN0(HAS_MARLINUI_MENU, pause_mode == PAUSE_MODE_PAUSE_PRINT)) return;
104
     if (TERN0(HAS_MARLINUI_MENU, pause_mode == PAUSE_MODE_PAUSE_PRINT)) return;

+ 1
- 1
Marlin/src/feature/spindle_laser.h View File

294
        * If not set defaults to 80% power
294
        * If not set defaults to 80% power
295
        */
295
        */
296
       static void test_fire_pulse() {
296
       static void test_fire_pulse() {
297
-        TERN_(HAS_BEEPER, buzzer.tone(30, 3000));
297
+        BUZZ(30, 3000);
298
         cutter_mode = CUTTER_MODE_STANDARD;// Menu needs standard mode.
298
         cutter_mode = CUTTER_MODE_STANDARD;// Menu needs standard mode.
299
         laser_menu_toggle(true);           // Laser On
299
         laser_menu_toggle(true);           // Laser On
300
         delay(testPulse);                  // Delay for time set by user in pulse ms menu screen.
300
         delay(testPulse);                  // Delay for time set by user in pulse ms menu screen.

+ 1
- 1
Marlin/src/gcode/gcode.cpp View File

765
         case 290: M290(); break;                                  // M290: Babystepping
765
         case 290: M290(); break;                                  // M290: Babystepping
766
       #endif
766
       #endif
767
 
767
 
768
-      #if HAS_BUZZER
768
+      #if HAS_SOUND
769
         case 300: M300(); break;                                  // M300: Play beep tone
769
         case 300: M300(); break;                                  // M300: Play beep tone
770
       #endif
770
       #endif
771
 
771
 

+ 1
- 1
Marlin/src/gcode/gcode.h View File

914
     static void M290();
914
     static void M290();
915
   #endif
915
   #endif
916
 
916
 
917
-  #if HAS_BUZZER
917
+  #if HAS_SOUND
918
     static void M300();
918
     static void M300();
919
   #endif
919
   #endif
920
 
920
 

+ 2
- 2
Marlin/src/gcode/lcd/M300.cpp View File

22
 
22
 
23
 #include "../../inc/MarlinConfig.h"
23
 #include "../../inc/MarlinConfig.h"
24
 
24
 
25
-#if HAS_BUZZER
25
+#if HAS_SOUND
26
 
26
 
27
 #include "../gcode.h"
27
 #include "../gcode.h"
28
 
28
 
42
   BUZZ(duration, frequency);
42
   BUZZ(duration, frequency);
43
 }
43
 }
44
 
44
 
45
-#endif // HAS_BUZZER
45
+#endif // HAS_SOUND

+ 8
- 4
Marlin/src/inc/Conditionals_post.h View File

3564
 #if PIN_EXISTS(BEEPER)
3564
 #if PIN_EXISTS(BEEPER)
3565
   #define HAS_BEEPER 1
3565
   #define HAS_BEEPER 1
3566
 #endif
3566
 #endif
3567
-#if ANY(HAS_BEEPER, LCD_USE_I2C_BUZZER, PCA9632_BUZZER)
3568
-  #define HAS_BUZZER 1
3567
+#if ANY(IS_TFTGLCD_PANEL, PCA9632_BUZZER, LCD_USE_I2C_BUZZER)
3568
+  #define USE_MARLINUI_BUZZER 1
3569
+#endif
3570
+#if EITHER(HAS_BEEPER, USE_MARLINUI_BUZZER)
3571
+  #define HAS_SOUND 1
3569
 #endif
3572
 #endif
3570
 
3573
 
3571
 #if ENABLED(LCD_USE_I2C_BUZZER)
3574
 #if ENABLED(LCD_USE_I2C_BUZZER)
3575
   #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
3578
   #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
3576
     #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100
3579
     #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100
3577
   #endif
3580
   #endif
3578
-#elif HAS_BUZZER
3581
+#elif HAS_SOUND
3579
   #ifndef LCD_FEEDBACK_FREQUENCY_HZ
3582
   #ifndef LCD_FEEDBACK_FREQUENCY_HZ
3580
     #define LCD_FEEDBACK_FREQUENCY_HZ 5000
3583
     #define LCD_FEEDBACK_FREQUENCY_HZ 5000
3581
   #endif
3584
   #endif
3584
   #endif
3587
   #endif
3585
 #endif
3588
 #endif
3586
 
3589
 
3587
-#if HAS_BUZZER
3590
+#if HAS_SOUND
3588
   #if LCD_FEEDBACK_FREQUENCY_DURATION_MS && LCD_FEEDBACK_FREQUENCY_HZ
3591
   #if LCD_FEEDBACK_FREQUENCY_DURATION_MS && LCD_FEEDBACK_FREQUENCY_HZ
3589
     #define HAS_CHIRP 1
3592
     #define HAS_CHIRP 1
3590
   #endif
3593
   #endif
3591
 #else
3594
 #else
3592
   #undef SOUND_MENU_ITEM   // No buzzer menu item without a buzzer
3595
   #undef SOUND_MENU_ITEM   // No buzzer menu item without a buzzer
3596
+  #undef SOUND_ON_DEFAULT
3593
 #endif
3597
 #endif
3594
 
3598
 
3595
 /**
3599
 /**

+ 3
- 2
Marlin/src/lcd/HD44780/marlinui_HD44780.cpp View File

120
 #endif
120
 #endif
121
 
121
 
122
 #if ENABLED(LCD_USE_I2C_BUZZER)
122
 #if ENABLED(LCD_USE_I2C_BUZZER)
123
+
123
   void MarlinUI::buzz(const long duration, const uint16_t freq) {
124
   void MarlinUI::buzz(const long duration, const uint16_t freq) {
124
-    if (!sound_on) return;
125
-    lcd.buzz(duration, freq);
125
+    if (sound_on) lcd.buzz(duration, freq);
126
   }
126
   }
127
+
127
 #endif
128
 #endif
128
 
129
 
129
 void MarlinUI::set_custom_characters(const HD44780CharSet screen_charset/*=CHARSET_INFO*/) {
130
 void MarlinUI::set_custom_characters(const HD44780CharSet screen_charset/*=CHARSET_INFO*/) {

+ 3
- 5
Marlin/src/lcd/e3v2/common/encoder.cpp View File

36
 #include "../../marlinui.h"
36
 #include "../../marlinui.h"
37
 #include "../../../HAL/shared/Delay.h"
37
 #include "../../../HAL/shared/Delay.h"
38
 
38
 
39
-#if HAS_BUZZER
39
+#if HAS_SOUND
40
   #include "../../../libs/buzzer.h"
40
   #include "../../../libs/buzzer.h"
41
 #endif
41
 #endif
42
 
42
 
50
 
50
 
51
 // TODO: Replace with ui.quick_feedback
51
 // TODO: Replace with ui.quick_feedback
52
 void Encoder_tick() {
52
 void Encoder_tick() {
53
-  #if PIN_EXISTS(BEEPER)
54
-    if (ui.sound_on) buzzer.click(10);
55
-  #endif
53
+  TERN_(HAS_BEEPER, if (ui.sound_on) buzzer.click(10));
56
 }
54
 }
57
 
55
 
58
 // Encoder initialization
56
 // Encoder initialization
66
   #if BUTTON_EXISTS(ENC)
64
   #if BUTTON_EXISTS(ENC)
67
     SET_INPUT_PULLUP(BTN_ENC);
65
     SET_INPUT_PULLUP(BTN_ENC);
68
   #endif
66
   #endif
69
-  #if PIN_EXISTS(BEEPER)
67
+  #if HAS_BEEPER
70
     SET_OUTPUT(BEEPER_PIN);     // TODO: Use buzzer.h which already inits this
68
     SET_OUTPUT(BEEPER_PIN);     // TODO: Use buzzer.h which already inits this
71
   #endif
69
   #endif
72
 }
70
 }

+ 7
- 9
Marlin/src/lcd/e3v2/creality/dwin.cpp View File

2625
 #include "../../../libs/buzzer.h"
2625
 #include "../../../libs/buzzer.h"
2626
 
2626
 
2627
 void HMI_AudioFeedback(const bool success=true) {
2627
 void HMI_AudioFeedback(const bool success=true) {
2628
-  #if HAS_BUZZER
2629
-    if (success) {
2630
-      buzzer.tone(100, 659);
2631
-      buzzer.tone(10, 0);
2632
-      buzzer.tone(100, 698);
2633
-    }
2634
-    else
2635
-      buzzer.tone(40, 440);
2636
-  #endif
2628
+  if (success) {
2629
+    BUZZ(100, 659);
2630
+    BUZZ(10, 0);
2631
+    BUZZ(100, 698);
2632
+  }
2633
+  else
2634
+    BUZZ(40, 440);
2637
 }
2635
 }
2638
 
2636
 
2639
 // Prepare
2637
 // Prepare

+ 8
- 15
Marlin/src/lcd/marlinui.cpp View File

119
   bool MarlinUI::sound_on = ENABLED(SOUND_ON_DEFAULT);
119
   bool MarlinUI::sound_on = ENABLED(SOUND_ON_DEFAULT);
120
 #endif
120
 #endif
121
 
121
 
122
-#if EITHER(PCA9632_BUZZER, HAS_BEEPER)
123
-  #if ENABLED(PCA9632_BUZZER)
124
-    #include "../feature/leds/pca9632.h"
125
-  #endif
122
+#if ENABLED(PCA9632_BUZZER)
126
   void MarlinUI::buzz(const long duration, const uint16_t freq) {
123
   void MarlinUI::buzz(const long duration, const uint16_t freq) {
127
-    if (!sound_on) return;
128
-    #if ENABLED(PCA9632_BUZZER)
129
-      PCA9632_buzz(duration, freq);
130
-    #elif HAS_BEEPER
131
-      buzzer.tone(duration, freq);
132
-    #endif
124
+    if (sound_on) PCA9632_buzz(duration, freq);
133
   }
125
   }
134
 #endif
126
 #endif
135
 
127
 
683
       if (old_frm != new_frm) {
675
       if (old_frm != new_frm) {
684
         feedrate_percentage = new_frm;
676
         feedrate_percentage = new_frm;
685
         encoderPosition = 0;
677
         encoderPosition = 0;
686
-        #if BOTH(HAS_BUZZER, BEEP_ON_FEEDRATE_CHANGE)
678
+        #if BOTH(HAS_SOUND, BEEP_ON_FEEDRATE_CHANGE)
687
           static millis_t next_beep;
679
           static millis_t next_beep;
688
           #ifndef GOT_MS
680
           #ifndef GOT_MS
689
             const millis_t ms = millis();
681
             const millis_t ms = millis();
741
       UNUSED(clear_buttons);
733
       UNUSED(clear_buttons);
742
     #endif
734
     #endif
743
 
735
 
744
-    #if HAS_CHIRP
745
-      chirp(); // Buzz and wait. Is the delay needed for buttons to settle?
746
-      #if BOTH(HAS_MARLINUI_MENU, HAS_BEEPER)
736
+    chirp();  // Buzz and wait. Is the delay needed for buttons to settle?
737
+
738
+    #if HAS_CHIRP && HAS_MARLINUI_MENU
739
+      #if HAS_BEEPER
747
         for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
740
         for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
748
-      #elif HAS_MARLINUI_MENU
741
+      #else
749
         delay(10);
742
         delay(10);
750
       #endif
743
       #endif
751
     #endif
744
     #endif

+ 4
- 4
Marlin/src/lcd/marlinui.h View File

225
     static constexpr bool sound_on = true;
225
     static constexpr bool sound_on = true;
226
   #endif
226
   #endif
227
 
227
 
228
-  #if HAS_BUZZER
228
+  #if USE_MARLINUI_BUZZER
229
     static void buzz(const long duration, const uint16_t freq);
229
     static void buzz(const long duration, const uint16_t freq);
230
   #endif
230
   #endif
231
 
231
 
232
-  FORCE_INLINE static void chirp() {
233
-    TERN_(HAS_CHIRP, TERN(HAS_BUZZER, buzz, BUZZ)(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ));
232
+  static void chirp() {
233
+    TERN_(HAS_CHIRP, TERN(USE_MARLINUI_BUZZER, buzz, BUZZ)(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ));
234
   }
234
   }
235
 
235
 
236
   #if ENABLED(LCD_HAS_STATUS_INDICATORS)
236
   #if ENABLED(LCD_HAS_STATUS_INDICATORS)
453
       #endif
453
       #endif
454
 
454
 
455
       static void quick_feedback(const bool clear_buttons=true);
455
       static void quick_feedback(const bool clear_buttons=true);
456
-      #if HAS_BUZZER
456
+      #if HAS_SOUND
457
         static void completion_feedback(const bool good=true);
457
         static void completion_feedback(const bool good=true);
458
       #else
458
       #else
459
         static void completion_feedback(const bool=true) { TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); }
459
         static void completion_feedback(const bool=true) { TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); }

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

28
 
28
 
29
 //#define MUTE_GAMES
29
 //#define MUTE_GAMES
30
 
30
 
31
-#if ENABLED(MUTE_GAMES) || !HAS_BUZZER
31
+#if ENABLED(MUTE_GAMES) || !HAS_SOUND
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)

+ 2
- 2
Marlin/src/lcd/menu/menu.cpp View File

31
 #include "../../module/temperature.h"
31
 #include "../../module/temperature.h"
32
 #include "../../gcode/queue.h"
32
 #include "../../gcode/queue.h"
33
 
33
 
34
-#if HAS_BUZZER
34
+#if HAS_SOUND
35
   #include "../../libs/buzzer.h"
35
   #include "../../libs/buzzer.h"
36
 #endif
36
 #endif
37
 
37
 
272
     encoderTopLine = encoderLine;
272
     encoderTopLine = encoderLine;
273
 }
273
 }
274
 
274
 
275
-#if HAS_BUZZER
275
+#if HAS_SOUND
276
   void MarlinUI::completion_feedback(const bool good/*=true*/) {
276
   void MarlinUI::completion_feedback(const bool good/*=true*/) {
277
     TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); // Wake up on rotary encoder click...
277
     TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); // Wake up on rotary encoder click...
278
     if (good) OKAY_BUZZ(); else ERR_BUZZ();
278
     if (good) OKAY_BUZZ(); else ERR_BUZZ();

+ 3
- 3
Marlin/src/libs/buzzer.h View File

117
   // Buzz directly via the BEEPER pin tone queue
117
   // Buzz directly via the BEEPER pin tone queue
118
   #define BUZZ(d,f) buzzer.tone(d, f)
118
   #define BUZZ(d,f) buzzer.tone(d, f)
119
 
119
 
120
-#elif HAS_BUZZER
120
+#elif USE_MARLINUI_BUZZER
121
 
121
 
122
-  // Buzz indirectly via the MarlinUI instance
123
-  #define BUZZ(d,f) ui.buzz(d,f)
122
+  // Use MarlinUI for a buzzer on the LCD
124
   #include "../lcd/marlinui.h"
123
   #include "../lcd/marlinui.h"
124
+  #define BUZZ(d,f) ui.buzz(d,f)
125
 
125
 
126
 #else
126
 #else
127
 
127
 

+ 2
- 2
Marlin/src/module/printcounter.cpp View File

37
 #include "../MarlinCore.h"
37
 #include "../MarlinCore.h"
38
 #include "../HAL/shared/eeprom_api.h"
38
 #include "../HAL/shared/eeprom_api.h"
39
 
39
 
40
-#if HAS_BUZZER && SERVICE_WARNING_BUZZES > 0
40
+#if HAS_SOUND && SERVICE_WARNING_BUZZES > 0
41
   #include "../libs/buzzer.h"
41
   #include "../libs/buzzer.h"
42
 #endif
42
 #endif
43
 
43
 
156
     #if SERVICE_INTERVAL_3 > 0
156
     #if SERVICE_INTERVAL_3 > 0
157
       if (data.nextService3 == 0) doBuzz = _service_warn(PSTR(" " SERVICE_NAME_3));
157
       if (data.nextService3 == 0) doBuzz = _service_warn(PSTR(" " SERVICE_NAME_3));
158
     #endif
158
     #endif
159
-    #if HAS_BUZZER && SERVICE_WARNING_BUZZES > 0
159
+    #if HAS_SOUND && SERVICE_WARNING_BUZZES > 0
160
       if (doBuzz) for (int i = 0; i < SERVICE_WARNING_BUZZES; i++) { BUZZ(200, 404); BUZZ(10, 0); }
160
       if (doBuzz) for (int i = 0; i < SERVICE_WARNING_BUZZES; i++) { BUZZ(200, 404); BUZZ(10, 0); }
161
     #else
161
     #else
162
       UNUSED(doBuzz);
162
       UNUSED(doBuzz);

+ 1
- 1
ini/features.ini View File

202
 HAS_LCD_CONTRAST                       = src_filter=+<src/gcode/lcd/M250.cpp>
202
 HAS_LCD_CONTRAST                       = src_filter=+<src/gcode/lcd/M250.cpp>
203
 HAS_GCODE_M255                         = src_filter=+<src/gcode/lcd/M255.cpp>
203
 HAS_GCODE_M255                         = src_filter=+<src/gcode/lcd/M255.cpp>
204
 HAS_LCD_BRIGHTNESS                     = src_filter=+<src/gcode/lcd/M256.cpp>
204
 HAS_LCD_BRIGHTNESS                     = src_filter=+<src/gcode/lcd/M256.cpp>
205
-HAS_BUZZER                             = src_filter=+<src/gcode/lcd/M300.cpp>
205
+HAS_SOUND                              = src_filter=+<src/gcode/lcd/M300.cpp>
206
 TOUCH_SCREEN_CALIBRATION               = src_filter=+<src/gcode/lcd/M995.cpp>
206
 TOUCH_SCREEN_CALIBRATION               = src_filter=+<src/gcode/lcd/M995.cpp>
207
 ARC_SUPPORT                            = src_filter=+<src/gcode/motion/G2_G3.cpp>
207
 ARC_SUPPORT                            = src_filter=+<src/gcode/motion/G2_G3.cpp>
208
 GCODE_MOTION_MODES                     = src_filter=+<src/gcode/motion/G80.cpp>
208
 GCODE_MOTION_MODES                     = src_filter=+<src/gcode/motion/G80.cpp>

Loading…
Cancel
Save