From 698c53ffebb0d730502eace449076a93f39a6700 Mon Sep 17 00:00:00 2001 From: Zefiro Date: Tue, 24 Nov 2020 23:56:24 +0100 Subject: [PATCH 1/4] Fixed typos in comments --- tasmota/support_float.ino | 8 ++------ tasmota/xdrv_04_light.ino | 12 ++++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/tasmota/support_float.ino b/tasmota/support_float.ino index e1b97ca89..1e2edc3f2 100644 --- a/tasmota/support_float.ino +++ b/tasmota/support_float.ino @@ -379,7 +379,7 @@ float sqrt1(const float x) // // PRE-CONDITIONS (if not satisfied, you may 'halt and catch fire') // from_min < from_max (not checked) -// from_min <= num <= from-max (chacked) +// from_min <= num <= from_max (checked) // POST-CONDITIONS // to_min <= result <= to_max // @@ -387,11 +387,7 @@ uint16_t changeUIntScale(uint16_t inum, uint16_t ifrom_min, uint16_t ifrom_max, uint16_t ito_min, uint16_t ito_max) { // guard-rails if (ifrom_min >= ifrom_max) { - if (ito_min > ito_max) { - return ito_max; - } else { - return ito_min; // invalid input, return arbitrary value - } + return (ito_min > ito_max ? ito_max : ito_min); // invalid input, return arbitrary value } // convert to uint31, it's more verbose but code is more compact uint32_t num = inum; diff --git a/tasmota/xdrv_04_light.ino b/tasmota/xdrv_04_light.ino index ea01afb28..6841c4c76 100644 --- a/tasmota/xdrv_04_light.ino +++ b/tasmota/xdrv_04_light.ino @@ -93,8 +93,8 @@ * 1 channel - 0:Brightness * 2 channels - 0:Coldwhite 1:Warmwhite * 3 channels - 0:Red 1:Green 2:Blue - * 4 chennels - 0:Red 1:Green 2:Blue 3:White - * 5 chennels - 0:Red 1:Green 2:Blue 3:ColdWhite 4:Warmwhite + * 4 channels - 0:Red 1:Green 2:Blue 3:White + * 5 channels - 0:Red 1:Green 2:Blue 3:ColdWhite 4:Warmwhite * * 3. In LightAnimate(), final PWM values are computed at next tick. * .a If color did not change since last tick - ignore. @@ -357,7 +357,7 @@ static uint32_t min3(uint32_t a, uint32_t b, uint32_t c) { // // Note: If you want the actual RGB, you need to multiply with Bri, or use getActualRGBCW() // Note: all values are stored as unsigned integer, no floats. -// Note: you can query vaules from this singleton. But to change values, +// Note: you can query values from this singleton. But to change values, // use the LightController - changing this object will have no effect on actual light. // class LightStateClass { @@ -1180,7 +1180,7 @@ LightControllerClass light_controller = LightControllerClass(light_state); /*********************************************************************************************\ * Change scales from 8 bits to 10 bits and vice versa \*********************************************************************************************/ -// 8 to 10 to 8 is garanteed to give the same result +// 8 to 10 to 8 is guaranteed to give the same result uint16_t change8to10(uint8_t v) { return changeUIntScale(v, 0, 255, 0, 1023); } @@ -1858,9 +1858,9 @@ void LightAnimate(void) // or set a maximum of PWM_MAX_SLEEP if light is on or Fade is running if (Light.power || Light.fade_running) { if (Settings.sleep > PWM_MAX_SLEEP) { - TasmotaGlobal.sleep = PWM_MAX_SLEEP; // set a maxumum value of 10 milliseconds to ensure that animations are smooth + TasmotaGlobal.sleep = PWM_MAX_SLEEP; // set a maximum value (in milliseconds) to sleep to ensure that animations are smooth } else { - TasmotaGlobal.sleep = Settings.sleep; // or keep the current sleep if it's lower than 50 + TasmotaGlobal.sleep = Settings.sleep; // or keep the current sleep if it's low enough } } else { TasmotaGlobal.sleep = Settings.sleep; From de0e2026a72b0a290e209990f3d3b03cb0fcfca8 Mon Sep 17 00:00:00 2001 From: Zefiro Date: Tue, 24 Nov 2020 23:56:24 +0100 Subject: [PATCH 2/4] Fixed typos in comments --- tasmota/support_float.ino | 8 ++------ tasmota/xdrv_04_light.ino | 12 ++++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/tasmota/support_float.ino b/tasmota/support_float.ino index e1b97ca89..1e2edc3f2 100644 --- a/tasmota/support_float.ino +++ b/tasmota/support_float.ino @@ -379,7 +379,7 @@ float sqrt1(const float x) // // PRE-CONDITIONS (if not satisfied, you may 'halt and catch fire') // from_min < from_max (not checked) -// from_min <= num <= from-max (chacked) +// from_min <= num <= from_max (checked) // POST-CONDITIONS // to_min <= result <= to_max // @@ -387,11 +387,7 @@ uint16_t changeUIntScale(uint16_t inum, uint16_t ifrom_min, uint16_t ifrom_max, uint16_t ito_min, uint16_t ito_max) { // guard-rails if (ifrom_min >= ifrom_max) { - if (ito_min > ito_max) { - return ito_max; - } else { - return ito_min; // invalid input, return arbitrary value - } + return (ito_min > ito_max ? ito_max : ito_min); // invalid input, return arbitrary value } // convert to uint31, it's more verbose but code is more compact uint32_t num = inum; diff --git a/tasmota/xdrv_04_light.ino b/tasmota/xdrv_04_light.ino index ea01afb28..6841c4c76 100644 --- a/tasmota/xdrv_04_light.ino +++ b/tasmota/xdrv_04_light.ino @@ -93,8 +93,8 @@ * 1 channel - 0:Brightness * 2 channels - 0:Coldwhite 1:Warmwhite * 3 channels - 0:Red 1:Green 2:Blue - * 4 chennels - 0:Red 1:Green 2:Blue 3:White - * 5 chennels - 0:Red 1:Green 2:Blue 3:ColdWhite 4:Warmwhite + * 4 channels - 0:Red 1:Green 2:Blue 3:White + * 5 channels - 0:Red 1:Green 2:Blue 3:ColdWhite 4:Warmwhite * * 3. In LightAnimate(), final PWM values are computed at next tick. * .a If color did not change since last tick - ignore. @@ -357,7 +357,7 @@ static uint32_t min3(uint32_t a, uint32_t b, uint32_t c) { // // Note: If you want the actual RGB, you need to multiply with Bri, or use getActualRGBCW() // Note: all values are stored as unsigned integer, no floats. -// Note: you can query vaules from this singleton. But to change values, +// Note: you can query values from this singleton. But to change values, // use the LightController - changing this object will have no effect on actual light. // class LightStateClass { @@ -1180,7 +1180,7 @@ LightControllerClass light_controller = LightControllerClass(light_state); /*********************************************************************************************\ * Change scales from 8 bits to 10 bits and vice versa \*********************************************************************************************/ -// 8 to 10 to 8 is garanteed to give the same result +// 8 to 10 to 8 is guaranteed to give the same result uint16_t change8to10(uint8_t v) { return changeUIntScale(v, 0, 255, 0, 1023); } @@ -1858,9 +1858,9 @@ void LightAnimate(void) // or set a maximum of PWM_MAX_SLEEP if light is on or Fade is running if (Light.power || Light.fade_running) { if (Settings.sleep > PWM_MAX_SLEEP) { - TasmotaGlobal.sleep = PWM_MAX_SLEEP; // set a maxumum value of 10 milliseconds to ensure that animations are smooth + TasmotaGlobal.sleep = PWM_MAX_SLEEP; // set a maximum value (in milliseconds) to sleep to ensure that animations are smooth } else { - TasmotaGlobal.sleep = Settings.sleep; // or keep the current sleep if it's lower than 50 + TasmotaGlobal.sleep = Settings.sleep; // or keep the current sleep if it's low enough } } else { TasmotaGlobal.sleep = Settings.sleep; From 878ce826bf29d526cb688af6570cd5144e9d07cb Mon Sep 17 00:00:00 2001 From: Zefiro Date: Wed, 25 Nov 2020 00:56:30 +0100 Subject: [PATCH 3/4] Neopixel Dragon extension --- platformio.ini | 2 +- tasmota/i18n.h | 1 + tasmota/settings.h | 11 ++- tasmota/xlgt_01_ws2812.ino | 180 ++++++++++++++++++++++++++++++++++++- 4 files changed, 188 insertions(+), 6 deletions(-) diff --git a/platformio.ini b/platformio.ini index 7645a668e..355455232 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,7 +12,7 @@ [build_envs] default_envs = ; *** Uncomment by deleting ";" in the line(s) below to select version(s) -; tasmota + tasmota ; tasmota-ircustom ; tasmota-minimal ; tasmota-lite diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 9a0528c9e..00075016d 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -439,6 +439,7 @@ #define D_CMND_WAKEUPDURATION "WakeUpDuration" #define D_CMND_WHITE "White" #define D_CMND_WIDTH "Width" +#define D_CMND_DRAGON "Dragon" // Commands xdrv_05_irremote.ino #define D_CMND_IRSEND "IRSend" diff --git a/tasmota/settings.h b/tasmota/settings.h index 44a6947a4..e3b3b6f72 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -639,7 +639,16 @@ struct { uint16_t shd_warmup_brightness; // F5C uint8_t shd_warmup_time; // F5E - uint8_t free_f5e[84]; // F5E - Decrement if adding new Setting variables just above and below + // DRAGON settings + uint16_t dragon_offset; + uint16_t dragon_len1; + uint16_t dragon_len2; + uint16_t dragon_len3; + uint8_t dragon_fx1; + uint8_t dragon_fx2; + uint8_t dragon_fx3; + + uint8_t free_f5e[84-11]; // F5E - Decrement if adding new Setting variables just above and below // Only 32 bit boundary variables below SysBitfield5 flag5; // FB4 diff --git a/tasmota/xlgt_01_ws2812.ino b/tasmota/xlgt_01_ws2812.ino index e98d3ec12..f0cec832f 100644 --- a/tasmota/xlgt_01_ws2812.ino +++ b/tasmota/xlgt_01_ws2812.ino @@ -32,18 +32,19 @@ * 5 yes no no Kwanzaa * 6 yes no no Rainbow * 7 yes no no Fire + * 8 Dragon * \*********************************************************************************************/ #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_LED "|" D_CMND_PIXELS "|" D_CMND_ROTATION "|" D_CMND_WIDTH "|" D_CMND_DRAGON; void (* const Ws2812Command[])(void) PROGMEM = { - &CmndLed, &CmndPixels, &CmndRotation, &CmndWidth }; + &CmndLed, &CmndPixels, &CmndRotation, &CmndWidth, &CmndDragon }; #include @@ -135,7 +136,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 }; -ColorScheme kSchemes[WS2812_SCHEMES -1] = { // Skip clock scheme +ColorScheme kSchemes[WS2812_SCHEMES -2] = { // Skip clock+dragon schemes kIncandescent, 2, kRgb, 3, kChristmas, 2, @@ -370,6 +371,104 @@ void Ws2812Bars(uint32_t schemenr) Ws2812StripShow(); } +// note: when using Settings.dimmer, scale it: changeUIntScale(dimmer, 0, 100, 0, 255) +long dragonOffset_current; +void Ws2812Dragon(void) +{ + dragonOffset_current = (Settings.light_speed > 0) ? ((u_int64_t) millis()) * 360 / 500 / Settings.light_speed / Settings.light_speed : 0; + + uint8_t a = 0; + uint8_t b = Settings.dragon_len1; + Ws2812Dragon_Fx(a, b, Light.power & 1 ? Settings.dragon_fx1 : 0, Settings.light_color[0]); + a = b; b += Settings.dragon_len2; + Ws2812Dragon_Fx(a, b, Light.power & 2 ? Settings.dragon_fx2 : 0, Settings.light_color[1]); + a = b; b += Settings.dragon_len3; + Ws2812Dragon_Fx(a, b, Light.power & 2 ? Settings.dragon_fx3 : 0, Settings.light_color[1]); + Ws2812StripShow(); +} + +void Ws2812Dragon_Fx(uint16_t firstLed, uint16_t lastLed, uint8_t fx, uint8_t dimmer) +{ +#if (USE_WS2812_CTYPE > NEO_3LED) + RgbwColor c; + c.W = 0; +#else + RgbColor c; +#endif + switch(fx) { + case 0: + c.R = 0; c.G = 0; c.B = 0; + for (uint32_t i = firstLed; i < lastLed; i++) { strip->SetPixelColor(i, c); } + break; + case 1: +#if (USE_WS2812_CTYPE > NEO_3LED) + c.R = (Light.power & 4) && Settings.light_color[2] < 128 ? changeUIntScale(128-Settings.light_color[2], 0, 127, 0, dimmer) : 0; + c.G = 0; + c.B = (Light.power & 4) && Settings.light_color[2] > 128 ? changeUIntScale(Settings.light_color[2]-128, 0, 127, 0, dimmer) : 0; + c.W = changeUIntScale(255, 0, 255, 0, dimmer); +#else + c.R = dimmer; c.G = c.R; c.B = c.R; +#endif + for (uint32_t i = firstLed; i < lastLed; i++) { strip->SetPixelColor(i, c); } + break; + case 2: + DragonFx_Rainbow(firstLed, lastLed, 0, dimmer); + break; + case 3: + DragonFx_Rainbow(firstLed, lastLed, Settings.dragon_offset, dimmer); + break; + case 4: + DragonFx_Rainbow(firstLed, lastLed, -Settings.dragon_offset, dimmer); + break; + case 5: + DragonFx_Blink(firstLed, lastLed, dimmer); + break; + } +} + +void DragonFx_Rainbow(uint16_t firstLed, uint16_t lastLed, int16_t speed, uint8_t dimmer) { +#if (USE_WS2812_CTYPE > NEO_3LED) + RgbwColor c; + c.W = 0; +#else + RgbColor c; +#endif + for (uint32_t i = firstLed; i < lastLed; i++) { + uint8_t r, g, b, sat; + uint16_t hue; + sat = 255; + dragonOffset_current = (dragonOffset_current + speed); + hue = dragonOffset_current / 10; + light_state.HsToRgb(hue, sat, &r, &g, &b); + c.R = changeUIntScale(r, 0, 255, 0, dimmer); + c.G = changeUIntScale(g, 0, 255, 0, dimmer); + c.B = changeUIntScale(b, 0, 255, 0, dimmer); + strip->SetPixelColor(i, c); + } +} + +void DragonFx_Blink(uint16_t firstLed, uint16_t lastLed, uint8_t dimmer) { +#if (USE_WS2812_CTYPE > NEO_3LED) + RgbwColor c; + c.W = 0; +#else + RgbColor c; +#endif + uint32_t now = millis(); + uint8_t i = Settings.light_speed; + while (i) { + now /= 10; + i--; + } + c.G = (now & 1) ? 255 : 0; + c.R = changeUIntScale(c.R, 0, 255, 0, dimmer); + c.G = changeUIntScale(c.G, 0, 255, 0, dimmer); + c.B = changeUIntScale(c.B, 0, 255, 0, dimmer); + for (uint32_t i = firstLed; i < lastLed; i++) { + strip->SetPixelColor(i, c); + } +} + void Ws2812Clear(void) { strip->ClearTo(0); @@ -466,6 +565,10 @@ void Ws2812ShowScheme(void) Ws2812.show_next = 0; } break; + case 8: // Dragon + Ws2812Dragon(); + Ws2812.show_next = 1; + break; default: if (1 == Settings.light_fade) { Ws2812Gradient(scheme -1); @@ -560,6 +663,75 @@ void CmndWidth(void) } } +/* Dragon Command: index vs payload + * > Index is 1 by default (not given or out of range) + * 1 - set hue-offset-per-led in rainbow mode. Use 'speed' for cycle speed (1-40) + * 2 - length (LEDs) of first segment + * 3 - length (LEDs) of second segment + * 4 - length (LEDs) of third segment + * 5 - effect for segment 1 + * 6 - effect for segment 2 + * 7 - effect for segment 3 + * + * magic value for "no parameter given" is -99 + * + * Effects + * 0 - all black (off) + * 1 - all white + * 2 - rainbow (all same color) + * 3 - rainbow (use Dragon1 to give hue offset per pixel) + * 4 - rainbow (like 4, but different direction) + */ +void CmndDragon(void) +{ + switch(XdrvMailbox.index) { + case 2: + if (-99 != XdrvMailbox.payload) { + Settings.dragon_len1 = XdrvMailbox.payload; + } + ResponseCmndIdxNumber(Settings.dragon_len1); + strip->ClearTo(0); + break; + case 3: + if (-99 != XdrvMailbox.payload) { + Settings.dragon_len2 = XdrvMailbox.payload; + } + ResponseCmndIdxNumber(Settings.dragon_len2); + strip->ClearTo(0); + break; + case 4: + if (-99 != XdrvMailbox.payload) { + Settings.dragon_len3 = XdrvMailbox.payload; + } + ResponseCmndIdxNumber(Settings.dragon_len3); + strip->ClearTo(0); + break; + case 5: + if (-99 != XdrvMailbox.payload) { + Settings.dragon_fx1 = XdrvMailbox.payload; + } + ResponseCmndIdxNumber(Settings.dragon_fx1); + break; + case 6: + if (-99 != XdrvMailbox.payload) { + Settings.dragon_fx2 = XdrvMailbox.payload; + } + ResponseCmndIdxNumber(Settings.dragon_fx2); + break; + case 7: + if (-99 != XdrvMailbox.payload) { + Settings.dragon_fx3 = XdrvMailbox.payload; + } + ResponseCmndIdxNumber(Settings.dragon_fx3); + break; + default: // set hue-offset-per-led in rainbow mode + if (-99 != XdrvMailbox.payload) { + Settings.dragon_offset = XdrvMailbox.payload; + } + ResponseCmndIdxNumber(Settings.dragon_offset); + } +} + /*********************************************************************************************\ * Interface \*********************************************************************************************/ From 712d735b1753723c71500100fb3aac4bc09309bf Mon Sep 17 00:00:00 2001 From: Zefiro Date: Sun, 29 Nov 2020 00:56:16 +0100 Subject: [PATCH 4/4] Revert "Neopixel Dragon extension" This reverts commit 878ce826bf29d526cb688af6570cd5144e9d07cb. --- platformio.ini | 2 +- tasmota/i18n.h | 1 - tasmota/settings.h | 11 +-- tasmota/xlgt_01_ws2812.ino | 180 +------------------------------------ 4 files changed, 6 insertions(+), 188 deletions(-) diff --git a/platformio.ini b/platformio.ini index 355455232..7645a668e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,7 +12,7 @@ [build_envs] default_envs = ; *** Uncomment by deleting ";" in the line(s) below to select version(s) - tasmota +; tasmota ; tasmota-ircustom ; tasmota-minimal ; tasmota-lite diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 00075016d..9a0528c9e 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -439,7 +439,6 @@ #define D_CMND_WAKEUPDURATION "WakeUpDuration" #define D_CMND_WHITE "White" #define D_CMND_WIDTH "Width" -#define D_CMND_DRAGON "Dragon" // Commands xdrv_05_irremote.ino #define D_CMND_IRSEND "IRSend" diff --git a/tasmota/settings.h b/tasmota/settings.h index e3b3b6f72..44a6947a4 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -639,16 +639,7 @@ struct { uint16_t shd_warmup_brightness; // F5C uint8_t shd_warmup_time; // F5E - // DRAGON settings - uint16_t dragon_offset; - uint16_t dragon_len1; - uint16_t dragon_len2; - uint16_t dragon_len3; - uint8_t dragon_fx1; - uint8_t dragon_fx2; - uint8_t dragon_fx3; - - uint8_t free_f5e[84-11]; // F5E - Decrement if adding new Setting variables just above and below + uint8_t free_f5e[84]; // F5E - Decrement if adding new Setting variables just above and below // Only 32 bit boundary variables below SysBitfield5 flag5; // FB4 diff --git a/tasmota/xlgt_01_ws2812.ino b/tasmota/xlgt_01_ws2812.ino index f0cec832f..e98d3ec12 100644 --- a/tasmota/xlgt_01_ws2812.ino +++ b/tasmota/xlgt_01_ws2812.ino @@ -32,19 +32,18 @@ * 5 yes no no Kwanzaa * 6 yes no no Rainbow * 7 yes no no Fire - * 8 Dragon * \*********************************************************************************************/ #define XLGT_01 1 -const uint8_t WS2812_SCHEMES = 9; // Number of WS2812 schemes +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_DRAGON; + D_CMND_LED "|" D_CMND_PIXELS "|" D_CMND_ROTATION "|" D_CMND_WIDTH ; void (* const Ws2812Command[])(void) PROGMEM = { - &CmndLed, &CmndPixels, &CmndRotation, &CmndWidth, &CmndDragon }; + &CmndLed, &CmndPixels, &CmndRotation, &CmndWidth }; #include @@ -136,7 +135,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 }; -ColorScheme kSchemes[WS2812_SCHEMES -2] = { // Skip clock+dragon schemes +ColorScheme kSchemes[WS2812_SCHEMES -1] = { // Skip clock scheme kIncandescent, 2, kRgb, 3, kChristmas, 2, @@ -371,104 +370,6 @@ void Ws2812Bars(uint32_t schemenr) Ws2812StripShow(); } -// note: when using Settings.dimmer, scale it: changeUIntScale(dimmer, 0, 100, 0, 255) -long dragonOffset_current; -void Ws2812Dragon(void) -{ - dragonOffset_current = (Settings.light_speed > 0) ? ((u_int64_t) millis()) * 360 / 500 / Settings.light_speed / Settings.light_speed : 0; - - uint8_t a = 0; - uint8_t b = Settings.dragon_len1; - Ws2812Dragon_Fx(a, b, Light.power & 1 ? Settings.dragon_fx1 : 0, Settings.light_color[0]); - a = b; b += Settings.dragon_len2; - Ws2812Dragon_Fx(a, b, Light.power & 2 ? Settings.dragon_fx2 : 0, Settings.light_color[1]); - a = b; b += Settings.dragon_len3; - Ws2812Dragon_Fx(a, b, Light.power & 2 ? Settings.dragon_fx3 : 0, Settings.light_color[1]); - Ws2812StripShow(); -} - -void Ws2812Dragon_Fx(uint16_t firstLed, uint16_t lastLed, uint8_t fx, uint8_t dimmer) -{ -#if (USE_WS2812_CTYPE > NEO_3LED) - RgbwColor c; - c.W = 0; -#else - RgbColor c; -#endif - switch(fx) { - case 0: - c.R = 0; c.G = 0; c.B = 0; - for (uint32_t i = firstLed; i < lastLed; i++) { strip->SetPixelColor(i, c); } - break; - case 1: -#if (USE_WS2812_CTYPE > NEO_3LED) - c.R = (Light.power & 4) && Settings.light_color[2] < 128 ? changeUIntScale(128-Settings.light_color[2], 0, 127, 0, dimmer) : 0; - c.G = 0; - c.B = (Light.power & 4) && Settings.light_color[2] > 128 ? changeUIntScale(Settings.light_color[2]-128, 0, 127, 0, dimmer) : 0; - c.W = changeUIntScale(255, 0, 255, 0, dimmer); -#else - c.R = dimmer; c.G = c.R; c.B = c.R; -#endif - for (uint32_t i = firstLed; i < lastLed; i++) { strip->SetPixelColor(i, c); } - break; - case 2: - DragonFx_Rainbow(firstLed, lastLed, 0, dimmer); - break; - case 3: - DragonFx_Rainbow(firstLed, lastLed, Settings.dragon_offset, dimmer); - break; - case 4: - DragonFx_Rainbow(firstLed, lastLed, -Settings.dragon_offset, dimmer); - break; - case 5: - DragonFx_Blink(firstLed, lastLed, dimmer); - break; - } -} - -void DragonFx_Rainbow(uint16_t firstLed, uint16_t lastLed, int16_t speed, uint8_t dimmer) { -#if (USE_WS2812_CTYPE > NEO_3LED) - RgbwColor c; - c.W = 0; -#else - RgbColor c; -#endif - for (uint32_t i = firstLed; i < lastLed; i++) { - uint8_t r, g, b, sat; - uint16_t hue; - sat = 255; - dragonOffset_current = (dragonOffset_current + speed); - hue = dragonOffset_current / 10; - light_state.HsToRgb(hue, sat, &r, &g, &b); - c.R = changeUIntScale(r, 0, 255, 0, dimmer); - c.G = changeUIntScale(g, 0, 255, 0, dimmer); - c.B = changeUIntScale(b, 0, 255, 0, dimmer); - strip->SetPixelColor(i, c); - } -} - -void DragonFx_Blink(uint16_t firstLed, uint16_t lastLed, uint8_t dimmer) { -#if (USE_WS2812_CTYPE > NEO_3LED) - RgbwColor c; - c.W = 0; -#else - RgbColor c; -#endif - uint32_t now = millis(); - uint8_t i = Settings.light_speed; - while (i) { - now /= 10; - i--; - } - c.G = (now & 1) ? 255 : 0; - c.R = changeUIntScale(c.R, 0, 255, 0, dimmer); - c.G = changeUIntScale(c.G, 0, 255, 0, dimmer); - c.B = changeUIntScale(c.B, 0, 255, 0, dimmer); - for (uint32_t i = firstLed; i < lastLed; i++) { - strip->SetPixelColor(i, c); - } -} - void Ws2812Clear(void) { strip->ClearTo(0); @@ -565,10 +466,6 @@ void Ws2812ShowScheme(void) Ws2812.show_next = 0; } break; - case 8: // Dragon - Ws2812Dragon(); - Ws2812.show_next = 1; - break; default: if (1 == Settings.light_fade) { Ws2812Gradient(scheme -1); @@ -663,75 +560,6 @@ void CmndWidth(void) } } -/* Dragon Command: index vs payload - * > Index is 1 by default (not given or out of range) - * 1 - set hue-offset-per-led in rainbow mode. Use 'speed' for cycle speed (1-40) - * 2 - length (LEDs) of first segment - * 3 - length (LEDs) of second segment - * 4 - length (LEDs) of third segment - * 5 - effect for segment 1 - * 6 - effect for segment 2 - * 7 - effect for segment 3 - * - * magic value for "no parameter given" is -99 - * - * Effects - * 0 - all black (off) - * 1 - all white - * 2 - rainbow (all same color) - * 3 - rainbow (use Dragon1 to give hue offset per pixel) - * 4 - rainbow (like 4, but different direction) - */ -void CmndDragon(void) -{ - switch(XdrvMailbox.index) { - case 2: - if (-99 != XdrvMailbox.payload) { - Settings.dragon_len1 = XdrvMailbox.payload; - } - ResponseCmndIdxNumber(Settings.dragon_len1); - strip->ClearTo(0); - break; - case 3: - if (-99 != XdrvMailbox.payload) { - Settings.dragon_len2 = XdrvMailbox.payload; - } - ResponseCmndIdxNumber(Settings.dragon_len2); - strip->ClearTo(0); - break; - case 4: - if (-99 != XdrvMailbox.payload) { - Settings.dragon_len3 = XdrvMailbox.payload; - } - ResponseCmndIdxNumber(Settings.dragon_len3); - strip->ClearTo(0); - break; - case 5: - if (-99 != XdrvMailbox.payload) { - Settings.dragon_fx1 = XdrvMailbox.payload; - } - ResponseCmndIdxNumber(Settings.dragon_fx1); - break; - case 6: - if (-99 != XdrvMailbox.payload) { - Settings.dragon_fx2 = XdrvMailbox.payload; - } - ResponseCmndIdxNumber(Settings.dragon_fx2); - break; - case 7: - if (-99 != XdrvMailbox.payload) { - Settings.dragon_fx3 = XdrvMailbox.payload; - } - ResponseCmndIdxNumber(Settings.dragon_fx3); - break; - default: // set hue-offset-per-led in rainbow mode - if (-99 != XdrvMailbox.payload) { - Settings.dragon_offset = XdrvMailbox.payload; - } - ResponseCmndIdxNumber(Settings.dragon_offset); - } -} - /*********************************************************************************************\ * Interface \*********************************************************************************************/