diff --git a/AVCLan_mini/AVCLanDrv.cpp b/AVCLan_mini/AVCLanDrv.cpp index 14cf8fe..5adebe7 100644 --- a/AVCLan_mini/AVCLanDrv.cpp +++ b/AVCLan_mini/AVCLanDrv.cpp @@ -1,10 +1,6 @@ #include "AVCLanDrv.h" #include "AVCLanHonda.h" -//#include "BuffSerial.h" -#include "SD_Log.h" -// AVCLan driver & timer2 init, -// char buff[80] = {0}; //-------------------------------------------------------------------------------- void AVCLanDrv::begin () //-------------------------------------------------------------------------------- diff --git a/AVCLan_mini/AVCLanHonda.cpp b/AVCLan_mini/AVCLanHonda.cpp index 1033530..e789ea2 100644 --- a/AVCLan_mini/AVCLanHonda.cpp +++ b/AVCLan_mini/AVCLanHonda.cpp @@ -1,10 +1,8 @@ //-------------------------------------------------------------------------------- #include "limits.h" -#include #include "AVCLanDrv.h" #include "AVCLanHonda.h" -//#include "BuffSerial.h" -#include "SD_Log.h" + #include //-------------------------------------------------------------------------------- @@ -41,18 +39,6 @@ const AvcInCmdTable mtSearchHead[] PROGMEM = { }; const byte mtSearchHeadSize = sizeof(mtSearchHead) / sizeof(AvcInCmdTable); -//char logBuff[40] = {0}; - -//-------------------------------------------------------------------------------- -void printAvcAction( AvcActionID id ) -//-------------------------------------------------------------------------------- -{ - //if (!bSDLog.bRedyToLog) return; - - // char mBuff[20] = { 0 }; - // sprintf( mBuff, "[%u]{%d}", millis(), id ); - // bSDLog.logs( mBuff ); -} //-------------------------------------------------------------------------------- void AVCLanHonda::begin() @@ -61,7 +47,7 @@ void AVCLanHonda::begin() avclan.deviceAddress = 0x0131; bShowHondaDisp = false; - isHondaDisLast = false; + bHondaDisLast = false; bShowRearCam = false; bFirstStart_20 = true; @@ -80,28 +66,16 @@ void AVCLanHonda::setWaitTime( const unsigned long mTime ) //-------------------------------------------------------------------------------- { waitTime = mTime; - if ( mTime > 0L ) { - bWait = true; - } else { - bWait = false; - } + bWait = (bool) waitTime; } -////-------------------------------------------------------------------------------- -//void AVCLanHonda::setLockTime( const unsigned long mTime ) -////-------------------------------------------------------------------------------- -//{ -// lockTime = mTime; -// bLock = true; -// setWaitTime(0L); -//} - -// Use the last received message to determine the corresponding action ID, store it in avclan object +// Use the last received message to determine the corresponding action ID, +// store it in avclan object //-------------------------------------------------------------------------------- void AVCLanHonda::getActionID() //-------------------------------------------------------------------------------- { - avclan.actionID = avclan.getActionID(mtSearchHead, mtSearchHeadSize); + avclan.actionID = avclan.getActionID( mtSearchHead, mtSearchHeadSize ); }; // process action @@ -111,7 +85,7 @@ void AVCLanHonda::processAction( AvcActionID ActionID ) { if ( bFirstStart_20 && (20000 > millis()) && (ACT_CAM_ON == ActionID) ) { bShowRearCam = true; - isHondaDisLast = false; + bHondaDisLast = false; //after reverse action should be GVN screen bShowHondaDisp = true; return; } @@ -131,27 +105,22 @@ void AVCLanHonda::processAction( AvcActionID ActionID ) break; case ACT_CAM_ON: bShowRearCam = true; - isHondaDisLast = isShowHondaDisp(); + bHondaDisLast = isShowHondaDisp(); bShowHondaDisp = true; setWaitTime(0L); - // setLockTime( (unsigned long)(millis() + LOCK_TIME) ); break; case ACT_DISP_OFF: if ( !bShowRearCam ) { bShowHondaDisp = false; - isHondaDisLast = false; + bHondaDisLast = false; setWaitTime(0L); - // printAvcAction(ActionID); - // setLockTime( (unsigned long)(millis() + LOCK_TIME) ); } break; case ACT_CAM_OFF: bShowRearCam = false; - bShowHondaDisp = isHondaDisLast; + bShowHondaDisp = bHondaDisLast; setWaitTime(0L); - // printAvcAction(ActionID); - // setLockTime( (unsigned long)(millis() + LOCK_TIME) ); break; } }; @@ -176,27 +145,19 @@ bool AVCLanHonda::getCommute() void AVCLanHonda::tryToShowHondaDisp() //-------------------------------------------------------------------------------- { - // if ( isLockTime() ) return; + bHondaDisLast = bShowHondaDisp; bShowHondaDisp = true; } //-------------------------------------------------------------------------------- -void AVCLanHonda::falseHondaDis() +void AVCLanHonda::setHondaDis( bool val ) //-------------------------------------------------------------------------------- { - bShowHondaDisp = false; - isHondaDisLast = false; + bShowHondaDisp = val; + bHondaDisLast = val; + setWaitTime(0L); } -////-------------------------------------------------------------------------------- -//bool AVCLanHonda::isLockTime() -////-------------------------------------------------------------------------------- -//{ -// if ( bLock ) { -// bLock = ( getLockTime() > millis() ); -// } -// return bLock; -//} AVCLanHonda avclanHonda; diff --git a/AVCLan_mini/AVCLanHonda.h b/AVCLan_mini/AVCLanHonda.h index 3ede59b..4f07f87 100644 --- a/AVCLan_mini/AVCLanHonda.h +++ b/AVCLan_mini/AVCLanHonda.h @@ -20,7 +20,6 @@ #define DISABLE_TIMER1_INT (cbi(TIMSK1, TOIE1)); #endif -// а�реса eeprom #define E_MASTER1 0 #define E_MASTER2 1 #define E_READONLY 2 @@ -28,7 +27,7 @@ #define AVCLANDEVICE_NAME " Honda Kb1" -#define AVCLANDEVICE_VERSION "0.0.8" +#define AVCLANDEVICE_VERSION "0.1.0" #define BUTT_WAIT 1000 #define LOCK_TIME 700 @@ -66,11 +65,6 @@ class AVCLanHonda void setWaitTime( const unsigned long mTime ); inline unsigned long getWaitTime() const; - // void setLockTime( const unsigned long mTime ); - // inline unsigned long getLockTime() const; - // bool isLockTime(); - - inline bool isWait() const; inline bool isShowRearCam() const; @@ -78,7 +72,7 @@ class AVCLanHonda void checkWait(); void checkLock(); - void falseHondaDis(); + void setHondaDis( bool val ); bool bFirstStart_20; @@ -92,13 +86,9 @@ class AVCLanHonda bool bShowRearCam; bool bShowHondaDisp; bool bTimeSwitch; - bool isHondaDisLast; + bool bHondaDisLast; }; -//unsigned long AVCLanHonda::getLockTime() const { -// return lockTime; -//} - unsigned long AVCLanHonda::getWaitTime() const { return waitTime; } diff --git a/AVCLan_mini/AVCLan_mini.ino b/AVCLan_mini/AVCLan_mini.ino index 1275534..e3896d7 100644 --- a/AVCLan_mini/AVCLan_mini.ino +++ b/AVCLan_mini/AVCLan_mini.ino @@ -1,12 +1,6 @@ -//-------------------------------------------------------------------------------- -#include -#include -#include #include "AVCLanDrv.h" #include "AVCLanHonda.h" -//#include "BuffSerial.h" -#include "SD_Log.h" #include "config.h" //-------------------------------------------------------------------------------- @@ -24,28 +18,19 @@ void setup() sbi(LED_DDR, COMMUT_OUT); cbi(LED_PORT, COMMUT_OUT); - // bSDLog.begin(); - - // Serial.begin(250000); - // if (Serial) { - // Serial.println("Start HONDA"); - // } - avclan.begin(); avclanHonda.begin(); - - EERPOM_read_config(); - // bSDLog.testLog(); } //-------------------------------------------------------------------------------- void loop() //-------------------------------------------------------------------------------- { - if ( avclanHonda.bFirstStart_20 && (11500 > millis()) ) { HONDA_DIS_ON; // initalize return; + } else if ( avclanHonda.bFirstStart_20 && !avclanHonda.isShowRearCam() && (11500 < millis()) ) { + avclanHonda.setHondaDis( false ); //Show GVN screen } if ( INPUT_IS_SET ) { @@ -58,7 +43,6 @@ void loop() } } - if ( avclanHonda.isWait() ) { avclanHonda.checkWait(); if ( !avclanHonda.isWait() ) avclanHonda.tryToShowHondaDisp(); @@ -69,73 +53,6 @@ void loop() HONDA_DIS_OFF; } } - - - //------------------------------- - - /* - - if ( !avclanHonda.isLockTime() ) - { - if ( avclanHonda.isWait() ) { - avclanHonda.checkWait(); - if (avclanHonda.isWait() == false) - avclanHonda.tryToShowHondaDisp(); - } - - if ( INPUT_IS_SET ) { - byte res = avclan.readMessage(); - if ( !res ) { - //LOG - // avclan.printMessage(true); - avclanHonda.getActionID(); - if ( avclan.actionID != ACT_NONE ) { - avclanHonda.processAction( (AvcActionID)avclan.actionID ); - } - } - } - } - else - { - //ON a start target - if ( 11500 > millis() ) { - HONDA_DIS_ON; // initalize - return; - } else if ( 18000 > millis() ) { - avclanHonda.falseHondaDis(); - if ( !avclanHonda.isShowRearCam() ) { - HONDA_DIS_OFF; - return; - } else { - HONDA_DIS_ON; - return; - } - } else if ( avclanHonda.getCommute() ) { - HONDA_DIS_ON; - } else { - HONDA_DIS_OFF; - } - } - - */ -} - -//-------------------------------------------------------------------------------- -void EERPOM_read_config() -//-------------------------------------------------------------------------------- -{ - if (EEPROM.read(E_INIT) != 'T') - { - EEPROM.write(E_MASTER1, 0x01); - EEPROM.write(E_MASTER2, 0x31); - EEPROM.write(E_READONLY, 0); - EEPROM.write(E_INIT, 'T'); - } - else - { - avclan.headAddress = (EEPROM.read(E_MASTER1) << 8) + EEPROM.read(E_MASTER2); - avclan.readonly = EEPROM.read(E_READONLY); - } } diff --git a/AVCLan_mini/SD_Log.cpp b/AVCLan_mini/SD_Log.cpp deleted file mode 100644 index 2874063..0000000 --- a/AVCLan_mini/SD_Log.cpp +++ /dev/null @@ -1,174 +0,0 @@ -#include "SD_Log.h" -#include "config.h" -//-------------------------------------------------------------------------------- - -const int chipSelect = 10; -static File dataFile; -char fileName[10] = {0}; - -//-------------------------------------------------------------------------------- -void SDLog::begin() -//-------------------------------------------------------------------------------- -{ - // canLog = false; - bRedyToLog = false; - // // see if the card is present and can be initialized: - // if (SD.begin(chipSelect)) { - // bRedyToLog = true; - // Serial.println(" READY TO LOG "); - // } -} - -//-------------------------------------------------------------------------------- -void SDLog::testLog() -//-------------------------------------------------------------------------------- -{ - char filetext[40] = {0}; - - File dataTestFile = SD.open( "test.txt", FILE_WRITE ); - if ( bRedyToLog && dataTestFile ) { - sprintf(filetext, "[%u] IEBUS HONDA V." IEBUS_VERSION, millis() ); - dataTestFile.println(filetext); - openFile(); - } else { - bRedyToLog = false; - } - dataTestFile.close(); -} - -//-------------------------------------------------------------------------------- -bool SDLog::openFile() -//-------------------------------------------------------------------------------- -{ - for ( int a = 1; a < 999; a++) - { - sprintf( fileName, "%d.txt", a ); - if ( !SD.exists( fileName ) ) - break; - } - - dataFile = SD.open( fileName, FILE_WRITE ); - if ( dataFile ) { - logs( String("IEBUS HONDA V.") + String(IEBUS_VERSION) ); - dataFile.close(); - return true; - } - return false; -} - -//-------------------------------------------------------------------------------- -void SDLog::logs(String dataString) -//-------------------------------------------------------------------------------- -{ - //SerialPrintLn(dataString.c_str()); - dataFile = SD.open( fileName, FILE_WRITE ); - if ( bRedyToLog && dataFile) { - dataFile.println(dataString); - dataFile.close(); - } -} - -//-------------------------------------------------------------------------------- -void SDLog::SerialPrintLn( const char *val ) -//-------------------------------------------------------------------------------- -{ - if ( Serial ) { - Serial.println( val ); - } -} - -//-------------------------------------------------------------------------------- -void SDLog::SerialPrint( const char *val ) -//-------------------------------------------------------------------------------- -{ - if ( Serial ) { - Serial.print( val ); - } -} -//-------------------------------------------------------------------------------- -void SDLog::sendByte(uint8_t data) -//-------------------------------------------------------------------------------- -{ - if (bRedyToLog) { - dataFile.close(); - dataFile = SD.open( fileName, FILE_WRITE ); - dataFile.print( (char)data ); - dataFile.close(); - - // SerialPrint(data); - /* - BASE (optional): the base sin which to print numbers: - BIN for binary (base 2), - DEC for decimal (base 10), - OCT for octal (base 8), - HEX for hexadecimal (base 16). - */ - } -} - -//-------------------------------------------------------------------------------- -void SDLog::printHex4(uint8_t data) -//-------------------------------------------------------------------------------- -{ - uint8_t c = data & 0x0f; - c += c < 10 ? '0' : 'A' - 10 ; - sendByte(c); -} - -//-------------------------------------------------------------------------------- -void SDLog::printHex8(uint8_t data) -//-------------------------------------------------------------------------------- -{ - printHex4(data >> 4); - printHex4(data); -} - -//-------------------------------------------------------------------------------- -void SDLog::print(const char *pBuf) -//-------------------------------------------------------------------------------- -{ - while (*pBuf) { - sendByte(*pBuf++); - } -} - -//-------------------------------------------------------------------------------- -void SDLog::print(const char pBuf) -//-------------------------------------------------------------------------------- -{ - sendByte(pBuf); -} - -//-------------------------------------------------------------------------------- -void SDLog::println(const char *pBuf) -//-------------------------------------------------------------------------------- -{ - print(pBuf); - println(); -} - -//-------------------------------------------------------------------------------- -void SDLog::println(const char pBuf) -//-------------------------------------------------------------------------------- -{ - print(pBuf); - println(); -} - -//-------------------------------------------------------------------------------- -void SDLog::println(void) -//-------------------------------------------------------------------------------- -{ - print("\n\r"); -} - -//void SDLog::_update() -//{ -// if ( bRedyToLog ) { -// dataFile.close(); -// } -//} - -SDLog bSDLog; - - diff --git a/AVCLan_mini/SD_Log.h b/AVCLan_mini/SD_Log.h deleted file mode 100644 index 20ca89a..0000000 --- a/AVCLan_mini/SD_Log.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef SD_LOG_h -#define SD_LOG_h - -#include "Arduino.h" -#include -#include - -class SDLog { - public: - void begin(); - bool bRedyToLog; - void logs(String dataString); - void testLog(); - - void SerialPrintLn( const char *val ); - void SerialPrint( const char *val ); - - void sendByte(uint8_t data); - void printHex4(uint8_t data); - void printHex8(uint8_t data); - - void print(const char *pBuf); - void print(const char pBuf); - - // print string from flash - void print_p(const char *pBuf); - void println(const char *pBuf); - void println(const char pBuf); - void println(void); - - void _update(); - private: - bool openFile(); - // bool canLog; -}; - -extern SDLog bSDLog; - -#endif //#SD_LOG_h - - -