diff --git a/config.h b/config.h index 8ad95b1..1043462 100644 --- a/config.h +++ b/config.h @@ -29,6 +29,10 @@ #define BUTTON_LEFT 38 #define BUTTON_MIDDLE 37 #define BUTTON_RIGHT 39 +#define SDCARD_CS 13 +#define SDCARD_MOSI 15 +#define SDCARD_MISO 2 +#define SDCARD_SCK 14 #endif // BOARD_TTGO_T4 ///////////////////////////////////////////////////////////// @@ -52,6 +56,10 @@ #define BUTTON_RIGHT 39 #define SPEAKER 25 #define INVERT_DISPLAY +#define SDCARD_CS 4 +#define SDCARD_MOSI 23 +#define SDCARD_MISO 19 +#define SDCARD_SCK 18 #endif // BOARD_M5STACK_CORE ///////////////////////////////////////////////////////////// diff --git a/enirodashboard.ino b/enirodashboard.ino index b74755d..5ba017e 100644 --- a/enirodashboard.ino +++ b/enirodashboard.ino @@ -27,14 +27,17 @@ <= 0°C BMS allows max 40A */ -#define APP_VERSION "v1.8.2b" +#define APP_VERSION "v1.9.0" +#include "FS.h" +#include "SD.h" #include "SPI.h" #include "TFT_eSPI.h" #include "BLEDevice.h" #include #include #include +#include #include "config.h" #include "struct.h" #include "menu.h" @@ -45,6 +48,10 @@ // PLEASE CHANGE THIS SETTING for your BLE4 uint32_t PIN = 1234; +const char* ssid = "your-ssid"; +const char* password = "your-password"; +long timezone = 1; +byte daysavetime = 1; // TFT TFT_eSPI tft = TFT_eSPI(); @@ -1180,6 +1187,12 @@ String menuItemCaption(int16_t menuItemId, String title) { if (menuItemId == 10) // Version suffix = APP_VERSION; + if (menuItemId == 3071) { // sdcard info + uint64_t cardSize = SD.cardSize() / (1024 * 1024); + sprintf(tmpStr1, "%lluMB", cardSize); + suffix = String(tmpStr1); + } + if (menuItemId == 401) // distance suffix = (settings.distanceUnit == 'k') ? "[km]" : "[mi]"; if (menuItemId == 402) // temperature @@ -1209,7 +1222,7 @@ bool showMenu() { if (menuItemSelected >= menuItemOffset + visibleCount) menuItemOffset = menuItemSelected - visibleCount + 1; if (menuItemSelected < menuItemOffset) - menuItemOffset = menuItemSelected; + menuItemOffset = menuItemSelected; // Print items for (uint16_t i = 0; i < menuItemsCount; ++i) { @@ -1333,6 +1346,8 @@ bool menuItemClick() { // Pre-drawn charg.graphs off/on case 3051: settings.predrawnChargingGraphs = 0; break; case 3052: settings.predrawnChargingGraphs = 1; break; + // Sdcard: + case 3072: SD.begin(SDCARD_CS, SDCARD_MOSI, SDCARD_MISO, SDCARD_SCK); break; // Distance case 4011: settings.distanceUnit = 'k'; break; case 4012: settings.distanceUnit = 'm'; break; @@ -1869,6 +1884,28 @@ void setup(void) { spr.createSprite(320, 240); redrawScreen(); + // Init SDCARD + if (!SD.begin(SDCARD_CS, SDCARD_MOSI, SDCARD_MISO, SDCARD_SCK)) { + Serial.println("Card Mount Failed"); + } + uint8_t cardType = SD.cardType(); + if (cardType == CARD_NONE) { + Serial.println("No SD card attached"); + } + Serial.print("SD Card Type: "); + if (cardType == CARD_MMC) { + Serial.println("MMC"); + } else if (cardType == CARD_SD) { + Serial.println("SDSC"); + } else if (cardType == CARD_SDHC) { + Serial.println("SDHC"); + } else { + Serial.println("UNKNOWN"); + } + + uint64_t cardSize = SD.cardSize() / (1024 * 1024); + Serial.printf("SD Card Size: %lluMB\n", cardSize); + // Init time library struct timeval tv; tv.tv_sec = 1589011873; diff --git a/menu.h b/menu.h index 1f968fc..4a639b9 100644 --- a/menu.h +++ b/menu.h @@ -8,7 +8,7 @@ typedef struct { char serviceUUID[40]; } MENU_ITEM; -#define menuItemsCount 67 +#define menuItemsCount 79 bool menuVisible = false; uint16_t menuCurrent = 0; uint8_t menuItemSelected = 0; @@ -41,6 +41,8 @@ MENU_ITEM menuItems[menuItemsCount] = { {303, 3, -1, "Debug screen off/on"}, {304, 3, -1, "LCD brightness"}, {305, 3, -1, "Pre-drawn ch.graphs 0/1"}, + {306, 3, -1, "WiFi network"}, + {307, 3, -1, "SD card"}, {400, 4, 0, "<- parent menu"}, {401, 4, -1, "Distance"}, @@ -72,6 +74,18 @@ MENU_ITEM menuItems[menuItemsCount] = { {3051, 305, -1, "Off"}, {3052, 305, -1, "On"}, + {3060, 306, 3, "<- parent menu"}, + {3061, 306, -1, "WiFi off/on"}, + {3062, 306, -1, "SSID"}, + {3063, 306, -1, "Password"}, + + {3070, 307, 3, "<- parent menu"}, + {3071, 307, -1, "Info:"}, + {3072, 307, -1, "Mount manually"}, + {3073, 307, -1, "Record now"}, + {3074, 307, -1, "Stop recording"}, + {3075, 307, -1, "Record on boot off/on"}, + {4010, 401, 4, "<- parent menu"}, {4011, 401, -1, "Kilometers"}, {4012, 401, -1, "Miles"}, diff --git a/struct.h b/struct.h index 1fa8959..d24f72c 100644 --- a/struct.h +++ b/struct.h @@ -122,7 +122,7 @@ typedef struct { // Setting stored to flash typedef struct { byte initFlag; // 183 value - byte settingsVersion; // current 3 + byte settingsVersion; // current 4 uint16_t carType; // 0 - Kia eNiro 2020, 1 - Hyundai Kona 2020, 2 - Hyudai Ioniq 2018 char obdMacAddress[20]; char serviceUUID[40]; @@ -137,6 +137,11 @@ typedef struct { byte lcdBrightness; // 0 - auto, 1 .. 100% byte debugScreen; // 0 - off, 1 - on byte predrawnChargingGraphs; // 0 - off, 1 - on + byte wifiEnable; // 0 off 1 on used for NTP datetime sync + char wifiSsid[32]; + char wifiPassword[32]; + byte sdcardAutoRecord; // 0 off 1 on + } SETTINGS_STRUC; PARAMS_STRUC params; // Realtime sensor values