mirror of https://github.com/arendst/Tasmota.git
Merge pull request #8166 from pcdiem/light-palette-1
Fix Color<1,2> <index> with palette
This commit is contained in:
commit
5d3736913b
|
@ -437,7 +437,7 @@
|
||||||
#define USE_SM2135 // Add support for SM2135 RGBCW led control as used in Action LSC (+0k6 code)
|
#define USE_SM2135 // Add support for SM2135 RGBCW led control as used in Action LSC (+0k6 code)
|
||||||
#define USE_SONOFF_L1 // Add support for Sonoff L1 led control
|
#define USE_SONOFF_L1 // Add support for Sonoff L1 led control
|
||||||
#define USE_ELECTRIQ_MOODL // Add support for ElectriQ iQ-wifiMOODL RGBW LED controller (+0k3 code)
|
#define USE_ELECTRIQ_MOODL // Add support for ElectriQ iQ-wifiMOODL RGBW LED controller (+0k3 code)
|
||||||
#define USE_LIGHT_PALETTE // Add support for color palette (+0k9 code)
|
#define USE_LIGHT_PALETTE // Add support for color palette (+0k7 code)
|
||||||
|
|
||||||
// -- Counter input -------------------------------
|
// -- Counter input -------------------------------
|
||||||
#define USE_COUNTER // Enable inputs as counter (+0k8 code)
|
#define USE_COUNTER // Enable inputs as counter (+0k8 code)
|
||||||
|
|
|
@ -1694,7 +1694,8 @@ void LightCycleColor(int8_t direction)
|
||||||
else {
|
else {
|
||||||
Light.wheel += direction;
|
Light.wheel += direction;
|
||||||
if (Light.wheel >= Light.palette_count) {
|
if (Light.wheel >= Light.palette_count) {
|
||||||
Light.wheel = (direction < 0 ? Light.palette_count - 1 : 0);
|
Light.wheel = 0;
|
||||||
|
if (direction < 0) Light.wheel = Light.palette_count - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LightSetPaletteEntry();
|
LightSetPaletteEntry();
|
||||||
|
@ -2267,13 +2268,16 @@ void LightHandleDevGroupItem(void)
|
||||||
break;
|
break;
|
||||||
case DGR_ITEM_LIGHT_FIXED_COLOR:
|
case DGR_ITEM_LIGHT_FIXED_COLOR:
|
||||||
if (Light.subtype >= LST_RGBW) {
|
if (Light.subtype >= LST_RGBW) {
|
||||||
|
send_state = true;
|
||||||
#ifdef USE_LIGHT_PALETTE
|
#ifdef USE_LIGHT_PALETTE
|
||||||
value = value % (Light.palette_count ? Light.palette_count : MAX_FIXED_COLOR);
|
if (Light.palette_count) {
|
||||||
if (Light.palette_count || value) {
|
Light.wheel = value % Light.palette_count;
|
||||||
#else // USE_LIGHT_PALETTE
|
LightSetPaletteEntry();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif // !USE_LIGHT_PALETTE
|
||||||
value = value % MAX_FIXED_COLOR;
|
value = value % MAX_FIXED_COLOR;
|
||||||
if (value) {
|
if (value) {
|
||||||
#endif // !USE_LIGHT_PALETTE
|
|
||||||
bool save_decimal_text = Settings.flag.decimal_text;
|
bool save_decimal_text = Settings.flag.decimal_text;
|
||||||
char str[16];
|
char str[16];
|
||||||
LightColorEntry(str, sprintf_P(str, PSTR("%u"), value));
|
LightColorEntry(str, sprintf_P(str, PSTR("%u"), value));
|
||||||
|
@ -2292,7 +2296,6 @@ void LightHandleDevGroupItem(void)
|
||||||
Light.power = 0xff;
|
Light.power = 0xff;
|
||||||
restore_power = true;
|
restore_power = true;
|
||||||
}
|
}
|
||||||
send_state = true;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DGR_ITEM_LIGHT_FADE:
|
case DGR_ITEM_LIGHT_FADE:
|
||||||
|
@ -2338,6 +2341,9 @@ bool LightColorEntry(char *buffer, uint32_t buffer_length)
|
||||||
char *str;
|
char *str;
|
||||||
uint32_t entry_type = 0; // Invalid
|
uint32_t entry_type = 0; // Invalid
|
||||||
uint8_t value = Light.fixed_color_index;
|
uint8_t value = Light.fixed_color_index;
|
||||||
|
#ifdef USE_LIGHT_PALETTE
|
||||||
|
if (Light.palette_count) value = Light.wheel;
|
||||||
|
#endif // USE_LIGHT_PALETTE
|
||||||
|
|
||||||
if (buffer[0] == '#') { // Optional hexadecimal entry
|
if (buffer[0] == '#') { // Optional hexadecimal entry
|
||||||
buffer++;
|
buffer++;
|
||||||
|
@ -2346,14 +2352,32 @@ bool LightColorEntry(char *buffer, uint32_t buffer_length)
|
||||||
|
|
||||||
if (Light.subtype >= LST_RGB) {
|
if (Light.subtype >= LST_RGB) {
|
||||||
char option = (1 == buffer_length) ? buffer[0] : '\0';
|
char option = (1 == buffer_length) ? buffer[0] : '\0';
|
||||||
if (('+' == option) && (Light.fixed_color_index < MAX_FIXED_COLOR)) {
|
if ('+' == option) {
|
||||||
value++;
|
#ifdef USE_LIGHT_PALETTE
|
||||||
|
if (Light.palette_count || Light.fixed_color_index < MAX_FIXED_COLOR) {
|
||||||
|
#else // USE_LIGHT_PALETTE
|
||||||
|
if (Light.fixed_color_index < MAX_FIXED_COLOR) {
|
||||||
|
#endif // !USE_LIGHT_PALETTE
|
||||||
|
value++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (('-' == option) && (Light.fixed_color_index > 1)) {
|
else if ('-' == option) {
|
||||||
value--;
|
#ifdef USE_LIGHT_PALETTE
|
||||||
|
if (Light.palette_count || Light.fixed_color_index > 1) {
|
||||||
|
#else // USE_LIGHT_PALETTE
|
||||||
|
if (Light.fixed_color_index > 1) {
|
||||||
|
#endif // !USE_LIGHT_PALETTE
|
||||||
|
value--;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
value = atoi(buffer);
|
value = atoi(buffer);
|
||||||
|
#ifdef USE_LIGHT_PALETTE
|
||||||
|
value--;
|
||||||
|
#endif // USE_LIGHT_PALETTE
|
||||||
}
|
}
|
||||||
|
#ifdef USE_LIGHT_PALETTE
|
||||||
|
if (Light.palette_count) value = value % Light.palette_count;
|
||||||
|
#endif // USE_LIGHT_PALETTE
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&Light.entry_color, 0x00, sizeof(Light.entry_color));
|
memset(&Light.entry_color, 0x00, sizeof(Light.entry_color));
|
||||||
|
@ -2378,6 +2402,13 @@ bool LightColorEntry(char *buffer, uint32_t buffer_length)
|
||||||
}
|
}
|
||||||
entry_type = 1; // Hexadecimal
|
entry_type = 1; // Hexadecimal
|
||||||
}
|
}
|
||||||
|
#ifdef USE_LIGHT_PALETTE
|
||||||
|
else if (Light.palette_count) {
|
||||||
|
Light.wheel = value;
|
||||||
|
memcpy_P(&Light.entry_color, &Light.palette[value * LST_MAX], LST_MAX);
|
||||||
|
entry_type = 1; // Hexadecimal
|
||||||
|
}
|
||||||
|
#endif // USE_LIGHT_PALETTE
|
||||||
else if ((Light.subtype >= LST_RGB) && (value > 0) && (value <= MAX_FIXED_COLOR)) {
|
else if ((Light.subtype >= LST_RGB) && (value > 0) && (value <= MAX_FIXED_COLOR)) {
|
||||||
Light.fixed_color_index = value;
|
Light.fixed_color_index = value;
|
||||||
memcpy_P(&Light.entry_color, &kFixedColor[value -1], 3);
|
memcpy_P(&Light.entry_color, &kFixedColor[value -1], 3);
|
||||||
|
@ -2409,48 +2440,20 @@ void CmndSupportColor(void)
|
||||||
{
|
{
|
||||||
bool valid_entry = false;
|
bool valid_entry = false;
|
||||||
bool coldim = false;
|
bool coldim = false;
|
||||||
#ifdef USE_LIGHT_PALETTE
|
|
||||||
uint8_t * color_ptr;
|
|
||||||
#endif // USE_LIGHT_PALETTE
|
|
||||||
|
|
||||||
if (XdrvMailbox.data_len > 0) {
|
if (XdrvMailbox.data_len > 0) {
|
||||||
#ifdef USE_LIGHT_PALETTE
|
valid_entry = LightColorEntry(XdrvMailbox.data, XdrvMailbox.data_len);
|
||||||
if (Light.palette_count) {
|
|
||||||
if (XdrvMailbox.data_len == 1 && ('+' == XdrvMailbox.data[0] || '-' == XdrvMailbox.data[0])) {
|
|
||||||
int8_t direction = ('+' == XdrvMailbox.data[0] ? 1 : -1);
|
|
||||||
Light.wheel += direction;
|
|
||||||
if (Light.wheel >= Light.palette_count) {
|
|
||||||
Light.wheel = (direction < 0 ? Light.palette_count - 1 : 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Light.wheel = (atoi(XdrvMailbox.data) - 1);
|
|
||||||
}
|
|
||||||
color_ptr = &Light.palette[Light.wheel * LST_MAX];
|
|
||||||
valid_entry = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
color_ptr = Light.entry_color;
|
|
||||||
#endif // USE_LIGHT_PALETTE
|
|
||||||
valid_entry = LightColorEntry(XdrvMailbox.data, XdrvMailbox.data_len);
|
|
||||||
#ifdef USE_LIGHT_PALETTE
|
|
||||||
}
|
|
||||||
#endif // USE_LIGHT_PALETTE
|
|
||||||
if (valid_entry) {
|
if (valid_entry) {
|
||||||
if (XdrvMailbox.index <= 2) { // Color(1), 2
|
if (XdrvMailbox.index <= 2) { // Color(1), 2
|
||||||
#ifdef USE_LIGHT_PALETTE
|
#ifdef USE_LIGHT_PALETTE
|
||||||
if (Light.palette_count && XdrvMailbox.index == 1) {
|
if (Light.palette_count && XdrvMailbox.index == 2) {
|
||||||
LightSetPaletteEntry();
|
LightSetPaletteEntry();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#endif // USE_LIGHT_PALETTE
|
#endif // USE_LIGHT_PALETTE
|
||||||
uint32_t old_bri = light_state.getBri();
|
uint32_t old_bri = light_state.getBri();
|
||||||
// change all channels to specified values
|
// change all channels to specified values
|
||||||
#ifdef USE_LIGHT_PALETTE
|
|
||||||
light_controller.changeChannels(color_ptr);
|
|
||||||
#else // USE_LIGHT_PALETTE
|
|
||||||
light_controller.changeChannels(Light.entry_color);
|
light_controller.changeChannels(Light.entry_color);
|
||||||
#endif // !USE_LIGHT_PALETTE
|
|
||||||
if (2 == XdrvMailbox.index) {
|
if (2 == XdrvMailbox.index) {
|
||||||
// If Color2, set back old brightness
|
// If Color2, set back old brightness
|
||||||
light_controller.changeBri(old_bri);
|
light_controller.changeBri(old_bri);
|
||||||
|
@ -2626,6 +2629,9 @@ void CmndScheme(void)
|
||||||
uint32_t parm[2];
|
uint32_t parm[2];
|
||||||
if (ParseParameters(2, parm) > 1) {
|
if (ParseParameters(2, parm) > 1) {
|
||||||
Light.wheel = parm[1];
|
Light.wheel = parm[1];
|
||||||
|
#ifdef USE_LIGHT_PALETTE
|
||||||
|
Light.wheel--;
|
||||||
|
#endif // USE_LIGHT_PALETTE
|
||||||
}
|
}
|
||||||
Settings.light_scheme = XdrvMailbox.payload;
|
Settings.light_scheme = XdrvMailbox.payload;
|
||||||
#ifdef USE_DEVICE_GROUPS
|
#ifdef USE_DEVICE_GROUPS
|
||||||
|
@ -2873,71 +2879,52 @@ void CmndWakeupDuration(void)
|
||||||
void CmndPalette(void)
|
void CmndPalette(void)
|
||||||
{
|
{
|
||||||
uint8_t * palette_entry;
|
uint8_t * palette_entry;
|
||||||
char * color;
|
|
||||||
char * p;
|
char * p;
|
||||||
|
|
||||||
// Palette Color[ ...]
|
// Palette Color[ ...]
|
||||||
if (XdrvMailbox.data_len) {
|
if (XdrvMailbox.data_len) {
|
||||||
Light.wheel = 0;
|
Light.wheel = 0;
|
||||||
|
Light.palette_count = 0;
|
||||||
if (Light.palette) {
|
if (Light.palette) {
|
||||||
free(Light.palette);
|
free(Light.palette);
|
||||||
Light.palette = nullptr;
|
Light.palette = nullptr;
|
||||||
Light.palette_count = 0;
|
|
||||||
}
|
}
|
||||||
if (XdrvMailbox.data_len > 1 || XdrvMailbox.data[0] != '0') {
|
if (XdrvMailbox.data_len > 1 || XdrvMailbox.data[0] != '0') {
|
||||||
for (int pass = 0;; pass++) {
|
uint8_t palette_count = 0;
|
||||||
Light.palette_count = 0;
|
char * color = XdrvMailbox.data;
|
||||||
color = XdrvMailbox.data;
|
if (!(Light.palette = (uint8_t *)malloc(255 * Light.subtype))) return;
|
||||||
for (;;) {
|
palette_entry = Light.palette;
|
||||||
p = strchr(color, ' ');
|
for (;;) {
|
||||||
if (p) *p = 0;
|
p = strchr(color, ' ');
|
||||||
color = Trim(color);
|
if (p) *p = 0;
|
||||||
if (*color && LightColorEntry(color, strlen(color))) {
|
color = Trim(color);
|
||||||
if (pass) {
|
if (*color && LightColorEntry(color, strlen(color))) {
|
||||||
memcpy(palette_entry, Light.entry_color, LST_MAX);
|
memcpy(palette_entry, Light.entry_color, Light.subtype);
|
||||||
if (!Light.pwm_multi_channels && LST_COLDWARM == Light.subtype) {
|
palette_entry += Light.subtype;
|
||||||
palette_entry[3] = palette_entry[0];
|
palette_count++;
|
||||||
palette_entry[4] = palette_entry[1];
|
|
||||||
}
|
|
||||||
palette_entry += LST_MAX;
|
|
||||||
}
|
|
||||||
Light.palette_count++;
|
|
||||||
}
|
|
||||||
if (!p) break;
|
|
||||||
*p = ' ';
|
|
||||||
color = p + 1;
|
|
||||||
}
|
}
|
||||||
if (pass) break;
|
if (!p) break;
|
||||||
if (!(Light.palette = (uint8_t *)malloc(Light.palette_count * LST_MAX))) return;
|
color = p + 1;
|
||||||
palette_entry = Light.palette;
|
|
||||||
}
|
}
|
||||||
|
if (!(Light.palette = (uint8_t *)realloc(Light.palette, palette_count * Light.subtype))) return;
|
||||||
|
Light.palette_count = palette_count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char palette_str[5 * Light.subtype * Light.palette_count + 3];
|
char palette_str[5 * Light.subtype * Light.palette_count + 3];
|
||||||
const char * fmt;
|
|
||||||
p = palette_str;
|
p = palette_str;
|
||||||
*p++ = '[';
|
*p++ = '[';
|
||||||
if (Light.palette_count) {
|
if (Light.palette_count) {
|
||||||
palette_entry = Light.palette;
|
palette_entry = Light.palette;
|
||||||
if (Settings.flag.decimal_text) { // SetOption17 - Switch between decimal or hexadecimal output
|
for (int entry = 0; entry < Light.palette_count; entry++) {
|
||||||
for (int entry = 0; entry < Light.palette_count; entry++) {
|
if (Settings.flag.decimal_text) { // SetOption17 - Switch between decimal or hexadecimal output
|
||||||
*p++ = '"';
|
*p++ = '"';
|
||||||
for (uint32_t i = 0; i < Light.subtype; i++) {
|
|
||||||
if (i > 0) *p++ = ',';
|
|
||||||
p += sprintf_P(p, PSTR("%d"), palette_entry[i]);
|
|
||||||
}
|
|
||||||
palette_entry += LST_MAX;
|
|
||||||
}
|
}
|
||||||
*p++ = '"';
|
memcpy(Light.current_color, palette_entry, Light.subtype);
|
||||||
*p++ = ',';
|
LightGetColor(p);
|
||||||
}
|
p += strlen(p);
|
||||||
else {
|
if (Settings.flag.decimal_text) { // SetOption17 - Switch between decimal or hexadecimal output
|
||||||
for (int entry = 0; entry < Light.palette_count; entry++) {
|
*p++ = '"';
|
||||||
for (uint32_t i = 0; i < Light.subtype; i++) {
|
|
||||||
p += sprintf_P(p, PSTR("%02X"), palette_entry[i]);
|
|
||||||
}
|
|
||||||
palette_entry += LST_MAX;
|
|
||||||
}
|
}
|
||||||
*p++ = ',';
|
*p++ = ',';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue