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
44
src/main.cpp
44
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};
|
||||
|
|
@ -762,15 +766,20 @@ void drawDashboard() {
|
|||
if (indexSelected[i] && strlen(indexTickers[i]) > 0) {
|
||||
lcd.drawString(String(getIndexFriendlyName(indexTickers[i])) + ":", col3X, indexY);
|
||||
lcd.drawString(formatPriceUS(indexPrices[i], 2), col3X, indexY + 28);
|
||||
indexY += 65;
|
||||
}
|
||||
indexY += 65;
|
||||
}
|
||||
}
|
||||
|
||||
lcd.fillSmoothRoundRect(0, SCREEN_HEIGHT - 40, SCREEN_WIDTH, 40, 8, TFT_ORANGE);
|
||||
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;
|
||||
|
|
@ -1161,22 +1170,19 @@ bool handleWifiPasswordTouch(int32_t x, int32_t y) {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (x >= SCREEN_WIDTH / 2 + 50 && x < SCREEN_WIDTH / 2 + 150 && y >= btnY && y < btnY + 36) {
|
||||
if (x >= SCREEN_WIDTH / 2 + 50 && x < SCREEN_WIDTH / 2 + 150 && y >= btnY && y < btnY + 36) {
|
||||
wifiPassword = String(keyboardBuffer);
|
||||
preferences.begin("wifi", false);
|
||||
preferences.putString("ssid", selectedSSID);
|
||||
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());
|
||||
|
||||
|
||||
currentScreen = SCREEN_DASHBOARD;
|
||||
needsRefresh = true;
|
||||
return true;
|
||||
|
|
@ -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