Reduce sleep during buzzer cycles to improve on/off period accuracy.

This commit is contained in:
hello-world-dot-c 2020-10-13 12:02:44 +02:00
parent 6d22c52fbd
commit a59c56d4b5
2 changed files with 10 additions and 2 deletions

View File

@ -262,7 +262,7 @@
#define APP_NORMAL_SLEEP false // [SetOption60] Enable normal sleep instead of dynamic sleep
#define APP_SLEEP 0 // [Sleep] Sleep time to lower energy consumption (0 = Off, 1 - 250 mSec),
#define PWM_MAX_SLEEP 10 // Sleep will be lowered to this value when light is on, to avoid flickering
#define PWM_MAX_SLEEP 10 // Sleep will be lowered to this value when light is on, to avoid flickering, and when buzzer is on for better on/off period accuracy
#define KEY_DEBOUNCE_TIME 50 // [ButtonDebounce] Number of mSeconds button press debounce time
#define KEY_HOLD_TIME 40 // [SetOption32] Number of 0.1 seconds to hold Button or external Pushbutton before sending HOLD message

View File

@ -100,7 +100,15 @@ void BuzzerBeep(uint32_t count, uint32_t on, uint32_t off, uint32_t tune, uint32
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("BUZ: %d(%d),%d,%d,0x%08X(0x%08X),%d"), count, Buzzer.count, on, off, tune, Buzzer.tune, Buzzer.freq_mode);
Buzzer.enable = (Buzzer.count > 0);
if (!Buzzer.enable) {
if (Buzzer.enable) {
if (Settings.sleep > PWM_MAX_SLEEP) {
ssleep = PWM_MAX_SLEEP; // set a maxumum value of 10 milliseconds to ensure that buzzer periods are a bit more accurate
} else {
ssleep = Settings.sleep; // or keep the current sleep if it's lower than 50
}
}
else {
ssleep = Settings.sleep; // restore original sleep
BuzzerSet(0);
}
}