feat(server): uniform LED signaling — off after 60s stable connection
This commit is contained in:
parent
ff99fe0a90
commit
d9ac8a578b
1 changed files with 42 additions and 18 deletions
58
src/main.cpp
58
src/main.cpp
|
|
@ -55,6 +55,10 @@ uint32_t lastSeq[MAX_CLIENTS] = {0, 0};
|
|||
uint16_t connHandles[MAX_CLIENTS] = {0xFFFF, 0xFFFF};
|
||||
int connectedCount = 0;
|
||||
|
||||
#define STABLE_LED_TIMEOUT_MS 60000
|
||||
uint32_t connectionStableMs = 0;
|
||||
uint32_t relayFlashUntil = 0;
|
||||
|
||||
bool otaInProgress = false;
|
||||
esp_ota_handle_t otaHandle = 0;
|
||||
const esp_partition_t *otaPartition = nullptr;
|
||||
|
|
@ -178,10 +182,6 @@ static void parseHexKey(const String &hex, uint8_t *out) {
|
|||
}
|
||||
}
|
||||
|
||||
static void ledOtaBusy() {
|
||||
leds[0] = (millis() / 100) % 2 ? CRGB::Green : CRGB::Black;
|
||||
}
|
||||
|
||||
static void otaReset() {
|
||||
otaInProgress = false;
|
||||
otaHandle = 0;
|
||||
|
|
@ -411,15 +411,9 @@ void setup() {
|
|||
pinMode(RELAY1_PIN, OUTPUT);
|
||||
pinMode(RELAY2_PIN, OUTPUT);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
leds[0] = CRGB::Green;
|
||||
leds[0] = CRGB::Red;
|
||||
FastLED.show();
|
||||
delay(200);
|
||||
leds[0] = CRGB::Black;
|
||||
FastLED.show();
|
||||
delay(200);
|
||||
}
|
||||
Serial.println("LED blink done, starting BLE...");
|
||||
Serial.println("LED red (no connection), starting BLE...");
|
||||
|
||||
NimBLEDevice::init("SylDa_Server");
|
||||
NimBLEDevice::setMTU(248);
|
||||
|
|
@ -550,8 +544,6 @@ void loop() {
|
|||
Serial.println("OTA: esp_ota_end OK, setting otaEnded=true, waiting for 0xFF confirm");
|
||||
otaEnded = true;
|
||||
otaEndedAt = millis();
|
||||
leds[0] = CRGB::Yellow;
|
||||
FastLED.show();
|
||||
}
|
||||
otaReady = false;
|
||||
Serial.printf("OTA: otaReady cleared — otaReady=%d, otaEnded=%d, otaConfirmed=%d, otaInProgress=%d\n",
|
||||
|
|
@ -601,14 +593,46 @@ void loop() {
|
|||
(connActive[0] && bleRelay1[0]) || (connActive[1] && bleRelay1[1]);
|
||||
relay2State = t2Active ||
|
||||
(connActive[0] && bleRelay2[0]) || (connActive[1] && bleRelay2[1]);
|
||||
|
||||
leds[0] = (connectedCount > 0) ? CRGB::Green : CRGB::Black;
|
||||
} else {
|
||||
relay1State = false;
|
||||
relay2State = false;
|
||||
ledOtaBusy();
|
||||
}
|
||||
|
||||
CRGB ledColor;
|
||||
|
||||
if (otaInProgress) {
|
||||
ledColor = otaEnded
|
||||
? CRGB::Yellow
|
||||
: (((millis() / 100) % 2) ? CRGB::Green : CRGB::Black);
|
||||
} else {
|
||||
if (connectedCount > 0) {
|
||||
if (connectionStableMs == 0) connectionStableMs = millis();
|
||||
} else {
|
||||
connectionStableMs = 0;
|
||||
}
|
||||
|
||||
if (connectedCount > 0) {
|
||||
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;
|
||||
|
||||
digitalWrite(RELAY1_PIN, relay1State ? HIGH : LOW);
|
||||
digitalWrite(RELAY2_PIN, relay2State ? HIGH : LOW);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue