Force PWM reapply after frequency change (#13141)

* Force PWM reapply after frequency change

* Fix compilation is USE_LIGHT is not defined
This commit is contained in:
s-hadinger 2021-09-15 19:54:55 +02:00 committed by GitHub
parent f9e1ab1c90
commit e8b30eadfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -1450,6 +1450,10 @@ void CmndPwmfrequency(void)
if ((1 == XdrvMailbox.payload) || ((XdrvMailbox.payload >= PWM_MIN) && (XdrvMailbox.payload <= PWM_MAX))) {
Settings->pwm_frequency = (1 == XdrvMailbox.payload) ? PWM_FREQ : XdrvMailbox.payload;
analogWriteFreq(Settings->pwm_frequency); // Default is 1000 (core_esp8266_wiring_pwm.c)
#ifdef USE_LIGHT
LightReapplyColor();
LightAnimate();
#endif // USE_LIGHT
}
ResponseCmndNumber(Settings->pwm_frequency);
}

View File

@ -1656,6 +1656,13 @@ uint8_t LightGetSpeedSetting(void) {
return Settings->light_speed;
}
// Force to reapply color, for example when PWM Frequency changed
void LightReapplyColor(void) {
for (uint32_t i = 0; i < LST_MAX; i++) {
Light.last_color[i] = 0;
}
}
// On entry Light.new_color[5] contains the color to be displayed
// and Light.last_color[5] the color currently displayed
// Light.power tells which lights or channels (SetOption68) are on/off