diff --git a/Board320_240.cpp b/Board320_240.cpp index 42896a2..3ae21d0 100644 --- a/Board320_240.cpp +++ b/Board320_240.cpp @@ -69,6 +69,8 @@ void Board320_240::afterSetup() { sdcardToggleRecording(); } } + + BoardInterface::afterSetup(); } /** diff --git a/Board320_240.h b/Board320_240.h index a8db8ec..1d6de3b 100644 --- a/Board320_240.h +++ b/Board320_240.h @@ -18,7 +18,7 @@ class Board320_240 : public BoardInterface { - private: + protected: // TFT, SD SPI TFT_eSPI tft = TFT_eSPI(); TFT_eSprite spr = TFT_eSprite(&tft); diff --git a/BoardInterface.cpp b/BoardInterface.cpp index b0be0a8..0f47d00 100644 --- a/BoardInterface.cpp +++ b/BoardInterface.cpp @@ -7,6 +7,8 @@ #include #include #include "BoardInterface.h" +#include "CommObd2Ble4.h"; +#include "CommObd2Can.h"; #include "LiveData.h" /** @@ -185,6 +187,23 @@ void BoardInterface::loadSettings() { } } +/** + * After setup + */ +void BoardInterface::afterSetup() { + + // Init Comm iterface + if (liveData->settings.commType == COMM_TYPE_OBD2BLE4) { + commInterface = new CommObd2Ble4(); + } else + if (liveData->settings.commType == COMM_TYPE_OBD2CAN) { + commInterface = new CommObd2Ble4(); + //commInterface = new CommObd2Can(); + } + //commInterface->initComm(liveData, NULL); + commInterface->connectDevice(); +} + /** Custom commands */ diff --git a/BoardInterface.h b/BoardInterface.h index 78f9160..3a2db28 100644 --- a/BoardInterface.h +++ b/BoardInterface.h @@ -4,10 +4,14 @@ #include #include "LiveData.h" #include "CarInterface.h" +#include "CommInterface.h" class BoardInterface { - private: + protected: + LiveData* liveData; + CarInterface* carInterface; + CommInterface* commInterface; public: // Screens, buttons byte displayScreen = SCREEN_AUTO; @@ -27,8 +31,6 @@ class BoardInterface { String debugLastString = "620101FFF7E7FF99000000000300B10EFE120F11100F12000018C438C30B00008400003864000035850000153A00001374000647010D017F0BDA0BDA03E8"; String debugPreviousString = "620101FFF7E7FFB3000000000300120F9B111011101011000014CC38CB3B00009100003A510000367C000015FB000013D3000690250D018E0000000003E8"; // - LiveData* liveData; - CarInterface* carInterface; void setLiveData(LiveData* pLiveData); void attachCar(CarInterface* pCarInterface); virtual void initBoard()=0; diff --git a/BoardM5stackCore.h b/BoardM5stackCore.h index 9ce7a4c..93078f8 100644 --- a/BoardM5stackCore.h +++ b/BoardM5stackCore.h @@ -37,7 +37,7 @@ class BoardM5stackCore : public Board320_240 { - private: + protected: public: void initBoard() override; void mainLoop() override; diff --git a/BoardTtgoT4v13.h b/BoardTtgoT4v13.h index e0a9bef..aa186db 100644 --- a/BoardTtgoT4v13.h +++ b/BoardTtgoT4v13.h @@ -36,7 +36,7 @@ // class BoardTtgoT4v13 : public Board320_240 { - private: + protected: public: void initBoard() override; diff --git a/CarHyundaiIoniq.h b/CarHyundaiIoniq.h index 32a5802..6a4cb01 100644 --- a/CarHyundaiIoniq.h +++ b/CarHyundaiIoniq.h @@ -5,7 +5,7 @@ class CarHyundaiIoniq : public CarInterface { - private: + protected: public: void activateCommandQueue() override; diff --git a/CarInterface.h b/CarInterface.h index 46966a9..6cc4abd 100644 --- a/CarInterface.h +++ b/CarInterface.h @@ -5,7 +5,7 @@ class CarInterface { - private: + protected: public: LiveData* liveData; void setLiveData(LiveData* pLiveData); diff --git a/CarKiaDebugObd2.h b/CarKiaDebugObd2.h index 35d7c64..43b4282 100644 --- a/CarKiaDebugObd2.h +++ b/CarKiaDebugObd2.h @@ -5,7 +5,7 @@ class CarKiaDebugObd2 : public CarInterface { - private: + protected: public: void activateCommandQueue() override; diff --git a/CarKiaEniro.h b/CarKiaEniro.h index a3f282a..b7f8033 100644 --- a/CarKiaEniro.h +++ b/CarKiaEniro.h @@ -5,7 +5,7 @@ class CarKiaEniro : public CarInterface { - private: + protected: public: void activateCommandQueue() override; diff --git a/CarRenaultZoe.h b/CarRenaultZoe.h index 307924c..75458c3 100644 --- a/CarRenaultZoe.h +++ b/CarRenaultZoe.h @@ -5,7 +5,7 @@ class CarRenaultZoe : public CarInterface { - private: + protected: public: void activateCommandQueue() override; diff --git a/CommInterface.cpp b/CommInterface.cpp index dea253e..f143257 100644 --- a/CommInterface.cpp +++ b/CommInterface.cpp @@ -2,6 +2,12 @@ #define COMMINTERFACE_CPP #include "CommInterface.h" +//#include "BoardInterface.h" #include "LiveData.h" +void CommInterface::initComm(LiveData* pLiveData/*, BoardInterface* pBoard*/) { + liveData = pLiveData; + //board = pBoard; +} + #endif // COMMINTERFACE_CPP diff --git a/CommInterface.h b/CommInterface.h index cf36e4b..076eb7f 100644 --- a/CommInterface.h +++ b/CommInterface.h @@ -2,11 +2,18 @@ #define COMMINTERFACE_H #include "LiveData.h" +//#include "BoardInterface.h" class CommInterface { - private: + protected: + LiveData* liveData; + //BoardInterface* board; public: + void initComm(LiveData* pLiveData/*, BoardInterface* pBoard**/); + virtual void connectDevice() = 0; + virtual void disconnectDevice() = 0; + virtual void scanDevices() = 0; }; #endif // COMMINTERFACE_H diff --git a/CommObd2Ble4.cpp b/CommObd2Ble4.cpp index 2960b66..b1f191c 100644 --- a/CommObd2Ble4.cpp +++ b/CommObd2Ble4.cpp @@ -1,7 +1,29 @@ #ifndef COMMOBD2BLE4_CPP #define COMMOBD2BLE4_CPP -#include "CommInterface.h" +#include +#include "CommObd2Ble4.h" #include "LiveData.h" +/** + * Connect ble4 adapter + */ +void CommObd2Ble4::connectDevice() { + Serial.println("COMM connectDevice"); +} + +/** + * Disconnect device + */ +void CommObd2Ble4::disconnectDevice() { + Serial.println("COMM disconnectDevice"); +} + +/** + * Scan device list + */ +void CommObd2Ble4::scanDevices() { + Serial.println("COMM scanDevices"); +} + #endif // COMMOBD2BLE4_CPP diff --git a/CommObd2Ble4.h b/CommObd2Ble4.h index 5062379..6681ae9 100644 --- a/CommObd2Ble4.h +++ b/CommObd2Ble4.h @@ -2,11 +2,16 @@ #define COMMOBD2BLE4_H #include "LiveData.h" +#include "CommInterface.h" class CommObd2Ble4 : public CommInterface { - private: + protected: + uint32_t PIN = 1234; public: + void connectDevice() override; + void disconnectDevice() override; + void scanDevices() override; }; #endif // COMMOBD2BLE4_H diff --git a/CommObd2Can.h b/CommObd2Can.h index 02b77ce..b408ba3 100644 --- a/CommObd2Can.h +++ b/CommObd2Can.h @@ -5,7 +5,7 @@ class CommObd2Can : public CommInterface { - private: + protected: public: }; diff --git a/LiveData.h b/LiveData.h index 5b87257..06a51ab 100644 --- a/LiveData.h +++ b/LiveData.h @@ -19,6 +19,10 @@ #define CAR_RENAULT_ZOE 5 #define CAR_DEBUG_OBD2_KIA 999 +// +#define COMM_TYPE_OBD2BLE4 0 +#define COMM_TYPE_OBD2CAN 1 + // SCREENS #define SCREEN_BLANK 0 #define SCREEN_AUTO 1 @@ -179,7 +183,7 @@ typedef struct { // class LiveData { - private: + protected: public: // Command loop uint16_t commandQueueCount; diff --git a/dist/m5stack_core1/evDash.ino.bin b/dist/m5stack_core1/evDash.ino.bin index c1926f0..c1bf155 100644 Binary files a/dist/m5stack_core1/evDash.ino.bin and b/dist/m5stack_core1/evDash.ino.bin differ diff --git a/evDash.ino b/evDash.ino index 1fc6749..d903fe5 100644 --- a/evDash.ino +++ b/evDash.ino @@ -39,7 +39,6 @@ //////////////////////////////////////////////////////////// #include -#include #include "BoardInterface.h" #ifdef BOARD_TTGO_T4 @@ -49,6 +48,7 @@ #include "BoardM5stackCore.h" #endif // BOARD_M5STACK_CORE +#include #include #include "config.h" #include "LiveData.h" @@ -66,9 +66,6 @@ SIM800L* sim800l; #endif //SIM800L_ENABLED -// PLEASE CHANGE THIS SETTING for your BLE4 -uint32_t PIN = 1234; - // Temporary variables char ch; String line; @@ -218,6 +215,8 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { } }; +uint32_t PIN = 1234; + /** BLE Security */ @@ -637,11 +636,11 @@ void loop() { } } - // Can send next command from queue to OBD - if (liveData->canSendNextAtCommand) { - liveData->canSendNextAtCommand = false; - doNextAtCommand(); - } + // Can send next command from queue to OBD + if (liveData->canSendNextAtCommand) { + liveData->canSendNextAtCommand = false; + doNextAtCommand(); + } #ifdef SIM800L_ENABLED if (liveData->params.lastDataSent + SIM800L_TIMER < liveData->params.currentTime && liveData->params.sim800l_enabled) {