Add WiFi configuration screen accessible by tapping WiFi status
This commit is contained in:
parent
96e632b869
commit
60bbeaeeda
1 changed files with 105 additions and 2 deletions
105
src/main.cpp
105
src/main.cpp
|
|
@ -167,7 +167,8 @@ unsigned long lastHistoryRefresh = 0;
|
||||||
enum ScreenState {
|
enum ScreenState {
|
||||||
SCREEN_DASHBOARD,
|
SCREEN_DASHBOARD,
|
||||||
SCREEN_CUSTOMIZE_STOCKS,
|
SCREEN_CUSTOMIZE_STOCKS,
|
||||||
SCREEN_CUSTOMIZE_INDICES
|
SCREEN_CUSTOMIZE_INDICES,
|
||||||
|
SCREEN_WIFI_CONFIG
|
||||||
};
|
};
|
||||||
ScreenState currentScreen = SCREEN_DASHBOARD;
|
ScreenState currentScreen = SCREEN_DASHBOARD;
|
||||||
|
|
||||||
|
|
@ -589,6 +590,65 @@ void drawIndexCustomizeScreen() {
|
||||||
lcd.drawString("CANCEL", SCREEN_WIDTH - 95, SCREEN_HEIGHT - 30);
|
lcd.drawString("CANCEL", SCREEN_WIDTH - 95, SCREEN_HEIGHT - 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void drawWifiConfigScreen() {
|
||||||
|
lcd.fillScreen(TFT_BLACK);
|
||||||
|
|
||||||
|
lcd.fillSmoothRoundRect(0, 0, SCREEN_WIDTH, 50, 8, TFT_ORANGE);
|
||||||
|
lcd.setTextColor(TFT_WHITE, TFT_ORANGE);
|
||||||
|
lcd.setFont(&fonts::DejaVu24);
|
||||||
|
lcd.setTextDatum(textdatum_t::middle_center);
|
||||||
|
lcd.drawString("WIFI CONFIGURATION", SCREEN_WIDTH / 2, 25);
|
||||||
|
|
||||||
|
preferences.begin("wifi", true);
|
||||||
|
String currentSsid = preferences.getString("ssid", "");
|
||||||
|
preferences.end();
|
||||||
|
|
||||||
|
lcd.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||||
|
lcd.setFont(&fonts::DejaVu18);
|
||||||
|
lcd.setTextDatum(textdatum_t::middle_left);
|
||||||
|
lcd.drawString("Current SSID:", 100, 80);
|
||||||
|
|
||||||
|
lcd.fillSmoothRoundRect(100, 100, 600, 40, 6, TFT_DARKGRAY);
|
||||||
|
lcd.setTextColor(TFT_WHITE, TFT_DARKGRAY);
|
||||||
|
lcd.setTextDatum(textdatum_t::middle_left);
|
||||||
|
if (currentSsid.length() > 0) {
|
||||||
|
lcd.drawString(currentSsid, 120, 120);
|
||||||
|
} else {
|
||||||
|
lcd.setTextColor(TFT_GRAY, TFT_DARKGRAY);
|
||||||
|
lcd.drawString("(not configured)", 120, 120);
|
||||||
|
}
|
||||||
|
|
||||||
|
lcd.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||||
|
lcd.drawString("New SSID:", 100, 170);
|
||||||
|
|
||||||
|
lcd.fillSmoothRoundRect(100, 190, 600, 40, 6, TFT_ORANGE);
|
||||||
|
lcd.setTextColor(TFT_WHITE, TFT_ORANGE);
|
||||||
|
lcd.setTextDatum(textdatum_t::middle_left);
|
||||||
|
String ssidDisplay = String(keyboardBuffer);
|
||||||
|
if (ssidDisplay.length() == 0) ssidDisplay = "_";
|
||||||
|
lcd.drawString(ssidDisplay, 120, 210);
|
||||||
|
|
||||||
|
lcd.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||||
|
lcd.drawString("Password:", 100, 260);
|
||||||
|
|
||||||
|
lcd.fillSmoothRoundRect(100, 280, 600, 40, 6, TFT_DARKGRAY);
|
||||||
|
lcd.setTextColor(TFT_GRAY, TFT_DARKGRAY);
|
||||||
|
lcd.setTextDatum(textdatum_t::middle_left);
|
||||||
|
lcd.drawString("(tap to enter)", 120, 300);
|
||||||
|
|
||||||
|
drawKeyboard(350);
|
||||||
|
|
||||||
|
lcd.fillSmoothRoundRect(100, SCREEN_HEIGHT - 50, 150, 40, 8, TFT_GRAY);
|
||||||
|
lcd.setTextColor(TFT_WHITE, TFT_GRAY);
|
||||||
|
lcd.setFont(&fonts::DejaVu18);
|
||||||
|
lcd.setTextDatum(textdatum_t::middle_center);
|
||||||
|
lcd.drawString("BACK", 175, SCREEN_HEIGHT - 30);
|
||||||
|
|
||||||
|
lcd.fillSmoothRoundRect(SCREEN_WIDTH - 250, SCREEN_HEIGHT - 50, 150, 40, 8, TFT_GREEN);
|
||||||
|
lcd.setTextColor(TFT_WHITE, TFT_GREEN);
|
||||||
|
lcd.drawString("SAVE", SCREEN_WIDTH - 175, SCREEN_HEIGHT - 30);
|
||||||
|
}
|
||||||
|
|
||||||
void drawDashboard() {
|
void drawDashboard() {
|
||||||
lcd.fillScreen(TFT_BLACK);
|
lcd.fillScreen(TFT_BLACK);
|
||||||
|
|
||||||
|
|
@ -766,6 +826,36 @@ bool handleStockCustomizeTouch(int32_t x, int32_t y) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool handleWifiConfigTouch(int32_t x, int32_t y) {
|
||||||
|
if (x >= 100 && x < 250 && y >= SCREEN_HEIGHT - 50 && y < SCREEN_HEIGHT - 10) {
|
||||||
|
currentScreen = SCREEN_DASHBOARD;
|
||||||
|
needsRefresh = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x >= SCREEN_WIDTH - 250 && x < SCREEN_WIDTH - 100 && y >= SCREEN_HEIGHT - 50 && y < SCREEN_HEIGHT - 10) {
|
||||||
|
if (keyboardPos > 0) {
|
||||||
|
preferences.begin("wifi", false);
|
||||||
|
preferences.putString("ssid", keyboardBuffer);
|
||||||
|
preferences.end();
|
||||||
|
currentScreen = SCREEN_DASHBOARD;
|
||||||
|
needsRefresh = true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x >= 100 && x < 700 && y >= 190 && y < 230) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int keyboardY = 350;
|
||||||
|
if (handleKeyboardTouch(x, y, keyboardY)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool handleIndexCustomizeTouch(int32_t x, int32_t y) {
|
bool handleIndexCustomizeTouch(int32_t x, int32_t y) {
|
||||||
int listY = 60;
|
int listY = 60;
|
||||||
int itemHeight = 40;
|
int itemHeight = 40;
|
||||||
|
|
@ -873,6 +963,13 @@ bool handleDashboardTouch(int32_t x, int32_t y) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (x >= 20 && x < 200 && y >= SCREEN_HEIGHT - 40 && y < SCREEN_HEIGHT) {
|
||||||
|
currentScreen = SCREEN_WIFI_CONFIG;
|
||||||
|
keyboardPos = 0;
|
||||||
|
keyboardBuffer[0] = '\0';
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -974,6 +1071,9 @@ void loop() {
|
||||||
case SCREEN_CUSTOMIZE_INDICES:
|
case SCREEN_CUSTOMIZE_INDICES:
|
||||||
handleIndexCustomizeTouch(x, y);
|
handleIndexCustomizeTouch(x, y);
|
||||||
break;
|
break;
|
||||||
|
case SCREEN_WIFI_CONFIG:
|
||||||
|
handleWifiConfigTouch(x, y);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!needsRefresh) {
|
if (!needsRefresh) {
|
||||||
|
|
@ -989,6 +1089,9 @@ void loop() {
|
||||||
case SCREEN_CUSTOMIZE_INDICES:
|
case SCREEN_CUSTOMIZE_INDICES:
|
||||||
drawIndexCustomizeScreen();
|
drawIndexCustomizeScreen();
|
||||||
break;
|
break;
|
||||||
|
case SCREEN_WIFI_CONFIG:
|
||||||
|
drawWifiConfigScreen();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue