From f80fb8966872cc591cfa04abaaab82d6e08ed0f6 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Wed, 21 Mar 2018 09:56:39 +0100 Subject: [PATCH] v5.12.0h - Add Channel status information 5.12.0h * Add Channel status information (#2211) --- sonoff/_releasenotes.ino | 1 + sonoff/xdrv_01_light.ino | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 2beb71f2f..63b563072 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -5,6 +5,7 @@ * Add PWM status to command State if PWM enabled (#2203) * Add command HSBColor Hue,Sat,Bri (#1642, #2203) * Add command Channel 0..100 to control dimmer value for individual color channels (#2111, #2203) + * Add Channel status information (#2211) * Change default option SetOption15 from 0 to 1 providing better initial PWM experience * * 5.12.0f diff --git a/sonoff/xdrv_01_light.ino b/sonoff/xdrv_01_light.ino index 61a599c86..54c7cebc9 100644 --- a/sonoff/xdrv_01_light.ino +++ b/sonoff/xdrv_01_light.ino @@ -550,15 +550,19 @@ void LightState(uint8_t append) mqtt_data, scommand, GetStateText(light_power), Settings.light_dimmer); if (light_subtype > LST_SINGLE) { snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_CMND_COLOR "\":\"%s\""), mqtt_data, LightGetColor(0, scolor)); - - // Add status for HSB + // Add status for HSB LightGetHsb(&hsb[0],&hsb[1],&hsb[2]); // Scale these percentages up to the numbers expected byt he client h = round(hsb[0] * 360); s = round(hsb[1] * 100); b = round(hsb[2] * 100); snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_CMND_HSBCOLOR "\":\"%d,%d,%d\""), mqtt_data, h,s,b); - + // Add status for each channel + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_CMND_CHANNEL "\":[" ), mqtt_data); + for (byte i = 0; i < light_subtype; i++) { + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s%d" ), mqtt_data, (i > 0 ? "," : ""), round(light_current_color[i]/2.55)); + } + snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s]" ), mqtt_data); } if ((LST_COLDWARM == light_subtype) || (LST_RGBWC == light_subtype)) { snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"" D_CMND_COLORTEMPERATURE "\":%d"), mqtt_data, LightGetColorTemp()); @@ -1074,8 +1078,7 @@ boolean LightCommand() LightSetColor(); coldim = true; } - snprintf_P(scolor, 25, PSTR("%d"), round(light_current_color[XdrvMailbox.index -1] / 2.55)); - snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, XdrvMailbox.index, scolor); + snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_NVALUE, command, XdrvMailbox.index, round(light_current_color[XdrvMailbox.index -1] / 2.55)); } else if ((CMND_HSBCOLOR == command_code) && ( light_subtype >= LST_RGB)) { // Implement method to "direct set" color by HSB (HSB is passed comma separated, 0