diff --git a/code/espurna/light.ino b/code/espurna/light.ino index 1870869eea..d41e5f2c1e 100644 --- a/code/espurna/light.ino +++ b/code/espurna/light.ino @@ -35,6 +35,7 @@ typedef struct { unsigned char inputValue; // value that has been inputted unsigned char value; // normalized value including brightness unsigned char shadow; // represented value + unsigned char correction; // correction factor double current; // transition value } channel_t; std::vector _light_channel; @@ -392,18 +393,19 @@ void _toCSV(char * buffer, size_t len, bool applyBrightness) { // PROVIDER // ----------------------------------------------------------------------------- -unsigned int _toPWM(unsigned long value, bool gamma, bool reverse) { +unsigned int _toPWM(unsigned long value, bool gamma, bool reverse, unsigned char correction) { value = constrain(value, 0, LIGHT_MAX_VALUE); if (gamma) value = _light_gamma_table[value]; if (LIGHT_MAX_VALUE != LIGHT_LIMIT_PWM) value = map(value, 0, LIGHT_MAX_VALUE, 0, LIGHT_LIMIT_PWM); if (reverse) value = LIGHT_LIMIT_PWM - value; + if (correction<255) value = (value * correction) / 255; return value; } // Returns a PWM value for the given channel ID unsigned int _toPWM(unsigned char id) { bool useGamma = _light_use_gamma && _light_has_color && (id < 3); - return _toPWM(_light_channel[id].shadow, useGamma, _light_channel[id].reverse); + return _toPWM(_light_channel[id].shadow, useGamma, _light_channel[id].reverse, _light_channel[id].correction); } void _shadow() { @@ -463,6 +465,7 @@ void _lightProviderUpdate() { void _lightColorSave() { for (unsigned int i=0; i < _light_channel.size(); i++) { setSetting("ch", i, _light_channel[i].inputValue); + setSetting("chCorrection", i, _light_channel[i].correction); } setSetting("brightness", _light_brightness); setSetting("mireds", _light_mireds); @@ -472,6 +475,7 @@ void _lightColorSave() { void _lightColorRestore() { for (unsigned int i=0; i < _light_channel.size(); i++) { _light_channel[i].inputValue = getSetting("ch", i, i==0 ? 255 : 0).toInt(); + _light_channel[i].correction = getSetting("chCorrection", i, 255).toInt(); } _light_brightness = getSetting("brightness", LIGHT_MAX_BRIGHTNESS).toInt(); _light_mireds = getSetting("mireds", _light_mireds).toInt(); @@ -790,7 +794,9 @@ void _lightWebSocketOnSend(JsonObject& root) { } JsonArray& channels = root.createNestedArray("channels"); for (unsigned char id=0; id < _light_channel.size(); id++) { - channels.add(lightChannel(id)); + JsonObject& channel = channels.createNestedObject(); + channel["value"] = lightChannel(id); + channel["correction"] = _light_channel[id].correction; } } @@ -824,6 +830,13 @@ void _lightWebSocketOnAction(uint32_t client_id, const char * action, JsonObject lightUpdate(true, true); } } + + if (strcmp(action, "correction") == 0) { + if (data.containsKey("id") && data.containsKey("value")) { + _light_channel[data["id"]].correction = data["value"]; + lightUpdate(true, true); + } + } } #endif diff --git a/code/html/custom.js b/code/html/custom.js index f9cc085372..ac255b074f 100644 --- a/code/html/custom.js +++ b/code/html/custom.js @@ -965,7 +965,7 @@ function initColorHSV() { function initChannels(num) { // check if already initialized - var done = $("#channels > div").length > 0; + var done = $("#channelcorrections > div").length > 0; if (done) { return; } // does it have color channels? @@ -986,24 +986,39 @@ function initChannels(num) { var onChannelSliderChange = function() { var id = $(this).attr("data"); + var type = $(this).attr("datatype"); var value = $(this).val(); var parent = $(this).parents(".pure-g"); $("span", parent).html(value); - sendAction("channel", {id: id, value: value}); + if (type == "correction") { + sendAction("correction", {id: id, value: value}); + } else { + sendAction("channel", {id: id, value: value}); + } }; // add templates var i = 0; var template = $("#channelTemplate").children(); - for (i=0; i= start) { + var line = $(template).clone(); + $("span.slider", line).attr("data", channel_id).attr("datatype", "value"); + $("input.slider", line).attr("data", channel_id).attr("datatype", "value").on("change", onChannelSliderChange); + $("label", line).html("Channel #" + channel_id); + line.appendTo("#channels"); + } + + var line = $(template).clone(); + $("span.slider", line).attr("data", channel_id).attr("datatype", "correction"); + $("input.slider", line).attr("data", channel_id).attr("datatype", "correction").on("change", onChannelSliderChange); + $("label", line).html("Correction Channel #" + channel_id); + line.appendTo("#channelcorrections"); } @@ -1208,8 +1223,10 @@ function processData(data) { initChannels(len); for (i in value) { var ch = value[i]; - $("input.slider[data=" + i + "]").val(ch); - $("span.slider[data=" + i + "]").html(ch); + $("input.slider[data=" + i + "][datatype=value]").val(ch.value); + $("span.slider[data=" + i + "][datatype=value]").html(ch.value); + $("input.slider[data=" + i + "][datatype=correction]").val(ch.correction); + $("span.slider[data=" + i + "][datatype=correction]").html(ch.correction); } return; } diff --git a/code/html/index.html b/code/html/index.html index a3535190f5..de55e22a48 100644 --- a/code/html/index.html +++ b/code/html/index.html @@ -496,6 +496,8 @@

Lights configuration

Sync color between different lights.
+ +
@@ -1541,7 +1543,7 @@

- +