Skip to content

Commit

Permalink
Status LED support in Bus manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Aircoookie committed Nov 30, 2021
1 parent 11c7ffa commit 48339b1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions wled00/FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
28 changes: 22 additions & 6 deletions wled00/bus_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion wled00/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion wled00/src/dependencies/espalexa/EspalexaDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class EspalexaDevice {
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;
Expand Down

0 comments on commit 48339b1

Please sign in to comment.