From e1448edb252cf013efc3b3ef2024d1796d0cae5d Mon Sep 17 00:00:00 2001 From: Andreas Schultz Date: Tue, 15 Oct 2019 16:41:53 +0200 Subject: [PATCH] add Web UI for PWM multi channel (Option68) --- sonoff/_changelog.ino | 1 + sonoff/xdrv_01_webserver.ino | 83 +++++++++++++++++------------------- 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 7d3a871b6..882d09787 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -8,6 +8,7 @@ * Add incremental beeps to Ifan03 remote control fan speed buttons (#6636) * Add rule support after every command execution like Fanspeed#Data=2 (#6636) * Fix handling of ligth channels when pwm_multichannel (Option68) is enabled + * Add WebUI for multiple, independent PWM channels * * 6.6.0.17 20191009 * Add command SetOption34 0..255 to set backlog delay. Default value is 200 (mSeconds) (#6562) diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino index 474ce1289..936b46c28 100644 --- a/sonoff/xdrv_01_webserver.ino +++ b/sonoff/xdrv_01_webserver.ino @@ -153,39 +153,17 @@ const char HTTP_SCRIPT_ROOT[] PROGMEM = #endif // USE_SCRIPT_WEB_DISPLAY #ifdef USE_JAVASCRIPT_ES6 - "lb=p=>la('&d='+p);" // Dark - Bright &d related to lb(value) and WebGetArg("d", tmp, sizeof(tmp)); - "lc=p=>la('&t='+p);" // Cold - Warm &t related to lc(value) and WebGetArg("t", tmp, sizeof(tmp)); + "lb=(v,p)=>la(`&${v}=${p}`);" + "lc=(v,i,p)=>la(`&${v}${i}=${p}`);" #else - "function lb(p){" - "la('&d='+p);" // &d related to WebGetArg("d", tmp, sizeof(tmp)); + "function lb(v,p){" + "la('&'+v+'='+p);" "}" - "function lc(p){" - "la('&t='+p);" // &t related to WebGetArg("t", tmp, sizeof(tmp)); + "function lc(v,i,p){" + "la('&'+v+i+'='+p);" "}" #endif // USE_JAVASCRIPT_ES6 -#ifdef USE_SHUTTER -#ifdef USE_JAVASCRIPT_ES6 - "ld1=p=>la('&u1='+p);" - "ld2=p=>la('&u2='+p);" - "ld3=p=>la('&u3='+p);" - "ld4=p=>la('&u4='+p);" -#else - "function ld1(p){" - "la('&u1='+p);" - "}" - "function ld2(p){" - "la('&u2='+p);" - "}" - "function ld3(p){" - "la('&u3='+p);" - "}" - "function ld4(p){" - "la('&u4='+p);" - "}" -#endif // USE_JAVASCRIPT_ES6 -#endif // USE_SHUTTER - "wl(la);"; const char HTTP_SCRIPT_WIFI[] PROGMEM = @@ -395,16 +373,11 @@ const char HTTP_HEAD_STYLE3[] PROGMEM = "

%s

"; const char HTTP_MSG_SLIDER1[] PROGMEM = - "
" D_COLDLIGHT "" D_WARMLIGHT "
" - "
"; + "
%s%s
" + "
"; const char HTTP_MSG_SLIDER2[] PROGMEM = - "
" D_DARKLIGHT "" D_BRIGHTLIGHT "
" - "
"; -#ifdef USE_SHUTTER -const char HTTP_MSG_SLIDER3[] PROGMEM = - "
" D_CLOSE "" D_OPEN "
" - "
"; -#endif // USE_SHUTTER + "
%s%s
" + "
"; const char HTTP_MSG_RSTRT[] PROGMEM = "
" D_DEVICE_WILL_RESTART "

"; @@ -1012,16 +985,31 @@ void HandleRoot(void) if (devices_present) { #ifdef USE_LIGHT if (light_type) { - if ((LST_COLDWARM == (light_type &7)) || (LST_RGBWC == (light_type &7))) { - WSContentSend_P(HTTP_MSG_SLIDER1, LightGetColorTemp()); - } - WSContentSend_P(HTTP_MSG_SLIDER2, Settings.light_dimmer); + if (!Settings.flag3.pwm_multi_channels) { + if ((LST_COLDWARM == (light_type &7)) || (LST_RGBWC == (light_type &7))) { + // Cold - Warm &t related to lb("t", value) and WebGetArg("t", tmp, sizeof(tmp)); + WSContentSend_P(HTTP_MSG_SLIDER1, F(D_COLDLIGHT), F(D_WARMLIGHT), + 153, 500, LightGetColorTemp(), 't'); + } + // Dark - Bright &d related to lb("d", value) and WebGetArg("d", tmp, sizeof(tmp)); + WSContentSend_P(HTTP_MSG_SLIDER1, F(D_DARKLIGHT), F(D_BRIGHTLIGHT), + 1, 100, Settings.light_dimmer, 'd'); + } else { // Settings.flag3.pwm_multi_channels + uint32_t pwm_channels = (light_type & 7) > LST_MAX ? LST_MAX : (light_type & 7); + for (uint32_t i = 0; i < pwm_channels; i++) { + snprintf_P(stemp, sizeof(stemp), PSTR("c%d"), i); + WSContentSend_P(HTTP_MSG_SLIDER2, stemp, FPSTR("100%"), + 1, 100, + changeUIntScale(Settings.light_color[i], 0, 255, 0, 100), 'd', i+1); + } + } // Settings.flag3.pwm_multi_channels } #endif #ifdef USE_SHUTTER if (Settings.flag3.shutter_mode) { for (uint32_t i = 0; i < shutters_present; i++) { - WSContentSend_P(HTTP_MSG_SLIDER3, Settings.shutter_position[i], i+1); + WSContentSend_P(HTTP_MSG_SLIDER2, F(D_CLOSE), F(D_OPEN), + 0, 100, Settings.shutter_position[i], 'u', i+1); } } #endif // USE_SHUTTER @@ -1097,6 +1085,7 @@ bool HandleRootStatusRefresh(void) char tmp[8]; // WebGetArg numbers only char svalue[32]; // Command and number parameter + char webindex[5]; // WebGetArg name WebGetArg("o", tmp, sizeof(tmp)); // 1 - 16 Device number for button Toggle or Fanspeed if (strlen(tmp)) { @@ -1122,13 +1111,21 @@ bool HandleRootStatusRefresh(void) snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_DIMMER " %s"), tmp); ExecuteWebCommand(svalue, SRC_WEBGUI); } + uint32_t pwm_channels = (light_type & 7) > LST_MAX ? LST_MAX : (light_type & 7); + for (uint32_t j = 1; j <= pwm_channels; j++) { + snprintf_P(webindex, sizeof(webindex), PSTR("d%d"), j); + WebGetArg(webindex, tmp, sizeof(tmp)); // 0 - 100 percent + if (strlen(tmp)) { + snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_CHANNEL "%d %s"), j, tmp); + ExecuteWebCommand(svalue, SRC_WEBGUI); + } + } WebGetArg("t", tmp, sizeof(tmp)); // 153 - 500 Color temperature if (strlen(tmp)) { snprintf_P(svalue, sizeof(svalue), PSTR(D_CMND_COLORTEMPERATURE " %s"), tmp); ExecuteWebCommand(svalue, SRC_WEBGUI); } #ifdef USE_SHUTTER - char webindex[5]; // WebGetArg name for (uint32_t j = 1; j <= shutters_present; j++) { snprintf_P(webindex, sizeof(webindex), PSTR("u%d"), j); WebGetArg(webindex, tmp, sizeof(tmp)); // 0 - 100 percent