diff --git a/README.md b/README.md index c43f03c..886bc36 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,9 @@ Screen list ## Release notes +- Fixed menu +- Automatic shutdown when car goes off + ### v1.8.2 2020-11-25 - Removed screen flickering. (via Sprites, esp32 with SRAM is now required!) - Code cleaning. Removed force no/yes redraw mode. Not required with sprites diff --git a/car_kia_eniro.h b/car_kia_eniro.h index 517b2a5..8d56d3d 100644 --- a/car_kia_eniro.h +++ b/car_kia_eniro.h @@ -90,6 +90,8 @@ bool activateCommandQueueForKiaENiro() { */ bool parseRowMergedKiaENiro() { + bool tempByte; + // ABS / ESP + AHB 7D1 if (currentAtshRequest.equals("ATSH7D1")) { if (commandRequest.equals("22C101")) { @@ -103,6 +105,12 @@ bool parseRowMergedKiaENiro() { // IGPM if (currentAtshRequest.equals("ATSH770")) { if (commandRequest.equals("22BC03")) { + tempByte = hexToDec(responseRowMerged.substring(16, 18).c_str(), 1, false); + params.ignitionOnPrevious = params.ignitionOn; + params.ignitionOn = (bitRead(tempByte, 5) == 1); + if (params.ignitionOnPrevious && !params.ignitionOn) + params.automatickShutdownTimer = params.currentTime; + params.lightInfo = hexToDec(responseRowMerged.substring(18, 20).c_str(), 1, false); params.headLights = (bitRead(params.lightInfo, 5) == 1); params.dayLights = (bitRead(params.lightInfo, 3) == 1); diff --git a/enirodashboard.ino b/enirodashboard.ino index 0dd6615..d3911f6 100644 --- a/enirodashboard.ino +++ b/enirodashboard.ino @@ -109,6 +109,32 @@ bool displayMessage(const char* row1, const char* row2) { return true; } +/** + Shutdown device +*/ +bool shutdownDevice() { + + Serial.println("Shutdown."); + + displayMessage("Shutdown in 3 sec.", ""); + delay(3000); + + setCpuFrequencyMhz(80); + analogWrite(TFT_BL, 0); + //WiFi.disconnect(true); + //WiFi.mode(WIFI_OFF); + btStop(); + //adc_power_off(); + //esp_wifi_stop(); + esp_bt_controller_disable(); + + delay(2000); + //esp_sleep_enable_timer_wakeup(/*minutes*/ 525600L * 60L * 1000000L); + esp_deep_sleep_start(); + + return true; +} + /** Load settings from flash memory, upgrade structure if version differs */ @@ -230,6 +256,9 @@ bool loadSettings() { */ bool initStructure() { + params.automatickShutdownTimer = 0; + params.ignitionOn = false; + params.ignitionOnPrevious = false; params.chargingStartTime = params.currentTime = 0; params.lightInfo = 0; params.headLights = false; @@ -1175,12 +1204,22 @@ bool showMenu() { spr.setTextDatum(TL_DATUM); spr.setFreeFont(&Roboto_Thin_24); + // Page scroll + uint8_t visibleCount = (int)(tft.height() / spr.fontHeight()); + if (menuItemSelected >= menuItemOffset + visibleCount) + menuItemOffset = menuItemSelected - visibleCount + 1; + if (menuItemSelected < menuItemOffset) + menuItemOffset = menuItemSelected; + + // Print items for (uint16_t i = 0; i < menuItemsCount; ++i) { if (menuCurrent == menuItems[i].parentId) { - spr.fillRect(0, posY, 320, spr.fontHeight() + 2, (menuItemSelected == tmpCurrMenuItem) ? TFT_DARKGREEN2 : TFT_BLACK); - spr.setTextColor((menuItemSelected == tmpCurrMenuItem) ? TFT_WHITE : TFT_WHITE, (menuItemSelected == tmpCurrMenuItem) ? TFT_DARKGREEN2 : TFT_BLACK); - spr.drawString(menuItemCaption(menuItems[i].id, menuItems[i].title), 0, posY + 2, GFXFF); - posY += spr.fontHeight(); + if (tmpCurrMenuItem >= menuItemOffset) { + spr.fillRect(0, posY, 320, spr.fontHeight() + 2, (menuItemSelected == tmpCurrMenuItem) ? TFT_DARKGREEN2 : TFT_BLACK); + spr.setTextColor((menuItemSelected == tmpCurrMenuItem) ? TFT_WHITE : TFT_WHITE, (menuItemSelected == tmpCurrMenuItem) ? TFT_DARKGREEN2 : TFT_BLACK); + spr.drawString(menuItemCaption(menuItems[i].id, menuItems[i].title), 0, posY + 2, GFXFF); + posY += spr.fontHeight(); + } tmpCurrMenuItem++; } } @@ -1215,7 +1254,7 @@ bool menuMove(bool forward) { tmpCount++; } } - menuItemSelected = (menuItemSelected > tmpCount) ? tmpCount : menuItemSelected + 1; + menuItemSelected = (menuItemSelected >= tmpCount - 1 ) ? tmpCount - 1 : menuItemSelected + 1; } else { menuItemSelected = (menuItemSelected <= 0) ? 0 : menuItemSelected - 1; } @@ -1311,6 +1350,8 @@ bool menuItemClick() { case 9: saveSettings(); break; // Version case 10: hideMenu(); return false; + // Shutdown + case 11: shutdownDevice(); return false; default: // Submenu menuCurrent = tmpMenuItem.id; @@ -1970,4 +2011,7 @@ void loop() { struct tm now; getLocalTime(&now, 0); params.currentTime = mktime(&now); + // Shutdown when car is off + if (params.automatickShutdownTimer != 0 && params.currentTime - params.automatickShutdownTimer > 5) + shutdownDevice(); } diff --git a/menu.h b/menu.h index e7eefa2..1f968fc 100644 --- a/menu.h +++ b/menu.h @@ -8,10 +8,11 @@ typedef struct { char serviceUUID[40]; } MENU_ITEM; -#define menuItemsCount 66 +#define menuItemsCount 67 bool menuVisible = false; uint16_t menuCurrent = 0; uint8_t menuItemSelected = 0; +uint8_t menuItemOffset = 0; uint16_t scanningDeviceIndex = 0; MENU_ITEM menuItems[menuItemsCount] = { @@ -23,6 +24,7 @@ MENU_ITEM menuItems[menuItemsCount] = { {8, 0, -1, "Factory reset"}, {9, 0, -1, "Save settings"}, {10, 0, -1, "Version"}, + {11, 0, -1, "Shutdown"}, {100, 1, 0, "<- parent menu"}, {101, 1, -1, "Kia eNiro 2020 64kWh"}, diff --git a/struct.h b/struct.h index f424331..1fa8959 100644 --- a/struct.h +++ b/struct.h @@ -33,6 +33,9 @@ String currentAtshRequest = ""; typedef struct { time_t currentTime; time_t chargingStartTime; + time_t automatickShutdownTimer; + bool ignitionOn; + bool ignitionOnPrevious; bool forwardDriveMode; bool reverseDriveMode; bool parkModeOrNeutral;