Browse Source

Allow to define useColor, useWhite and useGamma from web interface

fastled
Xose Pérez 7 years ago
parent
commit
8abb8ffaff
7 changed files with 3510 additions and 3496 deletions
  1. +3
    -2
      code/espurna/config/general.h
  2. +7
    -19
      code/espurna/light.ino
  3. +9
    -0
      code/espurna/settings.ino
  4. +3438
    -3434
      code/espurna/static/index.html.gz.h
  5. +22
    -34
      code/espurna/web.ino
  6. +3
    -3
      code/html/custom.js
  7. +28
    -4
      code/html/index.html

+ 3
- 2
code/espurna/config/general.h View File

@ -186,7 +186,8 @@ PROGMEM const char* const custom_reset_string[] = {
#define WS_TIMEOUT 1800000 // Timeout for secured websocket #define WS_TIMEOUT 1800000 // Timeout for secured websocket
#define WEBSERVER_PORT 80 // HTTP port #define WEBSERVER_PORT 80 // HTTP port
#define DNS_PORT 53 // MDNS port #define DNS_PORT 53 // MDNS port
#define ENABLE_MDNS 1 // Enabled MDNS
#define ENABLE_MDNS 1 // Enable MDNS by default
#define ENABLE_API 0 // Do not enable API by default
#define API_BUFFER_SIZE 10 // Size of the buffer for HTTP GET API responses #define API_BUFFER_SIZE 10 // Size of the buffer for HTTP GET API responses
#define WEB_MODE_NORMAL 0 #define WEB_MODE_NORMAL 0
@ -307,7 +308,7 @@ PROGMEM const char* const custom_reset_string[] = {
#define LIGHT_MAX_BRIGHTNESS 255 // Maximun brightness value #define LIGHT_MAX_BRIGHTNESS 255 // Maximun brightness value
#define LIGHT_USE_COLOR 1 // Use 3 first channels as RGB #define LIGHT_USE_COLOR 1 // Use 3 first channels as RGB
#define LIGHT_USE_WHITE 0 // Use white channel whenever RGB have the same value #define LIGHT_USE_WHITE 0 // Use white channel whenever RGB have the same value
#define LIGHT_ENABLE_GAMMA 0 // Enable gamma correction
#define LIGHT_USE_GAMMA 0 // Use gamma correction for color channels
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// DOMOTICZ // DOMOTICZ


+ 7
- 19
code/espurna/light.ino View File

@ -28,8 +28,6 @@ unsigned int _brightness = LIGHT_MAX_BRIGHTNESS;
my9291 * _my9291; my9291 * _my9291;
#endif #endif
#if LIGHT_ENABLE_GAMMA
// Gamma Correction lookup table for gamma=2.8 and 12 bit (4095) full scale // Gamma Correction lookup table for gamma=2.8 and 12 bit (4095) full scale
// TODO: move to PROGMEM // TODO: move to PROGMEM
const unsigned short gamma_table[LIGHT_MAX_VALUE+1] = { const unsigned short gamma_table[LIGHT_MAX_VALUE+1] = {
@ -50,8 +48,6 @@ const unsigned short gamma_table[LIGHT_MAX_VALUE+1] = {
2849,2884,2920,2957,2993,3030,3067,3105,3143,3181,3219,3258,3297,3336,3376,3416, 2849,2884,2920,2957,2993,3030,3067,3105,3143,3181,3219,3258,3297,3336,3376,3416,
3456,3496,3537,3578,3619,3661,3703,3745,3788,3831,3874,3918,3962,4006,4050,4095 }; 3456,3496,3537,3578,3619,3661,3703,3745,3788,3831,3874,3918,3962,4006,4050,4095 };
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// UTILS // UTILS
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -182,11 +178,7 @@ void _fromMireds(unsigned long mireds) {
unsigned int _toPWM(unsigned long value, bool bright, bool gamma, bool reverse) { unsigned int _toPWM(unsigned long value, bool bright, bool gamma, bool reverse) {
value = constrain(value, 0, LIGHT_MAX_VALUE); value = constrain(value, 0, LIGHT_MAX_VALUE);
if (bright) value *= ((float) _brightness / LIGHT_MAX_BRIGHTNESS); if (bright) value *= ((float) _brightness / LIGHT_MAX_BRIGHTNESS);
#if LIGHT_ENABLE_GAMMA
unsigned int pwm = gamma ? gamma_table[value] : map(value, 0, LIGHT_MAX_VALUE, 0, LIGHT_MAX_PWM);
#else
unsigned int pwm = map(value, 0, LIGHT_MAX_VALUE, 0, LIGHT_MAX_PWM);
#endif
unsigned int pwm = gamma ? gamma_table[value] : map(value, 0, LIGHT_MAX_VALUE, 0, LIGHT_MAX_PWM);
if (reverse) pwm = LIGHT_MAX_PWM - pwm; if (reverse) pwm = LIGHT_MAX_PWM - pwm;
return pwm; return pwm;
} }
@ -196,11 +188,7 @@ unsigned int _toPWM(unsigned char id) {
if (id < _channels.size()) { if (id < _channels.size()) {
bool isColor = (lightHasColor() && id < 3); bool isColor = (lightHasColor() && id < 3);
bool bright = isColor; bool bright = isColor;
#if LIGHT_ENABLE_GAMMA
bool gamma = isColor;
#else
bool gamma = false;
#endif
bool gamma = isColor & (getSetting("useGamma", LIGHT_USE_GAMMA).toInt() == 1);
return _toPWM(_channels[id].shadow, bright, gamma, _channels[id].reverse); return _toPWM(_channels[id].shadow, bright, gamma, _channels[id].reverse);
} }
return 0; return 0;
@ -363,11 +351,8 @@ unsigned char lightChannels() {
} }
bool lightHasColor() { bool lightHasColor() {
#if LIGHT_USE_COLOR
return _channels.size() > 2;
#else
return false;
#endif
bool useColor = getSetting("useColor", LIGHT_USE_COLOR).toInt() == 1;
return useColor && (_channels.size() > 2);
} }
unsigned char lightWhiteChannels() { unsigned char lightWhiteChannels() {
@ -410,6 +395,9 @@ void lightUpdate(bool save, bool forward) {
DynamicJsonBuffer jsonBuffer; DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject(); JsonObject& root = jsonBuffer.createObject();
root["colorVisible"] = 1; root["colorVisible"] = 1;
root["useColor"] = getSetting("useColor", LIGHT_USE_COLOR).toInt() == 1;
root["useWhite"] = getSetting("useWhite", LIGHT_USE_WHITE).toInt() == 1;
root["useGamma"] = getSetting("useGamma", LIGHT_USE_GAMMA).toInt() == 1;
if (lightHasColor()) { if (lightHasColor()) {
root["color"] = lightColor(); root["color"] = lightColor();
root["brightness"] = lightBrightness(); root["brightness"] = lightBrightness();


+ 9
- 0
code/espurna/settings.ino View File

@ -262,6 +262,14 @@ String getSetting(const String& key) {
return getSetting(key, ""); return getSetting(key, "");
} }
bool setBoolSetting(const String& key, bool value, bool defaultValue) {
if (value == defaultValue) {
return delSetting(key);
} else {
return setSetting(key, value ? 1 : 0);
}
}
template<typename T> bool setSetting(const String& key, T value) { template<typename T> bool setSetting(const String& key, T value) {
return Embedis::set(key, String(value)); return Embedis::set(key, String(value));
} }
@ -291,4 +299,5 @@ void saveSettings() {
#if not AUTO_SAVE #if not AUTO_SAVE
EEPROM.commit(); EEPROM.commit();
#endif #endif
settingsDump();
} }

+ 3438
- 3434
code/espurna/static/index.html.gz.h
File diff suppressed because it is too large
View File


+ 22
- 34
code/espurna/web.ino View File

@ -186,6 +186,9 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
bool apiEnabled = false; bool apiEnabled = false;
bool dstEnabled = false; bool dstEnabled = false;
bool mqttUseJson = false; bool mqttUseJson = false;
bool useColor = false;
bool useWhite = false;
bool useGamma = false;
#if ENABLE_FAUXMO #if ENABLE_FAUXMO
bool fauxmoEnabled = false; bool fauxmoEnabled = false;
#endif #endif
@ -271,23 +274,14 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
} }
// Checkboxes // Checkboxes
if (key == "apiEnabled") {
apiEnabled = true;
continue;
}
if (key == "ntpDST") {
dstEnabled = true;
continue;
}
if (key == "mqttUseJson") {
mqttUseJson = true;
continue;
}
if (key == "apiEnabled") { apiEnabled = true; continue; }
if (key == "ntpDST") { dstEnabled = true; continue; }
if (key == "mqttUseJson") { mqttUseJson = true; continue; }
if (key == "useColor") { useColor = true; continue; }
if (key == "useWhite") { useWhite = true; continue; }
if (key == "useGamma") { useGamma = true; continue; }
#if ENABLE_FAUXMO #if ENABLE_FAUXMO
if (key == "fauxmoEnabled") {
fauxmoEnabled = true;
continue;
}
if (key == "fauxmoEnabled") { fauxmoEnabled = true; continue; }
#endif #endif
if (key == "ssid") { if (key == "ssid") {
@ -323,23 +317,14 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
if (webMode == WEB_MODE_NORMAL) { if (webMode == WEB_MODE_NORMAL) {
// Checkboxes // Checkboxes
if (apiEnabled != (getSetting("apiEnabled").toInt() == 1)) {
setSetting("apiEnabled", apiEnabled);
save = changed = true;
}
if (dstEnabled != (getSetting("ntpDST").toInt() == 1)) {
setSetting("ntpDST", dstEnabled);
save = changed = changedNTP = true;
}
if (mqttUseJson != (getSetting("mqttUseJson").toInt() == 1)) {
setSetting("mqttUseJson", mqttUseJson);
save = changed = true;
}
setBoolSetting("apiEnabled", apiEnabled, ENABLE_API);
setBoolSetting("ntpDST", dstEnabled, NTP_DAY_LIGHT);
setBoolSetting("mqttUseJson", mqttUseJson, MQTT_USE_JSON);
setBoolSetting("useColor", useColor, LIGHT_USE_COLOR);
setBoolSetting("useWhite", useWhite, LIGHT_USE_WHITE);
setBoolSetting("useGamma", useGamma, LIGHT_USE_GAMMA);
#if ENABLE_FAUXMO #if ENABLE_FAUXMO
if (fauxmoEnabled != (getSetting("fauxmoEnabled").toInt() == 1)) {
setSetting("fauxmoEnabled", fauxmoEnabled);
save = changed = true;
}
setBoolSetting("fauxmoEnabled", fauxmoEnabled, FAUXMO_ENABLED);
#endif #endif
// Clean wifi networks // Clean wifi networks
@ -472,6 +457,9 @@ void _wsStart(uint32_t client_id) {
#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE #if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
root["colorVisible"] = 1; root["colorVisible"] = 1;
root["useColor"] = getSetting("useColor", LIGHT_USE_COLOR).toInt() == 1;
root["useWhite"] = getSetting("useWhite", LIGHT_USE_WHITE).toInt() == 1;
root["useGamma"] = getSetting("useGamma", LIGHT_USE_GAMMA).toInt() == 1;
if (lightHasColor()) { if (lightHasColor()) {
root["color"] = lightColor(); root["color"] = lightColor();
root["brightness"] = lightBrightness(); root["brightness"] = lightBrightness();
@ -494,7 +482,7 @@ void _wsStart(uint32_t client_id) {
root["webPort"] = getSetting("webPort", WEBSERVER_PORT).toInt(); root["webPort"] = getSetting("webPort", WEBSERVER_PORT).toInt();
root["apiEnabled"] = getSetting("apiEnabled").toInt() == 1;
root["apiEnabled"] = getSetting("apiEnabled", ENABLE_API).toInt() == 1;
root["apiKey"] = getSetting("apiKey"); root["apiKey"] = getSetting("apiKey");
root["tmpUnits"] = getSetting("tmpUnits", TMP_UNITS).toInt(); root["tmpUnits"] = getSetting("tmpUnits", TMP_UNITS).toInt();
@ -691,7 +679,7 @@ bool _authenticate(AsyncWebServerRequest *request) {
bool _authAPI(AsyncWebServerRequest *request) { bool _authAPI(AsyncWebServerRequest *request) {
if (getSetting("apiEnabled").toInt() == 0) {
if (getSetting("apiEnabled", ENABLE_API).toInt() == 0) {
DEBUG_MSG_P(PSTR("[WEBSERVER] HTTP API is not enabled\n")); DEBUG_MSG_P(PSTR("[WEBSERVER] HTTP API is not enabled\n"));
request->send(403); request->send(403);
return false; return false;


+ 3
- 3
code/html/custom.js View File

@ -414,7 +414,7 @@ function processData(data) {
if (key == "brightness") { if (key == "brightness") {
var slider = $("#brightness"); var slider = $("#brightness");
if (slider) slider.get(0).noUiSlider.set(data[key]);
if (slider.length) slider.get(0).noUiSlider.set(data[key]);
return; return;
} }
@ -422,8 +422,8 @@ function processData(data) {
var len = data[key].length; var len = data[key].length;
initChannels(len); initChannels(len);
for (var i=0; i<len; i++) { for (var i=0; i<len; i++) {
var slider = $(".channels[data=" + i + "]");
if (slider) slider.get(0).noUiSlider.set(data[key][i]);
var slider = $("div.channels[data=" + i + "]");
if (slider.length) slider.get(0).noUiSlider.set(data[key][i]);
} }
return; return;
} }


+ 28
- 4
code/html/index.html View File

@ -344,15 +344,39 @@
</div> </div>
</div> </div>
<div class="pure-g module module-color">
<div class="pure-u-1 pure-u-sm-1-4"><label for="useColor">Use colorpicker</label></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="checkbox" name="useColor" tabindex="8" /></div>
<div class="pure-u-0 pure-u-md-1-2">&nbsp;</div>
<div class="pure-u-0 pure-u-md-1-4">&nbsp;</div>
<div class="pure-u-1 pure-u-md-3-4 hint">Use color picker for the first 3 channels as RGB.<br />Will only work if the device has at least 3 dimmable channels.</div>
</div>
<div class="pure-g module module-color">
<div class="pure-u-1 pure-u-sm-1-4"><label for="useWhite">Use white channel</label></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="checkbox" name="useWhite" tabindex="9" /></div>
<div class="pure-u-0 pure-u-md-1-2">&nbsp;</div>
<div class="pure-u-0 pure-u-md-1-4">&nbsp;</div>
<div class="pure-u-1 pure-u-md-3-4 hint">Use forth dimmable channel as white when first 3 have the same RGB value.<br />Will only work if the device has at least 4 dimmable channels.</div>
</div>
<div class="pure-g module module-color">
<div class="pure-u-1 pure-u-sm-1-4"><label for="useGamma">Use gamma correction</label></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="checkbox" name="useGamma" tabindex="10" /></div>
<div class="pure-u-0 pure-u-md-1-2">&nbsp;</div>
<div class="pure-u-0 pure-u-md-1-4">&nbsp;</div>
<div class="pure-u-1 pure-u-md-3-4 hint">Use gamma correction for RGB channels.<br />Will only work if "use colorpicker" above is also ON.</div>
</div>
<div class="pure-g module module-fauxmo"> <div class="pure-g module module-fauxmo">
<div class="pure-u-1 pure-u-sm-1-4"><label for="fauxmoEnabled">Alexa integration</label></div> <div class="pure-u-1 pure-u-sm-1-4"><label for="fauxmoEnabled">Alexa integration</label></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="checkbox" name="fauxmoEnabled" tabindex="7" /></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="checkbox" name="fauxmoEnabled" tabindex="11" /></div>
</div> </div>
<div class="pure-g module module-ds module-dht"> <div class="pure-g module module-ds module-dht">
<label class="pure-u-1 pure-u-sm-1-4" for="tmpUnits">Temperature units</label> <label class="pure-u-1 pure-u-sm-1-4" for="tmpUnits">Temperature units</label>
<div class="pure-u-1 pure-u-sm-1-4"><input type="radio" name="tmpUnits" tabindex="8" value="0"> Celsius (ºC)</input></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="radio" name="tmpUnits" tabindex="9" value="1"> Fahrenheit (ºF)</input></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="radio" name="tmpUnits" tabindex="12" value="0"> Celsius (ºC)</input></div>
<div class="pure-u-1 pure-u-sm-1-4"><input type="radio" name="tmpUnits" tabindex="13" value="1"> Fahrenheit (ºF)</input></div>
</div> </div>
<div class="pure-g"> <div class="pure-g">
@ -801,7 +825,7 @@
<div id="channelTemplate" class="template"> <div id="channelTemplate" class="template">
<div class="pure-g"> <div class="pure-g">
<label class="pure-u-1 pure-u-sm-1-4">Channel #</label> <label class="pure-u-1 pure-u-sm-1-4">Channel #</label>
<div class="slider channels pure-u-1 pure-u-sm-1-4" data="0"></div>
<div class="slider channels pure-u-1 pure-u-sm-1-4" data="99"></div>
</div> </div>
</div> </div>


Loading…
Cancel
Save