This commit is contained in:
Lubos Petrovic
2020-12-05 00:05:34 +01:00
parent e7618a3cd8
commit 2ff9dfdad3
7 changed files with 91 additions and 62 deletions

View File

@@ -17,12 +17,6 @@ void Board320_240::initBoard() {
pinMode(pinButtonLeft, INPUT);
pinMode(pinButtonRight, INPUT);
// mute speaker
if (pinSpeaker != 0) {
Serial.println("Mute speaker for m5stack");
dacWrite(pinSpeaker, 0);
}
// Init display
Serial.println("Init tft display");
tft.begin();
@@ -1174,7 +1168,7 @@ void Board320_240::mainLoop() {
* skipAdapterScan
*/
bool Board320_240::skipAdapterScan() {
return digitalRead(pinButtonMiddle) == LOW || digitalRead(pinButtonRight) == LOW;
return digitalRead(pinButtonMiddle) == LOW || digitalRead(pinButtonLeft) == LOW || digitalRead(pinButtonRight) == LOW;
}
#endif // BOARD320_240_CPP

View File

@@ -80,12 +80,10 @@ void BoardInterface::loadSettings() {
String tmpStr;
// Init
// Default settings
liveData->settings.initFlag = 183;
liveData->settings.settingsVersion = 3;
liveData->settings.settingsVersion = 4;
liveData->settings.carType = CAR_KIA_ENIRO_2020_64;
// Default OBD adapter MAC and UUID's
tmpStr = "00:00:00:00:00:00"; // Pair via menu (middle button)
tmpStr.toCharArray(liveData->settings.obdMacAddress, tmpStr.length() + 1);
tmpStr = "000018f0-0000-1000-8000-00805f9b34fb"; // Default UUID's for VGate iCar Pro BLE4 adapter
@@ -94,7 +92,6 @@ void BoardInterface::loadSettings() {
tmpStr.toCharArray(liveData->settings.charTxUUID, tmpStr.length() + 1);
tmpStr = "00002af1-0000-1000-8000-00805f9b34fb";
tmpStr.toCharArray(liveData->settings.charRxUUID, tmpStr.length() + 1);
liveData->settings.displayRotation = 1; // 1,3
liveData->settings.distanceUnit = 'k';
liveData->settings.temperatureUnit = 'c';
@@ -103,15 +100,26 @@ void BoardInterface::loadSettings() {
liveData->settings.lcdBrightness = 0;
liveData->settings.debugScreen = 0;
liveData->settings.predrawnChargingGraphs = 1;
#ifdef SIM800L_ENABLED
liveData->settings.commType = 0; // BLE4
liveData->settings.wifiEnabled = 0;
tmpStr = "empty";
tmpStr.toCharArray(liveData->settings.wifiSsid, tmpStr.length() + 1);
tmpStr = "not_set";
tmpStr.toCharArray(liveData->settings.wifiPassword, tmpStr.length() + 1);
liveData->settings.ntpEnabled = 0;
liveData->settings.ntpTimezone = 1;
liveData->settings.ntpDaySaveTime = 0;
liveData->settings.sdcardEnabled = 0;
liveData->settings.sdcardAutstartLog = 1;
liveData->settings.gprsEnabled = 0;
tmpStr = "internet.t-mobile.cz";
tmpStr.toCharArray(liveData->settings.gprsApn, tmpStr.length() + 1);
// Remote upload
liveData->settings.remoteUploadEnabled = 0;
tmpStr = "http://api.example.com";
tmpStr.toCharArray(liveData->settings.remoteApiSrvr, tmpStr.length() + 1);
tmpStr.toCharArray(liveData->settings.remoteApiUrl, tmpStr.length() + 1);
tmpStr = "example";
tmpStr.toCharArray(liveData->settings.remoteApiKey, tmpStr.length() + 1);
#endif //SIM800L_ENABLED
// Load settings and replace default values
Serial.println("Reading settings from eeprom.");
@@ -124,7 +132,7 @@ void BoardInterface::loadSettings() {
saveSettings();
} else {
Serial.print("Loaded settings ver.: ");
Serial.println(liveData->settings.settingsVersion);
Serial.println(liveData->tmpSettings.settingsVersion);
// Upgrade structure
if (liveData->settings.settingsVersion != liveData->tmpSettings.settingsVersion) {
@@ -138,13 +146,37 @@ void BoardInterface::loadSettings() {
liveData->tmpSettings.settingsVersion = 3;
liveData->tmpSettings.predrawnChargingGraphs = liveData->settings.predrawnChargingGraphs;
}
saveSettings();
if (liveData->tmpSettings.settingsVersion == 3) {
liveData->tmpSettings.settingsVersion = 4;
liveData->tmpSettings.commType = 0; // BLE4
liveData->tmpSettings.wifiEnabled = 0;
tmpStr = "empty";
tmpStr.toCharArray(liveData->tmpSettings.wifiSsid, tmpStr.length() + 1);
tmpStr = "not_set";
tmpStr.toCharArray(liveData->tmpSettings.wifiPassword, tmpStr.length() + 1);
liveData->tmpSettings.ntpEnabled = 0;
liveData->tmpSettings.ntpTimezone = 1;
liveData->tmpSettings.ntpDaySaveTime = 0;
liveData->tmpSettings.sdcardEnabled = 0;
liveData->tmpSettings.sdcardAutstartLog = 1;
liveData->tmpSettings.gprsEnabled = 0;
tmpStr = "internet.t-mobile.cz";
tmpStr.toCharArray(liveData->tmpSettings.gprsApn, tmpStr.length() + 1);
// Remote upload
liveData->tmpSettings.remoteUploadEnabled = 0;
tmpStr = "http://api.example.com";
tmpStr.toCharArray(liveData->tmpSettings.remoteApiUrl, tmpStr.length() + 1);
tmpStr = "example";
tmpStr.toCharArray(liveData->tmpSettings.remoteApiKey, tmpStr.length() + 1);
}
// Save upgraded structure
liveData->settings = liveData->tmpSettings;
saveSettings();
}
// Save version? No need to upgrade structure
if (liveData->settings.settingsVersion == liveData->tmpSettings.settingsVersion) {
liveData->settings = liveData->tmpSettings;
}
// Apply settings from flash if needed
liveData->settings = liveData->tmpSettings;
}
}

View File

@@ -4,8 +4,6 @@
#include "BoardInterface.h"
#include "Board320_240.h"
#include "BoardM5stackCore.h"
#include <SPI.h>
#include <SD.h>
/**
Init board
@@ -19,41 +17,17 @@ void BoardM5stackCore::initBoard() {
pinSpeaker = SPEAKER_PIN;
pinBrightness = TFT_BL;
// Mute speaker
//ledcWriteTone(TONE_PIN_CHANNEL, 0);
digitalWrite(SPEAKER_PIN, 0);
//
Board320_240::initBoard();
}
void BoardM5stackCore::mainLoop() {
Board320_240::mainLoop();
/* if (!SD.begin(TFCARD_CS_PIN, SPI, 27000000)) {
Serial.println("Card Mount Failed");
return;
}
uint8_t cardType = SD.cardType();
if (cardType == CARD_NONE) {
Serial.println("No SD card attached");
return;
}
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);
Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024));
Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024));
*/
}
#endif // BOARDM5STACKCORE_CPP

View File

@@ -17,7 +17,10 @@
#define TFT_BL 32 // LED back-light
#define SPI_FREQUENCY 27000000
#define SPI_READ_FREQUENCY 5000000
// BEEP PIN
#define SPEAKER_PIN 25
#define TONE_PIN_CHANNEL 0
// SDCARD
#define TFCARD_CS_PIN 4
#define BUTTON_LEFT 37

View File

@@ -126,7 +126,9 @@ typedef struct {
// Setting stored to flash
typedef struct {
byte initFlag; // 183 value
byte settingsVersion; // current 3
byte settingsVersion; // current 4
// === settings version 1
// =================================
uint16_t carType; // 0 - Kia eNiro 2020, 1 - Hyundai Kona 2020, 2 - Hyudai Ioniq 2018
char obdMacAddress[20];
char serviceUUID[40];
@@ -136,16 +138,34 @@ typedef struct {
char distanceUnit; // k - kilometers
char temperatureUnit; // c - celsius
char pressureUnit; // b - bar
// version 2
// === settings version 3
// =================================
byte defaultScreen; // 1 .. 6
byte lcdBrightness; // 0 - auto, 1 .. 100%
byte debugScreen; // 0 - off, 1 - on
byte predrawnChargingGraphs; // 0 - off, 1 - on
#ifdef SIM800L_ENABLED
// === settings version 4
// =================================
byte commType; // 0 - OBD2 BLE4 adapter, 1 - CAN
// Wifi
byte wifiEnabled; // 0/1
char wifiSsid[32];
char wifiPassword[32];
// NTP
byte ntpEnabled; // 0/1
byte ntpTimezone;
byte ntpDaySaveTime; // 0/1
// SDcard logging
byte sdcardEnabled; // 0/1
byte sdcardAutstartLog; // 0/1
// GPRS SIM800L
byte gprsEnabled; // 0/1
char gprsApn[64];
char remoteApiSrvr[64];
char remoteApiKey[13];
#endif //SIM800L_ENABLED
// Remote upload
byte remoteUploadEnabled; // 0/1
char remoteApiUrl[64];
char remoteApiKey[32];
//
} SETTINGS_STRUC;

View File

@@ -1,5 +1,10 @@
# RELEASE NOTES
### DEV
- m5stack mute speaker
- settings v4 (wifi/gprs/sdcard/ntp/..)
- ble4 skipped if mac is not set (00:00:00:00:00:00)
### v2.0.0 2020-12-02
- Project renamed from eNiroDashboard to evDash

View File

@@ -366,7 +366,7 @@ void startBleScan() {
liveData->foundMyBleDevice = NULL;
liveData->scanningDeviceIndex = 0;
board->displayMessage(" > Scanning BLE4 devices", "40 seconds");
board->displayMessage(" > Scanning BLE4 devices", "40sec.or hold middle&RST");
// Start scanning
Serial.println("Scanning BLE devices...");
@@ -490,7 +490,7 @@ bool sendDataViaGPRS() {
Serial.println(payload);
Serial.print("Remote API server: ");
Serial.println(liveData->settings.remoteApiSrvr);
Serial.println(liveData->settings.remoteApiUrl);
uint16_t rc = sim800l->doPost(liveData->settings.remoteApiSrvr, "application/json", payload, 10000, 10000);
if(rc == 200) {
@@ -592,7 +592,8 @@ void setup(void) {
liveData->pBLEScan->setActiveScan(true);
// Skip BLE scan if middle button pressed
if (!board->skipAdapterScan()) {
Serial.println(liveData->settings.obdMacAddress);
if (strcmp(liveData->settings.obdMacAddress, "00:00:00:00:00:00") != 0 && !board->skipAdapterScan()) {
startBleScan();
}