menu fixes

This commit is contained in:
Lubos Petrovic
2020-12-05 19:53:56 +01:00
parent 49be75d06f
commit 7678d67cff
4 changed files with 87 additions and 83 deletions

View File

@@ -34,6 +34,14 @@ void Board320_240::initBoard() {
#endif #endif
spr.setColorDepth((psramUsed) ? 16 : 8); spr.setColorDepth((psramUsed) ? 16 : 8);
spr.createSprite(320, 240); spr.createSprite(320, 240);
// Wifi
if (liveData->settings.wifiEnabled == 1) {
Serial.println("WiFi init...");
//WiFi.mode(WIFI_STA);
//WiFi.begin(liveData->settings.wifiSsid, liveData->settings.wifiPassword);
Serial.println("WiFi init completed...");
}
} }
/** /**
@@ -46,12 +54,6 @@ void Board320_240::afterSetup() {
if (digitalRead(pinButtonRight) == LOW) { if (digitalRead(pinButtonRight) == LOW) {
loadTestData(); loadTestData();
} }
// Wifi
if (liveData->settings.wifiEnabled == 1) {
/*WiFi.mode(WIFI_STA);
WiFi.begin(liveData->settings.wifiSsid, liveData->settings.wifiPassword);*/
}
} }
/** /**
@@ -844,23 +846,23 @@ String Board320_240::menuItemCaption(int16_t menuItemId, String title) {
case 106: prefix = (liveData->settings.carType == CAR_RENAULT_ZOE) ? ">" : ""; break; case 106: prefix = (liveData->settings.carType == CAR_RENAULT_ZOE) ? ">" : ""; break;
case 107: prefix = (liveData->settings.carType == CAR_DEBUG_OBD2_KIA) ? ">" : ""; break; case 107: prefix = (liveData->settings.carType == CAR_DEBUG_OBD2_KIA) ? ">" : ""; break;
// //
case MENU_DEFAULT_SCREEN: sprintf(tmpStr1, "[%d]", liveData->settings.defaultScreen); suffix = tmpStr1; break;
case MENU_DEBUG_SCREEN: suffix = (liveData->settings.debugScreen == 1) ? "[on]" : "[off]"; break;
case MENU_SCREEN_BRIGHTNESS: sprintf(tmpStr1, "[%d%%]", liveData->settings.lcdBrightness); suffix = (liveData->settings.lcdBrightness == 0) ? "[auto]" : tmpStr1; break;
case MENU_PREDRAWN_GRAPHS: suffix = (liveData->settings.predrawnChargingGraphs == 1) ? "[on]" : "[off]"; break;
case MENU_WIFI: switch (WiFi.status()) { case MENU_WIFI: switch (WiFi.status()) {
WL_CONNECTED: suffix = "CONNECTED"; break; WL_CONNECTED: suffix = "CONNECTED"; break;
WL_NO_SHIELD: suffix = "NO_SHIELD"; break; WL_NO_SHIELD: suffix = "NO_SHIELD"; break;
WL_IDLE_STATUS: suffix = "IDLE_STATUS"; break; WL_IDLE_STATUS: suffix = "IDLE_STATUS"; break;
WL_NO_SSID_AVAIL: suffix = "NO_SSID_AVAIL"; break;
WL_SCAN_COMPLETED: suffix = "SCAN_COMPLETED"; break; WL_SCAN_COMPLETED: suffix = "SCAN_COMPLETED"; break;
WL_CONNECT_FAILED: suffix = "CONNECT_FAILED"; break; WL_CONNECT_FAILED: suffix = "CONNECT_FAILED"; break;
WL_CONNECTION_LOST: suffix = "CONNECTION_LOST"; break; WL_CONNECTION_LOST: suffix = "CONNECTION_LOST"; break;
WL_DISCONNECTED: suffix = "DISCONNECTED"; break; WL_DISCONNECTED: suffix = "DISCONNECTED"; break;
} }
break; break;
case MENU_HEADLIGHTS_REMINDER: suffix = (liveData->settings.headlightsReminder == 1) ? "[on]" : "[off]"; break;
case MENU_GPRS: sprintf(tmpStr1, "[%s] %s", (liveData->settings.gprsEnabled == 1) ? "on" : "off", liveData->settings.gprsApn); suffix = tmpStr1; break; case MENU_GPRS: sprintf(tmpStr1, "[%s] %s", (liveData->settings.gprsEnabled == 1) ? "on" : "off", liveData->settings.gprsApn); suffix = tmpStr1; break;
case MENU_SCREEN_ROTATION: suffix = (liveData->settings.displayRotation == 1) ? "[vertical]" : "[normal]"; break;
case MENU_DEFAULT_SCREEN: sprintf(tmpStr1, "[%d]", liveData->settings.defaultScreen); suffix = tmpStr1; break;
case MENU_SCREEN_BRIGHTNESS: sprintf(tmpStr1, "[%d%%]", liveData->settings.lcdBrightness); suffix = (liveData->settings.lcdBrightness == 0) ? "[auto]" : tmpStr1; break;
case MENU_PREDRAWN_GRAPHS: suffix = (liveData->settings.predrawnChargingGraphs == 1) ? "[on]" : "[off]"; break;
case MENU_HEADLIGHTS_REMINDER: suffix = (liveData->settings.headlightsReminder == 1) ? "[on]" : "[off]"; break;
case MENU_DEBUG_SCREEN: suffix = (liveData->settings.debugScreen == 1) ? "[on]" : "[off]"; break;
// //
case MENU_WIFI_ENABLED: suffix = (liveData->settings.wifiEnabled == 1) ? "[on]" : "[off]"; break; case MENU_WIFI_ENABLED: suffix = (liveData->settings.wifiEnabled == 1) ? "[on]" : "[off]"; break;
case MENU_WIFI_SSID: sprintf(tmpStr1, "%s", liveData->settings.wifiSsid); suffix = tmpStr1; break; case MENU_WIFI_SSID: sprintf(tmpStr1, "%s", liveData->settings.wifiSsid); suffix = tmpStr1; break;
@@ -949,8 +951,9 @@ void Board320_240::menuItemClick() {
MENU_ITEM* tmpMenuItem; MENU_ITEM* tmpMenuItem;
uint16_t tmpCurrMenuItem = 0; uint16_t tmpCurrMenuItem = 0;
int16_t parentMenu = -1; int16_t parentMenu = -1;
uint16_t i;
for (uint16_t i = 0; i < liveData->menuItemsCount; ++i) { for (i = 0; i < liveData->menuItemsCount; ++i) {
if (liveData->menuCurrent == liveData->menuItems[i].parentId) { if (liveData->menuCurrent == liveData->menuItems[i].parentId) {
if (parentMenu == -1) if (parentMenu == -1)
parentMenu = liveData->menuItems[i].targetParentId; parentMenu = liveData->menuItems[i].targetParentId;
@@ -963,18 +966,8 @@ void Board320_240::menuItemClick() {
} }
// Exit menu, parent level menu, open item // Exit menu, parent level menu, open item
if (liveData->menuItemSelected == 0) { bool showParentMenu = false;
// Exit menu if (liveData->menuItemSelected > 0) {
if (tmpMenuItem->parentId == 0 && tmpMenuItem->id == 0) {
liveData->menuVisible = false;
redrawScreen();
} else {
// Parent menu
liveData->menuCurrent = tmpMenuItem->targetParentId;
showMenu();
}
return;
} else {
Serial.println(tmpMenuItem->id); Serial.println(tmpMenuItem->id);
// Device list // Device list
if (tmpMenuItem->id > 10000 && tmpMenuItem->id < 10100) { if (tmpMenuItem->id > 10000 && tmpMenuItem->id < 10100) {
@@ -985,7 +978,6 @@ void Board320_240::menuItemClick() {
ESP.restart(); ESP.restart();
} }
// Other menus // Other menus
bool showParentMenu = false;
switch (tmpMenuItem->id) { switch (tmpMenuItem->id) {
// Set vehicle type // Set vehicle type
case 101: liveData->settings.carType = CAR_KIA_ENIRO_2020_64; showMenu(); return; break; case 101: liveData->settings.carType = CAR_KIA_ENIRO_2020_64; showMenu(); return; break;
@@ -996,21 +988,17 @@ void Board320_240::menuItemClick() {
case 106: liveData->settings.carType = CAR_RENAULT_ZOE; showMenu(); return; break; case 106: liveData->settings.carType = CAR_RENAULT_ZOE; showMenu(); return; break;
case 107: liveData->settings.carType = CAR_DEBUG_OBD2_KIA; showMenu(); return; break; case 107: liveData->settings.carType = CAR_DEBUG_OBD2_KIA; showMenu(); return; break;
// Screen orientation // Screen orientation
case 3011: liveData->settings.displayRotation = 1; tft.setRotation(liveData->settings.displayRotation); break; case MENU_SCREEN_ROTATION: liveData->settings.displayRotation = (liveData->settings.displayRotation == 1) ? 3 : 1; tft.setRotation(liveData->settings.displayRotation); showMenu(); return; break;
case 3012: liveData->settings.displayRotation = 3; tft.setRotation(liveData->settings.displayRotation); break;
// Default screen // Default screen
case 3021: liveData->settings.defaultScreen = 1; showParentMenu = true; break; case 3061: liveData->settings.defaultScreen = 1; showParentMenu = true; break;
case 3022: liveData->settings.defaultScreen = 2; showParentMenu = true; break; case 3062: liveData->settings.defaultScreen = 2; showParentMenu = true; break;
case 3023: liveData->settings.defaultScreen = 3; showParentMenu = true; break; case 3063: liveData->settings.defaultScreen = 3; showParentMenu = true; break;
case 3024: liveData->settings.defaultScreen = 4; showParentMenu = true; break; case 3064: liveData->settings.defaultScreen = 4; showParentMenu = true; break;
case 3025: liveData->settings.defaultScreen = 5; showParentMenu = true; break; case 3065: liveData->settings.defaultScreen = 5; showParentMenu = true; break;
// Debug screen off/on // Debug screen off/on
case MENU_DEBUG_SCREEN: liveData->settings.debugScreen = (liveData->settings.debugScreen == 1) ? 0 : 1; showMenu(); return; break; case MENU_DEBUG_SCREEN: liveData->settings.debugScreen = (liveData->settings.debugScreen == 1) ? 0 : 1; showMenu(); return; break;
// Lcd brightness case MENU_SCREEN_BRIGHTNESS: liveData->settings.lcdBrightness += 20; if (liveData->settings.lcdBrightness > 100) liveData->settings.lcdBrightness = 0;
case 3041: liveData->settings.lcdBrightness = 0; showParentMenu = true; break; setBrightness((liveData->settings.lcdBrightness == 0) ? 100 : liveData->settings.lcdBrightness); showMenu(); return; break;
case 3042: liveData->settings.lcdBrightness = 20; showParentMenu = true; break;
case 3043: liveData->settings.lcdBrightness = 50; showParentMenu = true; break;
case 3044: liveData->settings.lcdBrightness = 100; showParentMenu = true; break;
// Pre-drawn charg.graphs off/on // Pre-drawn charg.graphs off/on
case MENU_PREDRAWN_GRAPHS: liveData->settings.predrawnChargingGraphs = (liveData->settings.predrawnChargingGraphs == 1) ? 0 : 1; showMenu(); return; break; case MENU_PREDRAWN_GRAPHS: liveData->settings.predrawnChargingGraphs = (liveData->settings.predrawnChargingGraphs == 1) ? 0 : 1; showMenu(); return; break;
case MENU_HEADLIGHTS_REMINDER: liveData->settings.headlightsReminder = (liveData->settings.headlightsReminder == 1) ? 0 : 1; showMenu(); return; break; case MENU_HEADLIGHTS_REMINDER: liveData->settings.headlightsReminder = (liveData->settings.headlightsReminder == 1) ? 0 : 1; showMenu(); return; break;
@@ -1044,17 +1032,32 @@ void Board320_240::menuItemClick() {
showMenu(); showMenu();
return; return;
} }
}
if (showParentMenu && parentMenu != -1) { // Exit menu
liveData->menuCurrent = parentMenu; if (liveData->menuItemSelected == 0 || (showParentMenu && parentMenu != -1)) {
if (tmpMenuItem->parentId == 0 && tmpMenuItem->id == 0) {
liveData->menuVisible = false;
redrawScreen();
} else {
// Parent menu
liveData->menuItemSelected = 0; liveData->menuItemSelected = 0;
for (i = 0; i < liveData->menuItemsCount; ++i) {
if (parentMenu == liveData->menuItems[i].parentId) {
if (liveData->menuItems[i].id == liveData->menuCurrent)
break;
liveData->menuItemSelected++;
}
}
liveData->menuCurrent = parentMenu;
Serial.println(liveData->menuCurrent); Serial.println(liveData->menuCurrent);
showMenu(); showMenu();
} else {
// close menu
hideMenu();
} }
return;
} }
// Close menu
hideMenu();
} }
/** /**
@@ -1215,7 +1218,10 @@ void Board320_240::mainLoop() {
} }
} }
} }
// Both left&right button (hide menu)
if (digitalRead(pinButtonLeft) == LOW && digitalRead(pinButtonRight) == LOW) {
hideMenu();
}
} }
/** /**

View File

@@ -4,7 +4,7 @@
- m5stack mute speaker - m5stack mute speaker
- settings v4 (wifi/gprs/sdcard/ntp/..) - settings v4 (wifi/gprs/sdcard/ntp/..)
- ble4 skipped if mac is not set (00:00:00:00:00:00) - ble4 skipped if mac is not set (00:00:00:00:00:00)
- improved menu - improved menu (L&R buttons hides menu, parent menu now keep position)
- supported serial console commands - supported serial console commands
serviceUUID=xxx serviceUUID=xxx
charTxUUID=xxx charTxUUID=xxx

View File

@@ -69,19 +69,26 @@ typedef struct {
#define MENU_VEHICLE_TYPE 1 #define MENU_VEHICLE_TYPE 1
#define MENU_SAVE_SETTINGS 9 #define MENU_SAVE_SETTINGS 9
#define MENU_APP_VERSION 10 #define MENU_APP_VERSION 10
#define MENU_DEFAULT_SCREEN 302 //
#define MENU_DEBUG_SCREEN 303 #define MENU_WIFI 301
#define MENU_SCREEN_BRIGHTNESS 304 #define MENU_GPRS 302
#define MENU_PREDRAWN_GRAPHS 305 #define MENU_NTP 303
#define MENU_WIFI 306 #define MENU_SDCARD 304
#define MENU_WIFI_ENABLED 3061 #define MENU_REMOTE_UPLOAD 305
#define MENU_WIFI_SSID 3062 #define MENU_SCREEN_ROTATION 306
#define MENU_WIFI_PASSWORD 3063 #define MENU_DEFAULT_SCREEN 307
#define MENU_GPRS 308 #define MENU_SCREEN_BRIGHTNESS 308
#define MENU_PREDRAWN_GRAPHS 309
#define MENU_HEADLIGHTS_REMINDER 310 #define MENU_HEADLIGHTS_REMINDER 310
#define MENU_DEBUG_SCREEN 311
//
#define MENU_DISTANCE_UNIT 401 #define MENU_DISTANCE_UNIT 401
#define MENU_TEMPERATURE_UNIT 402 #define MENU_TEMPERATURE_UNIT 402
#define MENU_PRESSURE_UNIT 403 #define MENU_PRESSURE_UNIT 403
//
#define MENU_WIFI_ENABLED 3011
#define MENU_WIFI_SSID 3012
#define MENU_WIFI_PASSWORD 3013
#endif // CONFIG_H #endif // CONFIG_H

49
menu.h
View File

@@ -24,16 +24,17 @@ MENU_ITEM menuItemsSource[100] = {
{107, 1, -1, "Debug OBD2 Kia"}, {107, 1, -1, "Debug OBD2 Kia"},
{300, 3, 0, "<- parent menu"}, {300, 3, 0, "<- parent menu"},
{301, 3, -1, "Screen rotation"}, {MENU_WIFI, 3, -1, "[dev] WiFi network"},
{MENU_GPRS, 3, -1, "[dev] GSM/GPRS"},
{MENU_NTP, 3, -1, "[dev] NTP"},
{MENU_SDCARD, 3, -1, "[dev] SD card"},
{MENU_REMOTE_UPLOAD, 3, -1, "[dev] Remote upload"},
{MENU_SCREEN_ROTATION, 3, -1, "Screen rotation"},
{MENU_DEFAULT_SCREEN, 3, -1, "Default screen"}, {MENU_DEFAULT_SCREEN, 3, -1, "Default screen"},
{MENU_DEBUG_SCREEN, 3, -1, "Debug screen"},
{MENU_SCREEN_BRIGHTNESS, 3, -1, "LCD brightness"}, {MENU_SCREEN_BRIGHTNESS, 3, -1, "LCD brightness"},
{MENU_PREDRAWN_GRAPHS, 3, -1, "Pre-drawn ch.graphs"}, {MENU_PREDRAWN_GRAPHS, 3, -1, "Pre-drawn ch.graphs"},
{MENU_WIFI, 3, -1, "WiFi network"},
{307, 3, -1, "[DEV] SD card"},
{MENU_GPRS, 3, -1, "GPRS"},
{309, 3, -1, "[DEV] Remote upload"},
{MENU_HEADLIGHTS_REMINDER, 3, -1, "Headlight reminder"}, {MENU_HEADLIGHTS_REMINDER, 3, -1, "Headlight reminder"},
{MENU_DEBUG_SCREEN, 3, -1, "Debug screen"},
/* /*
// NTP // NTP
@@ -57,33 +58,23 @@ MENU_ITEM menuItemsSource[100] = {
{MENU_PRESSURE_UNIT, 4, -1, "Pressure"}, {MENU_PRESSURE_UNIT, 4, -1, "Pressure"},
{3010, 301, 3, "<- parent menu"}, {3010, 301, 3, "<- parent menu"},
{3011, 301, -1, "Normal"}, {MENU_WIFI_ENABLED, 301, -1, "WiFi enabled"},
{3012, 301, -1, "Flip vertical"}, {MENU_WIFI_SSID, 301, -1, "SSID"},
{MENU_WIFI_PASSWORD, 301, -1, "Password"},
{3020, 302, 3, "<- parent menu"},
{3021, 302, -1, "Auto mode"},
{3022, 302, -1, "Basic info"},
{3023, 302, -1, "Speed"},
{3024, 302, -1, "Battery cells"},
{3025, 302, -1, "Charging graph"},
{3040, 304, 3, "<- parent menu"}, {3040, 304, 3, "<- parent menu"},
{3041, 304, -1, "Auto"}, {3041, 304, -1, "Info:"},
{3042, 304, -1, "20%"}, {3042, 304, -1, "Mount manually"},
{3043, 304, -1, "50%"}, {3043, 304, -1, "Record now"},
{3044, 304, -1, "100%"}, {3044, 304, -1, "Stop recording"},
{3045, 304, -1, "Record on boot off/on"},
{3060, 306, 3, "<- parent menu"},
{MENU_WIFI_ENABLED, 306, -1, "WiFi enabled"},
{MENU_WIFI_SSID, 306, -1, "SSID"},
{MENU_WIFI_PASSWORD, 306, -1, "Password"},
{3070, 307, 3, "<- parent menu"}, {3070, 307, 3, "<- parent menu"},
{3071, 307, -1, "Info:"}, {3071, 307, -1, "Auto mode"},
{3072, 307, -1, "Mount manually"}, {3072, 307, -1, "Basic info"},
{3073, 307, -1, "Record now"}, {3073, 307, -1, "Speed"},
{3074, 307, -1, "Stop recording"}, {3074, 307, -1, "Battery cells"},
{3075, 307, -1, "Record on boot off/on"}, {3075, 307, -1, "Charging graph"},
{4010, 401, 4, "<- parent menu"}, {4010, 401, 4, "<- parent menu"},
{4011, 401, -1, "Kilometers"}, {4011, 401, -1, "Kilometers"},