From bf8a8c621e04b07f589b0091c90d94bf52523d0b Mon Sep 17 00:00:00 2001 From: kruzer Date: Mon, 1 Nov 2021 12:31:08 +0100 Subject: [PATCH 1/6] added config variable StepPixels --- tasmota/i18n.h | 1 + tasmota/settings.h | 3 ++- tasmota/xlgt_01_ws2812.ino | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 9c8aed881..73d8ade89 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -477,6 +477,7 @@ #define D_CMND_FADE "Fade" #define D_CMND_PALETTE "Palette" #define D_CMND_PIXELS "Pixels" +#define D_CMND_STEPPIXELS "StepPixels" #define D_CMND_RGBWWTABLE "RGBWWTable" #define D_CMND_ROTATION "Rotation" #define D_CMND_SCHEME "Scheme" diff --git a/tasmota/settings.h b/tasmota/settings.h index 4e41c5916..8c903d6a4 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -733,8 +733,9 @@ typedef struct { uint8_t shd_leading_edge; // F5B uint16_t shd_warmup_brightness; // F5C uint8_t shd_warmup_time; // F5E + uint8_t light_step_pixels; // F5F - uint8_t free_f5f[61]; // F5F - Decrement if adding new Setting variables just above and below + uint8_t free_f5f[60]; // F60 - Decrement if adding new Setting variables just above and below // Only 32 bit boundary variables below diff --git a/tasmota/xlgt_01_ws2812.ino b/tasmota/xlgt_01_ws2812.ino index a7e7c9927..89e8dc66c 100644 --- a/tasmota/xlgt_01_ws2812.ino +++ b/tasmota/xlgt_01_ws2812.ino @@ -40,10 +40,10 @@ const uint8_t WS2812_SCHEMES = 8; // Number of WS2812 schemes const char kWs2812Commands[] PROGMEM = "|" // No prefix - D_CMND_LED "|" D_CMND_PIXELS "|" D_CMND_ROTATION "|" D_CMND_WIDTH ; + D_CMND_LED "|" D_CMND_PIXELS "|" D_CMND_ROTATION "|" D_CMND_WIDTH "|" D_CMND_STEPPIXELS ; void (* const Ws2812Command[])(void) PROGMEM = { - &CmndLed, &CmndPixels, &CmndRotation, &CmndWidth }; + &CmndLed, &CmndPixels, &CmndRotation, &CmndWidth, &CmndStepPixels }; #include @@ -568,6 +568,17 @@ void CmndPixels(void) ResponseCmndNumber(Settings->light_pixels); } +void CmndStepPixels(void) +{ + if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= WS2812_MAX_LEDS)) { + Settings->light_step_pixels = XdrvMailbox.payload; + Ws2812Clear(); + Light.update = true; + } + ResponseCmndNumber(Settings->light_step_pixels); +} + + void CmndRotation(void) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < Settings->light_pixels)) { From 42267c2bd9685cadf014910c5b02a1e83f5f5453 Mon Sep 17 00:00:00 2001 From: kruzer Date: Wed, 3 Nov 2021 00:03:06 +0100 Subject: [PATCH 2/6] Working effects of gradual highligting based on scheme 13, bitwise rotation settings, fade effect --- tasmota/xlgt_01_ws2812.ino | 118 +++++++++++++++++++++++++++++++++++-- 1 file changed, 112 insertions(+), 6 deletions(-) diff --git a/tasmota/xlgt_01_ws2812.ino b/tasmota/xlgt_01_ws2812.ino index 89e8dc66c..dd91ebe5d 100644 --- a/tasmota/xlgt_01_ws2812.ino +++ b/tasmota/xlgt_01_ws2812.ino @@ -37,7 +37,7 @@ #define XLGT_01 1 -const uint8_t WS2812_SCHEMES = 8; // Number of WS2812 schemes +const uint8_t WS2812_SCHEMES = 9; // Number of WS2812 schemes const char kWs2812Commands[] PROGMEM = "|" // No prefix D_CMND_LED "|" D_CMND_PIXELS "|" D_CMND_ROTATION "|" D_CMND_WIDTH "|" D_CMND_STEPPIXELS ; @@ -166,6 +166,7 @@ WsColor kHanukkah[2] = { 0,0,255, 255,255,255 }; WsColor kwanzaa[3] = { 255,0,0, 0,0,0, 0,255,0 }; WsColor kRainbow[7] = { 255,0,0, 255,128,0, 255,255,0, 0,255,0, 0,0,255, 128,0,255, 255,0,255 }; WsColor kFire[3] = { 255,0,0, 255,102,0, 255,192,0 }; +WsColor kStairs[2] = { 0,0,0, 255,255,255 }; ColorScheme kSchemes[WS2812_SCHEMES -1] = { // Skip clock scheme kIncandescent, 2, kRgb, 3, @@ -173,7 +174,8 @@ ColorScheme kSchemes[WS2812_SCHEMES -1] = { // Skip clock scheme kHanukkah, 2, kwanzaa, 3, kRainbow, 7, - kFire, 3 }; + kFire, 3, + kStairs, 2 }; uint8_t kWidth[5] = { 1, // Small @@ -399,6 +401,106 @@ void Ws2812Bars(uint32_t schemenr) Ws2812StripShow(); } +void Ws2812Steps(uint32_t schemenr) +{ +#if (USE_WS2812_CTYPE > NEO_3LED) + RgbwColor c; + c.W = 0; +#else + RgbColor c; +#endif + + ColorScheme scheme = kSchemes[schemenr]; + if(0==scheme.colors[0].blue && 0==scheme.colors[0].red && 0==scheme.colors[0].green && scheme.count==2){ + scheme.colors[1].red = Settings->light_color[0]; + scheme.colors[1].green = Settings->light_color[1]; + scheme.colors[1].blue = Settings->light_color[2]; + } + uint8_t scheme_count=scheme.count; + + if(Settings->light_fade){ + scheme_count=Settings->ws_width[WS_HOUR];//Width4 + } + + WsColor mcolor[scheme_count]; + uint8_t color_start=0; + uint8_t color_end=1; + + if(Settings->light_rotation & 0x01){ + color_start=1; + color_end=0; + } + + if(Settings->light_fade){ + + for(uint32_t i=1; i < scheme_count - 1; i++){ + mcolor[i].red = (uint8_t) wsmap(i, 0, scheme_count, scheme.colors[color_start].red, scheme.colors[color_end].red); + mcolor[i].green = (uint8_t) wsmap(i, 0, scheme_count, scheme.colors[color_start].green, scheme.colors[color_end].green); + mcolor[i].blue = (uint8_t) wsmap(i, 0, scheme_count, scheme.colors[color_start].blue, scheme.colors[color_end].blue); + } + } else { + memcpy(mcolor, scheme.colors, sizeof(mcolor)); + } + mcolor[0].red=scheme.colors[color_start].red; + mcolor[0].green=scheme.colors[color_start].green; + mcolor[0].blue=scheme.colors[color_start].blue; + mcolor[scheme_count-1].red=scheme.colors[color_end].red; + mcolor[scheme_count-1].green=scheme.colors[color_end].green; + mcolor[scheme_count-1].blue=scheme.colors[color_end].blue; + + + float dimmer = 100 / (float)Settings->light_dimmer; + for (uint32_t i = 0; i < scheme_count; i++) { + float fmyRed = (float)mcolor[i].red / dimmer; + float fmyGrn = (float)mcolor[i].green / dimmer; + float fmyBlu = (float)mcolor[i].blue / dimmer; + mcolor[i].red = (uint8_t)fmyRed; + mcolor[i].green = (uint8_t)fmyGrn; + mcolor[i].blue = (uint8_t)fmyBlu; + } + + uint32_t speed = Settings->light_speed; + int32_t current_position = Light.strip_timer_counter / speed; + + //all is shown already + if(current_position > Settings->light_pixels / Settings->light_step_pixels + scheme_count ) { +// AddLog(LOG_LEVEL_INFO, PSTR("spd:%d cpos:%d tc:%d"), speed,current_position,Light.strip_timer_counter); + return; + } + + int32_t colorIndex; + //int32_t leading_step = current_position / Settings->light_step_pixels; + int32_t step_nr; + /*if( Light.strip_timer_counter % speed == 0){ + AddLog(LOG_LEVEL_INFO, PSTR("spd:%d cpos:%d lead:%d tc:%d"), speed,current_position,leading_step,Light.strip_timer_counter); + }*/ + + for (uint32_t i = 0; i < Settings->light_pixels; i++) { + step_nr = i / Settings->light_step_pixels; + colorIndex = current_position - step_nr; + if(colorIndex < 0) colorIndex = 0; + if(colorIndex > scheme_count - 1) colorIndex = scheme_count - 1; + c.R = mcolor[colorIndex].red; + c.G = mcolor[colorIndex].green; + c.B = mcolor[colorIndex].blue; + if( current_position % 3 == 0){ + //AddLog(LOG_LEVEL_INFO, PSTR("spd:%d cpos:%d lead:%d tc:%d"), speed,current_position,leading_step,Light.strip_timer_counter); + if(i < 15){ + // AddLog(LOG_LEVEL_INFO, PSTR("s_n:%d cidx:%d "), step_nr, colorIndex); + } + } +/* if(i < 2){ + AddLog(LOG_LEVEL_INFO, PSTR("s_n:%d cidx:%d "), step_nr, colorIndex); + }*/ + if(Settings->light_rotation & 0x02){ + strip->SetPixelColor(Settings->light_pixels - i - 1, c); + } else { + strip->SetPixelColor(i, c); + } + } + Ws2812StripShow(); +} + void Ws2812Clear(void) { strip->ClearTo(0); @@ -496,10 +598,14 @@ void Ws2812ShowScheme(void) } break; default: - if (1 == Settings->light_fade) { - Ws2812Gradient(scheme -1); - } else { - Ws2812Bars(scheme -1); + if(Settings->light_step_pixels > 0){ + Ws2812Steps(scheme -1); + } else { + if (1 == Settings->light_fade) { + Ws2812Gradient(scheme -1); + } else { + Ws2812Bars(scheme -1); + } } Ws2812.show_next = 1; break; From 08d8fef3c83e7f821badb592300eb071f3b7e4b7 Mon Sep 17 00:00:00 2001 From: kruzer Date: Sat, 6 Nov 2021 23:45:34 +0100 Subject: [PATCH 3/6] Merge settings --- tasmota/settings.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/settings.h b/tasmota/settings.h index 45e3671e4..1bb1c51b4 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -736,7 +736,7 @@ typedef struct { uint8_t tcp_config; // F5F uint8_t light_step_pixels; // F60 - uint8_t free_f60[5f]; // F61 - Decrement if adding new Setting variables just above and below + uint8_t free_f60[59]; // F61 - Decrement if adding new Setting variables just above and below // Only 32 bit boundary variables below From 759cc60489fdfa55eb39121995aff7711d02fd4e Mon Sep 17 00:00:00 2001 From: kruzer Date: Sat, 6 Nov 2021 23:48:15 +0100 Subject: [PATCH 4/6] fixed settings --- tasmota/settings.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/settings.h b/tasmota/settings.h index 1bb1c51b4..eba5ef88f 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -736,7 +736,7 @@ typedef struct { uint8_t tcp_config; // F5F uint8_t light_step_pixels; // F60 - uint8_t free_f60[59]; // F61 - Decrement if adding new Setting variables just above and below + uint8_t free_f59[59]; // F61 - Decrement if adding new Setting variables just above and below // Only 32 bit boundary variables below From ccd24754d36cd5757c4a92681b600037520f7b56 Mon Sep 17 00:00:00 2001 From: kruzer Date: Sun, 7 Nov 2021 02:40:52 +0100 Subject: [PATCH 5/6] code cleaning --- tasmota/xlgt_01_ws2812.ino | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/tasmota/xlgt_01_ws2812.ino b/tasmota/xlgt_01_ws2812.ino index dd91ebe5d..f47fe531f 100644 --- a/tasmota/xlgt_01_ws2812.ino +++ b/tasmota/xlgt_01_ws2812.ino @@ -462,18 +462,13 @@ void Ws2812Steps(uint32_t schemenr) uint32_t speed = Settings->light_speed; int32_t current_position = Light.strip_timer_counter / speed; - //all is shown already + //all pixels are shown already if(current_position > Settings->light_pixels / Settings->light_step_pixels + scheme_count ) { -// AddLog(LOG_LEVEL_INFO, PSTR("spd:%d cpos:%d tc:%d"), speed,current_position,Light.strip_timer_counter); return; } int32_t colorIndex; - //int32_t leading_step = current_position / Settings->light_step_pixels; int32_t step_nr; - /*if( Light.strip_timer_counter % speed == 0){ - AddLog(LOG_LEVEL_INFO, PSTR("spd:%d cpos:%d lead:%d tc:%d"), speed,current_position,leading_step,Light.strip_timer_counter); - }*/ for (uint32_t i = 0; i < Settings->light_pixels; i++) { step_nr = i / Settings->light_step_pixels; @@ -483,15 +478,6 @@ void Ws2812Steps(uint32_t schemenr) c.R = mcolor[colorIndex].red; c.G = mcolor[colorIndex].green; c.B = mcolor[colorIndex].blue; - if( current_position % 3 == 0){ - //AddLog(LOG_LEVEL_INFO, PSTR("spd:%d cpos:%d lead:%d tc:%d"), speed,current_position,leading_step,Light.strip_timer_counter); - if(i < 15){ - // AddLog(LOG_LEVEL_INFO, PSTR("s_n:%d cidx:%d "), step_nr, colorIndex); - } - } -/* if(i < 2){ - AddLog(LOG_LEVEL_INFO, PSTR("s_n:%d cidx:%d "), step_nr, colorIndex); - }*/ if(Settings->light_rotation & 0x02){ strip->SetPixelColor(Settings->light_pixels - i - 1, c); } else { From ab2438e9a325628ee15ce5ba72dc43d758b677fd Mon Sep 17 00:00:00 2001 From: kruzer Date: Sun, 7 Nov 2021 11:58:46 +0100 Subject: [PATCH 6/6] Added some comments --- tasmota/xlgt_01_ws2812.ino | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tasmota/xlgt_01_ws2812.ino b/tasmota/xlgt_01_ws2812.ino index f47fe531f..e0030dcb8 100644 --- a/tasmota/xlgt_01_ws2812.ino +++ b/tasmota/xlgt_01_ws2812.ino @@ -411,7 +411,8 @@ void Ws2812Steps(uint32_t schemenr) #endif ColorScheme scheme = kSchemes[schemenr]; - if(0==scheme.colors[0].blue && 0==scheme.colors[0].red && 0==scheme.colors[0].green && scheme.count==2){ + // apply main color if current sheme == kStairs + if(scheme.colors == kStairs){ scheme.colors[1].red = Settings->light_color[0]; scheme.colors[1].green = Settings->light_color[1]; scheme.colors[1].blue = Settings->light_color[2]; @@ -432,7 +433,7 @@ void Ws2812Steps(uint32_t schemenr) } if(Settings->light_fade){ - + // generate gradient (width = Width4) for(uint32_t i=1; i < scheme_count - 1; i++){ mcolor[i].red = (uint8_t) wsmap(i, 0, scheme_count, scheme.colors[color_start].red, scheme.colors[color_end].red); mcolor[i].green = (uint8_t) wsmap(i, 0, scheme_count, scheme.colors[color_start].green, scheme.colors[color_end].green); @@ -441,6 +442,7 @@ void Ws2812Steps(uint32_t schemenr) } else { memcpy(mcolor, scheme.colors, sizeof(mcolor)); } + // repair first & last color in gradient; apply scheme rotation if fade==0 mcolor[0].red=scheme.colors[color_start].red; mcolor[0].green=scheme.colors[color_start].green; mcolor[0].blue=scheme.colors[color_start].blue; @@ -449,6 +451,7 @@ void Ws2812Steps(uint32_t schemenr) mcolor[scheme_count-1].blue=scheme.colors[color_end].blue; + // Adjust to dimmer value float dimmer = 100 / (float)Settings->light_dimmer; for (uint32_t i = 0; i < scheme_count; i++) { float fmyRed = (float)mcolor[i].red / dimmer; @@ -462,7 +465,7 @@ void Ws2812Steps(uint32_t schemenr) uint32_t speed = Settings->light_speed; int32_t current_position = Light.strip_timer_counter / speed; - //all pixels are shown already + //all pixels are shown already | rotation change will not change current state if(current_position > Settings->light_pixels / Settings->light_step_pixels + scheme_count ) { return; } @@ -478,6 +481,7 @@ void Ws2812Steps(uint32_t schemenr) c.R = mcolor[colorIndex].red; c.G = mcolor[colorIndex].green; c.B = mcolor[colorIndex].blue; + // Adjust the scheme rotation if(Settings->light_rotation & 0x02){ strip->SetPixelColor(Settings->light_pixels - i - 1, c); } else {