Add status led (#1264)

* Add status led

* Shorten code

* Fix "Shorten code"

* Change ledStatusType to an unsigned short
This commit is contained in:
Jeff Rescignano
2020-10-19 12:08:45 -04:00
committed by GitHub
parent dcea584a9a
commit 235c123ad0
2 changed files with 36 additions and 0 deletions

View File

@@ -103,6 +103,7 @@ void WLED::loop()
}
yield();
handleWs();
handleStatusLED();
// DEBUG serial logging
#ifdef WLED_DEBUG
@@ -174,6 +175,10 @@ void WLED::setup()
SPIFFS.begin();
#endif
#if STATUSLED && STATUSLED != LEDPIN
pinMode(STATUSLED, OUTPUT);
#endif
DEBUG_PRINTLN(F("Load EEPROM"));
loadSettingsFromEEPROM(true);
beginStrip();
@@ -504,3 +509,26 @@ void WLED::handleConnection()
}
}
}
void WLED::handleStatusLED()
{
#if STATUSLED && STATUSLED != LEDPIN
ledStatusType = WLED_CONNECTED ? 0 : 2;
if (mqttEnabled && ledStatusType != 2) // Wi-Fi takes presendence over MQTT
ledStatusType = WLED_MQTT_CONNECTED ? 0 : 4;
if (ledStatusType) {
if (millis() - ledStatusLastMillis >= (1000/ledStatusType)) {
ledStatusLastMillis = millis();
ledStatusState = ledStatusState ? 0 : 1;
digitalWrite(STATUSLED, ledStatusState);
}
} else {
#ifdef STATUSLEDINVERTED
digitalWrite(STATUSLED, HIGH);
#else
digitalWrite(STATUSLED, LOW);
#endif
}
#endif
}