test fork
Dependencies: SPI_TFTx2 SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary_9341 by
Revision 152:a4d66901785d, committed 2013-10-06
- Comitter:
- TickTock
- Date:
- Sun Oct 06 14:49:09 2013 +0000
- Parent:
- 151:3047ebb3c9a8
- Child:
- 153:e94cfe3c339c
- Commit message:
- // Added clock sync with car clock option (MY2011,2012 only); // Fixed wrap bug in manual date update (january=00, not 01);
Changed in this revision
--- a/displayModes.cpp Mon Sep 30 15:31:01 2013 +0000 +++ b/displayModes.cpp Sun Oct 06 14:49:09 2013 +0000 @@ -296,6 +296,7 @@ void tripDisplay (bool force, bool showButtons){ static float lkWh=0; + float mpkwh_f; tt.background(White); if(force){ tt.cls(); @@ -306,8 +307,13 @@ tt.locate(6,210); printf("kWh : %s : Eff\n",distanceUnit()); for(int i=0; i<3; i++){ + if(kWh_trip[i]>0.01){ + mpkwh_f = convertDistance(miles_trip[i])/kWh_trip[i]; + } else { + mpkwh_f = 0; + } tt.locate(6,20+i*60); - printf("%3.2f : %3.1f : %2.1f \n",kWh_trip[i],convertDistance(miles_trip[i]),convertDistance(miles_trip[i])/kWh_trip[i]); + printf("%3.2f : %3.1f : %2.1f \n",kWh_trip[i],convertDistance(miles_trip[i]),mpkwh_f); } tt.foreground(Navy); tt.set_font((unsigned char*) Arial12x12); @@ -987,19 +993,49 @@ } void showDateTime(bool force, bool showButtons){ + //unsigned char year, month, day, hour, minute, second; + CANMessage msg; struct tm t; // pointer to a static tm structure time_t seconds ; tt.foreground(Yellow); tt.background(Black); - if (force) { + if (force||tock) { tt.cls(); - seconds = time(NULL); - t = *localtime(&seconds) ; - + + // Read time from car + /*msg = lastMsg[indexLastMsg[0x5fa]]; + month = msg.data[5]>>4; + day = msg.data[2]>>3; + msg = lastMsg[indexLastMsg[0x5fb]]; + year = msg.data[1]; + msg = lastMsg[indexLastMsg[0x5fc]]; + hour = msg.data[0]>>3; + minute = (msg.data[1]<<4&0x30)+(msg.data[2]>>4); + second = msg.data[1]>>2;*/ + tt.locate(10,10); tt.set_font((unsigned char*) Arial12x12); + if(accOn){ + seconds = time(NULL); + t = *localtime(&seconds); + msg = lastMsg[indexLastMsg[0x5fa]]; + t.tm_mon = (msg.data[5]>>4)-1; + t.tm_mday = msg.data[2]>>3; + msg = lastMsg[indexLastMsg[0x5fb]]; + //t.tm_year = msg.data[1]; + msg = lastMsg[indexLastMsg[0x5fc]]; + t.tm_hour = msg.data[0]>>3; + t.tm_min = (msg.data[1]<<4&0x30)+(msg.data[2]>>4); + t.tm_sec = msg.data[1]>>2; + strftime(sTemp1, 32, "%a %m/%d/%Y %X \n", &t); + //printf("Leaf: %02d:%02d:%02d %02d/%02d/%03d\n",hour,minute,second,month,day,year); + printf("Leaf: %s",sTemp1); + } + seconds = time(NULL); + t = *localtime(&seconds); strftime(sTemp1, 32, "%a %m/%d/%Y %X \n", &t); - printf("%s",sTemp1); + tt.locate(10,24); + printf("CANary: %s",sTemp1); if(showButtons){ switch(dtMode){ case 0: @@ -1024,8 +1060,16 @@ break; } showButton(0,1,sTemp1,"",4,4); - showButton(1,1," UP","",4,4); - showButton(2,1," DOWN","",4,4); + showButton(1,1," Up","",4,4); + showButton(2,1," Down","",4,4); + if(accOn){ + showButton(3,1," Sync","w/ car",4,4); + } + if(autoSync){ + showButton(3,2,"disable"," auto",4,4); + }else{ + showButton(3,2,"enable"," auto",4,4); + } } } } @@ -1234,13 +1278,9 @@ void testDisplay (bool force, bool showButtons){ static unsigned short maxPS=0; - unsigned char i, uData[8]; + unsigned char i, uData[8], year, month, day, hour, minute, second; CANMessage msg; - for (i=0; i<8; i++){ - msg = lastMsg[indexLastMsg[(uMsgId[i]>>4)]]; //Get ambient - uData[i] = msg.data[(uMsgId[i]&0x000f)]; - } tt.set_font((unsigned char*) Arial24x23); tt.foreground(Yellow); tt.background(Navy); @@ -1250,8 +1290,22 @@ if(pointerSep>maxPS){maxPS=pointerSep;} tt.locate(10,10); printf("%3d sep %3d max\n",pointerSep,maxPS); - tt.locate(10,40); - printf("%4.2fV %4.2fV \n",accV,accV2); + msg = lastMsg[indexLastMsg[0x5fa]]; + month = msg.data[5]>>4; + day = msg.data[2]>>3; + msg = lastMsg[indexLastMsg[0x5fb]]; + year = msg.data[1]; + msg = lastMsg[indexLastMsg[0x5fc]]; + hour = msg.data[0]>>3; + minute = (msg.data[1]<<4&0x30)+(msg.data[2]>>4); + second = msg.data[1]>>2; + tt.locate(0,40); + printf("%02d%02d%02d %02d%02d%03d\n",hour,minute,second,month,day,year); + //printf("%4.2fV %4.2fV \n",accV,accV2); + for (i=0; i<8; i++){ + msg = lastMsg[indexLastMsg[(uMsgId[i]>>4)]]; + uData[i] = msg.data[(uMsgId[i]&0x000f)]; + } for (i=0; i<4; i++){ tt.locate(10,90+i*30); printf("%4x:%2x %4x:%2x\n",uMsgId[i],uData[i],uMsgId[i+4],uData[i+4]);
--- a/displayModes.h Mon Sep 30 15:31:01 2013 +0000 +++ b/displayModes.h Sun Oct 06 14:49:09 2013 +0000 @@ -63,6 +63,8 @@ extern bool brakeMon; extern float curEff; extern unsigned short uMsgId[8]; +extern bool accOn; +extern bool autoSync; extern "C" { void printLast (bool force, bool showButtons);
--- a/main.cpp Mon Sep 30 15:31:01 2013 +0000 +++ b/main.cpp Sun Oct 06 14:49:09 2013 +0000 @@ -1,21 +1,21 @@ // main.cpp // //To Do: -// * User-configurable watchpoint // * Add 50% charge option // * Add coasting regen to regen/braking display -// * Change semilog efficiency graph to linear with 10 minute values +// * Add linear efficiency graph with 10 minute values // * Subtract accessory power from efficiency history (add back in when displaying) // * Add in-device config editor // * Store efficiency data at different temperatures // * Change pack volt color when CVLI fails -// * Add per-charge efficiency meter; add to triplop.txt // * Add tire pressure cal (40psi for me = FR 38, RR 38.2, FL 37.8, RL 38 - maybe 2psi error on my tire gauge?) // * Add heater activation warning message // * Add trip max/min efficiency reset +// * Add 2013 clock sync support -// rev151 -// added per_charge trip meter +// rev152 +// Added clock sync with car clock option (MY2011,2012 only) +// Fixed wrap bug in manual date update (january=00, not 01) #include "mbed.h" #include "CAN.h" @@ -26,7 +26,7 @@ #include "utility.h" #include "displayModes.h" #include "TOUCH_TFTx2.h" -char revStr[7] = "151"; // gg - revision string, max 6 characters +char revStr[7] = "152"; // gg - revision string, max 6 characters FATFS USBdrive; LocalFileSystem local("local"); @@ -64,6 +64,8 @@ bool yesBattLog = true; // gg - Batt Log unsigned char tNavRow = 3; // gg - 4x4 touch bool brakeMon = false; // disable until desired value read from config +bool autoSync = false; // auto clock sync on powerup +bool syncDone = true; FILE *hfile; // history file FIL efile; // external usb file @@ -155,6 +157,7 @@ bool moving=false; unsigned short chirpInt; unsigned short uMsgId[8] = {0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000}; // messages to display on debug screen msgId:byte +unsigned short modelYear = 2011; int main() { char sTemp[40]; @@ -599,12 +602,10 @@ if (dMode[whichTouched]==configScreen) { // gg - Batt Log Enable Button debugMode = !debugMode; } else if (dMode[whichTouched] == indexScreen) { // gg - index - dMode[whichTouched] = configScreen ; // GoTo Config Screen - /*} else if (dMode[whichTouched] == tripScreen) { - miles_trip[1]=0; - kWh_trip[1]=0; - sMode=0; - lastDMode[whichTouched]=99;//repaint to clear highlight*/ + dMode[whichTouched] = configScreen ; // GoTo Config Screen + } else if ((dMode[whichTouched]==dateScreen)&&accOn){ + syncDateTime(); + lastDMode[whichTouched]=99; } else { lastDMode[whichTouched]=99;//repaint to clear highlight } @@ -655,6 +656,9 @@ lastDMode[whichTouched]=99;//repaint to clear highlight } else if (dMode[whichTouched] == indexScreen) { dMode[whichTouched] = tripScreen ; + } else if (dMode[whichTouched]==dateScreen){ + autoSync=!autoSync; // toggle autoSync mode + lastDMode[whichTouched]=99; } else { lastDMode[whichTouched]=99;//repaint to clear highlight } @@ -759,6 +763,7 @@ } dMode[0]=healthScreen; } + syncDone=!autoSync; // clear syncDone flag if autoSync enabled } laccOn=accOn; if(!accOn&&userIdle&&!playbackEn){ // Car off and no user activity - turn off screen @@ -880,6 +885,12 @@ lastDMode[1]=99; } } + if(!syncDone){ + if((lastMsg[indexLastMsg[0x5fa]].data[2]>>3>0)&&(lastMsg[indexLastMsg[0x5fa]].data[2]>>3<32)&&(lastMsg[indexLastMsg[0x5fc]].data[1]>>2<60)){ // sanity check result first + syncDateTime(); + syncDone=true; + } + } tock=true; } // tick
--- a/utility.cpp Mon Sep 30 15:31:01 2013 +0000 +++ b/utility.cpp Sun Oct 06 14:49:09 2013 +0000 @@ -518,7 +518,7 @@ printMsg("Saving local config file.\n"); wait(2); cfile = fopen("/local/config.txt", "w"); - fprintf(cfile,"format 8\r\n"); + fprintf(cfile,"format 9\r\n"); fprintf(cfile,"x0_off %d\r\n",tt.x0_off); fprintf(cfile,"y0_off %d\r\n",tt.y0_off); fprintf(cfile,"x0_pp %d\r\n",tt.x0_pp); @@ -553,6 +553,8 @@ sprintf(sTemp,"usrMsgId %04x",uMsgId[i]); fprintf(cfile,"%s\r\n", sTemp ); } + fprintf(cfile,"modelYear %d\r\n",modelYear); + fprintf(cfile,"autoSync %d\r\n",(autoSync?1:0)); fclose(cfile); // Make copy of CONFIG.TXT @@ -593,7 +595,7 @@ void readConfig(){ FILE *cfile; - int ff,readhex; + int ff,readHex,readBool; char sTemp[16]; cfile = fopen("/local/config.txt", "r"); @@ -633,42 +635,42 @@ fscanf(cfile, "dtePeriod %d\r\n", &dtePeriod ); } if(ff>3){ - int iDebug; - fscanf(cfile, "DebugMode %d\r\n", &iDebug ); - debugMode = (bool)iDebug; + fscanf(cfile, "DebugMode %d\r\n", &readBool ); + debugMode = (bool)readBool; } if(ff>4) { - int iMetric; - fscanf(cfile, "metric %d\r\n", &iMetric ); - metric = (bool)iMetric; // This will get re-assigned based on dash selection - fscanf(cfile, "firmware %d\r\n", &iMetric ); - fwCount = iMetric; + fscanf(cfile, "metric %d\r\n", &readBool ); + metric = (bool)readBool; // This will get re-assigned based on dash selection + fscanf(cfile, "firmware %d\r\n", &fwCount ); } if(ff>5){ - int ishowHealth; - fscanf(cfile, "showHealth %d\r\n", &ishowHealth ); - showHealth = (bool)ishowHealth; + fscanf(cfile, "showHealth %d\r\n", &readBool ); + showHealth = (bool)readBool; } if(ff>6){ - int iBrakeMon; - fscanf(cfile, "brakeMon %d\r\n", &iBrakeMon ); - brakeMon = (bool)iBrakeMon; + fscanf(cfile, "brakeMon %d\r\n", &readBool ); + brakeMon = (bool)readBool; fscanf(cfile, "brkMonRate %d\r\n", &brkMonRate ); fscanf(cfile, "brkMonThr %d\r\n", &brkMonThr ); } if(ff>7){ for(char i=0;i<8;i++){ fscanf(cfile, "usrMsgId %s\r\n", &sTemp ); - sscanf(sTemp,"%x", &readhex); - uMsgId[i]=readhex; + sscanf(sTemp,"%x", &readHex); + uMsgId[i]=readHex; } } + if(ff>8){ + fscanf(cfile, "modelYear %d\r\n", &modelYear); + fscanf(cfile, "modelYear %d\r\n", &readBool); + autoSync = (bool)readBool; + } fclose(cfile); - if((ff>8)||(ff<1)||(ledHi<0.1)||(scale12V<10)||(tt.x_mid<16000)||(ledHi>1)||(ledLo>1)||(dMode[0]>maxScreens)||(dMode[1]>maxScreens)){ //Sanity check a few things + if((ff>9)||(ff<1)||(ledHi<0.1)||(scale12V<10)||(tt.x_mid<16000)||(ledHi>1)||(ledLo>1)||(dMode[0]>maxScreens)||(dMode[1]>maxScreens)){ //Sanity check a few things //Something wrong. Load defaults printf("Invalid config file. Loading defaults.\n"); wait(3); - ff=8; + ff=9; tt.x0_off=5732; tt.y0_off=34009; tt.x0_pp=77; @@ -678,8 +680,8 @@ tt.x1_pp=80; tt.y1_pp=104; tt.x_mid=31986; - dMode[0]=4; - dMode[1]=2; + dMode[0]=2; + dMode[1]=4; ledHi=0.800; ledLo=0.300; pollInt=300; @@ -701,8 +703,10 @@ uMsgId[5]=0x55b4; uMsgId[6]=0x0000; uMsgId[7]=0x0000; + modelYear=2011; + autoSync=false; } - if(ff<8){//If not latest format, save as latest format + if(ff<9){//If not latest format, save as latest format saveConfig(); printMsg("Config file format updated.\n"); // config forat updates } @@ -725,37 +729,37 @@ break; case 1: // month if (upDownBar) { - t.tm_mon = (t.tm_mon<12)?t.tm_mon+1:1; + t.tm_mon = (t.tm_mon<11)?t.tm_mon+1:0; } else { - t.tm_mon = (t.tm_mon>2)?t.tm_mon-1:12; + t.tm_mon = (t.tm_mon>0)?t.tm_mon-1:11; } break; case 2: // day if (upDownBar) { t.tm_mday = (t.tm_mday<31)?t.tm_mday+1:1; } else { - t.tm_mday = (t.tm_mday>2)?t.tm_mday-1:31; + t.tm_mday = (t.tm_mday>1)?t.tm_mday-1:31; } break; case 3: // hour if (upDownBar) { t.tm_hour = (t.tm_hour<23)?t.tm_hour+1:0; } else { - t.tm_hour = (t.tm_hour>1)?t.tm_hour-1:23; + t.tm_hour = (t.tm_hour>0)?t.tm_hour-1:23; } break; case 4: // minute if (upDownBar) { t.tm_min = (t.tm_min<59)?t.tm_min+1:0; } else { - t.tm_min = (t.tm_min>1)?t.tm_min-1:59; + t.tm_min = (t.tm_min>0)?t.tm_min-1:59; } break; case 5: // second if (upDownBar) { t.tm_sec = (t.tm_sec<59)?t.tm_sec+1:0; } else { - t.tm_sec = (t.tm_sec>1)?t.tm_sec-1:59; + t.tm_sec = (t.tm_sec>0)?t.tm_sec-1:59; } break; default: @@ -764,6 +768,24 @@ set_time(mktime(&t)); } +void syncDateTime(){ // doesn't work on MY2013 + struct tm t; // pointer to a static tm structure + time_t seconds ; + CANMessage msg; + seconds = time(NULL); + t = *localtime(&seconds); + msg = lastMsg[indexLastMsg[0x5fa]]; + t.tm_mon = (msg.data[5]>>4)-1; + t.tm_mday = msg.data[2]>>3; + msg = lastMsg[indexLastMsg[0x5fb]]; + //t.tm_year = msg.data[1]; // Have not figured out where the year is + msg = lastMsg[indexLastMsg[0x5fc]]; + t.tm_hour = msg.data[0]>>3; + t.tm_min = (msg.data[1]<<4&0x30)+(msg.data[2]>>4); + t.tm_sec = msg.data[1]>>2; + set_time(mktime(&t)); +} + void logPackVoltages() { // Turbo3 - routine to dump CP values to text file char sTemp[40]; struct tm t; // pointer to a static tm structure @@ -1010,8 +1032,8 @@ fclose(lfile); f_close(&efile); printf("Succesful.\n\n"); - printf("Rebooting in 3 seconds.\n"); - wait(3); + printf("Rebooting in 5 seconds.\n"); + wait(5); //Now run new firmware mbed_reset(); } @@ -1074,4 +1096,6 @@ usrMsgId 55b4 usrMsgId 0000 usrMsgId 0000 +modelYear 2011 +autoSync 1 */ \ No newline at end of file
--- a/utility.h Mon Sep 30 15:31:01 2013 +0000 +++ b/utility.h Sun Oct 06 14:49:09 2013 +0000 @@ -68,6 +68,7 @@ extern bool debugMode; extern bool shunt[96]; extern float accV; +extern bool accOn; extern float accV2; extern bool showHealth; extern float kWh_trip[0]; @@ -77,6 +78,8 @@ extern Ticker geiger; extern unsigned short chirpInt; extern unsigned short uMsgId[8]; +extern bool autoSync; +extern unsigned short modelYear; extern "C" { void mbed_reset(); @@ -100,6 +103,7 @@ void saveConfig(); void readConfig(); void upDate(unsigned char field, bool updownbar); + void syncDateTime(); void logPackVoltages(); // Turbo3 void tripLog(); // Turbo3 void updateFirmware(); // LM - Update firmware off USB