Dual CANbus monitor and instrumentation cluster supporting ILI9341 display controller
Dependencies: SPI_TFTx2_ILI9341 TOUCH_TFTx2_ILI9341 TFT_fonts mbed
Fork of CANary by
Diff: utility.cpp
- Revision:
- 152:a4d66901785d
- Parent:
- 151:3047ebb3c9a8
- Child:
- 153:e94cfe3c339c
--- 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