added connection status to the webUI
This commit is contained in:
@@ -156,6 +156,7 @@ uint16_t calOverrideSwitch;
|
||||
uint8_t selectedCalChannel = 0;
|
||||
bool overrideActive[NUM_CHANNELS] = {false};
|
||||
|
||||
uint16_t connectionStatusLabel;
|
||||
|
||||
// -------------------------------
|
||||
// Calibration interpolation
|
||||
@@ -270,6 +271,26 @@ void calOverrideSwitchCallback(Control *sender, int type) {
|
||||
}
|
||||
}
|
||||
|
||||
void updateConnectionStatusUI(ConnectionState state) {
|
||||
const char* text = "Unknown";
|
||||
|
||||
switch (state) {
|
||||
case STATE_DISCONNECTED:
|
||||
text = "Disconnected";
|
||||
break;
|
||||
case STATE_CONNECTING:
|
||||
text = "Connecting...";
|
||||
break;
|
||||
case STATE_WAIT_FOR_FIRST_PACKET:
|
||||
text = "Waiting for first UDP packet";
|
||||
break;
|
||||
case STATE_CONNECTED:
|
||||
text = "Connected";
|
||||
break;
|
||||
}
|
||||
|
||||
ESPUI.updateControlValue(connectionStatusLabel, text);
|
||||
}
|
||||
|
||||
// -------------------------------
|
||||
// Setup
|
||||
@@ -379,7 +400,39 @@ void setup() {
|
||||
// Row simulation: Port input + Save button
|
||||
// ------------------------------------------------------
|
||||
|
||||
// UDP Port Number input (shared label)
|
||||
// -------------------------------------------
|
||||
// Connection Status section
|
||||
// -------------------------------------------
|
||||
ESPUI.addControl(
|
||||
ControlType::Separator,
|
||||
"Connection Status",
|
||||
"",
|
||||
ControlColor::None,
|
||||
tabSettings
|
||||
);
|
||||
|
||||
// Live-updating connection status label
|
||||
connectionStatusLabel = ESPUI.addControl(
|
||||
ControlType::Label,
|
||||
"Status",
|
||||
"Disconnected",
|
||||
ControlColor::Wetasphalt,
|
||||
tabSettings
|
||||
);
|
||||
|
||||
// -------------------------------------------
|
||||
// UDP Telemetry Connection Settings section
|
||||
// -------------------------------------------
|
||||
|
||||
ESPUI.addControl(
|
||||
ControlType::Separator,
|
||||
"UDP Telemetry Connection Settings",
|
||||
"",
|
||||
ControlColor::None,
|
||||
tabSettings
|
||||
);
|
||||
|
||||
// UDP Port Number input
|
||||
portInput = ESPUI.addControl(
|
||||
ControlType::Number,
|
||||
"UDP Port",
|
||||
@@ -389,7 +442,7 @@ void setup() {
|
||||
portInputCallback
|
||||
);
|
||||
|
||||
// Save & Apply button (same label)
|
||||
// Save & Apply button
|
||||
ESPUI.addControl(
|
||||
ControlType::Button,
|
||||
"UDP Port",
|
||||
@@ -399,7 +452,7 @@ void setup() {
|
||||
savePortCallback
|
||||
);
|
||||
|
||||
// Separator line
|
||||
// Existing separator (leave as-is)
|
||||
ESPUI.addControl(
|
||||
ControlType::Separator,
|
||||
"",
|
||||
@@ -408,7 +461,7 @@ void setup() {
|
||||
tabSettings
|
||||
);
|
||||
|
||||
// Restart button at the bottom
|
||||
// Restart button (unchanged)
|
||||
ESPUI.addControl(
|
||||
ControlType::Button,
|
||||
"Restart ESP32",
|
||||
@@ -555,6 +608,7 @@ void loop() {
|
||||
// First valid packet after being disconnected → start CONNECTING
|
||||
Serial.println("STATE CHANGE: DISCONNECTED → CONNECTING (UDP connection established)");
|
||||
connectionState = STATE_CONNECTING;
|
||||
updateConnectionStatusUI(connectionState);
|
||||
|
||||
// Initialize fade-in: start from 0 on all non-override channels
|
||||
for (int ch = 0; ch < NUM_CHANNELS; ch++) {
|
||||
@@ -584,6 +638,7 @@ void loop() {
|
||||
slewStartTime = millis();
|
||||
lastPacketTime = millis();
|
||||
connectionState = STATE_CONNECTED;
|
||||
updateConnectionStatusUI(connectionState);
|
||||
|
||||
// Debug output
|
||||
Serial.println("Received UDP packet (first after fade-in):");
|
||||
@@ -643,6 +698,7 @@ void loop() {
|
||||
if (now - lastPacketTime > watchdogTimeout) {
|
||||
Serial.println("STATE CHANGE: CONNECTED → DISCONNECTED (UDP connection lost)");
|
||||
connectionState = STATE_DISCONNECTED;
|
||||
updateConnectionStatusUI(connectionState);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -667,6 +723,7 @@ void loop() {
|
||||
if (now - lastPacketTime > watchdogTimeout) {
|
||||
Serial.println("STATE CHANGE: CONNECTING → DISCONNECTED (no packets during fade-in)");
|
||||
connectionState = STATE_DISCONNECTED;
|
||||
updateConnectionStatusUI(connectionState);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -698,6 +755,7 @@ void loop() {
|
||||
if (allReached) {
|
||||
Serial.println("STATE CHANGE: CONNECTING → STATE_WAIT_FOR_FIRST_PACKET (fade-in complete)");
|
||||
connectionState = STATE_WAIT_FOR_FIRST_PACKET;
|
||||
updateConnectionStatusUI(connectionState);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
Reference in New Issue
Block a user