Переглянути джерело

♻️ Small sound / buzz refactor (#24520)

Scott Lahteine 2 роки тому
джерело
коміт
5f2908a117
Аккаунт користувача з таким Email не знайдено

+ 2
- 2
Marlin/src/feature/pause.cpp Переглянути файл

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

+ 1
- 1
Marlin/src/feature/spindle_laser.h Переглянути файл

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

+ 1
- 1
Marlin/src/gcode/gcode.cpp Переглянути файл

@@ -765,7 +765,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
765 765
         case 290: M290(); break;                                  // M290: Babystepping
766 766
       #endif
767 767
 
768
-      #if HAS_BUZZER
768
+      #if HAS_SOUND
769 769
         case 300: M300(); break;                                  // M300: Play beep tone
770 770
       #endif
771 771
 

+ 1
- 1
Marlin/src/gcode/gcode.h Переглянути файл

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

+ 2
- 2
Marlin/src/gcode/lcd/M300.cpp Переглянути файл

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

+ 8
- 4
Marlin/src/inc/Conditionals_post.h Переглянути файл

@@ -3564,8 +3564,11 @@
3564 3564
 #if PIN_EXISTS(BEEPER)
3565 3565
   #define HAS_BEEPER 1
3566 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 3572
 #endif
3570 3573
 
3571 3574
 #if ENABLED(LCD_USE_I2C_BUZZER)
@@ -3575,7 +3578,7 @@
3575 3578
   #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
3576 3579
     #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100
3577 3580
   #endif
3578
-#elif HAS_BUZZER
3581
+#elif HAS_SOUND
3579 3582
   #ifndef LCD_FEEDBACK_FREQUENCY_HZ
3580 3583
     #define LCD_FEEDBACK_FREQUENCY_HZ 5000
3581 3584
   #endif
@@ -3584,12 +3587,13 @@
3584 3587
   #endif
3585 3588
 #endif
3586 3589
 
3587
-#if HAS_BUZZER
3590
+#if HAS_SOUND
3588 3591
   #if LCD_FEEDBACK_FREQUENCY_DURATION_MS && LCD_FEEDBACK_FREQUENCY_HZ
3589 3592
     #define HAS_CHIRP 1
3590 3593
   #endif
3591 3594
 #else
3592 3595
   #undef SOUND_MENU_ITEM   // No buzzer menu item without a buzzer
3596
+  #undef SOUND_ON_DEFAULT
3593 3597
 #endif
3594 3598
 
3595 3599
 /**

+ 3
- 2
Marlin/src/lcd/HD44780/marlinui_HD44780.cpp Переглянути файл

@@ -120,10 +120,11 @@ static void createChar_P(const char c, const byte * const ptr) {
120 120
 #endif
121 121
 
122 122
 #if ENABLED(LCD_USE_I2C_BUZZER)
123
+
123 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 128
 #endif
128 129
 
129 130
 void MarlinUI::set_custom_characters(const HD44780CharSet screen_charset/*=CHARSET_INFO*/) {

+ 3
- 5
Marlin/src/lcd/e3v2/common/encoder.cpp Переглянути файл

@@ -36,7 +36,7 @@
36 36
 #include "../../marlinui.h"
37 37
 #include "../../../HAL/shared/Delay.h"
38 38
 
39
-#if HAS_BUZZER
39
+#if HAS_SOUND
40 40
   #include "../../../libs/buzzer.h"
41 41
 #endif
42 42
 
@@ -50,9 +50,7 @@ ENCODER_Rate EncoderRate;
50 50
 
51 51
 // TODO: Replace with ui.quick_feedback
52 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 56
 // Encoder initialization
@@ -66,7 +64,7 @@ void Encoder_Configuration() {
66 64
   #if BUTTON_EXISTS(ENC)
67 65
     SET_INPUT_PULLUP(BTN_ENC);
68 66
   #endif
69
-  #if PIN_EXISTS(BEEPER)
67
+  #if HAS_BEEPER
70 68
     SET_OUTPUT(BEEPER_PIN);     // TODO: Use buzzer.h which already inits this
71 69
   #endif
72 70
 }

+ 7
- 9
Marlin/src/lcd/e3v2/creality/dwin.cpp Переглянути файл

@@ -2625,15 +2625,13 @@ void Draw_HomeOff_Menu() {
2625 2625
 #include "../../../libs/buzzer.h"
2626 2626
 
2627 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 2637
 // Prepare

+ 8
- 15
Marlin/src/lcd/marlinui.cpp Переглянути файл

@@ -119,17 +119,9 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
119 119
   bool MarlinUI::sound_on = ENABLED(SOUND_ON_DEFAULT);
120 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 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 126
 #endif
135 127
 
@@ -683,7 +675,7 @@ void MarlinUI::init() {
683 675
       if (old_frm != new_frm) {
684 676
         feedrate_percentage = new_frm;
685 677
         encoderPosition = 0;
686
-        #if BOTH(HAS_BUZZER, BEEP_ON_FEEDRATE_CHANGE)
678
+        #if BOTH(HAS_SOUND, BEEP_ON_FEEDRATE_CHANGE)
687 679
           static millis_t next_beep;
688 680
           #ifndef GOT_MS
689 681
             const millis_t ms = millis();
@@ -741,11 +733,12 @@ void MarlinUI::init() {
741 733
       UNUSED(clear_buttons);
742 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 740
         for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
748
-      #elif HAS_MARLINUI_MENU
741
+      #else
749 742
         delay(10);
750 743
       #endif
751 744
     #endif

+ 4
- 4
Marlin/src/lcd/marlinui.h Переглянути файл

@@ -225,12 +225,12 @@ public:
225 225
     static constexpr bool sound_on = true;
226 226
   #endif
227 227
 
228
-  #if HAS_BUZZER
228
+  #if USE_MARLINUI_BUZZER
229 229
     static void buzz(const long duration, const uint16_t freq);
230 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 236
   #if ENABLED(LCD_HAS_STATUS_INDICATORS)
@@ -453,7 +453,7 @@ public:
453 453
       #endif
454 454
 
455 455
       static void quick_feedback(const bool clear_buttons=true);
456
-      #if HAS_BUZZER
456
+      #if HAS_SOUND
457 457
         static void completion_feedback(const bool good=true);
458 458
       #else
459 459
         static void completion_feedback(const bool=true) { TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); }

+ 1
- 1
Marlin/src/lcd/menu/game/game.h Переглянути файл

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

+ 2
- 2
Marlin/src/lcd/menu/menu.cpp Переглянути файл

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

+ 3
- 3
Marlin/src/libs/buzzer.h Переглянути файл

@@ -117,11 +117,11 @@
117 117
   // Buzz directly via the BEEPER pin tone queue
118 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 123
   #include "../lcd/marlinui.h"
124
+  #define BUZZ(d,f) ui.buzz(d,f)
125 125
 
126 126
 #else
127 127
 

+ 2
- 2
Marlin/src/module/printcounter.cpp Переглянути файл

@@ -37,7 +37,7 @@ Stopwatch print_job_timer;      // Global Print Job Timer instance
37 37
 #include "../MarlinCore.h"
38 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 41
   #include "../libs/buzzer.h"
42 42
 #endif
43 43
 
@@ -156,7 +156,7 @@ void PrintCounter::loadStats() {
156 156
     #if SERVICE_INTERVAL_3 > 0
157 157
       if (data.nextService3 == 0) doBuzz = _service_warn(PSTR(" " SERVICE_NAME_3));
158 158
     #endif
159
-    #if HAS_BUZZER && SERVICE_WARNING_BUZZES > 0
159
+    #if HAS_SOUND && SERVICE_WARNING_BUZZES > 0
160 160
       if (doBuzz) for (int i = 0; i < SERVICE_WARNING_BUZZES; i++) { BUZZ(200, 404); BUZZ(10, 0); }
161 161
     #else
162 162
       UNUSED(doBuzz);

+ 1
- 1
ini/features.ini Переглянути файл

@@ -202,7 +202,7 @@ HAS_STATUS_MESSAGE                     = src_filter=+<src/gcode/lcd/M117.cpp>
202 202
 HAS_LCD_CONTRAST                       = src_filter=+<src/gcode/lcd/M250.cpp>
203 203
 HAS_GCODE_M255                         = src_filter=+<src/gcode/lcd/M255.cpp>
204 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 206
 TOUCH_SCREEN_CALIBRATION               = src_filter=+<src/gcode/lcd/M995.cpp>
207 207
 ARC_SUPPORT                            = src_filter=+<src/gcode/motion/G2_G3.cpp>
208 208
 GCODE_MOTION_MODES                     = src_filter=+<src/gcode/motion/G80.cpp>

Завантаження…
Відмінити
Зберегти