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:
AnHardt 2015-06-17 16:31:14 +02:00 committed by Richard Wackerbarth
parent c461975140
commit 722829b058
5 changed files with 44 additions and 24 deletions

View File

@ -52,6 +52,7 @@
#include "language.h" #include "language.h"
#include "pins_arduino.h" #include "pins_arduino.h"
#include "math.h" #include "math.h"
#include "buzzer.h"
#ifdef BLINKM #ifdef BLINKM
#include "blinkm.h" #include "blinkm.h"

22
Marlin/buzzer.cpp Normal file
View 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
View 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

View File

@ -1302,6 +1302,13 @@ menu_edit_type(unsigned long, long5, ftostr5, 0.01)
* Audio feedback for controller clicks * 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() { void lcd_quick_feedback() {
lcdDrawUpdate = 2; lcdDrawUpdate = 2;
next_button_update_ms = millis() + 500; next_button_update_ms = millis() + 500;
@ -1313,7 +1320,7 @@ void lcd_quick_feedback() {
#ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
#define LCD_FEEDBACK_FREQUENCY_DURATION_MS (1000/6) #define LCD_FEEDBACK_FREQUENCY_DURATION_MS (1000/6)
#endif #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 #elif defined(BEEPER) && BEEPER >= 0
#ifndef LCD_FEEDBACK_FREQUENCY_HZ #ifndef LCD_FEEDBACK_FREQUENCY_HZ
#define LCD_FEEDBACK_FREQUENCY_HZ 5000 #define LCD_FEEDBACK_FREQUENCY_HZ 5000
@ -1749,25 +1756,6 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
#endif // ULTIPANEL #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 **/ /** Number to string conversion **/
/*********************************/ /*********************************/

View File

@ -2,6 +2,7 @@
#define ULTRALCD_H #define ULTRALCD_H
#include "Marlin.h" #include "Marlin.h"
#include "buzzer.h"
#ifdef ULTRA_LCD #ifdef ULTRA_LCD
int lcd_strlen(char *s); int lcd_strlen(char *s);
@ -15,6 +16,10 @@
void lcd_reset_alert_level(); void lcd_reset_alert_level();
bool lcd_detected(void); 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 #if defined(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
void dontExpireStatus(); void dontExpireStatus();
#endif #endif
@ -111,10 +116,6 @@
#endif //ULTRA_LCD #endif //ULTRA_LCD
#if HAS_BUZZER
void buzz(long duration,uint16_t freq);
#endif
char *itostr2(const uint8_t &x); char *itostr2(const uint8_t &x);
char *itostr31(const int &xx); char *itostr31(const int &xx);
char *itostr3(const int &xx); char *itostr3(const int &xx);