When selecting menu items at times buzzer continues to Beep, the only way to stop it is to press the LCD control button again.
This is prevalent in the SD menu section.
I suggest this change to buzzer.h. The best maths to test for time elapsed uses subtraction.
- else if (millis() >= this->state.timestamp) this->reset();
+ else if (ELAPSED(millis(), this->state.timestamp)) this->reset();
#define PENDING(NOW,SOON) ((long)(NOW-(SOON))<0)
#define ELAPSED(NOW,SOON) (!PENDING(NOW,SOON))
I note that lcd_buzz is still defined, but never used.
Another thing that may help in ultralcd.cpp…? This will set the tone (if the first) end-time before the added delay.
#if ENABLED(LCD_USE_I2C_BUZZER)
lcd.buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
#elif PIN_EXISTS(BEEPER)
buzzer.tone(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
+ buzzer.tick();
#endif
Alternatively… the delay in lcd_quick_feedback could be done as a loop which calls buzzer.tick every one or two ms. Sometimes these "buzz" click sounds are only 2ms long anyway.
#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
@lavato is it related with the SD card menu item(s) ?
@jbrazio
I would say yes.
Also, It appears that the sound will stop on its own if you leave it long enough.
I have a feeling that when the CPU is busy it just cannot stop the sound.
@thinkyhead
I'll try replacing lines with your suggested changes to see and get back.
Solution in issue #4249 also "fixed" my buzzer problem.
However, I still think there is an issue with the way how buzzer code stops the sound, as any delay or "hang" appears to cause this issue.
As I said above, I will try thinkyhead's code before closing this.
@thinkyhead
For me this worked with the "bad" SD card. Thank you!
- else if (millis() >= this->state.timestamp) this->reset();
+ else if (ELAPSED(millis(), this->state.timestamp)) this->reset();
#define PENDING(NOW,SOON) ((long)(NOW-(SOON))<0)
#define ELAPSED(NOW,SOON) (!PENDING(NOW,SOON))
BTW: How do you paste colored code into the comment?
BTW: How do you paste colored code into the comment?
When making a code block, after the three backticks you can append a file-extension for the language whose highlighting you want.
Start a block with ```cpp for C++ highlighting
Start a block with ```diff or ```patch for diff highlighting
et-cetera!
#define SOME_C_CODE true
if (SOME_C_CODE) {
printf("Hello %s\n", "world!");
}
@thinkyhead Cheers for that.