feat(client): uniform LED signaling — off after 60s stable connection
This commit is contained in:
parent
d9ac8a578b
commit
ebaaa8cc4b
1 changed files with 38 additions and 5 deletions
|
|
@ -47,6 +47,12 @@ static bool relay1SendState = false;
|
|||
static bool relay2SendState = false;
|
||||
static uint32_t seq = 0;
|
||||
|
||||
#define STABLE_LED_TIMEOUT_MS 60000
|
||||
uint32_t connectionStableMs = 0;
|
||||
uint32_t relayFlashUntil = 0;
|
||||
bool otaInProgress = false;
|
||||
bool otaEnded = false;
|
||||
|
||||
static bool bleReady = false;
|
||||
static bool serverFound = false;
|
||||
static NimBLEAddress serverAddress;
|
||||
|
|
@ -365,13 +371,40 @@ void loop() {
|
|||
bool relay1State = t1Active || btnActive;
|
||||
bool relay2State = t2Active;
|
||||
|
||||
if (relay1State || relay2State) {
|
||||
leds[0] = CRGB::Green;
|
||||
} else if (connected) {
|
||||
leds[0] = CRGB::Blue;
|
||||
CRGB ledColor;
|
||||
|
||||
if (otaInProgress) {
|
||||
ledColor = otaEnded
|
||||
? CRGB::Yellow
|
||||
: (((millis() / 100) % 2) ? CRGB::Green : CRGB::Black);
|
||||
} else {
|
||||
leds[0] = CRGB::Red;
|
||||
if (connected) {
|
||||
if (connectionStableMs == 0) connectionStableMs = millis();
|
||||
} else {
|
||||
connectionStableMs = 0;
|
||||
}
|
||||
|
||||
if (connected) {
|
||||
ledColor = (millis() - connectionStableMs >= STABLE_LED_TIMEOUT_MS)
|
||||
? CRGB::Black
|
||||
: CRGB::Yellow;
|
||||
} else {
|
||||
ledColor = CRGB::Red;
|
||||
}
|
||||
|
||||
static bool lastRelayActive = false;
|
||||
bool relayActive = relay1State || relay2State;
|
||||
if (relayActive != lastRelayActive) {
|
||||
relayFlashUntil = millis() + 150;
|
||||
}
|
||||
lastRelayActive = relayActive;
|
||||
|
||||
if (millis() < relayFlashUntil) {
|
||||
ledColor = CRGB::Green;
|
||||
}
|
||||
}
|
||||
|
||||
leds[0] = ledColor;
|
||||
FastLED.show();
|
||||
|
||||
if (connected && pCmdChar != nullptr) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue