Refactoring 2.
This commit is contained in:
1183
Board320_240.cpp
Normal file
1183
Board320_240.cpp
Normal file
File diff suppressed because it is too large
Load Diff
67
Board320_240.h
Normal file
67
Board320_240.h
Normal file
@@ -0,0 +1,67 @@
|
||||
#ifndef BOARD320_240_H
|
||||
#define BOARD320_240_H
|
||||
|
||||
// TFT COMMON
|
||||
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
|
||||
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
|
||||
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
|
||||
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
|
||||
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
|
||||
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
|
||||
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
|
||||
#define SMOOTH_FONT
|
||||
#define GFXFF 1 // TFT FOnts
|
||||
|
||||
//
|
||||
#include <TFT_eSPI.h>
|
||||
#include "BoardInterface.h"
|
||||
|
||||
class Board320_240 : public BoardInterface {
|
||||
|
||||
private:
|
||||
// TFT, SD SPI
|
||||
TFT_eSPI tft = TFT_eSPI();
|
||||
TFT_eSprite spr = TFT_eSprite(&tft);
|
||||
char tmpStr1[20];
|
||||
char tmpStr2[20];
|
||||
char tmpStr3[20];
|
||||
char tmpStr4[20];
|
||||
public:
|
||||
bool invertDisplay = false;
|
||||
byte pinButtonLeft = 0;
|
||||
byte pinButtonRight = 0;
|
||||
byte pinButtonMiddle = 0;
|
||||
byte pinSpeaker = 0;
|
||||
byte pinBrightness = 0;
|
||||
//
|
||||
void initBoard() override;
|
||||
void afterSetup() override;
|
||||
void mainLoop() override;
|
||||
bool skipAdapterScan() override;
|
||||
// Basic GUI
|
||||
void setBrightness(byte lcdBrightnessPerc) override;
|
||||
void displayMessage(const char* row1, const char* row2) override;
|
||||
void redrawScreen() override;
|
||||
// Custom screens
|
||||
void drawBigCell(int32_t x, int32_t y, int32_t w, int32_t h, const char* text, const char* desc, uint16_t bgColor, uint16_t fgColor);
|
||||
void drawSmallCell(int32_t x, int32_t y, int32_t w, int32_t h, const char* text, const char* desc, int16_t bgColor, int16_t fgColor);
|
||||
void showTires(int32_t x, int32_t y, int32_t w, int32_t h, const char* topleft, const char* topright, const char* bottomleft, const char* bottomright, uint16_t color);
|
||||
void drawSceneMain();
|
||||
void drawSceneSpeed();
|
||||
void drawSceneBatteryCells();
|
||||
void drawPreDrawnChargingGraphs(int zeroX, int zeroY, int mulX, int mulY);
|
||||
void drawSceneChargingGraph();
|
||||
void drawSceneSoc10Table();
|
||||
void drawSceneDebug();
|
||||
// Menu
|
||||
String menuItemCaption(int16_t menuItemId, String title);
|
||||
void showMenu() override;
|
||||
void hideMenu() override;
|
||||
void menuMove(bool forward);
|
||||
void menuItemClick();
|
||||
//
|
||||
void loadTestData();
|
||||
//
|
||||
};
|
||||
|
||||
#endif // BOARD320_240_H
|
||||
@@ -0,0 +1,151 @@
|
||||
#ifndef BOARDINTERFACE_CPP
|
||||
#define BOARDINTERFACE_CPP
|
||||
|
||||
#include <EEPROM.h>
|
||||
#include <BLEDevice.h>
|
||||
#include "BoardInterface.h"
|
||||
#include "LiveData.h"
|
||||
|
||||
/**
|
||||
Set live data
|
||||
*/
|
||||
void BoardInterface::setLiveData(LiveData* pLiveData) {
|
||||
this->liveData = pLiveData;
|
||||
}
|
||||
|
||||
/**
|
||||
Attach car interface
|
||||
*/
|
||||
void BoardInterface::attachCar(CarInterface* pCarInterface) {
|
||||
this->carInterface = pCarInterface;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Shutdown device
|
||||
*/
|
||||
void BoardInterface::shutdownDevice() {
|
||||
|
||||
Serial.println("Shutdown.");
|
||||
|
||||
this->displayMessage("Shutdown in 3 sec.", "");
|
||||
delay(3000);
|
||||
|
||||
setCpuFrequencyMhz(80);
|
||||
this->setBrightness(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(525600L * 60L * 1000000L); // minutes
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
/**
|
||||
Load settings from flash memory, upgrade structure if version differs
|
||||
*/
|
||||
void BoardInterface::saveSettings() {
|
||||
|
||||
// Flash to memory
|
||||
Serial.println("Settings saved to eeprom.");
|
||||
EEPROM.put(0, this->liveData->settings);
|
||||
EEPROM.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
Reset settings (factory reset)
|
||||
*/
|
||||
void BoardInterface::resetSettings() {
|
||||
|
||||
// Flash to memory
|
||||
Serial.println("Factory reset.");
|
||||
this->liveData->settings.initFlag = 1;
|
||||
EEPROM.put(0, this->liveData->settings);
|
||||
EEPROM.commit();
|
||||
|
||||
this->displayMessage("Settings erased", "Restarting in 5 seconds");
|
||||
|
||||
delay(5000);
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
/**
|
||||
Load setting from flash memory, upgrade structure if version differs
|
||||
*/
|
||||
void BoardInterface::loadSettings() {
|
||||
|
||||
String tmpStr;
|
||||
|
||||
// Init
|
||||
this->liveData->settings.initFlag = 183;
|
||||
this->liveData->settings.settingsVersion = 3;
|
||||
this->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(this->liveData->settings.obdMacAddress, tmpStr.length() + 1);
|
||||
tmpStr = "000018f0-0000-1000-8000-00805f9b34fb"; // Default UUID's for VGate iCar Pro BLE4 adapter
|
||||
tmpStr.toCharArray(this->liveData->settings.serviceUUID, tmpStr.length() + 1);
|
||||
tmpStr = "00002af0-0000-1000-8000-00805f9b34fb";
|
||||
tmpStr.toCharArray(this->liveData->settings.charTxUUID, tmpStr.length() + 1);
|
||||
tmpStr = "00002af1-0000-1000-8000-00805f9b34fb";
|
||||
tmpStr.toCharArray(this->liveData->settings.charRxUUID, tmpStr.length() + 1);
|
||||
|
||||
this->liveData->settings.displayRotation = 1; // 1,3
|
||||
this->liveData->settings.distanceUnit = 'k';
|
||||
this->liveData->settings.temperatureUnit = 'c';
|
||||
this->liveData->settings.pressureUnit = 'b';
|
||||
this->liveData->settings.defaultScreen = 1;
|
||||
this->liveData->settings.lcdBrightness = 0;
|
||||
this->liveData->settings.debugScreen = 0;
|
||||
this->liveData->settings.predrawnChargingGraphs = 1;
|
||||
|
||||
#ifdef SIM800L_ENABLED
|
||||
tmpStr = "internet.t-mobile.cz";
|
||||
tmpStr.toCharArray(liveData->settings.gprsApn, tmpStr.length() + 1);
|
||||
tmpStr = "http://api.example.com";
|
||||
tmpStr.toCharArray(liveData->settings.remoteApiSrvr, 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.");
|
||||
EEPROM.begin(sizeof(SETTINGS_STRUC));
|
||||
EEPROM.get(0, this->liveData->tmpSettings);
|
||||
|
||||
// Init flash with default settings
|
||||
if (this->liveData->tmpSettings.initFlag != 183) {
|
||||
Serial.println("Settings not found. Initialization.");
|
||||
this->saveSettings();
|
||||
} else {
|
||||
Serial.print("Loaded settings ver.: ");
|
||||
Serial.println(this->liveData->settings.settingsVersion);
|
||||
|
||||
// Upgrade structure
|
||||
if (this->liveData->settings.settingsVersion != this->liveData->tmpSettings.settingsVersion) {
|
||||
if (this->liveData->tmpSettings.settingsVersion == 1) {
|
||||
this->liveData->tmpSettings.settingsVersion = 2;
|
||||
this->liveData->tmpSettings.defaultScreen = this->liveData->settings.defaultScreen;
|
||||
this->liveData->tmpSettings.lcdBrightness = this->liveData->settings.lcdBrightness;
|
||||
this->liveData->tmpSettings.debugScreen = this->liveData->settings.debugScreen;
|
||||
}
|
||||
if (this->liveData->tmpSettings.settingsVersion == 2) {
|
||||
this->liveData->tmpSettings.settingsVersion = 3;
|
||||
this->liveData->tmpSettings.predrawnChargingGraphs = this->liveData->settings.predrawnChargingGraphs;
|
||||
}
|
||||
this->saveSettings();
|
||||
}
|
||||
|
||||
// Save version? No need to upgrade structure
|
||||
if (this->liveData->settings.settingsVersion == this->liveData->tmpSettings.settingsVersion) {
|
||||
this->liveData->settings = this->liveData->tmpSettings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // BOARDINTERFACE_CPP
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#ifndef BOARDINTERFACE_H
|
||||
#define BOARDINTERFACE_H
|
||||
|
||||
#include "LiveData.h"
|
||||
#include "CarInterface.h"
|
||||
|
||||
class BoardInterface {
|
||||
|
||||
private:
|
||||
public:
|
||||
// Screens, buttons
|
||||
byte displayScreen = SCREEN_AUTO;
|
||||
byte displayScreenAutoMode = 0;
|
||||
byte displayScreenSpeedHud = false;
|
||||
byte displayScreenCount = 7;
|
||||
bool btnLeftPressed = true;
|
||||
bool btnMiddlePressed = true;
|
||||
bool btnRightPressed = true;
|
||||
bool testDataMode = false;
|
||||
bool scanDevices = false;
|
||||
// Debug screen - next command with right button
|
||||
uint16_t debugCommandIndex = 0;
|
||||
String debugAtshRequest = "ATSH7E4";
|
||||
String debugCommandRequest = "220101";
|
||||
String debugLastString = "620101FFF7E7FF99000000000300B10EFE120F11100F12000018C438C30B00008400003864000035850000153A00001374000647010D017F0BDA0BDA03E8";
|
||||
String debugPreviousString = "620101FFF7E7FFB3000000000300120F9B111011101011000014CC38CB3B00009100003A510000367C000015FB000013D3000690250D018E0000000003E8";
|
||||
//
|
||||
LiveData* liveData;
|
||||
CarInterface* carInterface;
|
||||
void setLiveData(LiveData* pLiveData);
|
||||
void attachCar(CarInterface* pCarInterface);
|
||||
virtual void initBoard()=0;
|
||||
virtual void afterSetup()=0;
|
||||
virtual void mainLoop()=0;
|
||||
virtual bool skipAdapterScan() {return false;};
|
||||
// Graphics & GUI
|
||||
virtual void displayMessage(const char* row1, const char* row2)=0;
|
||||
virtual void setBrightness(byte lcdBrightnessPerc)=0;
|
||||
virtual void redrawScreen()=0;
|
||||
// Menu
|
||||
virtual void showMenu()=0;
|
||||
virtual void hideMenu()=0;
|
||||
// Common
|
||||
void shutdownDevice();
|
||||
void saveSettings();
|
||||
void resetSettings();
|
||||
void loadSettings();
|
||||
};
|
||||
|
||||
#endif // BOARDINTERFACE_H
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef BOARDM5STACKCORE_CPP
|
||||
#define BOARDM5STACKCORE_CPP
|
||||
|
||||
#include "BoardInterface.h"
|
||||
#include "Board320_240.h"
|
||||
#include "BoardM5stackCore.h"
|
||||
|
||||
/**
|
||||
Init board
|
||||
*/
|
||||
void BoardM5stackCore::initBoard() {
|
||||
|
||||
this->invertDisplay = true;
|
||||
this->pinButtonLeft = BUTTON_LEFT;
|
||||
this->pinButtonRight = BUTTON_RIGHT;
|
||||
this->pinButtonMiddle = BUTTON_MIDDLE;
|
||||
this->pinSpeaker = SPEAKER_PIN;
|
||||
this->pinBrightness = TFT_BL;
|
||||
|
||||
Board320_240::initBoard();
|
||||
|
||||
}
|
||||
|
||||
#endif // BOARDM5STACKCORE_CPP
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#ifndef BOARDM5STACKCORE_H
|
||||
#define BOARDM5STACKCORE_H
|
||||
|
||||
// Setup for m5stack core
|
||||
#define USER_SETUP_LOADED 1
|
||||
#define SPI_FREQUENCY 27000000
|
||||
#define SPI_TOUCH_FREQUENCY 2500000
|
||||
|
||||
#ifdef BOARD_M5STACK_CORE
|
||||
|
||||
#define USER_SETUP_LOADED 1
|
||||
#define ILI9341_DRIVER
|
||||
#define M5STACK
|
||||
@@ -19,7 +19,6 @@
|
||||
#define SPI_FREQUENCY 27000000
|
||||
#define SPI_READ_FREQUENCY 5000000
|
||||
#define SPEAKER_PIN 25
|
||||
#define INVERT_DISPLAY
|
||||
|
||||
#define BUTTON_LEFT 37
|
||||
#define BUTTON_MIDDLE 38
|
||||
@@ -30,4 +29,16 @@
|
||||
#define SD_MISO 19
|
||||
#define SD_SCLK 18
|
||||
|
||||
#endif // BOARD_M5STACK_CORE
|
||||
//
|
||||
#include "BoardInterface.h"
|
||||
#include "Board320_240.h"
|
||||
|
||||
class BoardM5stackCore : public Board320_240 {
|
||||
|
||||
private:
|
||||
public:
|
||||
void initBoard() override;
|
||||
|
||||
};
|
||||
|
||||
#endif // BOARDM5STACKCORE_H
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef BOARDTTGOT4V13_CPP
|
||||
#define BOARDTTGOT4V13_CPP
|
||||
|
||||
#include "BoardInterface.h"
|
||||
#include "Board320_240.h"
|
||||
#include "BoardTtgoT4v13.h"
|
||||
|
||||
/**
|
||||
Init board
|
||||
*/
|
||||
void BoardTtgoT4v13::initBoard() {
|
||||
|
||||
this->pinButtonLeft = BUTTON_LEFT;
|
||||
this->pinButtonRight = BUTTON_RIGHT;
|
||||
this->pinButtonMiddle = BUTTON_MIDDLE;
|
||||
//this->pinSpeaker = SPEAKER_PIN;
|
||||
this->pinBrightness = TFT_BL;
|
||||
|
||||
Board320_240::initBoard();
|
||||
}
|
||||
|
||||
#endif // BOARDTTGOT4V13_CPP
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#ifndef BOARDTTGOT4V13_H
|
||||
#define BOARDTTGOT4V13_H
|
||||
|
||||
// Setup for TTGO T4 v13
|
||||
#define USER_SETUP_LOADED 1
|
||||
#define SPI_FREQUENCY 27000000
|
||||
#define SPI_TOUCH_FREQUENCY 2500000
|
||||
|
||||
#ifdef BOARD_TTGO_T4
|
||||
|
||||
#define ILI9341_DRIVER
|
||||
#define TFT_MISO 12
|
||||
#define TFT_MOSI 23
|
||||
@@ -29,4 +29,17 @@
|
||||
#define BUTTON_MIDDLE 37
|
||||
#define BUTTON_RIGHT 39
|
||||
|
||||
#endif // BOARD_TTGO_T4
|
||||
//
|
||||
#include "BoardInterface.h"
|
||||
#include "Board320_240.h"
|
||||
|
||||
//
|
||||
class BoardTtgoT4v13 : public Board320_240 {
|
||||
|
||||
private:
|
||||
public:
|
||||
void initBoard() override;
|
||||
|
||||
};
|
||||
|
||||
#endif // BOARDTTGOT4V13_H
|
||||
|
||||
@@ -127,7 +127,7 @@ void CarKiaEniro::parseRowMerged() {
|
||||
this->liveData->params.ignitionOnPrevious = this->liveData->params.ignitionOn;
|
||||
this->liveData->params.ignitionOn = (bitRead(tempByte, 5) == 1);
|
||||
if (this->liveData->params.ignitionOnPrevious && !this->liveData->params.ignitionOn)
|
||||
this->liveData->params.automatickShutdownTimer = this->liveData->params.currentTime;
|
||||
this->liveData->params.automaticShutdownTimer = this->liveData->params.currentTime;
|
||||
|
||||
this->liveData->params.lightInfo = this->liveData->hexToDec(this->liveData->responseRowMerged.substring(18, 20).c_str(), 1, false);
|
||||
this->liveData->params.headLights = (bitRead(this->liveData->params.lightInfo, 5) == 1);
|
||||
|
||||
121
LiveData.cpp
121
LiveData.cpp
@@ -3,6 +3,103 @@
|
||||
#define LIVEDATA_CPP
|
||||
|
||||
#include "LiveData.h"
|
||||
#include "menu.h"
|
||||
|
||||
/**
|
||||
Init params with default values
|
||||
*/
|
||||
void LiveData::initParams() {
|
||||
|
||||
this->params.automaticShutdownTimer = 0;
|
||||
#ifdef SIM800L_ENABLED
|
||||
this->params.lastDataSent = 0;
|
||||
this->params.sim800l_enabled = false;
|
||||
#endif //SIM800L_ENABLED
|
||||
this->params.ignitionOn = false;
|
||||
this->params.ignitionOnPrevious = false;
|
||||
this->params.chargingStartTime = this->params.currentTime = 0;
|
||||
this->params.lightInfo = 0;
|
||||
this->params.headLights = false;
|
||||
this->params.dayLights = false;
|
||||
this->params.brakeLights = false;
|
||||
this->params.brakeLightInfo = 0;
|
||||
this->params.forwardDriveMode = false;
|
||||
this->params.reverseDriveMode = false;
|
||||
this->params.parkModeOrNeutral = false;
|
||||
this->params.espState = 0;
|
||||
this->params.speedKmh = -1;
|
||||
this->params.motorRpm = -1;
|
||||
this->params.odoKm = -1;
|
||||
this->params.socPerc = -1;
|
||||
this->params.socPercPrevious = -1;
|
||||
this->params.sohPerc = -1;
|
||||
this->params.cumulativeEnergyChargedKWh = -1;
|
||||
this->params.cumulativeEnergyChargedKWhStart = -1;
|
||||
this->params.cumulativeEnergyDischargedKWh = -1;
|
||||
this->params.cumulativeEnergyDischargedKWhStart = -1;
|
||||
this->params.availableChargePower = -1;
|
||||
this->params.availableDischargePower = -1;
|
||||
this->params.isolationResistanceKOhm = -1;
|
||||
this->params.batPowerAmp = -1;
|
||||
this->params.batPowerKw = -1;
|
||||
this->params.batPowerKwh100 = -1;
|
||||
this->params.batVoltage = -1;
|
||||
this->params.batCellMinV = -1;
|
||||
this->params.batCellMaxV = -1;
|
||||
this->params.batTempC = -1;
|
||||
this->params.batHeaterC = -1;
|
||||
this->params.batInletC = -1;
|
||||
this->params.batFanStatus = -1;
|
||||
this->params.batFanFeedbackHz = -1;
|
||||
this->params.batMinC = -1;
|
||||
this->params.batMaxC = -1;
|
||||
for (int i = 0; i < 12; i++) {
|
||||
this->params.batModuleTempC[i] = 0;
|
||||
}
|
||||
this->params.batModuleTempC[0] = -1;
|
||||
this->params.batModuleTempC[1] = -1;
|
||||
this->params.batModuleTempC[2] = -1;
|
||||
this->params.batModuleTempC[3] = -1;
|
||||
this->params.coolingWaterTempC = -1;
|
||||
this->params.coolantTemp1C = -1;
|
||||
this->params.coolantTemp2C = -1;
|
||||
this->params.bmsUnknownTempA = -1;
|
||||
this->params.bmsUnknownTempB = -1;
|
||||
this->params.bmsUnknownTempC = -1;
|
||||
this->params.bmsUnknownTempD = -1;
|
||||
this->params.auxPerc = -1;
|
||||
this->params.auxCurrentAmp = -1;
|
||||
this->params.auxVoltage = -1;
|
||||
this->params.indoorTemperature = -1;
|
||||
this->params.outdoorTemperature = -1;
|
||||
this->params.tireFrontLeftTempC = -1;
|
||||
this->params.tireFrontLeftPressureBar = -1;
|
||||
this->params.tireFrontRightTempC = -1;
|
||||
this->params.tireFrontRightPressureBar = -1;
|
||||
this->params.tireRearLeftTempC = -1;
|
||||
this->params.tireRearLeftPressureBar = -1;
|
||||
this->params.tireRearRightTempC = -1;
|
||||
this->params.tireRearRightPressureBar = -1;
|
||||
for (int i = 0; i <= 10; i++) {
|
||||
this->params.soc10ced[i] = this->params.soc10cec[i] = this->params.soc10odo[i] = -1;
|
||||
this->params.soc10time[i] = 0;
|
||||
}
|
||||
for (int i = 0; i < 98; i++) {
|
||||
this->params.cellVoltage[i] = 0;
|
||||
}
|
||||
this->params.cellCount = 0;
|
||||
for (int i = 0; i <= 100; i++) {
|
||||
this->params.chargingGraphMinKw[i] = -1;
|
||||
this->params.chargingGraphMaxKw[i] = -1;
|
||||
this->params.chargingGraphBatMinTempC[i] = -100;
|
||||
this->params.chargingGraphBatMaxTempC[i] = -100;
|
||||
this->params.chargingGraphHeaterTempC[i] = -100;
|
||||
this->params.chargingGraphWaterCoolantTempC[i] = -100;
|
||||
}
|
||||
|
||||
// Menu
|
||||
this->menuItems = menuItemsSource;
|
||||
}
|
||||
|
||||
/**
|
||||
Hex to dec (1-2 byte values, signed/unsigned)
|
||||
@@ -33,5 +130,29 @@ float LiveData::hexToDec(String hexString, byte bytes, bool signedNum) {
|
||||
return (decValue > 32767 ? (float)decValue - 65536.0 : decValue);
|
||||
}
|
||||
|
||||
/**
|
||||
Convert km to km or miles
|
||||
*/
|
||||
float LiveData::km2distance(float inKm) {
|
||||
return (this->settings.distanceUnit == 'k') ? inKm : inKm / 1.609344;
|
||||
}
|
||||
|
||||
/**
|
||||
Convert celsius to celsius or farenheit
|
||||
*/
|
||||
float LiveData::celsius2temperature(float inCelsius) {
|
||||
return (this->settings.temperatureUnit == 'c') ? inCelsius : (inCelsius * 1.8) + 32;
|
||||
}
|
||||
|
||||
/**
|
||||
Convert bar to bar or psi
|
||||
*/
|
||||
float LiveData::bar2pressure(float inBar) {
|
||||
return (this->settings.pressureUnit == 'b') ? inBar : inBar * 14.503773800722;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
#endif // LIVEDATA_CPP
|
||||
|
||||
33
LiveData.h
33
LiveData.h
@@ -7,6 +7,8 @@
|
||||
#include <WString.h>
|
||||
#include <String.h>
|
||||
#include <sys/time.h>
|
||||
#include <BLEDevice.h>
|
||||
#include "config.h"
|
||||
|
||||
// SUPPORTED CARS
|
||||
#define CAR_KIA_ENIRO_2020_64 0
|
||||
@@ -31,7 +33,7 @@
|
||||
typedef struct {
|
||||
time_t currentTime;
|
||||
time_t chargingStartTime;
|
||||
time_t automatickShutdownTimer;
|
||||
time_t automaticShutdownTimer;
|
||||
#ifdef SIM800L_ENABLED
|
||||
time_t lastDataSent;
|
||||
bool sim800l_enabled;
|
||||
@@ -147,6 +149,7 @@ typedef struct {
|
||||
} SETTINGS_STRUC;
|
||||
|
||||
|
||||
//
|
||||
class LiveData {
|
||||
private:
|
||||
public:
|
||||
@@ -160,10 +163,36 @@ class LiveData {
|
||||
bool canSendNextAtCommand = false;
|
||||
String commandRequest = "";
|
||||
String currentAtshRequest = "";
|
||||
//
|
||||
// Menu
|
||||
bool menuVisible = false;
|
||||
uint8_t menuItemsCount = 78;
|
||||
uint16_t menuCurrent = 0;
|
||||
uint8_t menuItemSelected = 0;
|
||||
uint8_t menuItemOffset = 0;
|
||||
uint16_t scanningDeviceIndex = 0;
|
||||
MENU_ITEM* menuItems;
|
||||
|
||||
// Bluetooth4
|
||||
boolean bleConnect = true;
|
||||
boolean bleConnected = false;
|
||||
BLEAddress *pServerAddress;
|
||||
BLERemoteCharacteristic* pRemoteCharacteristic;
|
||||
BLERemoteCharacteristic* pRemoteCharacteristicWrite;
|
||||
BLEAdvertisedDevice* foundMyBleDevice;
|
||||
BLEClient* pClient;
|
||||
BLEScan* pBLEScan;
|
||||
|
||||
// Params
|
||||
PARAMS_STRUC params; // Realtime sensor values
|
||||
// Settings
|
||||
SETTINGS_STRUC settings, tmpSettings; // Settings stored into flash
|
||||
|
||||
//
|
||||
void initParams();
|
||||
float hexToDec(String hexString, byte bytes = 2, bool signedNum = true);
|
||||
float km2distance(float inKm);
|
||||
float celsius2temperature(float inCelsius);
|
||||
float bar2pressure(float inBar);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
### v1.9.0 2020-11-30
|
||||
- Refactoring (classes)
|
||||
- Some SIM800L (m5stack) code from https://github.com/kolaCZek
|
||||
|
||||
### v1.8.3 2020-11-28
|
||||
- Automatic shutdown when car goes off
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
|
||||
rem slow GUI performance via arduino-cli yet
|
||||
|
||||
arduino-cli compile -v -b esp32:esp32:esp32wrover --build-properties build.extra_flags=-BOARD_TTGO_T4=1 -v enirodashboard.ino
|
||||
rem arduino-cli compile -v -b esp32:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app,CPUFreq=80 --build-properties build.extra_flags=-BOARD_TTGO_T4=1 -v enirodashboard.ino
|
||||
rem arduino-cli upload -b esp32:esp32:esp32 -v -p COM6
|
||||
rem rduino-cli upload -b esp32:esp32:esp32 -v -p COM6
|
||||
|
||||
rem arduino-cli compile -v -b esp32:esp32:m5stack-core-esp32 --build-properties build.extra_flags=-BOARD_M5STACK=1 enirodashboard.ino
|
||||
rem arduino-cli upload -v -b esp32:esp32:m5stack-core-esp32 -p COM9
|
||||
|
||||
26
config.h
26
config.h
@@ -1,16 +1,10 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
// TFT COMMON
|
||||
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
|
||||
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
|
||||
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
|
||||
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
|
||||
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
|
||||
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
|
||||
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
|
||||
#define SMOOTH_FONT
|
||||
#define GFXFF 1 // TFT FOnts
|
||||
#include <BLEDevice.h>
|
||||
|
||||
#define APP_VERSION "v1.9.0b"
|
||||
#define APP_RELEASE_DATE "2020-11-30"
|
||||
|
||||
// TFT COLORS FOR TTGO
|
||||
#define TFT_BLACK 0x0000 /* 0, 0, 0 */
|
||||
@@ -62,6 +56,14 @@
|
||||
#define SIM800L_TIMER 120
|
||||
#endif //SIM800L_ENABLED
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// MENU ITEM
|
||||
typedef struct {
|
||||
int16_t id;
|
||||
int16_t parentId;
|
||||
int16_t targetParentId;
|
||||
char title[50];
|
||||
char obdMacAddress[20];
|
||||
char serviceUUID[40];
|
||||
} MENU_ITEM;
|
||||
|
||||
#endif // CONFIG_H
|
||||
|
||||
1774
enirodashboard.ino
1774
enirodashboard.ino
File diff suppressed because it is too large
Load Diff
23
menu.h
23
menu.h
@@ -1,24 +1,8 @@
|
||||
|
||||
#ifndef MENU_H
|
||||
#define MENU_H
|
||||
|
||||
// Menu id/parent/title
|
||||
typedef struct {
|
||||
int16_t id;
|
||||
int16_t parentId;
|
||||
int16_t targetParentId;
|
||||
char title[50];
|
||||
char obdMacAddress[20];
|
||||
char serviceUUID[40];
|
||||
} MENU_ITEM;
|
||||
#include "config.h";
|
||||
|
||||
#define menuItemsCount 78
|
||||
bool menuVisible = false;
|
||||
uint16_t menuCurrent = 0;
|
||||
uint8_t menuItemSelected = 0;
|
||||
uint8_t menuItemOffset = 0;
|
||||
uint16_t scanningDeviceIndex = 0;
|
||||
MENU_ITEM menuItems[menuItemsCount] = {
|
||||
MENU_ITEM menuItemsSource[78] = {
|
||||
|
||||
{0, 0, 0, "<- exit menu"},
|
||||
{1, 0, -1, "Vehicle type"},
|
||||
@@ -114,6 +98,3 @@ MENU_ITEM menuItems[menuItemsCount] = {
|
||||
{10008, 9999, -1, "-"},
|
||||
{10009, 9999, -1, "-"},
|
||||
};
|
||||
|
||||
//
|
||||
#endif // MENU_H
|
||||
|
||||
Reference in New Issue
Block a user