mirror of
https://github.com/arendst/Tasmota.git
synced 2025-08-02 15:37:42 +00:00
Merge pull request #6014 from s-hadinger/fix_5993
Fix Not restoring white value on power off/power on (#5993)
This commit is contained in:
commit
2f701da069
@ -9,6 +9,7 @@
|
|||||||
* Add command SetOption40 0..250 to disable button functionality if activated for over 0.1 second. Needs SetOption1 1 and SetOption13 0 (#5449)
|
* Add command SetOption40 0..250 to disable button functionality if activated for over 0.1 second. Needs SetOption1 1 and SetOption13 0 (#5449)
|
||||||
* Change converted double to float in rules, and replaced trigonometric functions from stdlib with smaller versions saving 7k code space (#6005)
|
* Change converted double to float in rules, and replaced trigonometric functions from stdlib with smaller versions saving 7k code space (#6005)
|
||||||
* Add support for Sonoff L1 thanks to reef-actor (#6002)
|
* Add support for Sonoff L1 thanks to reef-actor (#6002)
|
||||||
|
* Fix Not restoring white value on power off/power on (#5993)
|
||||||
*
|
*
|
||||||
* 6.5.0.15 20190606
|
* 6.5.0.15 20190606
|
||||||
* Change pubsubclient MQTT_KEEPALIVE from 10 to 30 seconds in preparation of AWS IoT support
|
* Change pubsubclient MQTT_KEEPALIVE from 10 to 30 seconds in preparation of AWS IoT support
|
||||||
|
@ -408,7 +408,7 @@ class LightStateClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get full brightness values for wamr and cold channels.
|
// get full brightness values for wamr and cold channels.
|
||||||
// either w=c=0 (off) or w+c=255
|
// either w=c=0 (off) or w+c >= 255
|
||||||
void getCW(uint8_t *rc, uint8_t *rw) {
|
void getCW(uint8_t *rc, uint8_t *rw) {
|
||||||
if (rc) { *rc = _wc; }
|
if (rc) { *rc = _wc; }
|
||||||
if (rw) { *rw = _ww; }
|
if (rw) { *rw = _ww; }
|
||||||
@ -448,14 +448,20 @@ class LightStateClass {
|
|||||||
return _briCT;
|
return _briCT;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getDimmer() {
|
static inline uint8_t DimmerToBri(uint8_t dimmer) {
|
||||||
uint8_t bri = getBri();
|
return changeUIntScale(dimmer, 0, 100, 0, 255); // 0..255
|
||||||
uint8_t dimmer = changeUIntScale(bri, 0, 255, 0, 100); // 0.100
|
}
|
||||||
|
static uint8_t BriToDimmer(uint8_t bri) {
|
||||||
|
uint8_t dimmer = changeUIntScale(bri, 0, 255, 0, 100);
|
||||||
// if brightness is non zero, force dimmer to be non-zero too
|
// if brightness is non zero, force dimmer to be non-zero too
|
||||||
if ((dimmer == 0) && (bri > 0)) { dimmer = 1; }
|
if ((dimmer == 0) && (bri > 0)) { dimmer = 1; }
|
||||||
return dimmer;
|
return dimmer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t getDimmer() {
|
||||||
|
return BriToDimmer(getBri());
|
||||||
|
}
|
||||||
|
|
||||||
inline uint16_t getCT() {
|
inline uint16_t getCT() {
|
||||||
return _ct; // 153..500
|
return _ct; // 153..500
|
||||||
}
|
}
|
||||||
@ -496,7 +502,7 @@ class LightStateClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setDimmer(uint8_t dimmer) {
|
void setDimmer(uint8_t dimmer) {
|
||||||
setBri(changeUIntScale(dimmer, 0, 100, 0, 255)); // 0..255
|
setBri(DimmerToBri(dimmer));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCT(uint16_t ct) {
|
void setCT(uint16_t ct) {
|
||||||
@ -827,18 +833,16 @@ public:
|
|||||||
AddLog_P2(LOG_LEVEL_DEBUG_MORE, "LightControllerClass::loadSettings light_type/sub (%d %d)",
|
AddLog_P2(LOG_LEVEL_DEBUG_MORE, "LightControllerClass::loadSettings light_type/sub (%d %d)",
|
||||||
light_type, light_subtype);
|
light_type, light_subtype);
|
||||||
#endif
|
#endif
|
||||||
// TODO
|
// first try setting CW, if zero, it select RGB mode
|
||||||
// set the RGB from settings
|
_state->setCW(Settings.light_color[3], Settings.light_color[4], true);
|
||||||
_state->setRGB(Settings.light_color[0], Settings.light_color[1], Settings.light_color[2]);
|
_state->setRGB(Settings.light_color[0], Settings.light_color[1], Settings.light_color[2]);
|
||||||
|
// We apply dimmer in priority to RGB
|
||||||
// get CT only for lights that support it
|
uint8_t bri = _state->DimmerToBri(Settings.light_dimmer);
|
||||||
if ((LST_COLDWARM == light_subtype) || (LST_RGBW <= light_subtype)) {
|
if (Settings.light_color[0] + Settings.light_color[1] + Settings.light_color[2] > 0) {
|
||||||
// TODO check
|
_state->setBriRGB(bri);
|
||||||
_state->setCW(Settings.light_color[3], Settings.light_color[4], true);
|
} else {
|
||||||
|
_state->setBriCT(bri);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set Dimmer
|
|
||||||
_state->setDimmer(Settings.light_dimmer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void changeCTB(uint16_t new_ct, uint8_t briCT) {
|
void changeCTB(uint16_t new_ct, uint8_t briCT) {
|
||||||
@ -924,14 +928,21 @@ public:
|
|||||||
|
|
||||||
// save the current light state to Settings.
|
// save the current light state to Settings.
|
||||||
void saveSettings() {
|
void saveSettings() {
|
||||||
|
uint8_t cm = _state->getColorMode();
|
||||||
|
|
||||||
memset(&Settings.light_color[0], 0, sizeof(Settings.light_color));
|
memset(&Settings.light_color[0], 0, sizeof(Settings.light_color));
|
||||||
if (_state->getBriRGB() > 0) {
|
if (LCM_RGB & cm) { // can be either LCM_RGB or LCM_BOTH
|
||||||
_state->getRGB(&Settings.light_color[0], &Settings.light_color[1], &Settings.light_color[2]);
|
_state->getRGB(&Settings.light_color[0], &Settings.light_color[1], &Settings.light_color[2]);
|
||||||
}
|
Settings.light_dimmer = _state->BriToDimmer(_state->getBriRGB());
|
||||||
if (_state->getBriCT() > 0) {
|
// anyways we always store RGB with BrightnessRGB
|
||||||
|
if (LCM_BOTH == cm) {
|
||||||
|
// then store at actual brightness CW/WW if dual mode
|
||||||
|
_state->getActualRGBCW(nullptr, nullptr, nullptr, &Settings.light_color[3], &Settings.light_color[4]);
|
||||||
|
}
|
||||||
|
} else if (LCM_CT == cm) { // cm can only be LCM_CT
|
||||||
_state->getCW(&Settings.light_color[3], &Settings.light_color[4]);
|
_state->getCW(&Settings.light_color[3], &Settings.light_color[4]);
|
||||||
|
Settings.light_dimmer = _state->BriToDimmer(_state->getBriCT());
|
||||||
}
|
}
|
||||||
Settings.light_dimmer = _state->getDimmer();
|
|
||||||
#ifdef DEBUG_LIGHT
|
#ifdef DEBUG_LIGHT
|
||||||
AddLog_P2(LOG_LEVEL_DEBUG_MORE, "LightControllerClass::saveSettings Settings.light_color (%d %d %d %d %d - %d)",
|
AddLog_P2(LOG_LEVEL_DEBUG_MORE, "LightControllerClass::saveSettings Settings.light_color (%d %d %d %d %d - %d)",
|
||||||
Settings.light_color[0], Settings.light_color[1], Settings.light_color[2],
|
Settings.light_color[0], Settings.light_color[1], Settings.light_color[2],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user