mirror of https://github.com/arendst/Tasmota.git
Fix Color3 and Color4
Fix Color3 and Color4 and add more strict syntax check (#1019)
This commit is contained in:
parent
1296432da2
commit
e7c0bb01b9
|
@ -607,29 +607,30 @@ void LightSetHsb(float hue, float sat, float bri, uint16_t ct)
|
||||||
|
|
||||||
boolean LightColorEntry(char *buffer, uint8_t buffer_length)
|
boolean LightColorEntry(char *buffer, uint8_t buffer_length)
|
||||||
{
|
{
|
||||||
uint8_t entry_type = 0; // Decimal
|
|
||||||
char scolor[10];
|
char scolor[10];
|
||||||
char *p;
|
char *p;
|
||||||
char *str;
|
char *str;
|
||||||
|
uint8_t entry_type = 0; // Invalid
|
||||||
|
|
||||||
if (buffer[0] == '#') { // Optional hexadecimal entry
|
if (buffer[0] == '#') { // Optional hexadecimal entry
|
||||||
buffer++;
|
buffer++;
|
||||||
buffer_length--;
|
buffer_length--;
|
||||||
}
|
}
|
||||||
uint8_t size = (light_subtype > sizeof(light_entry_color)) ? sizeof(light_entry_color) : light_subtype;
|
if (strstr(buffer, ",")) { // Decimal entry
|
||||||
if (strstr(buffer, ",")) { // Decimal entry
|
|
||||||
int8_t i = 0;
|
int8_t i = 0;
|
||||||
for (str = strtok_r(buffer, ",", &p); str && i < size; str = strtok_r(NULL, ",", &p)) {
|
for (str = strtok_r(buffer, ",", &p); str && i < 6; str = strtok_r(NULL, ",", &p)) {
|
||||||
light_entry_color[i++] = atoi(str);
|
if (i < 5) {
|
||||||
|
light_entry_color[i++] = atoi(str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
entry_type = (size == i) ? 2 : 0; // Decimal
|
entry_type = (light_subtype == i) ? 2 : 0; // Decimal
|
||||||
}
|
}
|
||||||
else if ((2 * size) == buffer_length) { // Hexadecimal entry
|
else if ((2 * light_subtype) == buffer_length) { // Hexadecimal entry
|
||||||
for (byte i = 0; i < size; i++) {
|
for (byte i = 0; i < light_subtype; i++) {
|
||||||
strlcpy(scolor, buffer + (i *2), 3);
|
strlcpy(scolor, buffer + (i *2), 3);
|
||||||
light_entry_color[i] = (uint8_t)strtol(scolor, &p, 16);
|
light_entry_color[i] = (uint8_t)strtol(scolor, &p, 16);
|
||||||
}
|
}
|
||||||
entry_type = 1; // Hexadecimal
|
entry_type = 1; // Hexadecimal
|
||||||
}
|
}
|
||||||
if (entry_type) {
|
if (entry_type) {
|
||||||
Settings.flag.decimal_text = entry_type -1;
|
Settings.flag.decimal_text = entry_type -1;
|
||||||
|
@ -644,16 +645,21 @@ boolean LightCommand(char *type, uint16_t index, char *dataBuf, uint16_t data_le
|
||||||
boolean valid_entry = false;
|
boolean valid_entry = false;
|
||||||
char scolor[25];
|
char scolor[25];
|
||||||
|
|
||||||
if ((light_subtype > 1) && !strcasecmp_P(type, PSTR(D_CMND_COLOR)) && (index > 0) && (index <= 5)) {
|
if ((light_subtype > 1) && !strcasecmp_P(type, PSTR(D_CMND_COLOR)) && (index > 0) && (index <= 4)) {
|
||||||
if (data_len > 0) {
|
if (data_len > 0) {
|
||||||
valid_entry = LightColorEntry(dataBuf, data_len);
|
valid_entry = LightColorEntry(dataBuf, data_len);
|
||||||
if (valid_entry) {
|
if (valid_entry) {
|
||||||
if (1 == index) {
|
if (1 == index) { // Color(1)
|
||||||
|
// for (byte i = 0; i < light_subtype; i++) {
|
||||||
|
// light_current_color[i] = light_entry_color[i];
|
||||||
|
// }
|
||||||
memcpy(light_current_color, light_entry_color, sizeof(light_current_color));
|
memcpy(light_current_color, light_entry_color, sizeof(light_current_color));
|
||||||
LightSetColor();
|
LightSetColor();
|
||||||
coldim = true;
|
coldim = true;
|
||||||
} else {
|
} else { // Color2, 3 and 4
|
||||||
memcpy(Settings.ws_color + 3*(index -2), light_entry_color, 3);
|
for (byte i = 0; i < 3; i++) {
|
||||||
|
Settings.ws_color[index -2][i] = light_entry_color[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue