From a59c56d4b560097e6f96a5c749fc90f8ecd77427 Mon Sep 17 00:00:00 2001 From: hello-world-dot-c Date: Tue, 13 Oct 2020 12:02:44 +0200 Subject: [PATCH] Reduce sleep during buzzer cycles to improve on/off period accuracy. --- tasmota/my_user_config.h | 2 +- tasmota/xdrv_24_buzzer.ino | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index 871af4299..2f1d5b668 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -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 diff --git a/tasmota/xdrv_24_buzzer.ino b/tasmota/xdrv_24_buzzer.ino index 60f158d6f..1f9e6d08c 100644 --- a/tasmota/xdrv_24_buzzer.ino +++ b/tasmota/xdrv_24_buzzer.ino @@ -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); } }