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
36
src/main.cpp
36
src/main.cpp
|
|
@ -154,6 +154,10 @@ const char* getIndexFriendlyName(const char* ticker) {
|
||||||
unsigned long lastRefresh = 0;
|
unsigned long lastRefresh = 0;
|
||||||
const unsigned long REFRESH_INTERVAL = 180000;
|
const unsigned long REFRESH_INTERVAL = 180000;
|
||||||
const unsigned long HISTORY_REFRESH_INTERVAL = 3600000;
|
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
|
#define HISTORY_DAYS 30
|
||||||
double btcHistory[HISTORY_DAYS] = {0};
|
double btcHistory[HISTORY_DAYS] = {0};
|
||||||
|
|
@ -762,7 +766,7 @@ void drawDashboard() {
|
||||||
if (indexSelected[i] && strlen(indexTickers[i]) > 0) {
|
if (indexSelected[i] && strlen(indexTickers[i]) > 0) {
|
||||||
lcd.drawString(String(getIndexFriendlyName(indexTickers[i])) + ":", col3X, indexY);
|
lcd.drawString(String(getIndexFriendlyName(indexTickers[i])) + ":", col3X, indexY);
|
||||||
lcd.drawString(formatPriceUS(indexPrices[i], 2), col3X, indexY + 28);
|
lcd.drawString(formatPriceUS(indexPrices[i], 2), col3X, indexY + 28);
|
||||||
indexY += 65;
|
indexY += 65;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -770,7 +774,12 @@ void drawDashboard() {
|
||||||
lcd.setTextColor(TFT_WHITE, TFT_ORANGE);
|
lcd.setTextColor(TFT_WHITE, TFT_ORANGE);
|
||||||
lcd.setFont(&fonts::DejaVu18);
|
lcd.setFont(&fonts::DejaVu18);
|
||||||
lcd.setTextDatum(textdatum_t::middle_left);
|
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);
|
lcd.drawString("WiFi: " + wifiStatus, 20, SCREEN_HEIGHT - 20);
|
||||||
|
|
||||||
int secondsLeft = (REFRESH_INTERVAL - (millis() - lastRefresh)) / 1000;
|
int secondsLeft = (REFRESH_INTERVAL - (millis() - lastRefresh)) / 1000;
|
||||||
|
|
@ -1161,18 +1170,15 @@ bool handleWifiPasswordTouch(int32_t x, int32_t y) {
|
||||||
return true;
|
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);
|
wifiPassword = String(keyboardBuffer);
|
||||||
preferences.begin("wifi", false);
|
preferences.begin("wifi", false);
|
||||||
preferences.putString("ssid", selectedSSID);
|
preferences.putString("ssid", selectedSSID);
|
||||||
preferences.putString("password", wifiPassword);
|
preferences.putString("password", wifiPassword);
|
||||||
preferences.end();
|
preferences.end();
|
||||||
|
|
||||||
lcd.fillScreen(TFT_BLACK);
|
wifiConnecting = true;
|
||||||
lcd.setTextColor(TFT_WHITE, TFT_BLACK);
|
wifiConnectStartTime = millis();
|
||||||
lcd.setFont(&fonts::DejaVu24);
|
|
||||||
lcd.setTextDatum(textdatum_t::middle_center);
|
|
||||||
lcd.drawString("WiFi: Connecting...", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
|
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(selectedSSID.c_str(), wifiPassword.c_str());
|
WiFi.begin(selectedSSID.c_str(), wifiPassword.c_str());
|
||||||
|
|
@ -1447,6 +1453,20 @@ void loop() {
|
||||||
drawFooterCountdown();
|
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) {
|
if (currentScreen == SCREEN_DASHBOARD && millis() - lastHistoryRefresh > HISTORY_REFRESH_INTERVAL) {
|
||||||
fetchAllHistory();
|
fetchAllHistory();
|
||||||
lastHistoryRefresh = millis();
|
lastHistoryRefresh = millis();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue