Sfoglia il codice sorgente

Rework buzzing (PR#2296)

by:
Moving HAS_LCD_BUZZ macro to Coditionals.h
Renaming HAS_LCD_BUZZ to HAS_BUZZER to make clear is has nothing to do with the lcd.
Removing the ULTRALCD condition.

Moving declaration of lcd_buzz() out of the ULTRA_LCD block in ultralcd.h
Moving definition of lcd_buzz() out of the ULTIPANEL block in ultralcd.cpp
Renaming lcd_buzz() to buzz() to make clear is has nothing to do with the lcd.

All buzzing code is now only dependent on the existence of a BEEPER-pin or the definition of a LCD_USE_I2C_BUZZER.

To do: Check the conditions for the BEEPER-pin in all pin-files.
AnHardt 10 anni fa
parent
commit
6ab7b560af
4 ha cambiato i file con 22 aggiunte e 18 eliminazioni
  1. 2
    0
      Marlin/Conditionals.h
  2. 7
    8
      Marlin/Marlin_main.cpp
  3. 9
    7
      Marlin/ultralcd.cpp
  4. 4
    3
      Marlin/ultralcd.h

+ 2
- 0
Marlin/Conditionals.h Vedi File

504
     #define WRITE_FAN(v) WRITE(FAN_PIN, v)
504
     #define WRITE_FAN(v) WRITE(FAN_PIN, v)
505
   #endif
505
   #endif
506
 
506
 
507
+  #define HAS_BUZZER ((defined(BEEPER) && BEEPER >= 0) || defined(LCD_USE_I2C_BUZZER))
508
+
507
 #endif //CONFIGURATION_LCD
509
 #endif //CONFIGURATION_LCD
508
 #endif //CONDITIONALS_H
510
 #endif //CONDITIONALS_H

+ 7
- 8
Marlin/Marlin_main.cpp Vedi File

36
   #endif
36
   #endif
37
 #endif // ENABLE_AUTO_BED_LEVELING
37
 #endif // ENABLE_AUTO_BED_LEVELING
38
 
38
 
39
-#define HAS_LCD_BUZZ (defined(ULTRA_LCD) || (defined(BEEPER) && BEEPER >= 0) || defined(LCD_USE_I2C_BUZZER))
40
 #define SERVO_LEVELING (defined(ENABLE_AUTO_BED_LEVELING) && PROBE_SERVO_DEACTIVATION_DELAY > 0)
39
 #define SERVO_LEVELING (defined(ENABLE_AUTO_BED_LEVELING) && PROBE_SERVO_DEACTIVATION_DELAY > 0)
41
 
40
 
42
 #ifdef MESH_BED_LEVELING
41
 #ifdef MESH_BED_LEVELING
4349
 
4348
 
4350
 #endif // NUM_SERVOS > 0
4349
 #endif // NUM_SERVOS > 0
4351
 
4350
 
4352
-#if HAS_LCD_BUZZ
4351
+#if HAS_BUZZER
4353
 
4352
 
4354
   /**
4353
   /**
4355
    * M300: Play beep sound S<frequency Hz> P<duration ms>
4354
    * M300: Play beep sound S<frequency Hz> P<duration ms>
4358
     uint16_t beepS = code_seen('S') ? code_value_short() : 110;
4357
     uint16_t beepS = code_seen('S') ? code_value_short() : 110;
4359
     uint32_t beepP = code_seen('P') ? code_value_long() : 1000;
4358
     uint32_t beepP = code_seen('P') ? code_value_long() : 1000;
4360
     if (beepP > 5000) beepP = 5000; // limit to 5 seconds
4359
     if (beepP > 5000) beepP = 5000; // limit to 5 seconds
4361
-    lcd_buzz(beepP, beepS);
4360
+    buzz(beepP, beepS);
4362
   }
4361
   }
4363
 
4362
 
4364
-#endif // HAS_LCD_BUZZ
4363
+#endif // HAS_BUZZER
4365
 
4364
 
4366
 #ifdef PIDTEMP
4365
 #ifdef PIDTEMP
4367
 
4366
 
4791
         SERIAL_ERROR_START;
4790
         SERIAL_ERROR_START;
4792
         SERIAL_ERRORLNPGM(MSG_ERR_M428_TOO_FAR);
4791
         SERIAL_ERRORLNPGM(MSG_ERR_M428_TOO_FAR);
4793
         LCD_ALERTMESSAGEPGM("Err: Too far!");
4792
         LCD_ALERTMESSAGEPGM("Err: Too far!");
4794
-        #if HAS_LCD_BUZZ
4793
+        #if HAS_BUZZER
4795
           enqueuecommands_P(PSTR("M300 S40 P200"));
4794
           enqueuecommands_P(PSTR("M300 S40 P200"));
4796
         #endif
4795
         #endif
4797
         err = true;
4796
         err = true;
4805
     memcpy(home_offset, new_offs, sizeof(new_offs));
4804
     memcpy(home_offset, new_offs, sizeof(new_offs));
4806
     sync_plan_position();
4805
     sync_plan_position();
4807
     LCD_ALERTMESSAGEPGM("Offset applied.");
4806
     LCD_ALERTMESSAGEPGM("Offset applied.");
4808
-    #if HAS_LCD_BUZZ
4807
+    #if HAS_BUZZER
4809
       enqueuecommands_P(PSTR("M300 S659 P200\nM300 S698 P200"));
4808
       enqueuecommands_P(PSTR("M300 S659 P200\nM300 S698 P200"));
4810
     #endif
4809
     #endif
4811
   }
4810
   }
5607
           break;
5606
           break;
5608
       #endif // NUM_SERVOS > 0
5607
       #endif // NUM_SERVOS > 0
5609
 
5608
 
5610
-      #if HAS_LCD_BUZZ
5609
+      #if HAS_BUZZER
5611
         case 300: // M300 - Play beep tone
5610
         case 300: // M300 - Play beep tone
5612
           gcode_M300();
5611
           gcode_M300();
5613
           break;
5612
           break;
5614
-      #endif // HAS_LCD_BUZZ
5613
+      #endif // HAS_BUZZER
5615
 
5614
 
5616
       #ifdef PIDTEMP
5615
       #ifdef PIDTEMP
5617
         case 301: // M301
5616
         case 301: // M301

+ 9
- 7
Marlin/ultralcd.cpp Vedi File

1313
     #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
1313
     #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
1314
       #define LCD_FEEDBACK_FREQUENCY_DURATION_MS (1000/6)
1314
       #define LCD_FEEDBACK_FREQUENCY_DURATION_MS (1000/6)
1315
     #endif    
1315
     #endif    
1316
-    lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
1316
+    buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
1317
   #elif defined(BEEPER) && BEEPER >= 0
1317
   #elif defined(BEEPER) && BEEPER >= 0
1318
     #ifndef LCD_FEEDBACK_FREQUENCY_HZ
1318
     #ifndef LCD_FEEDBACK_FREQUENCY_HZ
1319
       #define LCD_FEEDBACK_FREQUENCY_HZ 5000
1319
       #define LCD_FEEDBACK_FREQUENCY_HZ 5000
1321
     #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
1321
     #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
1322
       #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2
1322
       #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2
1323
     #endif
1323
     #endif
1324
-    lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
1324
+    buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
1325
   #else
1325
   #else
1326
     #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
1326
     #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
1327
       #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2
1327
       #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2
1745
     #endif
1745
     #endif
1746
   }
1746
   }
1747
 
1747
 
1748
-  void lcd_buzz(long duration, uint16_t freq) {
1748
+  bool lcd_clicked() { return LCD_CLICKED; }
1749
+
1750
+#endif // ULTIPANEL
1751
+
1752
+#if HAS_BUZZER
1753
+  void buzz(long duration, uint16_t freq) {
1749
     if (freq > 0) {
1754
     if (freq > 0) {
1750
       #ifdef LCD_USE_I2C_BUZZER
1755
       #ifdef LCD_USE_I2C_BUZZER
1751
         lcd.buzz(duration, freq);
1756
         lcd.buzz(duration, freq);
1761
       delay(duration);
1766
       delay(duration);
1762
     }
1767
     }
1763
   }
1768
   }
1764
-
1765
-  bool lcd_clicked() { return LCD_CLICKED; }
1766
-
1767
-#endif // ULTIPANEL
1769
+#endif
1768
 
1770
 
1769
 /*********************************/
1771
 /*********************************/
1770
 /** Number to string conversion **/
1772
 /** Number to string conversion **/

+ 4
- 3
Marlin/ultralcd.h Vedi File

52
   #ifdef FILAMENT_LCD_DISPLAY
52
   #ifdef FILAMENT_LCD_DISPLAY
53
     extern millis_t previous_lcd_status_ms;
53
     extern millis_t previous_lcd_status_ms;
54
   #endif
54
   #endif
55
-
56
-  void lcd_buzz(long duration,uint16_t freq);
57
   void lcd_quick_feedback(); // Audible feedback for a button click - could also be visual
55
   void lcd_quick_feedback(); // Audible feedback for a button click - could also be visual
58
   bool lcd_clicked();
56
   bool lcd_clicked();
59
 
57
 
106
   FORCE_INLINE void lcd_setstatuspgm(const char* message, const uint8_t level=0) {}
104
   FORCE_INLINE void lcd_setstatuspgm(const char* message, const uint8_t level=0) {}
107
   FORCE_INLINE void lcd_buttons_update() {}
105
   FORCE_INLINE void lcd_buttons_update() {}
108
   FORCE_INLINE void lcd_reset_alert_level() {}
106
   FORCE_INLINE void lcd_reset_alert_level() {}
109
-  FORCE_INLINE void lcd_buzz(long duration, uint16_t freq) {}
110
   FORCE_INLINE bool lcd_detected(void) { return true; }
107
   FORCE_INLINE bool lcd_detected(void) { return true; }
111
 
108
 
112
   #define LCD_MESSAGEPGM(x) do{}while(0)
109
   #define LCD_MESSAGEPGM(x) do{}while(0)
114
 
111
 
115
 #endif //ULTRA_LCD
112
 #endif //ULTRA_LCD
116
 
113
 
114
+#if HAS_BUZZER
115
+  void buzz(long duration,uint16_t freq);
116
+#endif
117
+
117
 char *itostr2(const uint8_t &x);
118
 char *itostr2(const uint8_t &x);
118
 char *itostr31(const int &xx);
119
 char *itostr31(const int &xx);
119
 char *itostr3(const int &xx);
120
 char *itostr3(const int &xx);

Loading…
Annulla
Salva