Add wifiConnecting state flag for better WiFi status feedback
This commit is contained in:
parent
0aa90bdce2
commit
7d932adb20
1 changed files with 32 additions and 12 deletions
32
src/main.cpp
32
src/main.cpp
|
|
@ -154,6 +154,10 @@ const char* getIndexFriendlyName(const char* ticker) {
|
|||
unsigned long lastRefresh = 0;
|
||||
const unsigned long REFRESH_INTERVAL = 180000;
|
||||
const unsigned long HISTORY_REFRESH_INTERVAL = 3600000;
|
||||
const unsigned long WIFI_CONNECT_TIMEOUT = 15000;
|
||||
|
||||
bool wifiConnecting = false;
|
||||
unsigned long wifiConnectStartTime = 0;
|
||||
|
||||
#define HISTORY_DAYS 30
|
||||
double btcHistory[HISTORY_DAYS] = {0};
|
||||
|
|
@ -770,7 +774,12 @@ void drawDashboard() {
|
|||
lcd.setTextColor(TFT_WHITE, TFT_ORANGE);
|
||||
lcd.setFont(&fonts::DejaVu18);
|
||||
lcd.setTextDatum(textdatum_t::middle_left);
|
||||
String wifiStatus = WiFi.status() == WL_CONNECTED ? "OK" : "OFFLINE";
|
||||
String wifiStatus;
|
||||
if (wifiConnecting) {
|
||||
wifiStatus = "Connecting...";
|
||||
} else {
|
||||
wifiStatus = WiFi.status() == WL_CONNECTED ? "OK" : "OFFLINE";
|
||||
}
|
||||
lcd.drawString("WiFi: " + wifiStatus, 20, SCREEN_HEIGHT - 20);
|
||||
|
||||
int secondsLeft = (REFRESH_INTERVAL - (millis() - lastRefresh)) / 1000;
|
||||
|
|
@ -1168,11 +1177,8 @@ bool handleWifiPasswordTouch(int32_t x, int32_t y) {
|
|||
preferences.putString("password", wifiPassword);
|
||||
preferences.end();
|
||||
|
||||
lcd.fillScreen(TFT_BLACK);
|
||||
lcd.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
lcd.setFont(&fonts::DejaVu24);
|
||||
lcd.setTextDatum(textdatum_t::middle_center);
|
||||
lcd.drawString("WiFi: Connecting...", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
|
||||
wifiConnecting = true;
|
||||
wifiConnectStartTime = millis();
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(selectedSSID.c_str(), wifiPassword.c_str());
|
||||
|
|
@ -1447,6 +1453,20 @@ void loop() {
|
|||
drawFooterCountdown();
|
||||
}
|
||||
|
||||
if (wifiConnecting) {
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
wifiConnecting = false;
|
||||
if (currentScreen == SCREEN_DASHBOARD) {
|
||||
drawDashboard();
|
||||
}
|
||||
} else if (millis() - wifiConnectStartTime > WIFI_CONNECT_TIMEOUT) {
|
||||
wifiConnecting = false;
|
||||
if (currentScreen == SCREEN_DASHBOARD) {
|
||||
drawDashboard();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (currentScreen == SCREEN_DASHBOARD && millis() - lastHistoryRefresh > HISTORY_REFRESH_INTERVAL) {
|
||||
fetchAllHistory();
|
||||
lastHistoryRefresh = millis();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue