Browse Source

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

Ludy 5 years ago
parent
commit
05995d1fd6

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

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

+ 5
- 3
Marlin/src/feature/leds/pca9632.cpp View File

137
 }
137
 }
138
 
138
 
139
 #if ENABLED(PCA9632_BUZZER)
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
     uint8_t data[] = PCA9632_BUZZER_DATA;
143
     uint8_t data[] = PCA9632_BUZZER_DATA;
143
     Wire.beginTransmission(I2C_ADDRESS(PCA9632_ADDRESS));
144
     Wire.beginTransmission(I2C_ADDRESS(PCA9632_ADDRESS));
144
     Wire.write(data, sizeof(data));
145
     Wire.write(data, sizeof(data));
145
     Wire.endTransmission();
146
     Wire.endTransmission();
146
   }
147
   }
147
-#endif
148
+
149
+#endif // PCA9632_BUZZER
148
 
150
 
149
 #endif // PCA9632
151
 #endif // PCA9632

+ 2
- 1
Marlin/src/feature/leds/pca9632.h View File

32
 void pca9632_set_led_color(const LEDColor &color);
32
 void pca9632_set_led_color(const LEDColor &color);
33
 
33
 
34
 #if ENABLED(PCA9632_BUZZER)
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
 #endif
37
 #endif

+ 3
- 2
Marlin/src/inc/Conditionals_post.h View File

1048
 #define HAS_KILL        (PIN_EXISTS(KILL))
1048
 #define HAS_KILL        (PIN_EXISTS(KILL))
1049
 #define HAS_SUICIDE     (PIN_EXISTS(SUICIDE))
1049
 #define HAS_SUICIDE     (PIN_EXISTS(SUICIDE))
1050
 #define HAS_PHOTOGRAPH  (PIN_EXISTS(PHOTOGRAPH))
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
 #define HAS_CASE_LIGHT  (PIN_EXISTS(CASE_LIGHT) && ENABLED(CASE_LIGHT_ENABLE))
1053
 #define HAS_CASE_LIGHT  (PIN_EXISTS(CASE_LIGHT) && ENABLED(CASE_LIGHT_ENABLE))
1053
 
1054
 
1054
 // Digital control
1055
 // Digital control
1570
   #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
1571
   #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
1571
     #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100
1572
     #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100
1572
   #endif
1573
   #endif
1573
-#else
1574
+#elif HAS_BUZZER
1574
   #ifndef LCD_FEEDBACK_FREQUENCY_HZ
1575
   #ifndef LCD_FEEDBACK_FREQUENCY_HZ
1575
     #define LCD_FEEDBACK_FREQUENCY_HZ 5000
1576
     #define LCD_FEEDBACK_FREQUENCY_HZ 5000
1576
   #endif
1577
   #endif

+ 28
- 1
Marlin/src/lcd/HD44780/ultralcd_HD44780.cpp View File

360
   lcd.clear();
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
 void MarlinUI::clear_lcd() { lcd.clear(); }
390
 void MarlinUI::clear_lcd() { lcd.clear(); }
364
 
391
 
365
 #if ENABLED(SHOW_BOOTSCREEN)
392
 #if ENABLED(SHOW_BOOTSCREEN)
1063
 
1090
 
1064
   #if ENABLED(LCD_HAS_STATUS_INDICATORS)
1091
   #if ENABLED(LCD_HAS_STATUS_INDICATORS)
1065
 
1092
 
1066
-    static void MarlinUI::update_indicators() {
1093
+    void MarlinUI::update_indicators() {
1067
       // Set the LEDS - referred to as backlights by the LiquidTWI2 library
1094
       // Set the LEDS - referred to as backlights by the LiquidTWI2 library
1068
       static uint8_t ledsprev = 0;
1095
       static uint8_t ledsprev = 0;
1069
       uint8_t leds = 0;
1096
       uint8_t leds = 0;

+ 2
- 0
Marlin/src/lcd/dogm/ultralcd_DOGM.cpp View File

102
   }
102
   }
103
 }
103
 }
104
 
104
 
105
+bool MarlinUI::detected() { return true; }
106
+
105
 #if ENABLED(SHOW_BOOTSCREEN)
107
 #if ENABLED(SHOW_BOOTSCREEN)
106
 
108
 
107
   #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
109
   #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)

+ 20
- 39
Marlin/src/lcd/ultralcd.cpp View File

64
   uint8_t MarlinUI::progress_bar_percent; // = 0
64
   uint8_t MarlinUI::progress_bar_percent; // = 0
65
 #endif
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
 #if HAS_SPI_LCD
80
 #if HAS_SPI_LCD
68
 
81
 
69
 #if HAS_GRAPHICAL_LCD
82
 #if HAS_GRAPHICAL_LCD
89
   #include "../feature/bedlevel/bedlevel.h"
102
   #include "../feature/bedlevel/bedlevel.h"
90
 #endif
103
 #endif
91
 
104
 
92
-#if HAS_BUZZER
93
-  #include "../libs/buzzer.h"
94
-#endif
95
-
96
 #if HAS_TRINAMIC
105
 #if HAS_TRINAMIC
97
   #include "../feature/tmc_util.h"
106
   #include "../feature/tmc_util.h"
98
 #endif
107
 #endif
568
           const millis_t ms = millis();
577
           const millis_t ms = millis();
569
         #endif
578
         #endif
570
         if (ELAPSED(ms, next_beep)) {
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
           next_beep = ms + 500UL;
581
           next_beep = ms + 500UL;
573
         }
582
         }
574
       #endif
583
       #endif
611
   #if HAS_BUZZER
620
   #if HAS_BUZZER
612
     // Buzz and wait. Is the delay needed for buttons to settle?
621
     // Buzz and wait. Is the delay needed for buttons to settle?
613
     buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
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
     #endif
629
     #endif
622
   #endif
630
   #endif
623
 }
631
 }
729
 
737
 
730
 LCDViewAction MarlinUI::lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
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
 void MarlinUI::update() {
740
 void MarlinUI::update() {
743
 
741
 
744
   static uint16_t max_display_update_time = 0;
742
   static uint16_t max_display_update_time = 0;
1295
     #endif // HAS_ENCODER_WHEEL
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
 #endif // HAS_ENCODER_ACTION
1296
 #endif // HAS_ENCODER_ACTION
1316
 
1297
 
1317
 #endif // HAS_SPI_LCD
1298
 #endif // HAS_SPI_LCD

+ 5
- 9
Marlin/src/lcd/ultralcd.h View File

259
   }
259
   }
260
 
260
 
261
   #if HAS_BUZZER
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
   #endif
267
   #endif
272
 
268
 
273
   // LCD implementations
269
   // LCD implementations

+ 2
- 2
Marlin/src/libs/buzzer.cpp View File

22
 
22
 
23
 #include "../inc/MarlinConfig.h"
23
 #include "../inc/MarlinConfig.h"
24
 
24
 
25
-#if DISABLED(LCD_USE_I2C_BUZZER) && PIN_EXISTS(BEEPER)
25
+#if USE_BEEPER
26
 
26
 
27
 #include "buzzer.h"
27
 #include "buzzer.h"
28
 #include "../module/temperature.h"
28
 #include "../module/temperature.h"
78
   else if (ELAPSED(now, state.endtime)) reset();
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 View File

23
 
23
 
24
 #include "../inc/MarlinConfig.h"
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
   #include "circularqueue.h"
28
   #include "circularqueue.h"
38
 
29
 
120
 
111
 
121
   // Provide a buzzer instance
112
   // Provide a buzzer instance
122
   extern Buzzer buzzer;
113
   extern Buzzer buzzer;
114
+
115
+  // Buzz directly via the BEEPER pin tone queue
123
   #define BUZZ(d,f) buzzer.tone(d, f)
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
   #define BUZZ(d,f) NOOP
126
   #define BUZZ(d,f) NOOP
128
 
127
 
129
 #endif
128
 #endif

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

157
     #endif
157
     #endif
158
     #if HAS_BUZZER && SERVICE_WARNING_BUZZES > 0
158
     #if HAS_BUZZER && SERVICE_WARNING_BUZZES > 0
159
       if (doBuzz) for (int i = 0; i < SERVICE_WARNING_BUZZES; i++) BUZZ(200, 404);
159
       if (doBuzz) for (int i = 0; i < SERVICE_WARNING_BUZZES; i++) BUZZ(200, 404);
160
+    #else
161
+      UNUSED(doBuzz);
160
     #endif
162
     #endif
161
   #endif // HAS_SERVICE_INTERVALS
163
   #endif // HAS_SERVICE_INTERVALS
162
 }
164
 }

+ 2
- 2
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 && PIN_EXISTS(BEEPER)
71
+#if USE_BEEPER
72
   #include "../libs/buzzer.h"
72
   #include "../libs/buzzer.h"
73
 #endif
73
 #endif
74
 
74
 
749
 
749
 
750
 inline void loud_kill(PGM_P const lcd_msg) {
750
 inline void loud_kill(PGM_P const lcd_msg) {
751
   Running = false;
751
   Running = false;
752
-  #if HAS_BUZZER && PIN_EXISTS(BEEPER)
752
+  #if USE_BEEPER
753
     for (uint8_t i = 20; i--;) {
753
     for (uint8_t i = 20; i--;) {
754
       WRITE(BEEPER_PIN, HIGH); delay(25);
754
       WRITE(BEEPER_PIN, HIGH); delay(25);
755
       WRITE(BEEPER_PIN, LOW); delay(80);
755
       WRITE(BEEPER_PIN, LOW); delay(80);

Loading…
Cancel
Save