From 01ce2a31d3ecf575388510cce6df529ba18c1dee Mon Sep 17 00:00:00 2001 From: netpok Date: Mon, 25 Feb 2019 22:29:39 +0100 Subject: [PATCH] Implement RGB CT linking --- sonoff/sonoff.ino | 4 ---- sonoff/xdrv_04_light.ino | 12 ++++++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index b19841177..2c9392300 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -789,10 +789,6 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len) param_low = 1; param_high = 250; break; - case P_RGB_REMAP: - param_low = 0; - param_high = 119; - break; } if ((payload >= param_low) && (payload <= param_high)) { Settings.param[pindex] = payload; diff --git a/sonoff/xdrv_04_light.ino b/sonoff/xdrv_04_light.ino index 9b65cea2b..923d49035 100644 --- a/sonoff/xdrv_04_light.ino +++ b/sonoff/xdrv_04_light.ino @@ -111,6 +111,8 @@ uint8_t light_last_color[5]; uint8_t light_signal_color[5]; uint8_t light_color_remap[5]; +bool light_ct_rgb_linked; + uint8_t light_wheel = 0; uint8_t light_subtype = 0; uint8_t light_device = 0; @@ -570,9 +572,9 @@ void LightInit(void) void LightUpdateColorMapping(void) { - uint8_t param = Settings.param[P_RGB_REMAP]; + uint8_t param = Settings.param[P_RGB_REMAP] & 127; if(param > 119){ - param = 119; + param = 0; } uint8_t tmp[] = {0,1,2,3,4}; light_color_remap[0] = tmp[param / 24]; @@ -593,6 +595,8 @@ void LightUpdateColorMapping(void) light_color_remap[3] = tmp[param]; light_color_remap[4] = tmp[1-param]; + light_ct_rgb_linked = !(Settings.param[P_RGB_REMAP] & 128); + light_update = 1; //snprintf_P(log_data, sizeof(log_data), "%d colors: %d %d %d %d %d",Settings.param[P_RGB_REMAP], light_color_remap[0],light_color_remap[1],light_color_remap[2],light_color_remap[3],light_color_remap[4]); //AddLog(LOG_LEVEL_DEBUG); @@ -617,9 +621,11 @@ void LightSetColorTemp(uint16_t ct) Settings.light_color[1] = (uint8_t)icold; } else if (LST_RGBWC == light_subtype) { + if(light_ct_rgb_linked){ Settings.light_color[0] = 0; Settings.light_color[1] = 0; Settings.light_color[2] = 0; + } Settings.light_color[3] = (uint8_t)icold; Settings.light_color[4] = (uint8_t)iwarm; } else { @@ -1157,9 +1163,11 @@ void LightHsbToRgb(void) light_current_color[0] = (uint8_t)(r * 255.0f); light_current_color[1] = (uint8_t)(g * 255.0f); light_current_color[2] = (uint8_t)(b * 255.0f); + if(light_ct_rgb_linked){ light_current_color[3] = 0; light_current_color[4] = 0; } +} /********************************************************************************************/