Selaa lähdekoodia

Unify buzz methods as MarlinUI::buzz (#14803)

Ludy 5 vuotta sitten
vanhempi
commit
05995d1fd6

+ 2
- 2
Marlin/src/Marlin.cpp Näytä tiedosto

@@ -65,7 +65,7 @@
65 65
   #include "feature/host_actions.h"
66 66
 #endif
67 67
 
68
-#if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
68
+#if USE_BEEPER
69 69
   #include "libs/buzzer.h"
70 70
 #endif
71 71
 
@@ -702,7 +702,7 @@ void idle(
702 702
     print_job_timer.tick();
703 703
   #endif
704 704
 
705
-  #if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER) && DISABLED(PCA9632_BUZZER)
705
+  #if USE_BEEPER
706 706
     buzzer.tick();
707 707
   #endif
708 708
 

+ 5
- 3
Marlin/src/feature/leds/pca9632.cpp Näytä tiedosto

@@ -137,13 +137,15 @@ void pca9632_set_led_color(const LEDColor &color) {
137 137
 }
138 138
 
139 139
 #if ENABLED(PCA9632_BUZZER)
140
-  void pca9632_buzz(uint16_t const f, uint16_t d) {
141
-    UNUSED(f); UNUSED(d);
140
+
141
+  void pca9632_buzz(const long duration, const uint16_t freq) {
142
+    UNUSED(duration); UNUSED(freq);
142 143
     uint8_t data[] = PCA9632_BUZZER_DATA;
143 144
     Wire.beginTransmission(I2C_ADDRESS(PCA9632_ADDRESS));
144 145
     Wire.write(data, sizeof(data));
145 146
     Wire.endTransmission();
146 147
   }
147
-#endif
148
+
149
+#endif // PCA9632_BUZZER
148 150
 
149 151
 #endif // PCA9632

+ 2
- 1
Marlin/src/feature/leds/pca9632.h Näytä tiedosto

@@ -32,5 +32,6 @@ typedef LEDColor LEDColor;
32 32
 void pca9632_set_led_color(const LEDColor &color);
33 33
 
34 34
 #if ENABLED(PCA9632_BUZZER)
35
-  void pca9632_buzz(uint16_t const, uint16_t);
35
+  #include <stdint.h>
36
+  void pca9632_buzz(const long, const uint16_t);
36 37
 #endif

+ 3
- 2
Marlin/src/inc/Conditionals_post.h Näytä tiedosto

@@ -1048,7 +1048,8 @@
1048 1048
 #define HAS_KILL        (PIN_EXISTS(KILL))
1049 1049
 #define HAS_SUICIDE     (PIN_EXISTS(SUICIDE))
1050 1050
 #define HAS_PHOTOGRAPH  (PIN_EXISTS(PHOTOGRAPH))
1051
-#define HAS_BUZZER      (PIN_EXISTS(BEEPER) || ENABLED(LCD_USE_I2C_BUZZER) || ENABLED(PCA9632_BUZZER))
1051
+#define HAS_BUZZER      (PIN_EXISTS(BEEPER) || EITHER(LCD_USE_I2C_BUZZER, PCA9632_BUZZER))
1052
+#define USE_BEEPER      (HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER, PCA9632_BUZZER))
1052 1053
 #define HAS_CASE_LIGHT  (PIN_EXISTS(CASE_LIGHT) && ENABLED(CASE_LIGHT_ENABLE))
1053 1054
 
1054 1055
 // Digital control
@@ -1570,7 +1571,7 @@
1570 1571
   #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
1571 1572
     #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100
1572 1573
   #endif
1573
-#else
1574
+#elif HAS_BUZZER
1574 1575
   #ifndef LCD_FEEDBACK_FREQUENCY_HZ
1575 1576
     #define LCD_FEEDBACK_FREQUENCY_HZ 5000
1576 1577
   #endif

+ 28
- 1
Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp Näytä tiedosto

@@ -360,6 +360,33 @@ void MarlinUI::init_lcd() {
360 360
   lcd.clear();
361 361
 }
362 362
 
363
+bool MarlinUI::detected() {
364
+  return true
365
+    #if EITHER(LCD_I2C_TYPE_MCP23017, LCD_I2C_TYPE_MCP23008) && defined(DETECT_DEVICE)
366
+      && lcd.LcdDetected() == 1
367
+    #endif
368
+  ;
369
+}
370
+
371
+#if HAS_SLOW_BUTTONS
372
+  uint8_t MarlinUI::read_slow_buttons() {
373
+    #if ENABLED(LCD_I2C_TYPE_MCP23017)
374
+      // Reading these buttons this is likely to be too slow to call inside interrupt context
375
+      // so they are called during normal lcd_update
376
+      uint8_t slow_bits = lcd.readButtons()
377
+        #if !BUTTON_EXISTS(ENC)
378
+          << B_I2C_BTN_OFFSET
379
+        #endif
380
+      ;
381
+      #if ENABLED(LCD_I2C_VIKI)
382
+        if ((slow_bits & (B_MI | B_RI)) && PENDING(millis(), next_button_update_ms)) // LCD clicked
383
+          slow_bits &= ~(B_MI | B_RI); // Disable LCD clicked buttons if screen is updated
384
+      #endif // LCD_I2C_VIKI
385
+      return slow_bits;
386
+    #endif // LCD_I2C_TYPE_MCP23017
387
+  }
388
+#endif
389
+
363 390
 void MarlinUI::clear_lcd() { lcd.clear(); }
364 391
 
365 392
 #if ENABLED(SHOW_BOOTSCREEN)
@@ -1063,7 +1090,7 @@ void MarlinUI::draw_status_screen() {
1063 1090
 
1064 1091
   #if ENABLED(LCD_HAS_STATUS_INDICATORS)
1065 1092
 
1066
-    static void MarlinUI::update_indicators() {
1093
+    void MarlinUI::update_indicators() {
1067 1094
       // Set the LEDS - referred to as backlights by the LiquidTWI2 library
1068 1095
       static uint8_t ledsprev = 0;
1069 1096
       uint8_t leds = 0;

+ 2
- 0
Marlin/src/lcd/dogm/ultralcd_DOGM.cpp Näytä tiedosto

@@ -102,6 +102,8 @@ void MarlinUI::set_font(const MarlinFont font_nr) {
102 102
   }
103 103
 }
104 104
 
105
+bool MarlinUI::detected() { return true; }
106
+
105 107
 #if ENABLED(SHOW_BOOTSCREEN)
106 108
 
107 109
   #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)

+ 20
- 39
Marlin/src/lcd/ultralcd.cpp Näytä tiedosto

@@ -64,6 +64,19 @@
64 64
   uint8_t MarlinUI::progress_bar_percent; // = 0
65 65
 #endif
66 66
 
67
+#if HAS_BUZZER
68
+  #include "../libs/buzzer.h"
69
+  void MarlinUI::buzz(const long duration, const uint16_t freq) {
70
+    #if ENABLED(LCD_USE_I2C_BUZZER)
71
+      lcd.buzz(duration, freq);
72
+    #elif ENABLED(PCA9632_BUZZER)
73
+      pca9632_buzz(const long duration, const uint16_t freq) {
74
+    #elif USE_BEEPER
75
+      buzzer.tone(duration, freq);
76
+    #endif
77
+  }
78
+#endif
79
+
67 80
 #if HAS_SPI_LCD
68 81
 
69 82
 #if HAS_GRAPHICAL_LCD
@@ -89,10 +102,6 @@
89 102
   #include "../feature/bedlevel/bedlevel.h"
90 103
 #endif
91 104
 
92
-#if HAS_BUZZER
93
-  #include "../libs/buzzer.h"
94
-#endif
95
-
96 105
 #if HAS_TRINAMIC
97 106
   #include "../feature/tmc_util.h"
98 107
 #endif
@@ -568,7 +577,7 @@ void MarlinUI::status_screen() {
568 577
           const millis_t ms = millis();
569 578
         #endif
570 579
         if (ELAPSED(ms, next_beep)) {
571
-          BUZZ(FEEDRATE_CHANGE_BEEP_DURATION, FEEDRATE_CHANGE_BEEP_FREQUENCY);
580
+          buzz(FEEDRATE_CHANGE_BEEP_DURATION, FEEDRATE_CHANGE_BEEP_FREQUENCY);
572 581
           next_beep = ms + 500UL;
573 582
         }
574 583
       #endif
@@ -611,13 +620,12 @@ void MarlinUI::quick_feedback(const bool clear_buttons/*=true*/) {
611 620
   #if HAS_BUZZER
612 621
     // Buzz and wait. Is the delay needed for buttons to settle?
613 622
     buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
614
-  #endif
615
-
616
-  #if HAS_LCD_MENU
617
-    #if ENABLED(LCD_USE_I2C_BUZZER)
618
-      delay(10);
619
-    #elif PIN_EXISTS(BEEPER)
620
-      for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
623
+    #if HAS_LCD_MENU
624
+      #if USE_BEEPER
625
+        for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
626
+      #else
627
+        delay(10);
628
+      #endif
621 629
     #endif
622 630
   #endif
623 631
 }
@@ -729,16 +737,6 @@ void MarlinUI::quick_feedback(const bool clear_buttons/*=true*/) {
729 737
 
730 738
 LCDViewAction MarlinUI::lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
731 739
 
732
-bool MarlinUI::detected() {
733
-  return
734
-    #if EITHER(LCD_I2C_TYPE_MCP23017, LCD_I2C_TYPE_MCP23008) && defined(DETECT_DEVICE)
735
-      lcd.LcdDetected() == 1
736
-    #else
737
-      true
738
-    #endif
739
-  ;
740
-}
741
-
742 740
 void MarlinUI::update() {
743 741
 
744 742
   static uint16_t max_display_update_time = 0;
@@ -1295,23 +1293,6 @@ void MarlinUI::update() {
1295 1293
     #endif // HAS_ENCODER_WHEEL
1296 1294
   }
1297 1295
 
1298
-  #if HAS_SLOW_BUTTONS
1299
-
1300
-    uint8_t MarlinUI::read_slow_buttons() {
1301
-      #if ENABLED(LCD_I2C_TYPE_MCP23017)
1302
-        // Reading these buttons this is likely to be too slow to call inside interrupt context
1303
-        // so they are called during normal lcd_update
1304
-        uint8_t slow_bits = lcd.readButtons() << B_I2C_BTN_OFFSET;
1305
-        #if ENABLED(LCD_I2C_VIKI)
1306
-          if ((slow_bits & (B_MI | B_RI)) && PENDING(millis(), next_button_update_ms)) // LCD clicked
1307
-            slow_bits &= ~(B_MI | B_RI); // Disable LCD clicked buttons if screen is updated
1308
-        #endif // LCD_I2C_VIKI
1309
-        return slow_bits;
1310
-      #endif // LCD_I2C_TYPE_MCP23017
1311
-    }
1312
-
1313
-  #endif
1314
-
1315 1296
 #endif // HAS_ENCODER_ACTION
1316 1297
 
1317 1298
 #endif // HAS_SPI_LCD

+ 5
- 9
Marlin/src/lcd/ultralcd.h Näytä tiedosto

@@ -259,15 +259,11 @@ public:
259 259
   }
260 260
 
261 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
-      #elif ENABLED(PCA9632_BUZZER)
268
-        pca9632_buzz(duration, freq);
269
-      #endif
270
-    }
262
+    static void buzz(const long duration, const uint16_t freq);
263
+  #endif
264
+
265
+  #if ENABLED(LCD_HAS_STATUS_INDICATORS)
266
+    static void update_indicators();
271 267
   #endif
272 268
 
273 269
   // LCD implementations

+ 2
- 2
Marlin/src/libs/buzzer.cpp Näytä tiedosto

@@ -22,7 +22,7 @@
22 22
 
23 23
 #include "../inc/MarlinConfig.h"
24 24
 
25
-#if DISABLED(LCD_USE_I2C_BUZZER) && PIN_EXISTS(BEEPER)
25
+#if USE_BEEPER
26 26
 
27 27
 #include "buzzer.h"
28 28
 #include "../module/temperature.h"
@@ -78,4 +78,4 @@ void Buzzer::tick() {
78 78
   else if (ELAPSED(now, state.endtime)) reset();
79 79
 }
80 80
 
81
-#endif // !LCD_USE_I2C_BUZZER && BEEPER
81
+#endif // USE_BEEPER

+ 10
- 11
Marlin/src/libs/buzzer.h Näytä tiedosto

@@ -23,16 +23,7 @@
23 23
 
24 24
 #include "../inc/MarlinConfig.h"
25 25
 
26
-#if ENABLED(LCD_USE_I2C_BUZZER)
27
-
28
-  #define BUZZ(d,f) ui.buzz(d,f)
29
-
30
-#elif ENABLED(PCA9632_BUZZER)
31
-
32
-  #include "../feature/leds/pca9632.h"
33
-  #define BUZZ(d, f) pca9632_buzz(d,f)
34
-
35
-#elif PIN_EXISTS(BEEPER)
26
+#if USE_BEEPER
36 27
 
37 28
   #include "circularqueue.h"
38 29
 
@@ -120,10 +111,18 @@
120 111
 
121 112
   // Provide a buzzer instance
122 113
   extern Buzzer buzzer;
114
+
115
+  // Buzz directly via the BEEPER pin tone queue
123 116
   #define BUZZ(d,f) buzzer.tone(d, f)
124 117
 
125
-#else // No buzz capability
118
+#elif HAS_BUZZER
119
+
120
+  // Buzz indirectly via the MarlinUI instance
121
+  #define BUZZ(d,f) ui.buzz(d,f)
122
+
123
+#else
126 124
 
125
+  // No buzz capability
127 126
   #define BUZZ(d,f) NOOP
128 127
 
129 128
 #endif

+ 2
- 0
Marlin/src/module/printcounter.cpp Näytä tiedosto

@@ -157,6 +157,8 @@ void PrintCounter::loadStats() {
157 157
     #endif
158 158
     #if HAS_BUZZER && SERVICE_WARNING_BUZZES > 0
159 159
       if (doBuzz) for (int i = 0; i < SERVICE_WARNING_BUZZES; i++) BUZZ(200, 404);
160
+    #else
161
+      UNUSED(doBuzz);
160 162
     #endif
161 163
   #endif // HAS_SERVICE_INTERVALS
162 164
 }

+ 2
- 2
Marlin/src/module/temperature.cpp Näytä tiedosto

@@ -68,7 +68,7 @@
68 68
   #include "tool_change.h"
69 69
 #endif
70 70
 
71
-#if HAS_BUZZER && PIN_EXISTS(BEEPER)
71
+#if USE_BEEPER
72 72
   #include "../libs/buzzer.h"
73 73
 #endif
74 74
 
@@ -749,7 +749,7 @@ int16_t Temperature::getHeaterPower(const heater_ind_t heater_id) {
749 749
 
750 750
 inline void loud_kill(PGM_P const lcd_msg) {
751 751
   Running = false;
752
-  #if HAS_BUZZER && PIN_EXISTS(BEEPER)
752
+  #if USE_BEEPER
753 753
     for (uint8_t i = 20; i--;) {
754 754
       WRITE(BEEPER_PIN, HIGH); delay(25);
755 755
       WRITE(BEEPER_PIN, LOW); delay(80);

Loading…
Peruuta
Tallenna