wifi, sdcard support [dev]
This commit is contained in:
8
config.h
8
config.h
@@ -29,6 +29,10 @@
|
|||||||
#define BUTTON_LEFT 38
|
#define BUTTON_LEFT 38
|
||||||
#define BUTTON_MIDDLE 37
|
#define BUTTON_MIDDLE 37
|
||||||
#define BUTTON_RIGHT 39
|
#define BUTTON_RIGHT 39
|
||||||
|
#define SDCARD_CS 13
|
||||||
|
#define SDCARD_MOSI 15
|
||||||
|
#define SDCARD_MISO 2
|
||||||
|
#define SDCARD_SCK 14
|
||||||
#endif // BOARD_TTGO_T4
|
#endif // BOARD_TTGO_T4
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
@@ -52,6 +56,10 @@
|
|||||||
#define BUTTON_RIGHT 39
|
#define BUTTON_RIGHT 39
|
||||||
#define SPEAKER 25
|
#define SPEAKER 25
|
||||||
#define INVERT_DISPLAY
|
#define INVERT_DISPLAY
|
||||||
|
#define SDCARD_CS 4
|
||||||
|
#define SDCARD_MOSI 23
|
||||||
|
#define SDCARD_MISO 19
|
||||||
|
#define SDCARD_SCK 18
|
||||||
#endif // BOARD_M5STACK_CORE
|
#endif // BOARD_M5STACK_CORE
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -27,14 +27,17 @@
|
|||||||
<= 0°C BMS allows max 40A
|
<= 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 "SPI.h"
|
||||||
#include "TFT_eSPI.h"
|
#include "TFT_eSPI.h"
|
||||||
#include "BLEDevice.h"
|
#include "BLEDevice.h"
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <analogWrite.h>
|
#include <analogWrite.h>
|
||||||
|
#include <WiFi.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "struct.h"
|
#include "struct.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
@@ -45,6 +48,10 @@
|
|||||||
|
|
||||||
// PLEASE CHANGE THIS SETTING for your BLE4
|
// PLEASE CHANGE THIS SETTING for your BLE4
|
||||||
uint32_t PIN = 1234;
|
uint32_t PIN = 1234;
|
||||||
|
const char* ssid = "your-ssid";
|
||||||
|
const char* password = "your-password";
|
||||||
|
long timezone = 1;
|
||||||
|
byte daysavetime = 1;
|
||||||
|
|
||||||
// TFT
|
// TFT
|
||||||
TFT_eSPI tft = TFT_eSPI();
|
TFT_eSPI tft = TFT_eSPI();
|
||||||
@@ -1180,6 +1187,12 @@ String menuItemCaption(int16_t menuItemId, String title) {
|
|||||||
if (menuItemId == 10) // Version
|
if (menuItemId == 10) // Version
|
||||||
suffix = APP_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
|
if (menuItemId == 401) // distance
|
||||||
suffix = (settings.distanceUnit == 'k') ? "[km]" : "[mi]";
|
suffix = (settings.distanceUnit == 'k') ? "[km]" : "[mi]";
|
||||||
if (menuItemId == 402) // temperature
|
if (menuItemId == 402) // temperature
|
||||||
@@ -1209,7 +1222,7 @@ bool showMenu() {
|
|||||||
if (menuItemSelected >= menuItemOffset + visibleCount)
|
if (menuItemSelected >= menuItemOffset + visibleCount)
|
||||||
menuItemOffset = menuItemSelected - visibleCount + 1;
|
menuItemOffset = menuItemSelected - visibleCount + 1;
|
||||||
if (menuItemSelected < menuItemOffset)
|
if (menuItemSelected < menuItemOffset)
|
||||||
menuItemOffset = menuItemSelected;
|
menuItemOffset = menuItemSelected;
|
||||||
|
|
||||||
// Print items
|
// Print items
|
||||||
for (uint16_t i = 0; i < menuItemsCount; ++i) {
|
for (uint16_t i = 0; i < menuItemsCount; ++i) {
|
||||||
@@ -1333,6 +1346,8 @@ bool menuItemClick() {
|
|||||||
// Pre-drawn charg.graphs off/on
|
// Pre-drawn charg.graphs off/on
|
||||||
case 3051: settings.predrawnChargingGraphs = 0; break;
|
case 3051: settings.predrawnChargingGraphs = 0; break;
|
||||||
case 3052: settings.predrawnChargingGraphs = 1; break;
|
case 3052: settings.predrawnChargingGraphs = 1; break;
|
||||||
|
// Sdcard:
|
||||||
|
case 3072: SD.begin(SDCARD_CS, SDCARD_MOSI, SDCARD_MISO, SDCARD_SCK); break;
|
||||||
// Distance
|
// Distance
|
||||||
case 4011: settings.distanceUnit = 'k'; break;
|
case 4011: settings.distanceUnit = 'k'; break;
|
||||||
case 4012: settings.distanceUnit = 'm'; break;
|
case 4012: settings.distanceUnit = 'm'; break;
|
||||||
@@ -1869,6 +1884,28 @@ void setup(void) {
|
|||||||
spr.createSprite(320, 240);
|
spr.createSprite(320, 240);
|
||||||
redrawScreen();
|
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
|
// Init time library
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
tv.tv_sec = 1589011873;
|
tv.tv_sec = 1589011873;
|
||||||
|
|||||||
16
menu.h
16
menu.h
@@ -8,7 +8,7 @@ typedef struct {
|
|||||||
char serviceUUID[40];
|
char serviceUUID[40];
|
||||||
} MENU_ITEM;
|
} MENU_ITEM;
|
||||||
|
|
||||||
#define menuItemsCount 67
|
#define menuItemsCount 79
|
||||||
bool menuVisible = false;
|
bool menuVisible = false;
|
||||||
uint16_t menuCurrent = 0;
|
uint16_t menuCurrent = 0;
|
||||||
uint8_t menuItemSelected = 0;
|
uint8_t menuItemSelected = 0;
|
||||||
@@ -41,6 +41,8 @@ MENU_ITEM menuItems[menuItemsCount] = {
|
|||||||
{303, 3, -1, "Debug screen off/on"},
|
{303, 3, -1, "Debug screen off/on"},
|
||||||
{304, 3, -1, "LCD brightness"},
|
{304, 3, -1, "LCD brightness"},
|
||||||
{305, 3, -1, "Pre-drawn ch.graphs 0/1"},
|
{305, 3, -1, "Pre-drawn ch.graphs 0/1"},
|
||||||
|
{306, 3, -1, "WiFi network"},
|
||||||
|
{307, 3, -1, "SD card"},
|
||||||
|
|
||||||
{400, 4, 0, "<- parent menu"},
|
{400, 4, 0, "<- parent menu"},
|
||||||
{401, 4, -1, "Distance"},
|
{401, 4, -1, "Distance"},
|
||||||
@@ -72,6 +74,18 @@ MENU_ITEM menuItems[menuItemsCount] = {
|
|||||||
{3051, 305, -1, "Off"},
|
{3051, 305, -1, "Off"},
|
||||||
{3052, 305, -1, "On"},
|
{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"},
|
{4010, 401, 4, "<- parent menu"},
|
||||||
{4011, 401, -1, "Kilometers"},
|
{4011, 401, -1, "Kilometers"},
|
||||||
{4012, 401, -1, "Miles"},
|
{4012, 401, -1, "Miles"},
|
||||||
|
|||||||
7
struct.h
7
struct.h
@@ -122,7 +122,7 @@ typedef struct {
|
|||||||
// Setting stored to flash
|
// Setting stored to flash
|
||||||
typedef struct {
|
typedef struct {
|
||||||
byte initFlag; // 183 value
|
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
|
uint16_t carType; // 0 - Kia eNiro 2020, 1 - Hyundai Kona 2020, 2 - Hyudai Ioniq 2018
|
||||||
char obdMacAddress[20];
|
char obdMacAddress[20];
|
||||||
char serviceUUID[40];
|
char serviceUUID[40];
|
||||||
@@ -137,6 +137,11 @@ typedef struct {
|
|||||||
byte lcdBrightness; // 0 - auto, 1 .. 100%
|
byte lcdBrightness; // 0 - auto, 1 .. 100%
|
||||||
byte debugScreen; // 0 - off, 1 - on
|
byte debugScreen; // 0 - off, 1 - on
|
||||||
byte predrawnChargingGraphs; // 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;
|
} SETTINGS_STRUC;
|
||||||
|
|
||||||
PARAMS_STRUC params; // Realtime sensor values
|
PARAMS_STRUC params; // Realtime sensor values
|
||||||
|
|||||||
Reference in New Issue
Block a user