From 56ccbc5216f6d59b4d0993c6df5363ba54c61e77 Mon Sep 17 00:00:00 2001 From: Staars Date: Tue, 19 Nov 2019 21:22:45 +0100 Subject: [PATCH 1/4] Web-GUI color picker --- tasmota/xdrv_01_webserver.ino | 27 ++++++++++++++++++++++++++- tasmota/xdrv_04_light.ino | 4 ++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 64194c9c9..33a582d58 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -378,6 +378,9 @@ const char HTTP_MSG_SLIDER1[] PROGMEM = const char HTTP_MSG_SLIDER2[] PROGMEM = "
%s%s
" "
"; +const char HTTP_MSG_SLIDER3[] PROGMEM = // HUE and SATURATION + "

"; + const char HTTP_MSG_RSTRT[] PROGMEM = "
" D_DEVICE_WILL_RESTART "

"; @@ -1014,8 +1017,20 @@ void HandleRoot(void) changeUIntScale(Settings.light_color[i], 0, 255, 0, 100), 'd', i+1); } } // Settings.flag3.pwm_multi_channels + if (light_type > 3) { // TODO: check if this is the right way + char hexColor[65]; + snprintf_P(hexColor, sizeof(hexColor), PSTR("grey , #%02X%02X%02X );border-radius:0.3em;"), Settings.light_color[0],Settings.light_color[1],Settings.light_color[2]); + uint16_t hue; + uint8_t sat; + uint8_t bri; + LightGetHSB(&hue, &sat, &bri); + AddLog_P2(LOG_LEVEL_INFO, PSTR("HSB: %u %u %u "), hue,sat,bri); + + WSContentSend_P(HTTP_MSG_SLIDER3, F("red, orange, yellow, green, blue, indigo, violet);border-radius:0.3em;"), 0, 359, hue, 'u'); // hue + WSContentSend_P(HTTP_MSG_SLIDER3, hexColor, 0, 99, sat, 'n'); // saturation + } } -#endif +#endif // USE_LIGHT #ifdef USE_SHUTTER if (Settings.flag3.shutter_mode) { // SetOption80 - Enable shutter support for (uint32_t i = 0; i < shutters_present; i++) { @@ -1136,6 +1151,16 @@ bool HandleRootStatusRefresh(void) snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_COLORTEMPERATURE " %s"), tmp); ExecuteWebCommand(svalue, SRC_WEBGUI); } + WebGetArg("u", tmp, sizeof(tmp)); // 0 - 359 Hue value + if (strlen(tmp)) { + snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_HSBCOLOR "1 %s"), tmp); + ExecuteWebCommand(svalue, SRC_WEBGUI); + } + WebGetArg("n", tmp, sizeof(tmp)); // 0 - 99 Saturation value + if (strlen(tmp)) { + snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_HSBCOLOR "2 %s"), tmp); + ExecuteWebCommand(svalue, SRC_WEBGUI); + } #ifdef USE_SHUTTER for (uint32_t j = 1; j <= shutters_present; j++) { snprintf_P(webindex, sizeof(webindex), PSTR("u%d"), j); diff --git a/tasmota/xdrv_04_light.ino b/tasmota/xdrv_04_light.ino index c6f6b3e33..47f3639ba 100644 --- a/tasmota/xdrv_04_light.ino +++ b/tasmota/xdrv_04_light.ino @@ -1241,6 +1241,10 @@ void LightSetDimmer(uint8_t dimmer) { light_controller.changeDimmer(dimmer); } +uint32_t LightGetHSB(uint16_t *hue,uint8_t *sat, uint8_t *bri) { + light_state.getHSB(hue, sat, bri); +} + // If SetOption68 is set, get the brightness for a specific device uint8_t LightGetBri(uint8_t device) { uint8_t bri = 254; // default value if relay From 50a919c0945e59183272b591785fbe01d176401b Mon Sep 17 00:00:00 2001 From: Staars Date: Tue, 19 Nov 2019 21:41:42 +0100 Subject: [PATCH 2/4] fix saturation slider scaling --- tasmota/xdrv_01_webserver.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 33a582d58..91c8a35e9 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -1026,8 +1026,8 @@ void HandleRoot(void) LightGetHSB(&hue, &sat, &bri); AddLog_P2(LOG_LEVEL_INFO, PSTR("HSB: %u %u %u "), hue,sat,bri); - WSContentSend_P(HTTP_MSG_SLIDER3, F("red, orange, yellow, green, blue, indigo, violet);border-radius:0.3em;"), 0, 359, hue, 'u'); // hue - WSContentSend_P(HTTP_MSG_SLIDER3, hexColor, 0, 99, sat, 'n'); // saturation + WSContentSend_P(HTTP_MSG_SLIDER3, F("red, orange, yellow, green, blue, indigo, violet);border-radius:0.3em;"), 1, 359, hue, 'u'); // hue + WSContentSend_P(HTTP_MSG_SLIDER3, hexColor, 1, 100, changeUIntScale(sat, 0, 255, 0, 100), 'n'); // saturation } } #endif // USE_LIGHT From 9bba95a7cc3fcb3eb21283f35cc7924e44d7bc16 Mon Sep 17 00:00:00 2001 From: Staars Date: Thu, 21 Nov 2019 18:02:58 +0100 Subject: [PATCH 3/4] responsive color update, fix scaling --- tasmota/xdrv_01_webserver.ino | 30 +++++++++++++++++++++--------- tasmota/xdrv_04_light.ino | 3 ++- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 1502a35d6..302bc775c 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ - +#define USE_COLORPICKER #ifdef USE_WEBSERVER /*********************************************************************************************\ * Web server and WiFi Manager @@ -162,6 +162,12 @@ const char HTTP_SCRIPT_ROOT[] PROGMEM = "function lc(v,i,p){" "la('&'+v+i+'='+p);" "}" +#ifdef USE_COLORPICKER + "function ld(v,p){" // + "eb('s').style.backgroundImage='linear-gradient(to right,grey,hsl('+p+',100%%,50%%))';" + "la('&'+v+'='+p);" + "}" +#endif //USE_COLORPICKER #endif // USE_JAVASCRIPT_ES6 "wl(la);"; @@ -378,9 +384,12 @@ const char HTTP_MSG_SLIDER1[] PROGMEM = const char HTTP_MSG_SLIDER2[] PROGMEM = "
%s%s
" "
"; -const char HTTP_MSG_SLIDER3[] PROGMEM = // HUE and SATURATION - "

"; - +#ifdef USE_COLORPICKER +const char HTTP_MSG_SLIDER3[] PROGMEM = // HUE + "

"; +const char HTTP_MSG_SLIDER4[] PROGMEM = // SATURATION + "

"; +#endif // USE_COLORPICKER const char HTTP_MSG_RSTRT[] PROGMEM = "
" D_DEVICE_WILL_RESTART "

"; @@ -1017,18 +1026,19 @@ void HandleRoot(void) changeUIntScale(Settings.light_color[i], 0, 255, 0, 100), 'd', i+1); } } // Settings.flag3.pwm_multi_channels +#ifdef USE_COLORPICKER if (light_type > 3) { // TODO: check if this is the right way char hexColor[65]; - snprintf_P(hexColor, sizeof(hexColor), PSTR("grey , #%02X%02X%02X );border-radius:0.3em;"), Settings.light_color[0],Settings.light_color[1],Settings.light_color[2]); + snprintf_P(hexColor, sizeof(hexColor), PSTR("grey,#%02X%02X%02X );border-radius:0.3em;"), Settings.light_color[0],Settings.light_color[1],Settings.light_color[2]); uint16_t hue; uint8_t sat; uint8_t bri; LightGetHSB(&hue, &sat, &bri); - AddLog_P2(LOG_LEVEL_INFO, PSTR("HSB: %u %u %u "), hue,sat,bri); - - WSContentSend_P(HTTP_MSG_SLIDER3, F("red, orange, yellow, green, blue, indigo, violet);border-radius:0.3em;"), 1, 359, hue, 'u'); // hue - WSContentSend_P(HTTP_MSG_SLIDER3, hexColor, 1, 100, changeUIntScale(sat, 0, 255, 0, 100), 'n'); // saturation + // AddLog_P2(LOG_LEVEL_INFO, PSTR("HSB: %u %u %u "), hue,sat,bri); + WSContentSend_P(HTTP_MSG_SLIDER3, F("red,orange,yellow,green,blue,indigo,violet,red);border-radius:0.3em;"), 1, 359, hue, 'u'); // hue + WSContentSend_P(HTTP_MSG_SLIDER4, hexColor, 1, 100, changeUIntScale(sat, 0, 255, 0, 100), 'n'); // saturation } +#endif // USE_COLORPICKER } #endif // USE_LIGHT #ifdef USE_SHUTTER @@ -1151,6 +1161,7 @@ bool HandleRootStatusRefresh(void) snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_COLORTEMPERATURE " %s"), tmp); ExecuteWebCommand(svalue, SRC_WEBGUI); } +#ifdef USE_COLORPICKER WebGetArg("u", tmp, sizeof(tmp)); // 0 - 359 Hue value if (strlen(tmp)) { snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_HSBCOLOR "1 %s"), tmp); @@ -1161,6 +1172,7 @@ bool HandleRootStatusRefresh(void) snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_HSBCOLOR "2 %s"), tmp); ExecuteWebCommand(svalue, SRC_WEBGUI); } +#endif //USE_COLORPICKER #ifdef USE_SHUTTER for (uint32_t j = 1; j <= shutters_present; j++) { snprintf_P(webindex, sizeof(webindex), PSTR("u%d"), j); diff --git a/tasmota/xdrv_04_light.ino b/tasmota/xdrv_04_light.ino index a51c98619..198e88e40 100644 --- a/tasmota/xdrv_04_light.ino +++ b/tasmota/xdrv_04_light.ino @@ -1240,10 +1240,11 @@ void LightUpdateColorMapping(void) void LightSetDimmer(uint8_t dimmer) { light_controller.changeDimmer(dimmer); } - +#ifdef USE_COLORPICKER uint32_t LightGetHSB(uint16_t *hue,uint8_t *sat, uint8_t *bri) { light_state.getHSB(hue, sat, bri); } +#endif // USE_COLORPICKER // If SetOption68 is set, get the brightness for a specific device uint8_t LightGetBri(uint8_t device) { From 51f6b211cb8f1e583674ea029f8c581e4d546d73 Mon Sep 17 00:00:00 2001 From: Staars Date: Thu, 21 Nov 2019 19:17:57 +0100 Subject: [PATCH 4/4] remove some #ifdef stuff --- tasmota/xdrv_01_webserver.ino | 16 ++++------------ tasmota/xdrv_04_light.ino | 3 +-- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 302bc775c..701e25c53 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#define USE_COLORPICKER + #ifdef USE_WEBSERVER /*********************************************************************************************\ * Web server and WiFi Manager @@ -161,13 +161,11 @@ const char HTTP_SCRIPT_ROOT[] PROGMEM = "}" "function lc(v,i,p){" "la('&'+v+i+'='+p);" - "}" -#ifdef USE_COLORPICKER - "function ld(v,p){" // + "}" + "function ld(v,p){" "eb('s').style.backgroundImage='linear-gradient(to right,grey,hsl('+p+',100%%,50%%))';" "la('&'+v+'='+p);" "}" -#endif //USE_COLORPICKER #endif // USE_JAVASCRIPT_ES6 "wl(la);"; @@ -384,12 +382,10 @@ const char HTTP_MSG_SLIDER1[] PROGMEM = const char HTTP_MSG_SLIDER2[] PROGMEM = "
%s%s
" "
"; -#ifdef USE_COLORPICKER const char HTTP_MSG_SLIDER3[] PROGMEM = // HUE "

"; const char HTTP_MSG_SLIDER4[] PROGMEM = // SATURATION "

"; -#endif // USE_COLORPICKER const char HTTP_MSG_RSTRT[] PROGMEM = "
" D_DEVICE_WILL_RESTART "

"; @@ -1026,8 +1022,7 @@ void HandleRoot(void) changeUIntScale(Settings.light_color[i], 0, 255, 0, 100), 'd', i+1); } } // Settings.flag3.pwm_multi_channels -#ifdef USE_COLORPICKER - if (light_type > 3) { // TODO: check if this is the right way + if (light_type > 3) { char hexColor[65]; snprintf_P(hexColor, sizeof(hexColor), PSTR("grey,#%02X%02X%02X );border-radius:0.3em;"), Settings.light_color[0],Settings.light_color[1],Settings.light_color[2]); uint16_t hue; @@ -1038,7 +1033,6 @@ void HandleRoot(void) WSContentSend_P(HTTP_MSG_SLIDER3, F("red,orange,yellow,green,blue,indigo,violet,red);border-radius:0.3em;"), 1, 359, hue, 'u'); // hue WSContentSend_P(HTTP_MSG_SLIDER4, hexColor, 1, 100, changeUIntScale(sat, 0, 255, 0, 100), 'n'); // saturation } -#endif // USE_COLORPICKER } #endif // USE_LIGHT #ifdef USE_SHUTTER @@ -1161,7 +1155,6 @@ bool HandleRootStatusRefresh(void) snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_COLORTEMPERATURE " %s"), tmp); ExecuteWebCommand(svalue, SRC_WEBGUI); } -#ifdef USE_COLORPICKER WebGetArg("u", tmp, sizeof(tmp)); // 0 - 359 Hue value if (strlen(tmp)) { snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_HSBCOLOR "1 %s"), tmp); @@ -1172,7 +1165,6 @@ bool HandleRootStatusRefresh(void) snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_HSBCOLOR "2 %s"), tmp); ExecuteWebCommand(svalue, SRC_WEBGUI); } -#endif //USE_COLORPICKER #ifdef USE_SHUTTER for (uint32_t j = 1; j <= shutters_present; j++) { snprintf_P(webindex, sizeof(webindex), PSTR("u%d"), j); diff --git a/tasmota/xdrv_04_light.ino b/tasmota/xdrv_04_light.ino index 198e88e40..a51c98619 100644 --- a/tasmota/xdrv_04_light.ino +++ b/tasmota/xdrv_04_light.ino @@ -1240,11 +1240,10 @@ void LightUpdateColorMapping(void) void LightSetDimmer(uint8_t dimmer) { light_controller.changeDimmer(dimmer); } -#ifdef USE_COLORPICKER + uint32_t LightGetHSB(uint16_t *hue,uint8_t *sat, uint8_t *bri) { light_state.getHSB(hue, sat, bri); } -#endif // USE_COLORPICKER // If SetOption68 is set, get the brightness for a specific device uint8_t LightGetBri(uint8_t device) {