Skip to content

Commit

Permalink
Merge pull request #6984 from Staars/colorpicker
Browse files Browse the repository at this point in the history
add colorpicker to Web-UI
  • Loading branch information
arendst authored Nov 21, 2019
2 parents 94df1ba + 51f6b21 commit e838a76
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
31 changes: 30 additions & 1 deletion tasmota/xdrv_01_webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ const char HTTP_SCRIPT_ROOT[] PROGMEM =
"}"
"function lc(v,i,p){"
"la('&'+v+i+'='+p);"
"}"
"function ld(v,p){"
"eb('s').style.backgroundImage='linear-gradient(to right,grey,hsl('+p+',100%%,50%%))';"
"la('&'+v+'='+p);"
"}"
#endif // USE_JAVASCRIPT_ES6

Expand Down Expand Up @@ -378,6 +382,10 @@ const char HTTP_MSG_SLIDER1[] PROGMEM =
const char HTTP_MSG_SLIDER2[] PROGMEM =
"<div><span class='p'>%s</span><span class='q'>%s</span></div>"
"<div><input type='range' min='%d' max='%d' value='%d' onchange='lc(\"%c\", %d, value)'></div>";
const char HTTP_MSG_SLIDER3[] PROGMEM = // HUE
"<br><div style='background-image:linear-gradient(to right, %s'><input type='range' min='%d' max='%d' value='%d' onchange='ld(\"%c\", value)'></div><br>";
const char HTTP_MSG_SLIDER4[] PROGMEM = // SATURATION
"<br><div id='s' style='background-image:linear-gradient(to right, %s'><input type='range' min='%d' max='%d' value='%d' onchange='lb(\"%c\", value)'></div><br>";
const char HTTP_MSG_RSTRT[] PROGMEM =
"<br><div style='text-align:center;'>" D_DEVICE_WILL_RESTART "</div><br>";

Expand Down Expand Up @@ -1014,8 +1022,19 @@ void HandleRoot(void)
changeUIntScale(Settings.light_color[i], 0, 255, 0, 100), 'd', i+1);
}
} // Settings.flag3.pwm_multi_channels
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;
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,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
#endif // USE_LIGHT
#ifdef USE_SHUTTER
if (Settings.flag3.shutter_mode) { // SetOption80 - Enable shutter support
for (uint32_t i = 0; i < shutters_present; i++) {
Expand Down Expand Up @@ -1136,6 +1155,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);
Expand Down
4 changes: 4 additions & 0 deletions tasmota/xdrv_04_light.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e838a76

Please sign in to comment.