This commit is contained in:
Ján Mátik
2020-12-25 19:00:34 +01:00
10 changed files with 163 additions and 56 deletions

View File

@@ -1,4 +1,4 @@
#include <SD.h>
//#include <SD.h>
#include <FS.h>
#include <analogWrite.h>
#include <TFT_eSPI.h>
@@ -73,8 +73,13 @@ void Board320_240::afterSetup() {
// Init GPS
if (liveData->settings.gpsHwSerialPort <= 2) {
Serial.print("GPS initialization on hw uart: ");
Serial.print("GPS initialization on hwUart: ");
Serial.println(liveData->settings.gpsHwSerialPort);
if (liveData->settings.gpsHwSerialPort == 0) {
Serial.println("hwUart0 collision with serial console! Disabling serial console");
Serial.flush();
Serial.end();
}
gpsHwUart = new HardwareSerial(liveData->settings.gpsHwSerialPort);
gpsHwUart->begin(9600);
}
@@ -1058,7 +1063,24 @@ void Board320_240::menuItemClick() {
// Save settings
case 9: saveSettings(); break;
// Version
case 10: hideMenu(); return;
case 10:
/* commInterface->executeCommand("ATSH770");
delay(50);
commInterface->executeCommand("3E");
delay(50);
commInterface->executeCommand("1003");
delay(50);
commInterface->executeCommand("2FBC1003");
delay(5000);
commInterface->executeCommand("ATSH770");
delay(50);
commInterface->executeCommand("3E");
delay(50);
commInterface->executeCommand("1003");
delay(50);
commInterface->executeCommand("2FBC1103");
delay(5000);*/
hideMenu(); return;
// Shutdown
case 11: shutdownDevice(); return;
default:
@@ -1166,8 +1188,8 @@ void Board320_240::redrawScreen() {
// SDCARD recording
/*liveData->params.sdcardRecording*/
if (liveData->settings.sdcardEnabled == 1) {
spr.fillCircle((displayScreen == SCREEN_SPEED || displayScreenAutoMode == SCREEN_SPEED) ? 160 : 310, 10, 4, TFT_BLACK);
spr.fillCircle((displayScreen == SCREEN_SPEED || displayScreenAutoMode == SCREEN_SPEED) ? 160 : 310, 10, 3,
spr.fillCircle((displayScreen == SCREEN_SPEED || displayScreenAutoMode == SCREEN_SPEED) ? 140 : 310, 10, 4, TFT_BLACK);
spr.fillCircle((displayScreen == SCREEN_SPEED || displayScreenAutoMode == SCREEN_SPEED) ? 140 : 310, 10, 3,
(liveData->params.sdcardInit == 1) ?
(liveData->params.sdcardRecording) ?
(strlen(liveData->params.sdcardFilename) != 0) ?
@@ -1177,16 +1199,30 @@ void Board320_240::redrawScreen() {
TFT_YELLOW /* failed to initialize sdcard */
);
}
// GPS state
if (gpsHwUart != NULL && (displayScreen == SCREEN_SPEED || displayScreenAutoMode == SCREEN_SPEED)) {
spr.drawCircle(180, 10, 5, (gps.location.isValid()) ? TFT_GREEN : TFT_RED);
spr.drawCircle(160, 10, 5, (gps.location.isValid()) ? TFT_GREEN : TFT_RED);
spr.setTextSize(1);
spr.setTextColor((gps.location.isValid()) ? TFT_GREEN : TFT_WHITE, TFT_BLACK);
spr.setTextDatum(TL_DATUM);
sprintf(tmpStr1, "%d", liveData->params.gpsSat);
spr.drawString(tmpStr1, 194, 2, 2);
spr.drawString(tmpStr1, 174, 2, 2);
}
// Door status
if (liveData->params.trunkDoorOpen)
spr.fillRect(20, 0, 320 - 40, 20, TFT_YELLOW);
if (liveData->params.leftFrontDoorOpen)
spr.fillRect(0, 20, 20, 98, TFT_YELLOW);
if (liveData->params.rightFrontDoorOpen)
spr.fillRect(0, 122, 20, 98, TFT_YELLOW);
if (liveData->params.leftRearDoorOpen)
spr.fillRect(320 - 20, 20, 20, 98, TFT_YELLOW);
if (liveData->params.rightRearDoorOpen)
spr.fillRect(320 - 20, 122, 20, 98, TFT_YELLOW);
if (liveData->params.hoodDoorOpen)
spr.fillRect(20, 240 - 20, 320 - 40, 20, TFT_YELLOW);
// BLE not connected
if (!liveData->commConnected && liveData->bleConnect && liveData->tmpSettings.commType == COMM_TYPE_OBD2BLE4) {
// Print message
@@ -1208,7 +1244,7 @@ void Board320_240::redrawScreen() {
void Board320_240::loadTestData() {
Serial.println("Loading test data");
testDataMode = true; // skip lights off message
carInterface->loadTestData();
redrawScreen();
@@ -1371,13 +1407,14 @@ bool Board320_240::sdcardMount() {
Serial.print("Initializing SD card...");
#ifdef BOARD_TTGO_T4
Serial.print(" TTGO-T4 ");
SPIClass * hspi = new SPIClass(HSPI);
spiSD.begin(pinSdcardSclk, pinSdcardMiso, pinSdcardMosi, pinSdcardCs); //SCK,MISO,MOSI,ss
SdState = SD.begin(pinSdcardCs, *hspi, SPI_FREQUENCY);
#endif // BOARD_TTGO_T4
#ifdef BOARD_M5STACK_CORE
#endif BOARD_TTGO_T4
Serial.print(" M5STACK ");
SdState = SD.begin(pinSdcardCs);
#endif // BOARD_M5STACK_CORE
if (SdState) {
@@ -1484,7 +1521,7 @@ bool Board320_240::sim800lSetup() {
// SIM800L DebugMode:
//sim800l = new SIM800L((Stream *)gprsHwUart, SIM800L_RST, 512 , 512, (Stream *)&Serial);
bool sim800l_ready = sim800l->isReady();
bool sim800l_ready = sim800l->isReady();
for (uint8_t i = 0; i < 5 && !sim800l_ready; i++) {
Serial.println("Problem to initialize SIM800L module, retry in 1 sec");
delay(1000);

View File

@@ -38,7 +38,7 @@ void BoardInterface::shutdownDevice() {
}
#ifdef SIM800L_ENABLED
if(sim800l->isConnectedGPRS()) {
if (sim800l->isConnectedGPRS()) {
sim800l->disconnectGPRS();
}
sim800l->setPowerMode(MINIMUM);
@@ -49,7 +49,7 @@ void BoardInterface::shutdownDevice() {
//WiFi.disconnect(true);
//WiFi.mode(WIFI_OFF);
commInterface->disconnectDevice();
commInterface->disconnectDevice();
//adc_power_off();
//esp_wifi_stop();
esp_bt_controller_disable();
@@ -137,6 +137,10 @@ void BoardInterface::loadSettings() {
liveData->settings.headlightsReminder = 0;
liveData->settings.gpsHwSerialPort = 255; // off
liveData->settings.gprsHwSerialPort = 255; // off
liveData->settings.serialConsolePort = 0; // hwuart0
liveData->settings.debugLevel = 1; // 0 - info only, 1 - debug communication (BLE/CAN), 2 - debug GSM, 3 - debug SDcard
liveData->settings.sdcardLogIntervalSec = 2;
liveData->settings.gprsLogIntervalSec = 60;
// Load settings and replace default values
Serial.println("Reading settings from eeprom.");
@@ -191,6 +195,13 @@ void BoardInterface::loadSettings() {
liveData->tmpSettings.settingsVersion = 5;
liveData->tmpSettings.gpsHwSerialPort = 255; // off
}
if (liveData->tmpSettings.settingsVersion == 5) {
liveData->tmpSettings.settingsVersion = 6;
liveData->tmpSettings.serialConsolePort = 0; // hwuart0
liveData->tmpSettings.debugLevel = 1; // 1 - debug communication (BLE/CAN)
liveData->tmpSettings.sdcardLogIntervalSec = 2;
liveData->tmpSettings.gprsLogIntervalSec = 60;
}
// Save upgraded structure
liveData->settings = liveData->tmpSettings;
@@ -210,7 +221,7 @@ void BoardInterface::afterSetup() {
// Init Comm iterface
Serial.print("Init communication device: ");
Serial.println(liveData->settings.commType);
if (liveData->settings.commType == COMM_TYPE_OBD2BLE4) {
commInterface = new CommObd2Ble4();
} else if (liveData->settings.commType == COMM_TYPE_OBD2CAN) {
@@ -247,10 +258,10 @@ void BoardInterface::customConsoleCommand(String cmd) {
}
/**
* Parser response from obd2/can
*/
Parser response from obd2/can
*/
void BoardInterface::parseRowMerged() {
carInterface->parseRowMerged();
}

View File

@@ -21,7 +21,7 @@ void BoardM5stackCore::initBoard() {
// Mute speaker
//ledcWriteTone(TONE_PIN_CHANNEL, 0);
digitalWrite(SPEAKER_PIN, 0);
dacWrite(SPEAKER_PIN, 0);
//
Board320_240::initBoard();

View File

@@ -85,7 +85,7 @@ void CarHyundaiIoniq::activateCommandQueue() {
*/
void CarHyundaiIoniq::parseRowMerged() {
bool tempByte;
uint8_t tempByte;
float tempFloat;
String tmpStr;
@@ -97,7 +97,6 @@ void CarHyundaiIoniq::parseRowMerged() {
liveData->params.speedKmh = 0;
}
if (liveData->commandRequest.equals("2102")) {
liveData->params.auxPerc = liveData->hexToDecFromResponse(50, 52, 1, false);
liveData->params.auxCurrentAmp = - liveData->hexToDecFromResponse(46, 50, 2, true) / 1000.0;
}
}
@@ -111,15 +110,15 @@ void CarHyundaiIoniq::parseRowMerged() {
liveData->params.lastIgnitionOnTime = liveData->params.currentTime;
}
int32_t secDiff = liveData->params.currentTime - liveData->params.currentTime;
if (liveData->commConnected && secDiff > 30 && secDiff < MONTH_SEC && !liveData->params.ignitionOn)
if (liveData->commConnected && secDiff > 30 && secDiff < MONTH_SEC && !liveData->params.ignitionOn && !liveData->params.chargingOn)
liveData->params.automaticShutdownTimer = liveData->params.currentTime;
liveData->params.lightInfo = liveData->hexToDecFromResponse(18, 20, 1, false);
liveData->params.headLights = (bitRead(liveData->params.lightInfo, 5) == 1);
liveData->params.dayLights = (bitRead(liveData->params.lightInfo, 3) == 1);
tempByte = liveData->hexToDecFromResponse(18, 20, 1, false);
liveData->params.headLights = (bitRead(tempByte, 5) == 1);
liveData->params.dayLights = (bitRead(tempByte, 3) == 1);
}
if (liveData->commandRequest.equals("22BC06")) {
liveData->params.brakeLightInfo = liveData->hexToDecFromResponse(14, 16, 1, false);
liveData->params.brakeLights = (bitRead(liveData->params.brakeLightInfo, 5) == 1);
tempByte = liveData->hexToDecFromResponse(14, 16, 1, false);
liveData->params.brakeLights = (bitRead(tempByte, 5) == 1);
}
}
@@ -157,6 +156,20 @@ void CarHyundaiIoniq::parseRowMerged() {
liveData->params.batFanStatus = liveData->hexToDecFromResponse(58, 60, 2, true);
liveData->params.batFanFeedbackHz = liveData->hexToDecFromResponse(60, 62, 2, true);
liveData->params.auxVoltage = liveData->hexToDecFromResponse(62, 64, 2, true) / 10.0;
float tmpAuxPerc;
if(liveData->params.ignitionOn) {
tmpAuxPerc = map(liveData->params.auxVoltage * 10, 128, 148, 0, 1000) / 10;
} else {
tmpAuxPerc = map(liveData->params.auxVoltage * 10, 116, 128, 0, 1000) / 10;
}
if(tmpAuxPerc > 100) {
liveData->params.auxPerc = 100;
} else if(tmpAuxPerc < 0) {
liveData->params.auxPerc = 0;
} else {
liveData->params.auxPerc = tmpAuxPerc;
}
liveData->params.batPowerAmp = - liveData->hexToDecFromResponse(24, 28, 2, true) / 10.0;
liveData->params.batVoltage = liveData->hexToDecFromResponse(28, 32, 2, false) / 10.0;
liveData->params.batPowerKw = (liveData->params.batPowerAmp * liveData->params.batVoltage) / 1000.0;
@@ -174,6 +187,9 @@ void CarHyundaiIoniq::parseRowMerged() {
//liveData->params.batMaxC = liveData->hexToDecFromResponse(32, 34, 1, true);
//liveData->params.batMinC = liveData->hexToDecFromResponse(34, 36, 1, true);
tempByte = liveData->hexToDecFromResponse(104, 106, 1, false);
liveData->params.chargingOn = (bitRead(tempByte, 2) == 1);
// This is more accurate than min/max from BMS. It's required to detect kona/eniro cold gates (min 15C is needed > 43kW charging, min 25C is needed > 58kW charging)
liveData->params.batInletC = liveData->hexToDecFromResponse(48, 50, 1, true);
if (liveData->params.speedKmh < 10 && liveData->params.batPowerKw >= 1 && liveData->params.socPerc > 0 && liveData->params.socPerc <= 100) {

View File

@@ -1,12 +1,12 @@
/*
* eNiro/Kona chargings limits depending on battery temperature (min.value of 01-04 battery module)
/*
eNiro/Kona chargings limits depending on battery temperature (min.value of 01-04 battery module)
>= 35°C BMS allows max 180A
>= 25°C without limit (200A)
>= 15°C BMS allows max 120A
>= 5°C BMS allows max 90A
>= 1°C BMS allows max 60A
<= 0°C BMS allows max 40A
*/
*/
#include <Arduino.h>
#include <stdint.h>
@@ -20,8 +20,8 @@
#define commandQueueLoopFromKiaENiro 8
/**
* activateCommandQueue
*/
activateCommandQueue
*/
void CarKiaEniro::activateCommandQueue() {
String commandQueueKiaENiro[commandQueueCountKiaENiro] = {
@@ -102,11 +102,11 @@ void CarKiaEniro::activateCommandQueue() {
}
/**
* parseRowMerged
*/
parseRowMerged
*/
void CarKiaEniro::parseRowMerged() {
bool tempByte;
uint8_t tempByte;
float tempFloat;
String tmpStr;
@@ -123,21 +123,31 @@ void CarKiaEniro::parseRowMerged() {
// IGPM
if (liveData->currentAtshRequest.equals("ATSH770")) {
if (liveData->commandRequest.equals("22BC03")) {
//
tempByte = liveData->hexToDecFromResponse(14, 16, 1, false);
liveData->params.hoodDoorOpen = (bitRead(tempByte, 7) == 1);
liveData->params.leftFrontDoorOpen = (bitRead(tempByte, 5) == 1);
liveData->params.rightFrontDoorOpen = (bitRead(tempByte, 0) == 1);
liveData->params.leftRearDoorOpen = (bitRead(tempByte, 4) == 1);
liveData->params.rightRearDoorOpen = (bitRead(tempByte, 2) == 1);
//
tempByte = liveData->hexToDecFromResponse(16, 18, 1, false);
liveData->params.ignitionOn = (bitRead(tempByte, 5) == 1);
liveData->params.trunkDoorOpen = (bitRead(tempByte, 0) == 1);
if (liveData->params.ignitionOn) {
liveData->params.lastIgnitionOnTime = liveData->params.currentTime;
}
int32_t secDiff = liveData->params.currentTime - liveData->params.currentTime;
if (liveData->commConnected && secDiff > 30 && secDiff < MONTH_SEC && !liveData->params.ignitionOn)
if (liveData->commConnected && secDiff > 30 && secDiff < MONTH_SEC && !liveData->params.ignitionOn && !liveData->params.chargingOn)
liveData->params.automaticShutdownTimer = liveData->params.currentTime;
liveData->params.lightInfo = liveData->hexToDecFromResponse(18, 20, 1, false);
liveData->params.headLights = (bitRead(liveData->params.lightInfo, 5) == 1);
liveData->params.dayLights = (bitRead(liveData->params.lightInfo, 3) == 1);
tempByte = liveData->hexToDecFromResponse(18, 20, 1, false);
liveData->params.headLights = (bitRead(tempByte, 5) == 1);
liveData->params.dayLights = (bitRead(tempByte, 3) == 1);
}
if (liveData->commandRequest.equals("22BC06")) {
liveData->params.brakeLightInfo = liveData->hexToDecFromResponse(14, 16, 1, false);
liveData->params.brakeLights = (bitRead(liveData->params.brakeLightInfo, 5) == 1);
tempByte = liveData->hexToDecFromResponse(14, 16, 1, false);
liveData->params.brakeLights = (bitRead(tempByte, 5) == 1);
}
}
@@ -207,6 +217,8 @@ void CarKiaEniro::parseRowMerged() {
//liveData->params.batTempC = liveData->hexToDecFromResponse(36, 38, 1, true);
//liveData->params.batMaxC = liveData->hexToDecFromResponse(34, 36, 1, true);
//liveData->params.batMinC = liveData->hexToDecFromResponse(36, 38, 1, true);
tempByte = liveData->hexToDecFromResponse(106, 108, 1, false);
liveData->params.chargingOn = (bitRead(tempByte, 2) == 1);
// This is more accurate than min/max from BMS. It's required to detect kona/eniro cold gates (min 15C is needed > 43kW charging, min 25C is needed > 58kW charging)
liveData->params.batMinC = liveData->params.batMaxC = liveData->params.batModuleTempC[0];
@@ -303,8 +315,8 @@ void CarKiaEniro::parseRowMerged() {
}
/**
* loadTestData
*/
loadTestData
*/
void CarKiaEniro::loadTestData() {
// IGPM

View File

@@ -6,8 +6,8 @@
#include "LiveData.h"
#include "CarRenaultZoe.h"
#define commandQueueCountRenaultZoe 83
#define commandQueueLoopFromRenaultZoe 9
#define commandQueueCountRenaultZoe 34
#define commandQueueLoopFromRenaultZoe 8
/**
activateCommandQueue
@@ -108,7 +108,9 @@ void CarRenaultZoe::activateCommandQueue() {
//
liveData->params.batModuleTempCount = 12; // 24, 12 is display limit
liveData->params.batteryTotalAvailableKWh = 28;
liveData->params.batteryTotalAvailableKWh = 22;
// usable 22, total 26
// Empty and fill command queue
for (int i = 0; i < 300; i++) {
@@ -127,7 +129,7 @@ void CarRenaultZoe::activateCommandQueue() {
*/
void CarRenaultZoe::parseRowMerged() {
bool tempByte;
uint8_t tempByte;
// LBC 79B
if (liveData->currentAtshRequest.equals("ATSH79B")) {

View File

@@ -202,7 +202,7 @@ void CommObd2Can::sendPID(const uint16_t pid, const String& cmd) {
*/
void CommObd2Can::sendFlowControlFrame() {
uint8_t txBuf[8] = { 0x30, requestFramesCount /*request count*/, 14 /*ms between frames*/ , 0, 0, 0, 0, 0 };
uint8_t txBuf[8] = { 0x30, requestFramesCount /*request count*/, 20 /*ms between frames*/ , 0, 0, 0, 0, 0 };
// insert 0x07 into beginning for BMW i3
if (liveData->settings.carType == CAR_BMW_I3_2014) {
@@ -228,7 +228,7 @@ void CommObd2Can::sendFlowControlFrame() {
Receive PID
*/
uint8_t CommObd2Can::receivePID() {
if (!digitalRead(pinCanInt)) // If CAN0_INT pin is low, read receive buffer
{
lastDataSent = millis();
@@ -259,6 +259,16 @@ uint8_t CommObd2Can::receivePID() {
Serial.println(" [Ignored packet]");
return 0xff;
}
// Filter received messages (Ioniq only)
if(liveData->settings.carType == CAR_HYUNDAI_IONIQ_2018) {
long unsigned int atsh_response = liveData->hexToDec(liveData->currentAtshRequest.substring(4), 2, false) + 8;
if(rxId != atsh_response) {
Serial.println(" [Filtered packet]");
return 0xff;
}
}
Serial.println();
processFrameBytes();

View File

@@ -27,15 +27,19 @@ void LiveData::initParams() {
params.lastIgnitionOnTime = 0;
params.operationTimeSec = 0;
params.chargingStartTime = params.currentTime = 0;
params.lightInfo = 0;
params.chargingOn = false;
params.headLights = false;
params.dayLights = false;
params.brakeLights = false;
params.brakeLightInfo = 0;
params.trunkDoorOpen = false;
params.leftFrontDoorOpen = false;
params.rightFrontDoorOpen = false;
params.leftRearDoorOpen = false;
params.rightRearDoorOpen = false;
params.hoodDoorOpen = false;
params.forwardDriveMode = false;
params.reverseDriveMode = false;
params.parkModeOrNeutral = false;
params.espState = 0;
params.speedKmh = -1;
params.motorRpm = -1;
params.odoKm = -1;

View File

@@ -58,6 +58,7 @@ typedef struct {
char sdcardFilename[32];
// Car params
bool ignitionOn;
bool chargingOn;
time_t lastIgnitionOnTime;
uint64_t operationTimeSec;
bool sdcardCanNotify;
@@ -67,9 +68,15 @@ typedef struct {
bool headLights;
bool dayLights;
bool brakeLights;
uint8_t lightInfo;
bool trunkDoorOpen;
bool leftFrontDoorOpen;
bool rightFrontDoorOpen;
bool leftRearDoorOpen;
bool rightRearDoorOpen;
bool hoodDoorOpen;
/* uint8_t lightInfo;
uint8_t brakeLightInfo;
uint8_t espState;
uint8_t espState;*/
float batteryTotalAvailableKWh;
float speedKmh;
float motorRpm;
@@ -193,6 +200,14 @@ typedef struct {
// =================================
byte gpsHwSerialPort; // 255-off, 0,1,2 - hw serial
byte gprsHwSerialPort; // 255-off, 0,1,2 - hw serial
// === settings version 6
// =================================
byte serialConsolePort; // 255-off, 0 - hw serial (std)
byte debugLevel; // 0 - info only, 1 - debug communication (BLE/CAN), 2 - debug GSM, 3 - debug SDcard
uint16_t sdcardLogIntervalSec; // every x seconds
uint16_t gprsLogIntervalSec; // every x seconds
//
} SETTINGS_STRUC;

View File

@@ -1,4 +1,4 @@
/*
/*
Project renamed from eNiroDashboard to evDash
Serial console commands