2017-09-18 17:06:46 +01:00
|
|
|
/*
|
2019-10-27 10:13:24 +00:00
|
|
|
xlgt_01_ws2812.ino - led string support for Tasmota
|
2017-09-18 17:06:46 +01:00
|
|
|
|
2021-01-01 12:44:04 +00:00
|
|
|
Copyright (C) 2021 Theo Arends
|
2017-09-18 17:06:46 +01:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-06-16 15:43:23 +01:00
|
|
|
#ifdef USE_LIGHT
|
2017-09-18 17:06:46 +01:00
|
|
|
#ifdef USE_WS2812
|
|
|
|
/*********************************************************************************************\
|
2017-11-11 15:02:18 +00:00
|
|
|
* WS2812 RGB / RGBW Leds using NeopixelBus library
|
2019-10-08 16:46:03 +01:00
|
|
|
*
|
|
|
|
* light_scheme WS2812 3+ Colors 1+2 Colors Effect
|
|
|
|
* ------------ ------ --------- ---------- -----------------
|
2021-11-20 13:13:54 +00:00
|
|
|
* 0 (5) yes no no Clock
|
|
|
|
* 1 (6) yes no no Incandescent
|
|
|
|
* 2 (7) yes no no RGB
|
|
|
|
* 3 (8) yes no no Christmas
|
|
|
|
* 4 (9) yes no no Hanukkah
|
|
|
|
* 5 (10) yes no no Kwanzaa
|
|
|
|
* 6 (11) yes no no Rainbow
|
|
|
|
* 7 (12) yes no no Fire
|
|
|
|
* 8 (13) yes no no Stairs
|
2017-09-18 17:06:46 +01:00
|
|
|
\*********************************************************************************************/
|
|
|
|
|
2019-10-08 16:46:03 +01:00
|
|
|
#define XLGT_01 1
|
|
|
|
|
2021-12-12 17:23:49 +00:00
|
|
|
#ifdef USE_NETWORK_LIGHT_SCHEMES
|
|
|
|
const uint8_t WS2812_SCHEMES = 10; // Number of WS2812 schemes
|
|
|
|
#else
|
2021-11-02 23:03:06 +00:00
|
|
|
const uint8_t WS2812_SCHEMES = 9; // Number of WS2812 schemes
|
2021-12-12 17:23:49 +00:00
|
|
|
#endif
|
2019-10-08 16:46:03 +01:00
|
|
|
|
|
|
|
const char kWs2812Commands[] PROGMEM = "|" // No prefix
|
2021-11-01 11:31:08 +00:00
|
|
|
D_CMND_LED "|" D_CMND_PIXELS "|" D_CMND_ROTATION "|" D_CMND_WIDTH "|" D_CMND_STEPPIXELS ;
|
2019-10-08 16:46:03 +01:00
|
|
|
|
|
|
|
void (* const Ws2812Command[])(void) PROGMEM = {
|
2021-11-01 11:31:08 +00:00
|
|
|
&CmndLed, &CmndPixels, &CmndRotation, &CmndWidth, &CmndStepPixels };
|
2019-10-08 16:46:03 +01:00
|
|
|
|
2017-09-18 17:06:46 +01:00
|
|
|
#include <NeoPixelBus.h>
|
|
|
|
|
2021-03-10 19:38:19 +00:00
|
|
|
// See NeoEspDmaMethod.h for available options
|
|
|
|
// See NeoEspBitBangMethod.h for available options
|
|
|
|
|
|
|
|
// Build `selectedNeoFeatureType` as Neo-Rgb-Feature
|
|
|
|
// parametrized as: NEO_FEATURE_NEO+NEO_FEATURE_TYPE+NEO_FEATURE_FEATURE
|
|
|
|
#define CONCAT2(A,B) CONCAT2_(A,B) // ensures expansion first, see https://stackoverflow.com/questions/3221896/how-can-i-guarantee-full-macro-expansion-of-a-parameter-before-paste
|
|
|
|
#define CONCAT2_(A,B) A ## B
|
|
|
|
#define CONCAT3(A,B,C) CONCAT3_(A,B,C) // ensures expansion first, see https://stackoverflow.com/questions/3221896/how-can-i-guarantee-full-macro-expansion-of-a-parameter-before-paste
|
|
|
|
#define CONCAT3_(A,B,C) A ## B ## C
|
|
|
|
|
|
|
|
#define NEO_FEATURE_NEO Neo
|
|
|
|
#define NEO_FEATURE_FEATURE Feature
|
|
|
|
|
|
|
|
// select the right Neo feature based on USE_WS2812_CTYPE
|
|
|
|
// NEO_FEATURE_TYPE can be one of: Rgb (default), Grb, Brg, Rgb, Rgbw, Grbw
|
|
|
|
#if (USE_WS2812_CTYPE == NEO_GRB)
|
|
|
|
#define NEO_FEATURE_TYPE Grb
|
2018-03-17 14:22:29 +00:00
|
|
|
#elif (USE_WS2812_CTYPE == NEO_BRG)
|
2021-03-10 19:38:19 +00:00
|
|
|
#define NEO_FEATURE_TYPE Brg
|
2018-03-17 14:22:29 +00:00
|
|
|
#elif (USE_WS2812_CTYPE == NEO_RBG)
|
2021-03-10 19:38:19 +00:00
|
|
|
#define NEO_FEATURE_TYPE Rbg
|
2018-03-17 14:22:29 +00:00
|
|
|
#elif (USE_WS2812_CTYPE == NEO_RGBW)
|
2021-06-15 20:14:01 +01:00
|
|
|
#define NEO_FEATURE_TYPE Rgbw
|
2018-03-17 14:22:29 +00:00
|
|
|
#elif (USE_WS2812_CTYPE == NEO_GRBW)
|
2021-03-10 19:38:19 +00:00
|
|
|
#define NEO_FEATURE_TYPE Grbw
|
|
|
|
#else
|
|
|
|
#define NEO_FEATURE_TYPE Rgb
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Exception for NEO_HW_P9813
|
|
|
|
#if (USE_WS2812_HARDWARE == NEO_HW_P9813)
|
|
|
|
#undef NEO_FEATURE_NEO
|
|
|
|
#undef NEO_FEATURE_TYPE
|
|
|
|
#define NEO_FEATURE_NEO P9813 // P9813BgrFeature
|
|
|
|
#define NEO_FEATURE_TYPE Bgr
|
|
|
|
#undef USE_WS2812_DMA
|
|
|
|
#undef USE_WS2812_INVERTED
|
2017-09-18 17:06:46 +01:00
|
|
|
#endif // USE_WS2812_CTYPE
|
2019-02-26 08:08:11 +00:00
|
|
|
|
2021-03-10 19:38:19 +00:00
|
|
|
typedef CONCAT3(NEO_FEATURE_NEO,NEO_FEATURE_TYPE,NEO_FEATURE_FEATURE) selectedNeoFeatureType;
|
2019-08-30 13:35:08 +01:00
|
|
|
|
2021-03-10 19:38:19 +00:00
|
|
|
// selectedNeoSpeedType is built as Neo+Esp8266+Dma+Inverted+Ws2812x+Method
|
|
|
|
// Or NEO_NEO+NEO_CHIP+NEO_PROTO+NEO_INV+NEO_HW+Method
|
|
|
|
#define CONCAT6(A,B,C,D,E,F) CONCAT6_(A,B,C,D,E,F) // ensures expansion first, see https://stackoverflow.com/questions/3221896/how-can-i-guarantee-full-macro-expansion-of-a-parameter-before-paste
|
|
|
|
#define CONCAT6_(A,B,C,D,E,F) A ## B ## C ## D ## E ## F
|
2020-10-05 18:03:40 +01:00
|
|
|
|
2021-03-10 19:38:19 +00:00
|
|
|
#define NEO_NEO Neo
|
2019-08-30 13:35:08 +01:00
|
|
|
|
2021-03-10 19:38:19 +00:00
|
|
|
#ifdef ESP32
|
|
|
|
#define NEO_CHIP Esp32
|
|
|
|
#else
|
|
|
|
#define NEO_CHIP Esp8266
|
|
|
|
#endif
|
2020-10-05 18:03:40 +01:00
|
|
|
|
2021-03-10 19:38:19 +00:00
|
|
|
// Proto = DMA or BigBang
|
|
|
|
#if defined(USE_WS2812_DMA) && defined(ESP8266)
|
|
|
|
#define NEO_PROTO Dma
|
|
|
|
#elif defined(USE_WS2812_RMT) && defined(ESP32)
|
|
|
|
#define NEO_PROTO CONCAT2(Rmt,USE_WS2812_RMT)
|
|
|
|
#elif defined(USE_WS2812_I2S) && defined(ESP32)
|
|
|
|
#define NEO_PROTO CONCAT2(I2s,USE_WS2812_I2S)
|
|
|
|
#else
|
|
|
|
#define NEO_PROTO BitBang
|
|
|
|
#endif
|
2019-08-30 13:35:08 +01:00
|
|
|
|
2020-10-05 18:03:40 +01:00
|
|
|
#ifdef USE_WS2812_INVERTED
|
2021-03-10 19:38:19 +00:00
|
|
|
#define NEO_INV Inverted
|
|
|
|
#else
|
|
|
|
#define NEO_INV
|
|
|
|
#endif
|
2020-10-05 18:03:40 +01:00
|
|
|
|
|
|
|
#if (USE_WS2812_HARDWARE == NEO_HW_WS2812X)
|
2021-03-10 19:38:19 +00:00
|
|
|
#define NEO_HW Ws2812x
|
2020-10-05 18:03:40 +01:00
|
|
|
#elif (USE_WS2812_HARDWARE == NEO_HW_SK6812)
|
2021-03-10 19:38:19 +00:00
|
|
|
#define NEO_HW Sk6812
|
|
|
|
#elif (USE_WS2812_HARDWARE == NEO_HW_APA106)
|
|
|
|
#define NEO_HW Apa106
|
2020-10-05 18:03:40 +01:00
|
|
|
#else // USE_WS2812_HARDWARE
|
2021-03-10 19:38:19 +00:00
|
|
|
#define NEO_HW 800Kbps
|
2020-10-05 18:03:40 +01:00
|
|
|
#endif // USE_WS2812_HARDWARE
|
|
|
|
|
|
|
|
|
2020-12-17 15:33:26 +00:00
|
|
|
#if (USE_WS2812_HARDWARE == NEO_HW_P9813)
|
2021-03-10 19:38:19 +00:00
|
|
|
#undef NEO_NEO
|
|
|
|
#define NEO_NEO
|
|
|
|
#undef NEO_CHIP
|
|
|
|
#define NEO_CHIP
|
|
|
|
#undef NEO_PROTO
|
|
|
|
#define NEO_PROTO
|
|
|
|
#undef NEO_INV
|
|
|
|
#define NEO_INV
|
|
|
|
#undef NEO_HW
|
|
|
|
#define NEO_HW P9813 // complete driver is P9813Method
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(ESP8266) && defined(USE_WS2812_DMA)
|
|
|
|
typedef CONCAT6(NEO_NEO,NEO_CHIP,NEO_PROTO,NEO_INV,NEO_HW,Method) selectedNeoSpeedType;
|
|
|
|
#else // Dma : different naming scheme
|
|
|
|
typedef CONCAT6(NEO_NEO,NEO_CHIP,NEO_PROTO,NEO_HW,NEO_INV,Method) selectedNeoSpeedType;
|
|
|
|
#endif
|
2019-08-30 13:35:08 +01:00
|
|
|
|
|
|
|
NeoPixelBus<selectedNeoFeatureType, selectedNeoSpeedType> *strip = nullptr;
|
2017-09-18 17:06:46 +01:00
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
struct WsColor {
|
2017-09-18 17:06:46 +01:00
|
|
|
uint8_t red, green, blue;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ColorScheme {
|
2017-10-18 17:22:34 +01:00
|
|
|
WsColor* colors;
|
2017-09-18 17:06:46 +01:00
|
|
|
uint8_t count;
|
|
|
|
};
|
|
|
|
|
2017-11-11 11:33:30 +00:00
|
|
|
WsColor kIncandescent[2] = { 255,140,20, 0,0,0 };
|
|
|
|
WsColor kRgb[3] = { 255,0,0, 0,255,0, 0,0,255 };
|
|
|
|
WsColor kChristmas[2] = { 255,0,0, 0,255,0 };
|
|
|
|
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 };
|
2021-11-02 23:03:06 +00:00
|
|
|
WsColor kStairs[2] = { 0,0,0, 255,255,255 };
|
2021-12-12 17:23:49 +00:00
|
|
|
|
|
|
|
#ifdef USE_NETWORK_LIGHT_SCHEMES
|
|
|
|
ColorScheme kSchemes[WS2812_SCHEMES -2] = { // Skip clock scheme and DDP scheme
|
|
|
|
#else
|
2019-10-08 16:46:03 +01:00
|
|
|
ColorScheme kSchemes[WS2812_SCHEMES -1] = { // Skip clock scheme
|
2021-12-12 17:23:49 +00:00
|
|
|
#endif
|
2017-10-18 17:22:34 +01:00
|
|
|
kIncandescent, 2,
|
|
|
|
kRgb, 3,
|
|
|
|
kChristmas, 2,
|
|
|
|
kHanukkah, 2,
|
2017-09-18 17:06:46 +01:00
|
|
|
kwanzaa, 3,
|
2017-10-18 17:22:34 +01:00
|
|
|
kRainbow, 7,
|
2021-11-20 13:13:54 +00:00
|
|
|
kFire, 3,
|
2021-11-02 23:03:06 +00:00
|
|
|
kStairs, 2 };
|
2017-09-18 17:06:46 +01:00
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
uint8_t kWidth[5] = {
|
2017-09-18 17:06:46 +01:00
|
|
|
1, // Small
|
|
|
|
2, // Medium
|
|
|
|
4, // Large
|
|
|
|
8, // Largest
|
|
|
|
255 }; // All
|
2018-11-20 14:53:56 +00:00
|
|
|
uint8_t kWsRepeat[5] = {
|
2017-09-18 17:06:46 +01:00
|
|
|
8, // Small
|
|
|
|
6, // Medium
|
|
|
|
4, // Large
|
|
|
|
2, // Largest
|
|
|
|
1 }; // All
|
|
|
|
|
2019-10-08 16:46:03 +01:00
|
|
|
struct WS2812 {
|
|
|
|
uint8_t show_next = 1;
|
|
|
|
uint8_t scheme_offset = 0;
|
|
|
|
bool suspend_update = false;
|
|
|
|
} Ws2812;
|
2019-07-31 15:59:12 +01:00
|
|
|
|
2017-09-18 17:06:46 +01:00
|
|
|
/********************************************************************************************/
|
|
|
|
|
2021-01-20 14:06:34 +00:00
|
|
|
// For some reason map fails to compile so renamed to wsmap
|
|
|
|
long wsmap(long x, long in_min, long in_max, long out_min, long out_max) {
|
|
|
|
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void Ws2812StripShow(void)
|
2017-09-18 17:06:46 +01:00
|
|
|
{
|
2018-03-17 14:22:29 +00:00
|
|
|
#if (USE_WS2812_CTYPE > NEO_3LED)
|
2017-11-11 15:02:18 +00:00
|
|
|
RgbwColor c;
|
|
|
|
#else
|
2017-09-18 17:06:46 +01:00
|
|
|
RgbColor c;
|
2017-11-11 15:02:18 +00:00
|
|
|
#endif
|
2017-09-18 17:06:46 +01:00
|
|
|
|
2021-06-11 17:14:12 +01:00
|
|
|
if (Settings->light_correction) {
|
|
|
|
for (uint32_t i = 0; i < Settings->light_pixels; i++) {
|
2017-09-18 17:06:46 +01:00
|
|
|
c = strip->GetPixelColor(i);
|
2019-04-30 22:03:08 +01:00
|
|
|
c.R = ledGamma(c.R);
|
|
|
|
c.G = ledGamma(c.G);
|
|
|
|
c.B = ledGamma(c.B);
|
2018-03-17 14:22:29 +00:00
|
|
|
#if (USE_WS2812_CTYPE > NEO_3LED)
|
2019-04-30 22:03:08 +01:00
|
|
|
c.W = ledGamma(c.W);
|
2017-11-11 15:02:18 +00:00
|
|
|
#endif
|
|
|
|
strip->SetPixelColor(i, c);
|
2017-09-18 17:06:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
strip->Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
int mod(int a, int b)
|
|
|
|
{
|
|
|
|
int ret = a % b;
|
2018-03-10 16:58:54 +00:00
|
|
|
if (ret < 0) ret += b;
|
2017-09-18 17:06:46 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-11-21 15:06:51 +00:00
|
|
|
void Ws2812UpdatePixelColor(int position, struct WsColor hand_color, float offset)
|
2017-10-18 17:22:34 +01:00
|
|
|
{
|
2018-03-17 14:22:29 +00:00
|
|
|
#if (USE_WS2812_CTYPE > NEO_3LED)
|
2017-11-11 15:02:18 +00:00
|
|
|
RgbwColor color;
|
|
|
|
#else
|
2017-10-18 17:22:34 +01:00
|
|
|
RgbColor color;
|
2017-11-11 15:02:18 +00:00
|
|
|
#endif
|
2017-10-18 17:22:34 +01:00
|
|
|
|
2021-06-11 17:14:12 +01:00
|
|
|
uint32_t mod_position = mod(position, (int)Settings->light_pixels);
|
2017-10-18 17:22:34 +01:00
|
|
|
|
|
|
|
color = strip->GetPixelColor(mod_position);
|
2021-06-11 17:14:12 +01:00
|
|
|
float dimmer = 100 / (float)Settings->light_dimmer;
|
2018-07-14 11:10:13 +01:00
|
|
|
color.R = tmin(color.R + ((hand_color.red / dimmer) * offset), 255);
|
|
|
|
color.G = tmin(color.G + ((hand_color.green / dimmer) * offset), 255);
|
|
|
|
color.B = tmin(color.B + ((hand_color.blue / dimmer) * offset), 255);
|
2017-10-18 17:22:34 +01:00
|
|
|
strip->SetPixelColor(mod_position, color);
|
|
|
|
}
|
|
|
|
|
2019-07-31 15:59:12 +01:00
|
|
|
void Ws2812UpdateHand(int position, uint32_t index)
|
2017-10-18 17:22:34 +01:00
|
|
|
{
|
2021-06-11 17:14:12 +01:00
|
|
|
uint32_t width = Settings->light_width;
|
|
|
|
if (index < WS_MARKER) { width = Settings->ws_width[index]; }
|
2019-07-31 15:59:12 +01:00
|
|
|
if (!width) { return; } // Skip
|
|
|
|
|
2021-06-11 17:14:12 +01:00
|
|
|
position = (position + Settings->light_rotation) % Settings->light_pixels;
|
2018-03-10 16:58:54 +00:00
|
|
|
|
2021-06-11 17:14:12 +01:00
|
|
|
if (Settings->flag.ws_clock_reverse) { // SetOption16 - Switch between clockwise or counter-clockwise
|
|
|
|
position = Settings->light_pixels -position;
|
2019-11-03 11:33:36 +00:00
|
|
|
}
|
2021-06-11 17:14:12 +01:00
|
|
|
WsColor hand_color = { Settings->ws_color[index][WS_RED], Settings->ws_color[index][WS_GREEN], Settings->ws_color[index][WS_BLUE] };
|
2017-10-23 11:18:15 +01:00
|
|
|
|
2017-11-21 15:06:51 +00:00
|
|
|
Ws2812UpdatePixelColor(position, hand_color, 1);
|
2018-03-10 16:58:54 +00:00
|
|
|
|
2019-07-31 15:59:12 +01:00
|
|
|
uint32_t range = ((width -1) / 2) +1;
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t h = 1; h < range; h++) {
|
2017-11-21 15:06:51 +00:00
|
|
|
float offset = (float)(range - h) / (float)range;
|
|
|
|
Ws2812UpdatePixelColor(position -h, hand_color, offset);
|
|
|
|
Ws2812UpdatePixelColor(position +h, hand_color, offset);
|
2017-10-18 17:22:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void Ws2812Clock(void)
|
2017-09-18 17:06:46 +01:00
|
|
|
{
|
2017-10-18 17:22:34 +01:00
|
|
|
strip->ClearTo(0); // Reset strip
|
2021-06-11 17:14:12 +01:00
|
|
|
int clksize = 60000 / (int)Settings->light_pixels;
|
2018-03-10 16:58:54 +00:00
|
|
|
|
2017-11-21 15:06:51 +00:00
|
|
|
Ws2812UpdateHand((RtcTime.second * 1000) / clksize, WS_SECOND);
|
|
|
|
Ws2812UpdateHand((RtcTime.minute * 1000) / clksize, WS_MINUTE);
|
2019-02-12 14:28:45 +00:00
|
|
|
Ws2812UpdateHand((((RtcTime.hour % 12) * 5000) + ((RtcTime.minute * 1000) / 12 )) / clksize, WS_HOUR);
|
2021-06-11 17:14:12 +01:00
|
|
|
if (Settings->ws_color[WS_MARKER][WS_RED] + Settings->ws_color[WS_MARKER][WS_GREEN] + Settings->ws_color[WS_MARKER][WS_BLUE]) {
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < 12; i++) {
|
2018-03-10 16:58:54 +00:00
|
|
|
Ws2812UpdateHand((i * 5000) / clksize, WS_MARKER);
|
|
|
|
}
|
|
|
|
}
|
2017-10-29 17:18:46 +00:00
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
Ws2812StripShow();
|
2017-09-18 17:06:46 +01:00
|
|
|
}
|
|
|
|
|
2019-07-31 15:59:12 +01:00
|
|
|
void Ws2812GradientColor(uint32_t schemenr, struct WsColor* mColor, uint32_t range, uint32_t gradRange, uint32_t i)
|
2017-09-18 17:06:46 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Compute the color of a pixel at position i using a gradient of the color scheme.
|
|
|
|
* This function is used internally by the gradient function.
|
|
|
|
*/
|
2017-10-18 17:22:34 +01:00
|
|
|
ColorScheme scheme = kSchemes[schemenr];
|
2019-07-31 15:59:12 +01:00
|
|
|
uint32_t curRange = i / range;
|
|
|
|
uint32_t rangeIndex = i % range;
|
|
|
|
uint32_t colorIndex = rangeIndex / gradRange;
|
|
|
|
uint32_t start = colorIndex;
|
|
|
|
uint32_t end = colorIndex +1;
|
2017-09-18 17:06:46 +01:00
|
|
|
if (curRange % 2 != 0) {
|
|
|
|
start = (scheme.count -1) - start;
|
|
|
|
end = (scheme.count -1) - end;
|
|
|
|
}
|
2021-06-11 17:14:12 +01:00
|
|
|
float dimmer = 100 / (float)Settings->light_dimmer;
|
2021-01-20 14:06:34 +00:00
|
|
|
float fmyRed = (float)wsmap(rangeIndex % gradRange, 0, gradRange, scheme.colors[start].red, scheme.colors[end].red) / dimmer;
|
|
|
|
float fmyGrn = (float)wsmap(rangeIndex % gradRange, 0, gradRange, scheme.colors[start].green, scheme.colors[end].green) / dimmer;
|
|
|
|
float fmyBlu = (float)wsmap(rangeIndex % gradRange, 0, gradRange, scheme.colors[start].blue, scheme.colors[end].blue) / dimmer;
|
2017-09-18 17:06:46 +01:00
|
|
|
mColor->red = (uint8_t)fmyRed;
|
|
|
|
mColor->green = (uint8_t)fmyGrn;
|
|
|
|
mColor->blue = (uint8_t)fmyBlu;
|
|
|
|
}
|
|
|
|
|
2019-07-31 15:59:12 +01:00
|
|
|
void Ws2812Gradient(uint32_t schemenr)
|
2017-09-18 17:06:46 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This routine courtesy Tony DiCola (Adafruit)
|
|
|
|
* Display a gradient of colors for the current color scheme.
|
|
|
|
* Repeat is the number of repetitions of the gradient (pick a multiple of 2 for smooth looping of the gradient).
|
|
|
|
*/
|
2018-03-17 14:22:29 +00:00
|
|
|
#if (USE_WS2812_CTYPE > NEO_3LED)
|
2017-11-11 15:02:18 +00:00
|
|
|
RgbwColor c;
|
|
|
|
c.W = 0;
|
|
|
|
#else
|
2017-09-18 17:06:46 +01:00
|
|
|
RgbColor c;
|
2017-11-11 15:02:18 +00:00
|
|
|
#endif
|
2017-09-18 17:06:46 +01:00
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
ColorScheme scheme = kSchemes[schemenr];
|
2019-07-31 15:59:12 +01:00
|
|
|
if (scheme.count < 2) { return; }
|
2017-09-18 17:06:46 +01:00
|
|
|
|
2021-06-11 17:14:12 +01:00
|
|
|
uint32_t repeat = kWsRepeat[Settings->light_width]; // number of scheme.count per ledcount
|
|
|
|
uint32_t range = (uint32_t)ceil((float)Settings->light_pixels / (float)repeat);
|
2019-07-31 15:59:12 +01:00
|
|
|
uint32_t gradRange = (uint32_t)ceil((float)range / (float)(scheme.count - 1));
|
2021-06-11 17:14:12 +01:00
|
|
|
uint32_t speed = ((Settings->light_speed * 2) -1) * (STATES / 10);
|
2019-08-17 12:17:30 +01:00
|
|
|
uint32_t offset = speed > 0 ? Light.strip_timer_counter / speed : 0;
|
2017-09-18 17:06:46 +01:00
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
WsColor oldColor, currentColor;
|
|
|
|
Ws2812GradientColor(schemenr, &oldColor, range, gradRange, offset);
|
2017-09-18 17:06:46 +01:00
|
|
|
currentColor = oldColor;
|
2020-12-07 21:24:00 +00:00
|
|
|
speed = speed ? speed : 1; // should never happen, just avoid div0
|
2021-06-11 17:14:12 +01:00
|
|
|
for (uint32_t i = 0; i < Settings->light_pixels; i++) {
|
|
|
|
if (kWsRepeat[Settings->light_width] > 1) {
|
2020-12-07 21:24:00 +00:00
|
|
|
Ws2812GradientColor(schemenr, ¤tColor, range, gradRange, i + offset + 1);
|
2017-09-18 17:06:46 +01:00
|
|
|
}
|
2020-12-07 21:24:00 +00:00
|
|
|
// Blend old and current color based on time for smooth movement.
|
2021-01-20 14:06:34 +00:00
|
|
|
c.R = wsmap(Light.strip_timer_counter % speed, 0, speed, oldColor.red, currentColor.red);
|
|
|
|
c.G = wsmap(Light.strip_timer_counter % speed, 0, speed, oldColor.green, currentColor.green);
|
|
|
|
c.B = wsmap(Light.strip_timer_counter % speed, 0, speed, oldColor.blue, currentColor.blue);
|
2017-09-18 17:06:46 +01:00
|
|
|
strip->SetPixelColor(i, c);
|
|
|
|
oldColor = currentColor;
|
|
|
|
}
|
2017-10-18 17:22:34 +01:00
|
|
|
Ws2812StripShow();
|
2017-09-18 17:06:46 +01:00
|
|
|
}
|
|
|
|
|
2019-07-31 15:59:12 +01:00
|
|
|
void Ws2812Bars(uint32_t schemenr)
|
2017-09-18 17:06:46 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This routine courtesy Tony DiCola (Adafruit)
|
|
|
|
* Display solid bars of color for the current color scheme.
|
|
|
|
* Width is the width of each bar in pixels/lights.
|
|
|
|
*/
|
2018-03-17 14:22:29 +00:00
|
|
|
#if (USE_WS2812_CTYPE > NEO_3LED)
|
2017-11-11 15:02:18 +00:00
|
|
|
RgbwColor c;
|
|
|
|
c.W = 0;
|
|
|
|
#else
|
2017-09-18 17:06:46 +01:00
|
|
|
RgbColor c;
|
2017-11-11 15:02:18 +00:00
|
|
|
#endif
|
2017-09-18 17:06:46 +01:00
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
ColorScheme scheme = kSchemes[schemenr];
|
2017-09-18 17:06:46 +01:00
|
|
|
|
2021-06-11 17:14:12 +01:00
|
|
|
uint32_t maxSize = Settings->light_pixels / scheme.count;
|
|
|
|
if (kWidth[Settings->light_width] > maxSize) { maxSize = 0; }
|
2017-09-18 17:06:46 +01:00
|
|
|
|
2021-06-11 17:14:12 +01:00
|
|
|
uint32_t speed = ((Settings->light_speed * 2) -1) * (STATES / 10);
|
2019-08-17 12:17:30 +01:00
|
|
|
uint32_t offset = (speed > 0) ? Light.strip_timer_counter / speed : 0;
|
2017-09-18 17:06:46 +01:00
|
|
|
|
2017-10-18 17:22:34 +01:00
|
|
|
WsColor mcolor[scheme.count];
|
2017-09-18 17:06:46 +01:00
|
|
|
memcpy(mcolor, scheme.colors, sizeof(mcolor));
|
2021-06-11 17:14:12 +01:00
|
|
|
float dimmer = 100 / (float)Settings->light_dimmer;
|
2019-07-31 15:59:12 +01:00
|
|
|
for (uint32_t i = 0; i < scheme.count; i++) {
|
2017-10-18 17:22:34 +01:00
|
|
|
float fmyRed = (float)mcolor[i].red / dimmer;
|
|
|
|
float fmyGrn = (float)mcolor[i].green / dimmer;
|
|
|
|
float fmyBlu = (float)mcolor[i].blue / dimmer;
|
2017-09-18 17:06:46 +01:00
|
|
|
mcolor[i].red = (uint8_t)fmyRed;
|
|
|
|
mcolor[i].green = (uint8_t)fmyGrn;
|
|
|
|
mcolor[i].blue = (uint8_t)fmyBlu;
|
|
|
|
}
|
2019-07-31 15:59:12 +01:00
|
|
|
uint32_t colorIndex = offset % scheme.count;
|
2021-06-11 17:14:12 +01:00
|
|
|
for (uint32_t i = 0; i < Settings->light_pixels; i++) {
|
|
|
|
if (maxSize) { colorIndex = ((i + offset) % (scheme.count * kWidth[Settings->light_width])) / kWidth[Settings->light_width]; }
|
2017-09-18 17:06:46 +01:00
|
|
|
c.R = mcolor[colorIndex].red;
|
|
|
|
c.G = mcolor[colorIndex].green;
|
|
|
|
c.B = mcolor[colorIndex].blue;
|
|
|
|
strip->SetPixelColor(i, c);
|
|
|
|
}
|
2017-10-18 17:22:34 +01:00
|
|
|
Ws2812StripShow();
|
2017-09-18 17:06:46 +01:00
|
|
|
}
|
|
|
|
|
2021-11-20 13:13:54 +00:00
|
|
|
void Ws2812Steps(uint32_t schemenr) {
|
2021-11-02 23:03:06 +00:00
|
|
|
#if (USE_WS2812_CTYPE > NEO_3LED)
|
|
|
|
RgbwColor c;
|
|
|
|
c.W = 0;
|
|
|
|
#else
|
|
|
|
RgbColor c;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ColorScheme scheme = kSchemes[schemenr];
|
2021-11-07 10:58:46 +00:00
|
|
|
// apply main color if current sheme == kStairs
|
2021-11-20 13:13:54 +00:00
|
|
|
if (scheme.colors == kStairs) {
|
2021-11-02 23:03:06 +00:00
|
|
|
scheme.colors[1].red = Settings->light_color[0];
|
|
|
|
scheme.colors[1].green = Settings->light_color[1];
|
|
|
|
scheme.colors[1].blue = Settings->light_color[2];
|
|
|
|
}
|
|
|
|
|
2021-11-20 13:13:54 +00:00
|
|
|
uint8_t scheme_count = scheme.count;
|
|
|
|
if (Settings->light_fade) {
|
|
|
|
scheme_count = Settings->ws_width[WS_HOUR]; // Width4
|
2021-11-02 23:03:06 +00:00
|
|
|
}
|
2021-11-20 13:13:54 +00:00
|
|
|
if (scheme_count < 2) {
|
|
|
|
scheme_count = 2;
|
|
|
|
}
|
2021-11-02 23:03:06 +00:00
|
|
|
|
|
|
|
WsColor mcolor[scheme_count];
|
|
|
|
|
2021-11-20 13:13:54 +00:00
|
|
|
uint8_t color_start = 0;
|
|
|
|
uint8_t color_end = 1;
|
|
|
|
if (Settings->light_rotation & 0x01) {
|
|
|
|
color_start = 1;
|
|
|
|
color_end = 0;
|
2021-11-02 23:03:06 +00:00
|
|
|
}
|
|
|
|
|
2021-11-20 13:13:54 +00:00
|
|
|
if (Settings->light_fade) {
|
2021-11-07 10:58:46 +00:00
|
|
|
// generate gradient (width = Width4)
|
2021-11-20 13:13:54 +00:00
|
|
|
for (uint32_t i = 1; i < scheme_count - 1; i++) {
|
2021-11-02 23:03:06 +00:00
|
|
|
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));
|
|
|
|
}
|
2021-11-20 13:13:54 +00:00
|
|
|
// 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;
|
|
|
|
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;
|
2021-11-02 23:03:06 +00:00
|
|
|
|
2021-11-07 10:58:46 +00:00
|
|
|
// Adjust to dimmer value
|
2021-11-02 23:03:06 +00:00
|
|
|
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;
|
|
|
|
|
2021-11-07 10:58:46 +00:00
|
|
|
//all pixels are shown already | rotation change will not change current state
|
2021-11-20 13:13:54 +00:00
|
|
|
if (current_position > Settings->light_pixels / Settings->light_step_pixels + scheme_count ) {
|
2021-11-02 23:03:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t colorIndex;
|
|
|
|
int32_t step_nr;
|
2021-11-20 13:13:54 +00:00
|
|
|
|
2021-11-02 23:03:06 +00:00
|
|
|
for (uint32_t i = 0; i < Settings->light_pixels; i++) {
|
|
|
|
step_nr = i / Settings->light_step_pixels;
|
2021-11-20 13:13:54 +00:00
|
|
|
colorIndex = current_position - step_nr;
|
|
|
|
if (colorIndex < 0) { colorIndex = 0; }
|
|
|
|
if (colorIndex > scheme_count - 1) { colorIndex = scheme_count - 1; }
|
2021-11-02 23:03:06 +00:00
|
|
|
c.R = mcolor[colorIndex].red;
|
|
|
|
c.G = mcolor[colorIndex].green;
|
|
|
|
c.B = mcolor[colorIndex].blue;
|
2021-11-07 10:58:46 +00:00
|
|
|
// Adjust the scheme rotation
|
2021-11-20 13:13:54 +00:00
|
|
|
if (Settings->light_rotation & 0x02) {
|
2021-11-02 23:03:06 +00:00
|
|
|
strip->SetPixelColor(Settings->light_pixels - i - 1, c);
|
|
|
|
} else {
|
|
|
|
strip->SetPixelColor(i, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ws2812StripShow();
|
|
|
|
}
|
|
|
|
|
2021-12-12 17:23:49 +00:00
|
|
|
#ifdef USE_NETWORK_LIGHT_SCHEMES
|
|
|
|
void Ws2812DDP(void)
|
|
|
|
{
|
|
|
|
#if (USE_WS2812_CTYPE > NEO_3LED)
|
|
|
|
RgbwColor c;
|
|
|
|
c.W = 0;
|
|
|
|
#else
|
|
|
|
RgbColor c;
|
|
|
|
#endif
|
|
|
|
c.R = 0;
|
|
|
|
c.G = 0;
|
|
|
|
c.B = 0;
|
|
|
|
|
|
|
|
// Can't be trying to initialize UDP too early.
|
|
|
|
if (TasmotaGlobal.restart_flag || TasmotaGlobal.global_state.network_down) return;
|
|
|
|
|
|
|
|
// Start DDP listener, if fail, just set last ddp_color
|
|
|
|
if (!ddp_udp_up) {
|
|
|
|
if (!ddp_udp.begin(4048)) return;
|
|
|
|
ddp_udp_up = 1;
|
|
|
|
AddLog(LOG_LEVEL_DEBUG_MORE, "DDP: UDP Listener Started: WS2812 Scheme");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the DDP payload over UDP
|
|
|
|
std::vector<uint8_t> payload;
|
|
|
|
while (uint16_t packet_size = ddp_udp.parsePacket()) {
|
|
|
|
payload.resize(packet_size);
|
|
|
|
if (!ddp_udp.read(&payload[0], payload.size())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No verification checks performed against packet besides length
|
|
|
|
if (payload.size() > (9+3*Settings->light_pixels)) {
|
|
|
|
for (uint32_t i = 0; i < Settings->light_pixels; i++) {
|
|
|
|
c.R = payload[10+3*i];
|
|
|
|
c.G = payload[11+3*i];
|
|
|
|
c.B = payload[12+3*i];
|
|
|
|
strip->SetPixelColor(i, c);
|
|
|
|
}
|
|
|
|
Ws2812StripShow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-14 13:32:09 +00:00
|
|
|
void Ws2812Clear(void)
|
2017-09-18 17:06:46 +01:00
|
|
|
{
|
|
|
|
strip->ClearTo(0);
|
|
|
|
strip->Show();
|
2019-10-08 16:46:03 +01:00
|
|
|
Ws2812.show_next = 1;
|
2017-09-18 17:06:46 +01:00
|
|
|
}
|
|
|
|
|
2019-07-31 15:59:12 +01:00
|
|
|
void Ws2812SetColor(uint32_t led, uint8_t red, uint8_t green, uint8_t blue, uint8_t white)
|
2017-09-18 17:06:46 +01:00
|
|
|
{
|
2018-03-17 14:22:29 +00:00
|
|
|
#if (USE_WS2812_CTYPE > NEO_3LED)
|
2017-11-11 15:02:18 +00:00
|
|
|
RgbwColor lcolor;
|
|
|
|
lcolor.W = white;
|
|
|
|
#else
|
2017-09-18 17:06:46 +01:00
|
|
|
RgbColor lcolor;
|
2017-11-11 15:02:18 +00:00
|
|
|
#endif
|
|
|
|
|
2017-09-18 17:06:46 +01:00
|
|
|
lcolor.R = red;
|
|
|
|
lcolor.G = green;
|
|
|
|
lcolor.B = blue;
|
|
|
|
if (led) {
|
|
|
|
strip->SetPixelColor(led -1, lcolor); // Led 1 is strip Led 0 -> substract offset 1
|
|
|
|
} else {
|
|
|
|
// strip->ClearTo(lcolor); // Set WS2812_MAX_LEDS pixels
|
2021-06-11 17:14:12 +01:00
|
|
|
for (uint32_t i = 0; i < Settings->light_pixels; i++) {
|
2017-09-18 17:06:46 +01:00
|
|
|
strip->SetPixelColor(i, lcolor);
|
|
|
|
}
|
|
|
|
}
|
2018-06-16 14:23:11 +01:00
|
|
|
|
2019-10-08 16:46:03 +01:00
|
|
|
if (!Ws2812.suspend_update) {
|
2018-06-16 14:23:11 +01:00
|
|
|
strip->Show();
|
2019-10-08 16:46:03 +01:00
|
|
|
Ws2812.show_next = 1;
|
2018-06-16 14:23:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-31 15:59:12 +01:00
|
|
|
char* Ws2812GetColor(uint32_t led, char* scolor)
|
2017-09-18 17:06:46 +01:00
|
|
|
{
|
2017-11-11 15:02:18 +00:00
|
|
|
uint8_t sl_ledcolor[4];
|
2017-09-18 17:06:46 +01:00
|
|
|
|
2018-03-17 14:22:29 +00:00
|
|
|
#if (USE_WS2812_CTYPE > NEO_3LED)
|
2017-11-11 15:02:18 +00:00
|
|
|
RgbwColor lcolor = strip->GetPixelColor(led -1);
|
|
|
|
sl_ledcolor[3] = lcolor.W;
|
|
|
|
#else
|
2017-09-18 17:06:46 +01:00
|
|
|
RgbColor lcolor = strip->GetPixelColor(led -1);
|
2017-11-11 15:02:18 +00:00
|
|
|
#endif
|
2017-09-18 17:06:46 +01:00
|
|
|
sl_ledcolor[0] = lcolor.R;
|
|
|
|
sl_ledcolor[1] = lcolor.G;
|
|
|
|
sl_ledcolor[2] = lcolor.B;
|
|
|
|
scolor[0] = '\0';
|
2019-08-17 12:17:30 +01:00
|
|
|
for (uint32_t i = 0; i < Light.subtype; i++) {
|
2021-06-11 17:14:12 +01:00
|
|
|
if (Settings->flag.decimal_text) { // SetOption17 - Switch between decimal or hexadecimal output (0 = hexadecimal, 1 = decimal)
|
2017-10-23 11:18:15 +01:00
|
|
|
snprintf_P(scolor, 25, PSTR("%s%s%d"), scolor, (i > 0) ? "," : "", sl_ledcolor[i]);
|
|
|
|
} else {
|
|
|
|
snprintf_P(scolor, 25, PSTR("%s%02X"), scolor, sl_ledcolor[i]);
|
|
|
|
}
|
2017-09-18 17:06:46 +01:00
|
|
|
}
|
|
|
|
return scolor;
|
|
|
|
}
|
|
|
|
|
2019-10-08 16:46:03 +01:00
|
|
|
/*********************************************************************************************\
|
|
|
|
* Public - used by scripter only
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
|
|
|
void Ws2812ForceSuspend (void)
|
|
|
|
{
|
|
|
|
Ws2812.suspend_update = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Ws2812ForceUpdate (void)
|
|
|
|
{
|
|
|
|
Ws2812.suspend_update = false;
|
|
|
|
strip->Show();
|
|
|
|
Ws2812.show_next = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************************/
|
|
|
|
|
|
|
|
bool Ws2812SetChannels(void)
|
|
|
|
{
|
|
|
|
uint8_t *cur_col = (uint8_t*)XdrvMailbox.data;
|
|
|
|
|
|
|
|
Ws2812SetColor(0, cur_col[0], cur_col[1], cur_col[2], cur_col[3]);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Ws2812ShowScheme(void)
|
2017-09-18 17:06:46 +01:00
|
|
|
{
|
2021-06-11 17:14:12 +01:00
|
|
|
uint32_t scheme = Settings->light_scheme - Ws2812.scheme_offset;
|
2021-12-12 17:23:49 +00:00
|
|
|
|
|
|
|
#ifdef USE_NETWORK_LIGHT_SCHEMES
|
|
|
|
if ((scheme != 9) && (ddp_udp_up)) {
|
|
|
|
ddp_udp.stop();
|
|
|
|
ddp_udp_up = 0;
|
|
|
|
AddLog(LOG_LEVEL_DEBUG_MORE, "DDP: UDP Stopped: WS2812 Scheme not DDP");
|
|
|
|
}
|
|
|
|
#endif
|
2017-09-18 17:06:46 +01:00
|
|
|
switch (scheme) {
|
|
|
|
case 0: // Clock
|
2020-10-29 12:58:50 +00:00
|
|
|
if ((1 == TasmotaGlobal.state_250mS) || (Ws2812.show_next)) {
|
2017-10-18 17:22:34 +01:00
|
|
|
Ws2812Clock();
|
2019-10-08 16:46:03 +01:00
|
|
|
Ws2812.show_next = 0;
|
2017-09-18 17:06:46 +01:00
|
|
|
}
|
|
|
|
break;
|
2021-12-12 17:23:49 +00:00
|
|
|
#ifdef USE_NETWORK_LIGHT_SCHEMES
|
|
|
|
case 9:
|
|
|
|
Ws2812DDP();
|
|
|
|
break;
|
|
|
|
#endif
|
2017-09-18 17:06:46 +01:00
|
|
|
default:
|
2021-11-02 23:03:06 +00:00
|
|
|
if(Settings->light_step_pixels > 0){
|
|
|
|
Ws2812Steps(scheme -1);
|
|
|
|
} else {
|
|
|
|
if (1 == Settings->light_fade) {
|
|
|
|
Ws2812Gradient(scheme -1);
|
|
|
|
} else {
|
|
|
|
Ws2812Bars(scheme -1);
|
|
|
|
}
|
2017-09-18 17:06:46 +01:00
|
|
|
}
|
2019-10-08 16:46:03 +01:00
|
|
|
Ws2812.show_next = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Ws2812ModuleSelected(void)
|
|
|
|
{
|
2020-12-17 15:33:26 +00:00
|
|
|
#if (USE_WS2812_HARDWARE == NEO_HW_P9813)
|
|
|
|
if (PinUsed(GPIO_P9813_CLK) && PinUsed(GPIO_P9813_DAT)) { // RGB led
|
|
|
|
strip = new NeoPixelBus<selectedNeoFeatureType, selectedNeoSpeedType>(WS2812_MAX_LEDS, Pin(GPIO_P9813_CLK), Pin(GPIO_P9813_DAT));
|
|
|
|
#else
|
2020-04-27 11:54:07 +01:00
|
|
|
if (PinUsed(GPIO_WS2812)) { // RGB led
|
2019-10-08 16:46:03 +01:00
|
|
|
// For DMA, the Pin is ignored as it uses GPIO3 due to DMA hardware use.
|
2020-04-27 10:54:23 +01:00
|
|
|
strip = new NeoPixelBus<selectedNeoFeatureType, selectedNeoSpeedType>(WS2812_MAX_LEDS, Pin(GPIO_WS2812));
|
2020-12-17 15:33:26 +00:00
|
|
|
#endif // NEO_HW_P9813
|
2019-10-08 16:46:03 +01:00
|
|
|
strip->Begin();
|
|
|
|
|
|
|
|
Ws2812Clear();
|
|
|
|
|
|
|
|
Ws2812.scheme_offset = Light.max_scheme +1;
|
|
|
|
Light.max_scheme += WS2812_SCHEMES;
|
|
|
|
|
|
|
|
#if (USE_WS2812_CTYPE > NEO_3LED)
|
2020-10-30 11:29:48 +00:00
|
|
|
TasmotaGlobal.light_type = LT_RGBW;
|
2019-10-08 16:46:03 +01:00
|
|
|
#else
|
2020-10-30 11:29:48 +00:00
|
|
|
TasmotaGlobal.light_type = LT_RGB;
|
2019-10-08 16:46:03 +01:00
|
|
|
#endif
|
2020-10-30 11:29:48 +00:00
|
|
|
TasmotaGlobal.light_driver = XLGT_01;
|
2019-10-08 16:46:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************************/
|
|
|
|
|
|
|
|
void CmndLed(void)
|
|
|
|
{
|
2021-06-11 17:14:12 +01:00
|
|
|
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= Settings->light_pixels)) {
|
2019-10-08 16:46:03 +01:00
|
|
|
if (XdrvMailbox.data_len > 0) {
|
|
|
|
char *p;
|
|
|
|
uint16_t idx = XdrvMailbox.index;
|
|
|
|
Ws2812ForceSuspend();
|
|
|
|
for (char *color = strtok_r(XdrvMailbox.data, " ", &p); color; color = strtok_r(nullptr, " ", &p)) {
|
|
|
|
if (LightColorEntry(color, strlen(color))) {
|
|
|
|
Ws2812SetColor(idx, Light.entry_color[0], Light.entry_color[1], Light.entry_color[2], Light.entry_color[3]);
|
|
|
|
idx++;
|
2021-06-11 17:14:12 +01:00
|
|
|
if (idx > Settings->light_pixels) { break; }
|
2019-10-08 16:46:03 +01:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ws2812ForceUpdate();
|
|
|
|
}
|
|
|
|
char scolor[LIGHT_COLOR_SIZE];
|
|
|
|
ResponseCmndIdxChar(Ws2812GetColor(XdrvMailbox.index, scolor));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndPixels(void)
|
|
|
|
{
|
|
|
|
if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload <= WS2812_MAX_LEDS)) {
|
2021-06-11 17:14:12 +01:00
|
|
|
Settings->light_pixels = XdrvMailbox.payload;
|
|
|
|
Settings->light_rotation = 0;
|
2019-10-08 16:46:03 +01:00
|
|
|
Ws2812Clear();
|
|
|
|
Light.update = true;
|
|
|
|
}
|
2021-06-11 17:14:12 +01:00
|
|
|
ResponseCmndNumber(Settings->light_pixels);
|
2019-10-08 16:46:03 +01:00
|
|
|
}
|
|
|
|
|
2021-11-01 11:31:08 +00:00
|
|
|
void CmndStepPixels(void)
|
|
|
|
{
|
2021-11-22 15:08:24 +00:00
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 255)) {
|
|
|
|
Settings->light_step_pixels = (XdrvMailbox.payload > WS2812_MAX_LEDS) ? WS2812_MAX_LEDS : XdrvMailbox.payload;
|
2021-11-01 11:31:08 +00:00
|
|
|
Ws2812Clear();
|
|
|
|
Light.update = true;
|
|
|
|
}
|
|
|
|
ResponseCmndNumber(Settings->light_step_pixels);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-08 16:46:03 +01:00
|
|
|
void CmndRotation(void)
|
|
|
|
{
|
2021-06-11 17:14:12 +01:00
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < Settings->light_pixels)) {
|
|
|
|
Settings->light_rotation = XdrvMailbox.payload;
|
2019-10-08 16:46:03 +01:00
|
|
|
}
|
2021-06-11 17:14:12 +01:00
|
|
|
ResponseCmndNumber(Settings->light_rotation);
|
2019-10-08 16:46:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CmndWidth(void)
|
|
|
|
{
|
|
|
|
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= 4)) {
|
|
|
|
if (1 == XdrvMailbox.index) {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 4)) {
|
2021-06-11 17:14:12 +01:00
|
|
|
Settings->light_width = XdrvMailbox.payload;
|
2019-10-08 16:46:03 +01:00
|
|
|
}
|
2021-06-11 17:14:12 +01:00
|
|
|
ResponseCmndNumber(Settings->light_width);
|
2019-10-08 16:46:03 +01:00
|
|
|
} else {
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 32)) {
|
2021-06-11 17:14:12 +01:00
|
|
|
Settings->ws_width[XdrvMailbox.index -2] = XdrvMailbox.payload;
|
2019-10-08 16:46:03 +01:00
|
|
|
}
|
2021-06-11 17:14:12 +01:00
|
|
|
ResponseCmndIdxNumber(Settings->ws_width[XdrvMailbox.index -2]);
|
2019-10-08 16:46:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************************************\
|
|
|
|
* Interface
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
2022-11-11 09:44:56 +00:00
|
|
|
bool Xlgt01(uint32_t function)
|
2019-10-08 16:46:03 +01:00
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
switch (function) {
|
|
|
|
case FUNC_SET_CHANNELS:
|
|
|
|
result = Ws2812SetChannels();
|
|
|
|
break;
|
|
|
|
case FUNC_SET_SCHEME:
|
|
|
|
Ws2812ShowScheme();
|
|
|
|
break;
|
|
|
|
case FUNC_COMMAND:
|
|
|
|
result = DecodeCommand(kWs2812Commands, Ws2812Command);
|
|
|
|
break;
|
|
|
|
case FUNC_MODULE_INIT:
|
|
|
|
Ws2812ModuleSelected();
|
2017-09-18 17:06:46 +01:00
|
|
|
break;
|
|
|
|
}
|
2019-10-08 16:46:03 +01:00
|
|
|
return result;
|
2017-09-18 17:06:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // USE_WS2812
|
2020-12-07 21:24:00 +00:00
|
|
|
#endif // USE_LIGHT
|