Преглед изворни кода

✨ SOUND_ON_DEFAULT option (#24102)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
Pauli Jokela пре 2 година
родитељ
комит
04fe50936e
No account linked to committer's email address

+ 1
- 0
Marlin/Configuration_adv.h Прегледај датотеку

1337
 
1337
 
1338
 #if ANY(HAS_DISPLAY, DWIN_LCD_PROUI, DWIN_CREALITY_LCD_JYERSUI)
1338
 #if ANY(HAS_DISPLAY, DWIN_LCD_PROUI, DWIN_CREALITY_LCD_JYERSUI)
1339
   //#define SOUND_MENU_ITEM   // Add a mute option to the LCD menu
1339
   //#define SOUND_MENU_ITEM   // Add a mute option to the LCD menu
1340
+  #define SOUND_ON_DEFAULT    // Buzzer/speaker default enabled state
1340
 #endif
1341
 #endif
1341
 
1342
 
1342
 #if EITHER(HAS_DISPLAY, DWIN_LCD_PROUI)
1343
 #if EITHER(HAS_DISPLAY, DWIN_LCD_PROUI)

+ 3
- 3
Marlin/src/MarlinCore.cpp Прегледај датотеку

97
   #include "feature/host_actions.h"
97
   #include "feature/host_actions.h"
98
 #endif
98
 #endif
99
 
99
 
100
-#if USE_BEEPER
100
+#if HAS_BEEPER
101
   #include "libs/buzzer.h"
101
   #include "libs/buzzer.h"
102
 #endif
102
 #endif
103
 
103
 
827
   TERN_(PRINTCOUNTER, print_job_timer.tick());
827
   TERN_(PRINTCOUNTER, print_job_timer.tick());
828
 
828
 
829
   // Update the Beeper queue
829
   // Update the Beeper queue
830
-  TERN_(USE_BEEPER, buzzer.tick());
830
+  TERN_(HAS_BEEPER, buzzer.tick());
831
 
831
 
832
   // Handle UI input / draw events
832
   // Handle UI input / draw events
833
   TERN(DWIN_CREALITY_LCD, DWIN_Update(), ui.update());
833
   TERN(DWIN_CREALITY_LCD, DWIN_Update(), ui.update());
1287
   calibrate_delay_loop();
1287
   calibrate_delay_loop();
1288
 
1288
 
1289
   // Init buzzer pin(s)
1289
   // Init buzzer pin(s)
1290
-  #if USE_BEEPER
1290
+  #if HAS_BEEPER
1291
     SETUP_RUN(buzzer.init());
1291
     SETUP_RUN(buzzer.init());
1292
   #endif
1292
   #endif
1293
 
1293
 

+ 2
- 2
Marlin/src/feature/spindle_laser.h Прегледај датотеку

30
 
30
 
31
 #include "spindle_laser_types.h"
31
 #include "spindle_laser_types.h"
32
 
32
 
33
-#if USE_BEEPER
33
+#if HAS_BEEPER
34
   #include "../libs/buzzer.h"
34
   #include "../libs/buzzer.h"
35
 #endif
35
 #endif
36
 
36
 
272
        * If not set defaults to 80% power
272
        * If not set defaults to 80% power
273
        */
273
        */
274
       static void test_fire_pulse() {
274
       static void test_fire_pulse() {
275
-        TERN_(USE_BEEPER, buzzer.tone(30, 3000));
275
+        TERN_(HAS_BEEPER, buzzer.tone(30, 3000));
276
         enable_forward();                  // Turn Laser on (Spindle speak but same funct)
276
         enable_forward();                  // Turn Laser on (Spindle speak but same funct)
277
         delay(testPulse);                  // Delay for time set by user in pulse ms menu screen.
277
         delay(testPulse);                  // Delay for time set by user in pulse ms menu screen.
278
         disable();                         // Turn laser off
278
         disable();                         // Turn laser off

+ 2
- 2
Marlin/src/inc/Conditionals_post.h Прегледај датотеку

3552
  * Buzzer/Speaker
3552
  * Buzzer/Speaker
3553
  */
3553
  */
3554
 #if PIN_EXISTS(BEEPER)
3554
 #if PIN_EXISTS(BEEPER)
3555
-  #define USE_BEEPER 1
3555
+  #define HAS_BEEPER 1
3556
 #endif
3556
 #endif
3557
-#if USE_BEEPER || ANY(LCD_USE_I2C_BUZZER, PCA9632_BUZZER)
3557
+#if ANY(HAS_BEEPER, LCD_USE_I2C_BUZZER, PCA9632_BUZZER)
3558
   #define HAS_BUZZER 1
3558
   #define HAS_BUZZER 1
3559
 #endif
3559
 #endif
3560
 
3560
 

+ 1
- 1
Marlin/src/lcd/HD44780/marlinui_HD44780.cpp Прегледај датотеку

121
 
121
 
122
 #if ENABLED(LCD_USE_I2C_BUZZER)
122
 #if ENABLED(LCD_USE_I2C_BUZZER)
123
   void MarlinUI::buzz(const long duration, const uint16_t freq) {
123
   void MarlinUI::buzz(const long duration, const uint16_t freq) {
124
-    if (!buzzer_enabled) return;
124
+    if (!sound_on) return;
125
     lcd.buzz(duration, freq);
125
     lcd.buzz(duration, freq);
126
   }
126
   }
127
 #endif
127
 #endif

+ 1
- 1
Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp Прегледај датотеку

301
 // Duration in ms, freq in Hz
301
 // Duration in ms, freq in Hz
302
 void MarlinUI::buzz(const long duration, const uint16_t freq) {
302
 void MarlinUI::buzz(const long duration, const uint16_t freq) {
303
   if (!PanelDetected) return;
303
   if (!PanelDetected) return;
304
-  if (!buzzer_enabled) return;
304
+  if (!sound_on) return;
305
   #if ENABLED(TFTGLCD_PANEL_SPI)
305
   #if ENABLED(TFTGLCD_PANEL_SPI)
306
     WRITE(TFTGLCD_CS, LOW);
306
     WRITE(TFTGLCD_CS, LOW);
307
     SPI_SEND_ONE(BUZZER);
307
     SPI_SEND_ONE(BUZZER);

+ 1
- 5
Marlin/src/lcd/e3v2/common/encoder.cpp Прегледај датотеку

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)
53
   #if PIN_EXISTS(BEEPER)
54
-    if (ui.buzzer_enabled) {
55
-      WRITE(BEEPER_PIN, HIGH);
56
-      delay(10);
57
-      WRITE(BEEPER_PIN, LOW);
58
-    }
54
+    if (ui.sound_on) buzzer.click(10);
59
   #endif
55
   #endif
60
 }
56
 }
61
 
57
 

+ 5
- 5
Marlin/src/lcd/e3v2/jyersui/dwin.cpp Прегледај датотеку

2587
           case ADVANCED_BEEPER:
2587
           case ADVANCED_BEEPER:
2588
             if (draw) {
2588
             if (draw) {
2589
               Draw_Menu_Item(row, ICON_Version, F("LCD Beeper"));
2589
               Draw_Menu_Item(row, ICON_Version, F("LCD Beeper"));
2590
-              Draw_Checkbox(row, ui.buzzer_enabled);
2590
+              Draw_Checkbox(row, ui.sound_on);
2591
             }
2591
             }
2592
             else {
2592
             else {
2593
-              ui.buzzer_enabled = !ui.buzzer_enabled;
2594
-              Draw_Checkbox(row, ui.buzzer_enabled);
2593
+              ui.sound_on = !ui.sound_on;
2594
+              Draw_Checkbox(row, ui.sound_on);
2595
             }
2595
             }
2596
             break;
2596
             break;
2597
         #endif
2597
         #endif
4602
 }
4602
 }
4603
 
4603
 
4604
 void CrealityDWINClass::AudioFeedback(const bool success/*=true*/) {
4604
 void CrealityDWINClass::AudioFeedback(const bool success/*=true*/) {
4605
-  if (ui.buzzer_enabled)
4605
+  if (ui.sound_on)
4606
     DONE_BUZZ(success);
4606
     DONE_BUZZ(success);
4607
   else
4607
   else
4608
     Update_Status(success ? "Success" : "Failed");
4608
     Update_Status(success ? "Success" : "Failed");
4646
   eeprom_settings.coordinates_split_line = 0;
4646
   eeprom_settings.coordinates_split_line = 0;
4647
   TERN_(AUTO_BED_LEVELING_UBL, mesh_conf.tilt_grid = eeprom_settings.tilt_grid_size + 1);
4647
   TERN_(AUTO_BED_LEVELING_UBL, mesh_conf.tilt_grid = eeprom_settings.tilt_grid_size + 1);
4648
   corner_pos = eeprom_settings.corner_pos / 10.0f;
4648
   corner_pos = eeprom_settings.corner_pos / 10.0f;
4649
-  TERN_(SOUND_MENU_ITEM, ui.buzzer_enabled = true);
4649
+  TERN_(SOUND_MENU_ITEM, ui.sound_on = ENABLED(SOUND_ON_DEFAULT));
4650
   Redraw_Screen();
4650
   Redraw_Screen();
4651
 }
4651
 }
4652
 
4652
 

+ 3
- 3
Marlin/src/lcd/e3v2/proui/dwin.cpp Прегледај датотеку

2106
 
2106
 
2107
 #if ENABLED(SOUND_MENU_ITEM)
2107
 #if ENABLED(SOUND_MENU_ITEM)
2108
   void SetEnableSound() {
2108
   void SetEnableSound() {
2109
-    ui.buzzer_enabled = !ui.buzzer_enabled;
2110
-    Draw_Chkb_Line(CurrentMenu->line(), ui.buzzer_enabled);
2109
+    ui.sound_on = !ui.sound_on;
2110
+    Draw_Chkb_Line(CurrentMenu->line(), ui.sound_on);
2111
     DWIN_UpdateLCD();
2111
     DWIN_UpdateLCD();
2112
   }
2112
   }
2113
 #endif
2113
 #endif
2638
 #endif
2638
 #endif
2639
 
2639
 
2640
 #if ENABLED(SOUND_MENU_ITEM)
2640
 #if ENABLED(SOUND_MENU_ITEM)
2641
-  void onDrawEnableSound(MenuItemClass* menuitem, int8_t line) { onDrawChkbMenu(menuitem, line, ui.buzzer_enabled); }
2641
+  void onDrawEnableSound(MenuItemClass* menuitem, int8_t line) { onDrawChkbMenu(menuitem, line, ui.sound_on); }
2642
 #endif
2642
 #endif
2643
 
2643
 
2644
 #ifdef BLTOUCH_HS_MODE
2644
 #ifdef BLTOUCH_HS_MODE

+ 4
- 5
Marlin/src/lcd/extui/anycubic_chiron/Tunes.cpp Прегледај датотеку

35
 
35
 
36
 #include "../../../inc/MarlinConfigPre.h"
36
 #include "../../../inc/MarlinConfigPre.h"
37
 
37
 
38
+// TODO: Use Marlin's built-in tone player instead.
39
+
38
 #if ENABLED(ANYCUBIC_LCD_CHIRON)
40
 #if ENABLED(ANYCUBIC_LCD_CHIRON)
39
 
41
 
40
 #include "Tunes.h"
42
 #include "Tunes.h"
44
 
46
 
45
   void PlayTune(uint8_t beeperPin, const uint16_t *tune, uint8_t speed=1) {
47
   void PlayTune(uint8_t beeperPin, const uint16_t *tune, uint8_t speed=1) {
46
     uint8_t pos = 1;
48
     uint8_t pos = 1;
47
-    uint16_t wholenotelen = tune[0] / speed;
49
+    const uint16_t wholenotelen = tune[0] / speed;
48
     do {
50
     do {
49
-      uint16_t freq = tune[pos];
50
-      uint16_t notelen = wholenotelen / tune[pos + 1];
51
-
51
+      const uint16_t freq = tune[pos], notelen = wholenotelen / tune[pos + 1];
52
       ::tone(beeperPin, freq, notelen);
52
       ::tone(beeperPin, freq, notelen);
53
       ExtUI::delay_ms(notelen);
53
       ExtUI::delay_ms(notelen);
54
       pos += 2;
54
       pos += 2;
55
-
56
       if (pos >= MAX_TUNE_LENGTH) break;
55
       if (pos >= MAX_TUNE_LENGTH) break;
57
     } while (tune[pos] != n_END);
56
     } while (tune[pos] != n_END);
58
   }
57
   }

+ 1
- 3
Marlin/src/lcd/extui/anycubic_i3mega/anycubic_extui.cpp Прегледај датотеку

42
   void onMediaError()     { AnycubicTFT.OnSDCardError(); }
42
   void onMediaError()     { AnycubicTFT.OnSDCardError(); }
43
   void onMediaRemoved()   { AnycubicTFT.OnSDCardStateChange(false); }
43
   void onMediaRemoved()   { AnycubicTFT.OnSDCardStateChange(false); }
44
   void onPlayTone(const uint16_t frequency, const uint16_t duration) {
44
   void onPlayTone(const uint16_t frequency, const uint16_t duration) {
45
-    #if ENABLED(SPEAKER)
46
-      ::tone(BEEPER_PIN, frequency, duration);
47
-    #endif
45
+    TERN_(SPEAKER, ::tone(BEEPER_PIN, frequency, duration));
48
   }
46
   }
49
   void onPrintTimerStarted()  { AnycubicTFT.OnPrintTimerStarted(); }
47
   void onPrintTimerStarted()  { AnycubicTFT.OnPrintTimerStarted(); }
50
   void onPrintTimerPaused()   { AnycubicTFT.OnPrintTimerPaused(); }
48
   void onPrintTimerPaused()   { AnycubicTFT.OnPrintTimerPaused(); }

+ 3
- 6
Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp Прегледај датотеку

160
     #endif
160
     #endif
161
   }
161
   }
162
 
162
 
163
+  #include "../../../libs/buzzer.h"
164
+
163
   void init_test_gpio() {
165
   void init_test_gpio() {
164
     endstops.init();
166
     endstops.init();
165
 
167
 
201
     #endif
203
     #endif
202
   }
204
   }
203
 
205
 
204
-  void mks_test_beeper() {
205
-    WRITE(BEEPER_PIN, HIGH);
206
-    delay(100);
207
-    WRITE(BEEPER_PIN, LOW);
208
-    delay(100);
209
-  }
206
+  void mks_test_beeper() { buzzer.click(100); }
210
 
207
 
211
   #if ENABLED(SDSUPPORT)
208
   #if ENABLED(SDSUPPORT)
212
 
209
 

+ 7
- 8
Marlin/src/lcd/marlinui.cpp Прегледај датотеку

118
 #endif
118
 #endif
119
 
119
 
120
 #if ENABLED(SOUND_MENU_ITEM)
120
 #if ENABLED(SOUND_MENU_ITEM)
121
-  bool MarlinUI::buzzer_enabled = true;
121
+  bool MarlinUI::sound_on = ENABLED(SOUND_ON_DEFAULT);
122
 #endif
122
 #endif
123
 
123
 
124
-#if EITHER(PCA9632_BUZZER, USE_BEEPER)
125
-  #include "../libs/buzzer.h" // for BUZZ() macro
124
+#if EITHER(PCA9632_BUZZER, HAS_BEEPER)
126
   #if ENABLED(PCA9632_BUZZER)
125
   #if ENABLED(PCA9632_BUZZER)
127
     #include "../feature/leds/pca9632.h"
126
     #include "../feature/leds/pca9632.h"
128
   #endif
127
   #endif
129
   void MarlinUI::buzz(const long duration, const uint16_t freq) {
128
   void MarlinUI::buzz(const long duration, const uint16_t freq) {
130
-    if (!buzzer_enabled) return;
129
+    if (!sound_on) return;
131
     #if ENABLED(PCA9632_BUZZER)
130
     #if ENABLED(PCA9632_BUZZER)
132
       PCA9632_buzz(duration, freq);
131
       PCA9632_buzz(duration, freq);
133
-    #elif USE_BEEPER
132
+    #elif HAS_BEEPER
134
       buzzer.tone(duration, freq);
133
       buzzer.tone(duration, freq);
135
     #endif
134
     #endif
136
   }
135
   }
694
             const millis_t ms = millis();
693
             const millis_t ms = millis();
695
           #endif
694
           #endif
696
           if (ELAPSED(ms, next_beep)) {
695
           if (ELAPSED(ms, next_beep)) {
697
-            buzz(FEEDRATE_CHANGE_BEEP_DURATION, FEEDRATE_CHANGE_BEEP_FREQUENCY);
696
+            BUZZ(FEEDRATE_CHANGE_BEEP_DURATION, FEEDRATE_CHANGE_BEEP_FREQUENCY);
698
             next_beep = ms + 500UL;
697
             next_beep = ms + 500UL;
699
           }
698
           }
700
         #endif
699
         #endif
748
 
747
 
749
     #if HAS_CHIRP
748
     #if HAS_CHIRP
750
       chirp(); // Buzz and wait. Is the delay needed for buttons to settle?
749
       chirp(); // Buzz and wait. Is the delay needed for buttons to settle?
751
-      #if BOTH(HAS_MARLINUI_MENU, USE_BEEPER)
750
+      #if BOTH(HAS_MARLINUI_MENU, HAS_BEEPER)
752
         for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
751
         for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
753
       #elif HAS_MARLINUI_MENU
752
       #elif HAS_MARLINUI_MENU
754
         delay(10);
753
         delay(10);
1646
 
1645
 
1647
   void MarlinUI::flow_fault() {
1646
   void MarlinUI::flow_fault() {
1648
     LCD_ALERTMESSAGE(MSG_FLOWMETER_FAULT);
1647
     LCD_ALERTMESSAGE(MSG_FLOWMETER_FAULT);
1649
-    TERN_(HAS_BUZZER, buzz(1000, 440));
1648
+    BUZZ(1000, 440);
1650
     TERN_(HAS_MARLINUI_MENU, return_to_status());
1649
     TERN_(HAS_MARLINUI_MENU, return_to_status());
1651
   }
1650
   }
1652
 
1651
 

+ 9
- 11
Marlin/src/lcd/marlinui.h Прегледај датотеку

21
  */
21
  */
22
 #pragma once
22
 #pragma once
23
 
23
 
24
+#include "../inc/MarlinConfig.h"
24
 #include "../sd/cardreader.h"
25
 #include "../sd/cardreader.h"
25
 #include "../module/motion.h"
26
 #include "../module/motion.h"
26
-#include "buttons.h"
27
+#include "../libs/buzzer.h"
27
 
28
 
28
-#include "../inc/MarlinConfig.h"
29
-
30
-#if HAS_BUZZER
31
-  #include "../libs/buzzer.h"
32
-#endif
29
+#include "buttons.h"
33
 
30
 
34
 #if ENABLED(TOUCH_SCREEN_CALIBRATION)
31
 #if ENABLED(TOUCH_SCREEN_CALIBRATION)
35
   #include "tft_io/touch_calibration.h"
32
   #include "tft_io/touch_calibration.h"
192
 //////////// MarlinUI Singleton ////////////
189
 //////////// MarlinUI Singleton ////////////
193
 ////////////////////////////////////////////
190
 ////////////////////////////////////////////
194
 
191
 
192
+class MarlinUI;
193
+extern MarlinUI ui;
194
+
195
 class MarlinUI {
195
 class MarlinUI {
196
 public:
196
 public:
197
 
197
 
225
   #endif
225
   #endif
226
 
226
 
227
   #if ENABLED(SOUND_MENU_ITEM)
227
   #if ENABLED(SOUND_MENU_ITEM)
228
-    static bool buzzer_enabled; // Initialized by settings.load()
228
+    static bool sound_on; // Initialized by settings.load()
229
   #else
229
   #else
230
-    static constexpr bool buzzer_enabled = true;
230
+    static constexpr bool sound_on = true;
231
   #endif
231
   #endif
232
 
232
 
233
   #if HAS_BUZZER
233
   #if HAS_BUZZER
235
   #endif
235
   #endif
236
 
236
 
237
   FORCE_INLINE static void chirp() {
237
   FORCE_INLINE static void chirp() {
238
-    TERN_(HAS_CHIRP, buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ));
238
+    TERN_(HAS_CHIRP, TERN(HAS_BUZZER, buzz, BUZZ)(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ));
239
   }
239
   }
240
 
240
 
241
   #if ENABLED(LCD_HAS_STATUS_INDICATORS)
241
   #if ENABLED(LCD_HAS_STATUS_INDICATORS)
786
   #endif
786
   #endif
787
 };
787
 };
788
 
788
 
789
-extern MarlinUI ui;
790
-
791
 #define LCD_MESSAGE_F(S)       ui.set_status(F(S))
789
 #define LCD_MESSAGE_F(S)       ui.set_status(F(S))
792
 #define LCD_MESSAGE(M)         ui.set_status(GET_TEXT_F(M))
790
 #define LCD_MESSAGE(M)         ui.set_status(GET_TEXT_F(M))
793
 #define LCD_ALERTMESSAGE_F(S)  ui.set_alert_status(F(S))
791
 #define LCD_ALERTMESSAGE_F(S)  ui.set_alert_status(F(S))

+ 1
- 1
Marlin/src/lcd/menu/menu_bed_corners.cpp Прегледај датотеку

247
       probe_triggered = PROBE_TRIGGERED();
247
       probe_triggered = PROBE_TRIGGERED();
248
       if (probe_triggered) {
248
       if (probe_triggered) {
249
         endstops.hit_on_purpose();
249
         endstops.hit_on_purpose();
250
-        TERN_(LEVEL_CORNERS_AUDIO_FEEDBACK, ui.buzz(200, 600));
250
+        TERN_(LEVEL_CORNERS_AUDIO_FEEDBACK, BUZZ(200, 600));
251
       }
251
       }
252
       idle();
252
       idle();
253
     }
253
     }

+ 1
- 1
Marlin/src/lcd/menu/menu_configuration.cpp Прегледај датотеку

574
   #endif
574
   #endif
575
 
575
 
576
   #if ENABLED(SOUND_MENU_ITEM)
576
   #if ENABLED(SOUND_MENU_ITEM)
577
-    EDIT_ITEM(bool, MSG_SOUND, &ui.buzzer_enabled, []{ ui.chirp(); });
577
+    EDIT_ITEM(bool, MSG_SOUND, &ui.sound_on, []{ ui.chirp(); });
578
   #endif
578
   #endif
579
 
579
 
580
   #if ENABLED(EEPROM_SETTINGS)
580
   #if ENABLED(EEPROM_SETTINGS)

+ 1
- 1
Marlin/src/lcd/tft/ui_1024x600.cpp Прегледај датотеку

596
 static void quick_feedback() {
596
 static void quick_feedback() {
597
   #if HAS_CHIRP
597
   #if HAS_CHIRP
598
     ui.chirp(); // Buzz and wait. Is the delay needed for buttons to settle?
598
     ui.chirp(); // Buzz and wait. Is the delay needed for buttons to settle?
599
-    #if BOTH(HAS_MARLINUI_MENU, USE_BEEPER)
599
+    #if BOTH(HAS_MARLINUI_MENU, HAS_BEEPER)
600
       for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
600
       for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
601
     #elif HAS_MARLINUI_MENU
601
     #elif HAS_MARLINUI_MENU
602
       delay(10);
602
       delay(10);

+ 1
- 1
Marlin/src/lcd/tft/ui_320x240.cpp Прегледај датотеку

578
 static void quick_feedback() {
578
 static void quick_feedback() {
579
   #if HAS_CHIRP
579
   #if HAS_CHIRP
580
     ui.chirp(); // Buzz and wait. Is the delay needed for buttons to settle?
580
     ui.chirp(); // Buzz and wait. Is the delay needed for buttons to settle?
581
-    #if BOTH(HAS_MARLINUI_MENU, USE_BEEPER)
581
+    #if BOTH(HAS_MARLINUI_MENU, HAS_BEEPER)
582
       for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
582
       for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
583
     #elif HAS_MARLINUI_MENU
583
     #elif HAS_MARLINUI_MENU
584
       delay(10);
584
       delay(10);

+ 1
- 1
Marlin/src/lcd/tft/ui_480x320.cpp Прегледај датотеку

583
 static void quick_feedback() {
583
 static void quick_feedback() {
584
   #if HAS_CHIRP
584
   #if HAS_CHIRP
585
     ui.chirp(); // Buzz and wait. Is the delay needed for buttons to settle?
585
     ui.chirp(); // Buzz and wait. Is the delay needed for buttons to settle?
586
-    #if BOTH(HAS_MARLINUI_MENU, USE_BEEPER)
586
+    #if BOTH(HAS_MARLINUI_MENU, HAS_BEEPER)
587
       for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
587
       for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
588
     #elif HAS_MARLINUI_MENU
588
     #elif HAS_MARLINUI_MENU
589
       delay(10);
589
       delay(10);

+ 4
- 4
Marlin/src/libs/buzzer.cpp Прегледај датотеку

22
 
22
 
23
 #include "../inc/MarlinConfig.h"
23
 #include "../inc/MarlinConfig.h"
24
 
24
 
25
-#if USE_BEEPER
25
+#if HAS_BEEPER
26
 
26
 
27
 #include "buzzer.h"
27
 #include "buzzer.h"
28
 #include "../module/temperature.h"
28
 #include "../module/temperature.h"
45
  * @param frequency Frequency of the tone in hertz
45
  * @param frequency Frequency of the tone in hertz
46
  */
46
  */
47
 void Buzzer::tone(const uint16_t duration, const uint16_t frequency/*=0*/) {
47
 void Buzzer::tone(const uint16_t duration, const uint16_t frequency/*=0*/) {
48
-  if (!ui.buzzer_enabled) return;
48
+  if (!ui.sound_on) return;
49
   while (buffer.isFull()) {
49
   while (buffer.isFull()) {
50
     tick();
50
     tick();
51
     thermalManager.manage_heater();
51
     thermalManager.manage_heater();
55
 }
55
 }
56
 
56
 
57
 void Buzzer::tick() {
57
 void Buzzer::tick() {
58
-  if (!ui.buzzer_enabled) return;
58
+  if (!ui.sound_on) return;
59
   const millis_t now = millis();
59
   const millis_t now = millis();
60
 
60
 
61
   if (!state.endtime) {
61
   if (!state.endtime) {
81
   else if (ELAPSED(now, state.endtime)) reset();
81
   else if (ELAPSED(now, state.endtime)) reset();
82
 }
82
 }
83
 
83
 
84
-#endif // USE_BEEPER
84
+#endif // HAS_BEEPER

+ 16
- 14
Marlin/src/libs/buzzer.h Прегледај датотеку

23
 
23
 
24
 #include "../inc/MarlinConfig.h"
24
 #include "../inc/MarlinConfig.h"
25
 
25
 
26
-#if USE_BEEPER
26
+#if HAS_BEEPER
27
 
27
 
28
   #include "circularqueue.h"
28
   #include "circularqueue.h"
29
 
29
 
62
       FORCE_INLINE static void invert() { TOGGLE(BEEPER_PIN); }
62
       FORCE_INLINE static void invert() { TOGGLE(BEEPER_PIN); }
63
 
63
 
64
       /**
64
       /**
65
-       * @brief Turn off a digital PIN
66
-       * @details Alias of digitalWrite(PIN, LOW) using FastIO
67
-       */
68
-      FORCE_INLINE static void off() { WRITE(BEEPER_PIN, LOW); }
69
-
70
-      /**
71
-       * @brief Turn on a digital PIN
72
-       * @details Alias of digitalWrite(PIN, HIGH) using FastIO
73
-       */
74
-      FORCE_INLINE static void on() { WRITE(BEEPER_PIN, HIGH); }
75
-
76
-      /**
77
        * @brief Resets the state of the class
65
        * @brief Resets the state of the class
78
        * @details Brings the class state to a known one.
66
        * @details Brings the class state to a known one.
79
        */
67
        */
92
       }
80
       }
93
 
81
 
94
       /**
82
       /**
83
+       * @brief Turn on a digital PIN
84
+       * @details Alias of digitalWrite(PIN, HIGH) using FastIO
85
+       */
86
+      FORCE_INLINE static void on() { WRITE(BEEPER_PIN, HIGH); }
87
+
88
+      /**
89
+       * @brief Turn off a digital PIN
90
+       * @details Alias of digitalWrite(PIN, LOW) using FastIO
91
+       */
92
+      FORCE_INLINE static void off() { WRITE(BEEPER_PIN, LOW); }
93
+
94
+      static void click(const uint16_t duration) { on(); delay(duration); off(); }
95
+
96
+      /**
95
        * @brief Add a tone to the queue
97
        * @brief Add a tone to the queue
96
        * @details Adds a tone_t structure to the ring buffer, will block IO if the
98
        * @details Adds a tone_t structure to the ring buffer, will block IO if the
97
        *          queue is full waiting for one slot to get available.
99
        *          queue is full waiting for one slot to get available.
118
 #elif HAS_BUZZER
120
 #elif HAS_BUZZER
119
 
121
 
120
   // Buzz indirectly via the MarlinUI instance
122
   // Buzz indirectly via the MarlinUI instance
121
-  #include "../lcd/marlinui.h"
122
   #define BUZZ(d,f) ui.buzz(d,f)
123
   #define BUZZ(d,f) ui.buzz(d,f)
124
+  #include "../lcd/marlinui.h"
123
 
125
 
124
 #else
126
 #else
125
 
127
 

+ 7
- 5
Marlin/src/module/settings.cpp Прегледај датотеку

541
   // Buzzer enable/disable
541
   // Buzzer enable/disable
542
   //
542
   //
543
   #if ENABLED(SOUND_MENU_ITEM)
543
   #if ENABLED(SOUND_MENU_ITEM)
544
-    bool buzzer_enabled;
544
+    bool sound_on;
545
   #endif
545
   #endif
546
 
546
 
547
   //
547
   //
1576
     // Buzzer enable/disable
1576
     // Buzzer enable/disable
1577
     //
1577
     //
1578
     #if ENABLED(SOUND_MENU_ITEM)
1578
     #if ENABLED(SOUND_MENU_ITEM)
1579
-      EEPROM_WRITE(ui.buzzer_enabled);
1579
+      EEPROM_WRITE(ui.sound_on);
1580
     #endif
1580
     #endif
1581
 
1581
 
1582
     //
1582
     //
2546
       // Buzzer enable/disable
2546
       // Buzzer enable/disable
2547
       //
2547
       //
2548
       #if ENABLED(SOUND_MENU_ITEM)
2548
       #if ENABLED(SOUND_MENU_ITEM)
2549
-        _FIELD_TEST(buzzer_enabled);
2550
-        EEPROM_READ(ui.buzzer_enabled);
2549
+        _FIELD_TEST(sound_on);
2550
+        EEPROM_READ(ui.sound_on);
2551
       #endif
2551
       #endif
2552
 
2552
 
2553
       //
2553
       //
2945
   //
2945
   //
2946
   // Buzzer enable/disable
2946
   // Buzzer enable/disable
2947
   //
2947
   //
2948
-  TERN_(SOUND_MENU_ITEM, ui.buzzer_enabled = true);
2948
+  #if ENABLED(SOUND_MENU_ITEM)
2949
+    ui.sound_on = ENABLED(SOUND_ON_DEFAULT);
2950
+  #endif
2949
 
2951
 
2950
   //
2952
   //
2951
   // Magnetic Parking Extruder
2953
   // Magnetic Parking Extruder

+ 5
- 9
Marlin/src/module/temperature.cpp Прегледај датотеку

178
   #include "tool_change.h"
178
   #include "tool_change.h"
179
 #endif
179
 #endif
180
 
180
 
181
-#if USE_BEEPER
181
+#if HAS_BEEPER
182
   #include "../libs/buzzer.h"
182
   #include "../libs/buzzer.h"
183
 #endif
183
 #endif
184
 
184
 
1224
 inline void loud_kill(FSTR_P const lcd_msg, const heater_id_t heater_id) {
1224
 inline void loud_kill(FSTR_P const lcd_msg, const heater_id_t heater_id) {
1225
   marlin_state = MF_KILLED;
1225
   marlin_state = MF_KILLED;
1226
   thermalManager.disable_all_heaters();
1226
   thermalManager.disable_all_heaters();
1227
-  #if USE_BEEPER
1227
+  #if HAS_BEEPER
1228
     for (uint8_t i = 20; i--;) {
1228
     for (uint8_t i = 20; i--;) {
1229
-      WRITE(BEEPER_PIN, HIGH);
1230
-      delay(25);
1231
       watchdog_refresh();
1229
       watchdog_refresh();
1232
-      WRITE(BEEPER_PIN, LOW);
1233
-      delay(40);
1234
-      watchdog_refresh();
1235
-      delay(40);
1230
+      buzzer.click(25);
1231
+      delay(80);
1236
       watchdog_refresh();
1232
       watchdog_refresh();
1237
     }
1233
     }
1238
-    WRITE(BEEPER_PIN, HIGH);
1234
+    buzzer.on();
1239
   #endif
1235
   #endif
1240
   #if ENABLED(NOZZLE_PARK_FEATURE)
1236
   #if ENABLED(NOZZLE_PARK_FEATURE)
1241
     if (!homing_needed_error()) {
1237
     if (!homing_needed_error()) {

Loading…
Откажи
Сачувај