Skip to content

Commit

Permalink
Merge pull request #4265 from thinkyhead/rc_buzzer_patchup
Browse files Browse the repository at this point in the history
Two strategies to address a stuck buzzer
  • Loading branch information
thinkyhead authored Jul 11, 2016
2 parents 4a100c6 + d1dffc7 commit 6121c90
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 7 additions & 7 deletions Marlin/buzzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Buzzer {
private:
struct state_t {
tone_t tone;
uint32_t timestamp;
uint32_t endtime;
} state;

protected:
Expand Down Expand Up @@ -82,7 +82,7 @@ class Buzzer {
*/
void reset() {
this->off();
this->state.timestamp = 0;
this->state.endtime = 0;
}

public:
Expand All @@ -97,7 +97,7 @@ class Buzzer {
/**
* @brief Add a tone to the queue
* @details Adds a tone_t structure to the ring buffer, will block IO if the
* queue is full waiting for one slot to get available.
* queue is full waiting for one slot to get available.
*
* @param duration Duration of the tone in milliseconds
* @param frequency Frequency of the tone in hertz
Expand All @@ -114,17 +114,17 @@ class Buzzer {
/**
* @brief Loop function
* @details This function should be called at loop, it will take care of
* playing the tones in the queue.
* playing the tones in the queue.
*/
virtual void tick() {
if (!this->state.timestamp) {
if (!this->state.endtime) {
if (this->buffer.isEmpty()) return;

this->state.tone = this->buffer.dequeue();
this->state.timestamp = millis() + this->state.tone.duration;
this->state.endtime = millis() + this->state.tone.duration;
if (this->state.tone.frequency > 0) this->on();
}
else if (millis() >= this->state.timestamp) this->reset();
else if (ELAPSED(millis(), this->state.endtime)) this->reset();
}
};

Expand Down
4 changes: 3 additions & 1 deletion Marlin/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2334,12 +2334,14 @@ void kill_screen(const char* lcd_msg) {
lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
next_button_update_ms = millis() + 500;

// Buzz and wait. The delay is needed for buttons to settle!
#if ENABLED(LCD_USE_I2C_BUZZER)
lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
delay(10);
#elif PIN_EXISTS(BEEPER)
buzzer.tone(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
#endif
delay(10); // needed for buttons to settle
}

/**
Expand Down

0 comments on commit 6121c90

Please sign in to comment.