From 48339b19d4535776efbbcea76fa58cf54ba3b05e Mon Sep 17 00:00:00 2001 From: cschwinne Date: Tue, 30 Nov 2021 22:52:17 +0100 Subject: [PATCH] Status LED support in Bus manager --- wled00/FX_fcn.cpp | 2 ++ wled00/bus_manager.h | 28 +++++++++++++++---- wled00/const.h | 2 +- .../dependencies/espalexa/EspalexaDevice.h | 2 +- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index b1e5e8bf9..9077cdaa6 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -1166,6 +1166,8 @@ uint32_t WS2812FX::gamma32(uint32_t color) } WS2812FX* WS2812FX::instance = nullptr; + +//Bus static member definition, would belong in bus_manager.cpp int16_t Bus::_cct = -1; uint8_t Bus::_cctBlend = 0; uint8_t Bus::_autoWhiteMode = RGBW_MODE_DUAL; \ No newline at end of file diff --git a/wled00/bus_manager.h b/wled00/bus_manager.h index bc6b2221b..c3d913270 100644 --- a/wled00/bus_manager.h +++ b/wled00/bus_manager.h @@ -85,10 +85,11 @@ class Bus { virtual void show() {} virtual bool canShow() { return true; } - virtual void setPixelColor(uint16_t pix, uint32_t c) {}; - virtual uint32_t getPixelColor(uint16_t pix) { return 0; }; - virtual void setBrightness(uint8_t b) {}; - virtual void cleanup() {}; + virtual void setStatusPixel(uint32_t c) {} + virtual void setPixelColor(uint16_t pix, uint32_t c) {} + virtual uint32_t getPixelColor(uint16_t pix) { return 0; } + virtual void setBrightness(uint8_t b) {} + virtual void cleanup() {} virtual uint8_t getPins(uint8_t* pinArray) { return 0; } inline uint16_t getLength() { return _len; } virtual void setColorOrder() {} @@ -192,6 +193,15 @@ class BusDigital : public Bus { PolyBus::setBrightness(_busPtr, _iType, b); } + //If LEDs are skipped, it is possible to use the first as a status LED. + //TODO only show if no new show due in the next 50ms + void setStatusPixel(uint32_t c) { + if (_skip && canShow()) { + PolyBus::setPixelColor(_busPtr, _iType, 0, c, _colorOrder); + PolyBus::show(_busPtr, _iType); + } + } + void setPixelColor(uint16_t pix, uint32_t c) { if (_type == TYPE_SK6812_RGBW || _type == TYPE_TM1814) c = autoWhiteCalc(c); if (_cct >= 1900) c = colorBalanceFromKelvin(_cct, c); //color correction from CCT @@ -292,10 +302,10 @@ class BusPwm : public Bus { void setPixelColor(uint16_t pix, uint32_t c) { if (pix != 0 || !_valid) return; //only react to first pixel - if (_type == TYPE_ANALOG_3CH && _cct >= 1900) { + if (_type != TYPE_ANALOG_3CH) c = autoWhiteCalc(c); + if (_cct >= 1900 && (_type == TYPE_ANALOG_3CH || _type == TYPE_ANALOG_4CH)) { c = colorBalanceFromKelvin(_cct, c); //color correction from CCT } - if (_type != TYPE_ANALOG_3CH) c = autoWhiteCalc(c); uint8_t r = R(c); uint8_t g = G(c); uint8_t b = B(c); @@ -562,6 +572,12 @@ class BusManager { } } + void setStatusPixel(uint32_t c) { + for (uint8_t i = 0; i < numBusses; i++) { + busses[i]->setStatusPixel(c); + } + } + void setPixelColor(uint16_t pix, uint32_t c, int16_t cct=-1) { for (uint8_t i = 0; i < numBusses; i++) { Bus* b = busses[i]; diff --git a/wled00/const.h b/wled00/const.h index 5b834bf36..04cdfb7b1 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -124,7 +124,7 @@ // - 0b010 (dec. 32-47) analog (PWM) // - 0b011 (dec. 48-63) digital (data + clock / SPI) // - 0b100 (dec. 64-79) unused/reserved -// - 0b101 (dec. 80-95) digital (data + clock / SPI) +// - 0b101 (dec. 80-95) virtual network busses // - 0b110 (dec. 96-111) unused/reserved // - 0b111 (dec. 112-127) unused/reserved //bit 7 is reserved and set to 0 diff --git a/wled00/src/dependencies/espalexa/EspalexaDevice.h b/wled00/src/dependencies/espalexa/EspalexaDevice.h index 3cf97fb69..db9a8a7bf 100644 --- a/wled00/src/dependencies/espalexa/EspalexaDevice.h +++ b/wled00/src/dependencies/espalexa/EspalexaDevice.h @@ -22,7 +22,7 @@ private: ColorCallbackFunction _callbackCol = nullptr; uint8_t _val, _val_last, _sat = 0; uint16_t _hue = 0, _ct = 0; - float _x = 0.5, _y = 0.5; + float _x = 0.5f, _y = 0.5f; uint32_t _rgb = 0; uint8_t _id = 0; EspalexaDeviceType _type;