Move buzzing code to buzzr.h & buzzer.cpp (PR#2307)
at least the lcd independent part from Marlin_main.cpp.
This commit is contained in:
parent
c461975140
commit
722829b058
@ -52,6 +52,7 @@
|
||||
#include "language.h"
|
||||
#include "pins_arduino.h"
|
||||
#include "math.h"
|
||||
#include "buzzer.h"
|
||||
|
||||
#ifdef BLINKM
|
||||
#include "blinkm.h"
|
||||
|
22
Marlin/buzzer.cpp
Normal file
22
Marlin/buzzer.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "Marlin.h"
|
||||
#include "buzzer.h"
|
||||
#include "ultralcd.h"
|
||||
|
||||
#if HAS_BUZZER
|
||||
void buzz(long duration, uint16_t freq) {
|
||||
if (freq > 0) {
|
||||
#ifdef LCD_USE_I2C_BUZZER
|
||||
lcd_buzz(duration, freq);
|
||||
#elif defined(BEEPER) && BEEPER >= 0 // on-board buzzers have no further condition
|
||||
SET_OUTPUT(BEEPER);
|
||||
tone(BEEPER, freq, duration);
|
||||
delay(duration);
|
||||
#else
|
||||
delay(duration);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
delay(duration);
|
||||
}
|
||||
}
|
||||
#endif
|
8
Marlin/buzzer.h
Normal file
8
Marlin/buzzer.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef BUZZER_H
|
||||
#define BUZZER_H
|
||||
|
||||
#if HAS_BUZZER
|
||||
void buzz(long duration,uint16_t freq);
|
||||
#endif
|
||||
|
||||
#endif BUZZER_H
|
@ -1302,6 +1302,13 @@ menu_edit_type(unsigned long, long5, ftostr5, 0.01)
|
||||
* Audio feedback for controller clicks
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef LCD_USE_I2C_BUZZER
|
||||
void lcd_buzz(long duration, uint16_t freq) { // called from buzz() in Marlin_main.cpp where lcd is unknown
|
||||
lcd.buzz(duration, freq);
|
||||
}
|
||||
#endif
|
||||
|
||||
void lcd_quick_feedback() {
|
||||
lcdDrawUpdate = 2;
|
||||
next_button_update_ms = millis() + 500;
|
||||
@ -1313,7 +1320,7 @@ void lcd_quick_feedback() {
|
||||
#ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
|
||||
#define LCD_FEEDBACK_FREQUENCY_DURATION_MS (1000/6)
|
||||
#endif
|
||||
buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
|
||||
lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
|
||||
#elif defined(BEEPER) && BEEPER >= 0
|
||||
#ifndef LCD_FEEDBACK_FREQUENCY_HZ
|
||||
#define LCD_FEEDBACK_FREQUENCY_HZ 5000
|
||||
@ -1749,25 +1756,6 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
|
||||
|
||||
#endif // ULTIPANEL
|
||||
|
||||
#if HAS_BUZZER
|
||||
void buzz(long duration, uint16_t freq) {
|
||||
if (freq > 0) {
|
||||
#ifdef LCD_USE_I2C_BUZZER
|
||||
lcd.buzz(duration, freq);
|
||||
#elif defined(BEEPER) && BEEPER >= 0
|
||||
SET_OUTPUT(BEEPER);
|
||||
tone(BEEPER, freq, duration);
|
||||
delay(duration);
|
||||
#else
|
||||
delay(duration);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
delay(duration);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************************/
|
||||
/** Number to string conversion **/
|
||||
/*********************************/
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define ULTRALCD_H
|
||||
|
||||
#include "Marlin.h"
|
||||
#include "buzzer.h"
|
||||
|
||||
#ifdef ULTRA_LCD
|
||||
int lcd_strlen(char *s);
|
||||
@ -15,6 +16,10 @@
|
||||
void lcd_reset_alert_level();
|
||||
bool lcd_detected(void);
|
||||
|
||||
#ifdef LCD_USE_I2C_BUZZER
|
||||
void lcd_buzz(long duration, uint16_t freq);
|
||||
#endif
|
||||
|
||||
#if defined(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
|
||||
void dontExpireStatus();
|
||||
#endif
|
||||
@ -111,10 +116,6 @@
|
||||
|
||||
#endif //ULTRA_LCD
|
||||
|
||||
#if HAS_BUZZER
|
||||
void buzz(long duration,uint16_t freq);
|
||||
#endif
|
||||
|
||||
char *itostr2(const uint8_t &x);
|
||||
char *itostr31(const int &xx);
|
||||
char *itostr3(const int &xx);
|
||||
|
Loading…
Reference in New Issue
Block a user