Browse Source

Tested encoder support

ech1560
Xose Pérez 6 years ago
parent
commit
01802741f2
8 changed files with 6074 additions and 6080 deletions
  1. +4
    -3
      code/espurna/config/hardware.h
  2. BIN
      code/espurna/data/index.all.html.gz
  3. BIN
      code/espurna/data/index.light.html.gz
  4. +78
    -71
      code/espurna/light.ino
  5. +3001
    -3001
      code/espurna/static/index.all.html.gz.h
  6. +2959
    -2959
      code/espurna/static/index.light.html.gz.h
  7. +28
    -38
      code/html/custom.js
  8. +4
    -8
      code/html/index.html

+ 4
- 3
code/espurna/config/hardware.h View File

@ -70,13 +70,13 @@
// Buttons // Buttons
#define BUTTON1_PIN 0 #define BUTTON1_PIN 0
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH #define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
#define BUTTON1_RELAY 1
#define BUTTON1_RELAY 1
// Relays
// Hidden button will enter AP mode if dblclick and reset the device when long-long-clicked
#define RELAY1_PIN 12 #define RELAY1_PIN 12
#define RELAY1_TYPE RELAY_TYPE_NORMAL #define RELAY1_TYPE RELAY_TYPE_NORMAL
// LEDs
// Light
#define LED1_PIN 2 #define LED1_PIN 2
#define LED1_PIN_INVERSE 1 #define LED1_PIN_INVERSE 1
@ -2706,6 +2706,7 @@
// Light // Light
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
#define DUMMY_RELAY_COUNT 1 #define DUMMY_RELAY_COUNT 1
#define LIGHT_STEP 8
#define LIGHT_CHANNELS 2 #define LIGHT_CHANNELS 2
#define LIGHT_CH1_PIN 5 // warm white #define LIGHT_CH1_PIN 5 // warm white
#define LIGHT_CH1_INVERSE 0 #define LIGHT_CH1_INVERSE 0


BIN
code/espurna/data/index.all.html.gz View File


BIN
code/espurna/data/index.light.html.gz View File


+ 78
- 71
code/espurna/light.ino View File

@ -145,13 +145,9 @@ void _generateBrightness() {
} else { } else {
// Don't apply brightness, it is already in the target:
// Apply brightness equally to all channels
for (unsigned char i=0; i < _light_channel.size(); i++) { for (unsigned char i=0; i < _light_channel.size(); i++) {
if (_light_has_color & (i<3)) {
_light_channel[i].value = _light_channel[i].inputValue * brightness;
} else {
_light_channel[i].value = _light_channel[i].inputValue;
}
_light_channel[i].value = _light_channel[i].inputValue * brightness;
} }
} }
@ -569,6 +565,7 @@ void _lightMQTTCallback(unsigned int type, const char * topic, const char * payl
} }
void lightMQTT() { void lightMQTT() {
char buffer[20]; char buffer[20];
if (_light_has_color) { if (_light_has_color) {
@ -584,13 +581,10 @@ void lightMQTT() {
_toHSV(buffer, sizeof(buffer)); _toHSV(buffer, sizeof(buffer));
mqttSend(MQTT_TOPIC_COLOR_HSV, buffer); mqttSend(MQTT_TOPIC_COLOR_HSV, buffer);
// Brightness
snprintf_P(buffer, sizeof(buffer), PSTR("%d"), _light_brightness);
mqttSend(MQTT_TOPIC_BRIGHTNESS, buffer);
// Mireds // Mireds
snprintf_P(buffer, sizeof(buffer), PSTR("%d"), _light_mireds); snprintf_P(buffer, sizeof(buffer), PSTR("%d"), _light_mireds);
mqttSend(MQTT_TOPIC_MIRED, buffer); mqttSend(MQTT_TOPIC_MIRED, buffer);
} }
// Channels // Channels
@ -599,6 +593,10 @@ void lightMQTT() {
mqttSend(MQTT_TOPIC_CHANNEL, i, buffer); mqttSend(MQTT_TOPIC_CHANNEL, i, buffer);
} }
// Brightness
snprintf_P(buffer, sizeof(buffer), PSTR("%d"), _light_brightness);
mqttSend(MQTT_TOPIC_BRIGHTNESS, buffer);
} }
void lightMQTTGroup() { void lightMQTTGroup() {
@ -735,7 +733,7 @@ unsigned int lightChannel(unsigned char id) {
return 0; return 0;
} }
void lightChannel(unsigned char id, unsigned int value) {
void lightChannel(unsigned char id, int value) {
if (id <= _light_channel.size()) { if (id <= _light_channel.size()) {
_light_channel[id].inputValue = constrain(value, 0, LIGHT_MAX_VALUE); _light_channel[id].inputValue = constrain(value, 0, LIGHT_MAX_VALUE);
} }
@ -787,7 +785,6 @@ void _lightWebSocketOnSend(JsonObject& root) {
} }
if (useRGB) { if (useRGB) {
root["rgb"] = lightColor(true); root["rgb"] = lightColor(true);
root["brightness"] = lightBrightness();
} else { } else {
root["hsv"] = lightColor(false); root["hsv"] = lightColor(false);
} }
@ -796,9 +793,11 @@ void _lightWebSocketOnSend(JsonObject& root) {
for (unsigned char id=0; id < _light_channel.size(); id++) { for (unsigned char id=0; id < _light_channel.size(); id++) {
channels.add(lightChannel(id)); channels.add(lightChannel(id));
} }
root["brightness"] = lightBrightness();
} }
void _lightWebSocketOnAction(uint32_t client_id, const char * action, JsonObject& data) { void _lightWebSocketOnAction(uint32_t client_id, const char * action, JsonObject& data) {
if (_light_has_color) { if (_light_has_color) {
if (strcmp(action, "color") == 0) { if (strcmp(action, "color") == 0) {
if (data.containsKey("rgb")) { if (data.containsKey("rgb")) {
@ -809,10 +808,6 @@ void _lightWebSocketOnAction(uint32_t client_id, const char * action, JsonObject
lightColor(data["hsv"], false); lightColor(data["hsv"], false);
lightUpdate(true, true); lightUpdate(true, true);
} }
if (data.containsKey("brightness")) {
lightBrightness(data["brightness"]);
lightUpdate(true, true);
}
} }
if (_light_use_cct) { if (_light_use_cct) {
if (strcmp(action, "mireds") == 0) { if (strcmp(action, "mireds") == 0) {
@ -828,6 +823,14 @@ void _lightWebSocketOnAction(uint32_t client_id, const char * action, JsonObject
lightUpdate(true, true); lightUpdate(true, true);
} }
} }
if (strcmp(action, "brightness") == 0) {
if (data.containsKey("value")) {
lightBrightness(data["value"]);
lightUpdate(true, true);
}
}
} }
#endif #endif
@ -835,35 +838,70 @@ void _lightWebSocketOnAction(uint32_t client_id, const char * action, JsonObject
#if API_SUPPORT #if API_SUPPORT
void _lightAPISetup() { void _lightAPISetup() {
// API entry points (protected with apikey)
if (_light_has_color) {
apiRegister(MQTT_TOPIC_COLOR_RGB,
[](char * buffer, size_t len) {
if (getSetting("useCSS", LIGHT_USE_CSS).toInt() == 1) {
_toRGB(buffer, len);
} else {
_toLong(buffer, len);
if (_light_has_color) {
apiRegister(MQTT_TOPIC_COLOR_RGB,
[](char * buffer, size_t len) {
if (getSetting("useCSS", LIGHT_USE_CSS).toInt() == 1) {
_toRGB(buffer, len);
} else {
_toLong(buffer, len);
}
},
[](const char * payload) {
lightColor(payload, true);
lightUpdate(true, true);
} }
},
[](const char * payload) {
lightColor(payload, true);
lightUpdate(true, true);
}
);
);
apiRegister(MQTT_TOPIC_COLOR_HSV,
[](char * buffer, size_t len) {
_toHSV(buffer, len);
},
[](const char * payload) {
lightColor(payload, false);
lightUpdate(true, true);
}
);
apiRegister(MQTT_TOPIC_COLOR_HSV,
[](char * buffer, size_t len) {
_toHSV(buffer, len);
},
[](const char * payload) {
lightColor(payload, false);
lightUpdate(true, true);
}
);
apiRegister(MQTT_TOPIC_KELVIN,
[](char * buffer, size_t len) {},
[](const char * payload) {
_fromKelvin(atol(payload));
lightUpdate(true, true);
}
);
apiRegister(MQTT_TOPIC_MIRED,
[](char * buffer, size_t len) {},
[](const char * payload) {
_fromMireds(atol(payload));
lightUpdate(true, true);
}
);
}
for (unsigned int id=0; id<_light_channel.size(); id++) {
char key[15];
snprintf_P(key, sizeof(key), PSTR("%s/%d"), MQTT_TOPIC_CHANNEL, id);
apiRegister(key,
[id](char * buffer, size_t len) {
snprintf_P(buffer, len, PSTR("%d"), lightChannel(id));
},
[id](const char * payload) {
lightChannel(id, atoi(payload));
lightUpdate(true, true);
}
);
}
apiRegister(MQTT_TOPIC_BRIGHTNESS, apiRegister(MQTT_TOPIC_BRIGHTNESS,
[](char * buffer, size_t len) { [](char * buffer, size_t len) {
snprintf_P(buffer, len, PSTR("%d"), _light_brightness);
snprintf_P(buffer, len, PSTR("%d"), _light_brightness);
}, },
[](const char * payload) { [](const char * payload) {
lightBrightness(atoi(payload)); lightBrightness(atoi(payload));
@ -871,37 +909,6 @@ void _lightAPISetup() {
} }
); );
apiRegister(MQTT_TOPIC_KELVIN,
[](char * buffer, size_t len) {},
[](const char * payload) {
_fromKelvin(atol(payload));
lightUpdate(true, true);
}
);
apiRegister(MQTT_TOPIC_MIRED,
[](char * buffer, size_t len) {},
[](const char * payload) {
_fromMireds(atol(payload));
lightUpdate(true, true);
}
);
}
for (unsigned int id=0; id<_light_channel.size(); id++) {
char key[15];
snprintf_P(key, sizeof(key), PSTR("%s/%d"), MQTT_TOPIC_CHANNEL, id);
apiRegister(key,
[id](char * buffer, size_t len) {
snprintf_P(buffer, len, PSTR("%d"), lightChannel(id));
},
[id](const char * payload) {
lightChannel(id, atoi(payload));
lightUpdate(true, true);
}
);
}
} }
#endif // API_SUPPORT #endif // API_SUPPORT


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


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


+ 28
- 38
code/html/custom.js View File

@ -895,31 +895,29 @@ function initMagnitudes(data) {
<!-- removeIf(!light)--> <!-- removeIf(!light)-->
function initColorRGB() {
function initColor(rgb) {
// check if already initialized // check if already initialized
var done = $("#colors > div").length; var done = $("#colors > div").length;
if (done > 0) { return; } if (done > 0) { return; }
// add template // add template
var template = $("#colorRGBTemplate").children();
var template = $("#colorTemplate").children();
var line = $(template).clone(); var line = $(template).clone();
line.appendTo("#colors"); line.appendTo("#colors");
// init color wheel // init color wheel
$("input[name='color']").wheelColorPicker({ $("input[name='color']").wheelColorPicker({
sliders: "wrgbp"
sliders: (rgb ? "wrgbp" : "whsvp")
}).on("sliderup", function() { }).on("sliderup", function() {
var value = $(this).wheelColorPicker("getValue", "css");
sendAction("color", {rgb: value});
});
// init bright slider
$("#brightness").on("change", function() {
var value = $(this).val();
var parent = $(this).parents(".pure-g");
$("span", parent).html(value);
sendAction("color", {brightness: value});
if (rgb) {
var value = $(this).wheelColorPicker("getValue", "css");
sendAction("color", {rgb: value});
} else {
var color = $(this).wheelColorPicker("getColor");
var value = parseInt(color.h * 360, 10) + "," + parseInt(color.s * 100, 10) + "," + parseInt(color.v * 100, 10);
sendAction("color", {hsv: value});
}
}); });
} }
@ -940,28 +938,6 @@ function initCCT() {
}); });
} }
function initColorHSV() {
// check if already initialized
var done = $("#colors > div").length;
if (done > 0) { return; }
// add template
var template = $("#colorHSVTemplate").children();
var line = $(template).clone();
line.appendTo("#colors");
// init color wheel
$("input[name='color']").wheelColorPicker({
sliders: "whsvp"
}).on("sliderup", function() {
var color = $(this).wheelColorPicker("getColor");
var value = parseInt(color.h * 360, 10) + "," + parseInt(color.s * 100, 10) + "," + parseInt(color.v * 100, 10);
sendAction("color", {hsv: value});
});
}
function initChannels(num) { function initChannels(num) {
// check if already initialized // check if already initialized
@ -992,7 +968,7 @@ function initChannels(num) {
sendAction("channel", {id: id, value: value}); sendAction("channel", {id: id, value: value});
}; };
// add templates
// add channel templates
var i = 0; var i = 0;
var template = $("#channelTemplate").children(); var template = $("#channelTemplate").children();
for (i=0; i<max; i++) { for (i=0; i<max; i++) {
@ -1007,11 +983,25 @@ function initChannels(num) {
} }
// Init channel dropdowns
for (i=0; i<num; i++) { for (i=0; i<num; i++) {
$("select.islight").append( $("select.islight").append(
$("<option></option>").attr("value",i).text("Channel #" + i)); $("<option></option>").attr("value",i).text("Channel #" + i));
} }
// add brightness template
var template = $("#brightnessTemplate").children();
var line = $(template).clone();
line.appendTo("#channels");
// init bright slider
$("#brightness").on("change", function() {
var value = $(this).val();
var parent = $(this).parents(".pure-g");
$("span", parent).html(value);
sendAction("brightness", {value: value});
});
} }
<!-- endRemoveIf(!light)--> <!-- endRemoveIf(!light)-->
@ -1180,13 +1170,13 @@ function processData(data) {
<!-- removeIf(!light)--> <!-- removeIf(!light)-->
if ("rgb" === key) { if ("rgb" === key) {
initColorRGB();
initColor(true);
$("input[name='color']").wheelColorPicker("setValue", value, true); $("input[name='color']").wheelColorPicker("setValue", value, true);
return; return;
} }
if ("hsv" === key) { if ("hsv" === key) {
initColorHSV();
initColor(false);
// wheelColorPicker expects HSV to be between 0 and 1 all of them // wheelColorPicker expects HSV to be between 0 and 1 all of them
var chunks = value.split(","); var chunks = value.split(",");
var obj = {}; var obj = {};


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

@ -1530,12 +1530,15 @@
<!-- endRemoveIf(!sensor) --> <!-- endRemoveIf(!sensor) -->
<!-- removeIf(!light) --> <!-- removeIf(!light) -->
<div id="colorRGBTemplate" class="template">
<div id="colorTemplate" class="template">
<div class="pure-g"> <div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">Color</label> <label class="pure-u-1 pure-u-lg-1-4">Color</label>
<input class="pure-u-1 pure-u-lg-1-4" data-wcp-layout="block" name="color" readonly /> <input class="pure-u-1 pure-u-lg-1-4" data-wcp-layout="block" name="color" readonly />
</div> </div>
</div>
<div id="brightnessTemplate" class="template">
<div class="pure-g"> <div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">Brightness</label> <label class="pure-u-1 pure-u-lg-1-4">Brightness</label>
<input type="range" min="0" max="255" class="slider pure-u-lg-1-4" id="brightness"> <input type="range" min="0" max="255" class="slider pure-u-lg-1-4" id="brightness">
@ -1543,13 +1546,6 @@
</div> </div>
</div> </div>
<div id="colorHSVTemplate" class="template">
<div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">Color</label>
<input class="pure-u-1 pure-u-lg-1-4" data-wcp-layout="block" name="color" readonly />
</div>
</div>
<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-lg-1-4">Channel #</label> <label class="pure-u-1 pure-u-lg-1-4">Channel #</label>


Loading…
Cancel
Save