Use sacrificial pixel as a STATUSLED

This commit is contained in:
Blaz Kristan 2021-11-30 16:28:26 +01:00
parent d6be7b4cae
commit 0f8d464706
3 changed files with 44 additions and 16 deletions

View File

@ -87,11 +87,12 @@ class Bus {
virtual void show() {}
virtual bool canShow() { return true; }
virtual void setPixelColor(uint16_t pix, uint32_t c) {};
virtual void setPixelColor(uint16_t pix, uint32_t c, uint8_t cct) {};
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 void setPixelColor(uint16_t pix, uint32_t c, uint8_t cct) {}
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() {}
@ -180,6 +181,13 @@ class BusDigital : public Bus {
PolyBus::setBrightness(_busPtr, _iType, b);
}
void setStatusPixel(uint32_t c) {
if (_skip && canShow()) {
for (uint8_t i=0; i<_skip; i--) PolyBus::setPixelColor(_busPtr, _iType, i, c, _colorOrder);
PolyBus::show(_busPtr, _iType);
}
}
void setPixelColor(uint16_t pix, uint32_t c) {
if (getAutoWhiteMode() != RGBW_MODE_MANUAL_ONLY) c = autoWhiteCalc(c);
if (reversed) pix = _len - pix -1;
@ -559,6 +567,10 @@ 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];

View File

@ -264,7 +264,7 @@ void WLED::setup()
DEBUG_PRINTLN(F("Reading config"));
deserializeConfigFromFS();
#if STATUSLED
#if defined(STATUSLED) && STATUSLED>=0
if (!pinManager.isPinAllocated(STATUSLED)) {
// NOTE: Special case: The status LED should *NOT* be allocated.
// See comments in handleStatusLed().
@ -711,32 +711,48 @@ void WLED::handleConnection()
// else turn the status LED off
void WLED::handleStatusLED()
{
#if STATUSLED
#if defined(STATUSLED)
uint32_t c = 0;
static unsigned long ledStatusLastMillis = 0;
static unsigned short ledStatusType = 0; // current status type - corresponds to number of blinks per second
static bool ledStatusState = 0; // the current LED state
static bool ledStatusState = false; // the current LED state
#if STATUSLED>=0
if (pinManager.isPinAllocated(STATUSLED)) {
return; //lower priority if something else uses the same pin
}
#endif
ledStatusType = WLED_CONNECTED ? 0 : 2;
if (mqttEnabled && ledStatusType != 2) { // Wi-Fi takes precendence over MQTT
ledStatusType = WLED_MQTT_CONNECTED ? 0 : 4;
if (WLED_CONNECTED) {
c = RGBW32(0,255,0,0);
ledStatusType = 2;
} else if (WLED_MQTT_CONNECTED) {
c = RGBW32(0,128,0,0);
ledStatusType = 4;
} else if (apActive) {
c = RGBW32(0,0,255,0);
ledStatusType = 2;
}
if (ledStatusType) {
if (millis() - ledStatusLastMillis >= (1000/ledStatusType)) {
ledStatusLastMillis = millis();
ledStatusState = ledStatusState ? 0 : 1;
ledStatusState = !ledStatusState;
#if STATUSLED>=0
digitalWrite(STATUSLED, ledStatusState);
#else
busses.setStatusPixel(ledStatusState ? c : 0);
#endif
}
} else {
#ifdef STATUSLEDINVERTED
#if STATUSLED>=0
#ifdef STATUSLEDINVERTED
digitalWrite(STATUSLED, HIGH);
#else
#else
digitalWrite(STATUSLED, LOW);
#endif
#else
busses.setStatusPixel(0);
#endif
}
#endif
}

View File

@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2111251
#define VERSION 2111301
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG