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:
- 130:1a9d2a6d99ce
- Parent:
- 128:25314f339565
- Child:
- 131:0d926c080a65
--- a/utility.cpp Sun Jul 21 23:59:00 2013 +0000 +++ b/utility.cpp Mon Jul 22 00:02:51 2013 +0000 @@ -490,7 +490,7 @@ void saveConfig(){ FILE *cfile; cfile = fopen("/local/config.txt", "w"); - fprintf(cfile,"format 6\r\n"); + fprintf(cfile,"format 5\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); @@ -517,14 +517,12 @@ fprintf(cfile,"DebugMode %d\r\n",(debugMode?1:0)); fprintf(cfile,"metric %d\r\n",(metric?1:0)); fprintf(cfile, "firmware %d\r\n", fwCount ); - fprintf(cfile,"showHealth %d\r\n",(showHealth?1:0)); fclose(cfile); } void readConfig(){ FILE *cfile; int ff; - cfile = fopen("/local/config.txt", "r"); if (cfile==NULL){ // if doesn't exist --> create printMsg("No config file found.\n"); // no config file @@ -573,13 +571,8 @@ fscanf(cfile, "firmware %d\r\n", &iMetric ); fwCount = iMetric; } - if(ff>5){ - int ishowHealth; - fscanf(cfile, "showHealth %d\r\n", &ishowHealth ); - showHealth = (bool)ishowHealth; - } fclose(cfile); - if(ff<6){//If not latest format, save as latest format + if(ff<4){//If not latest format, save as latest format saveConfig(); printMsg("Config file format updated.\n"); // config forat updates } @@ -752,15 +745,14 @@ f_printf(&bfile,"%s,",sTemp); f_printf(&bfile,"%d,%d,%d,%d,",(battData[(BatDataBaseG4*7)+ 3]<<8)+battData[(BatDataBaseG4*7)+ 4],battData[(BatDataBaseG4*7)+ 5],(battData[(BatDataBaseG4*7)+ 6]<<8)+battData[(BatDataBaseG4*7)+ 7],battData[(BatDataBaseG4*7)+ 8]); f_printf(&bfile,"%d,%d,%d,%d", (battData[(BatDataBaseG4*7)+ 9]<<8)+battData[(BatDataBaseG4*7)+10],battData[(BatDataBaseG4*7)+11],(battData[(BatDataBaseG4*7)+12]<<8)+battData[(BatDataBaseG4*7)+13],battData[(BatDataBaseG4*7)+14]); - /*for(i=0; i<96; i++) { + for(i=0; i<96; i++) { bd=(battData[BatDataBaseG2*7+i*2+3]<<8)+battData[BatDataBaseG2*7+i*2+4]; f_printf(&bfile,",%d",bd); - }*/ + } // temporariliy dump everything - for(i=0; i<BatDataBufMax; i++) { - sprintf(sTemp,",%02x",battData[i]); - f_printf(&bfile,"%s",sTemp); - } + /*for(i=0; i<BatDataBufMax; i++) { + f_printf(&bfile,",%02x",battData[i]); + }*/ f_printf(&bfile,"\r\n"); f_close(&bfile); @@ -775,26 +767,6 @@ FRESULT sfr; // external file access flags unsigned int bytesRW; char sTemp[40]; - const int bufSize = 2048; - char buffer[bufSize]; - FILE *destFile; - - // Check for config file on USB drive - sfr = f_open(&sfile,"CONFIG.TXT",FA_READ|FA_OPEN_EXISTING); - if(sfr == FR_OK) - { - printf("Copy config file from USB\n"); - destFile = fopen("/local/CONFIG.TXT", "w"); - while (!f_eof(&sfile)) - { - sfr=f_read(&sfile,&buffer,bufSize,&bytesRW); - fwrite(buffer, 1, bytesRW, destFile); - } - fflush(destFile); - fclose(destFile); - f_close(&sfile); - } - sfr = f_open(&sfile,"firmware.bin",FA_READ|FA_OPEN_EXISTING); if(sfr != FR_OK) { @@ -839,17 +811,21 @@ printf("copying new firmware\n"); tt.cls(); //Copy the new firmware from usb->local - //The newest bin file is the one that is used by the mbed + //The newest bin file is the one that is used by the mbed + const int bufSize = 2048; + FILE *destFile; sprintf(sTemp,"/local/fw%d.bin",fwCount); printf("Writing %s\n",sTemp); wait(2); destFile = fopen(sTemp, "wb"); if(destFile == NULL) { - printf("Couldn't Open Destination\n"); + sprintf(sTemp,"Couldn't Open Destination\n"); + printf(sTemp); wait(3); return; } + char buffer[bufSize]; while (!f_eof(&sfile)) { @@ -869,39 +845,11 @@ } bool detectUSB(void){ - /*FIL tfile; // external usb file + FIL tfile; // external usb file bool usbEn = (f_open(&tfile,"usb.det",FA_WRITE|FA_OPEN_ALWAYS)==FR_OK); if(usbEn){ f_close(&tfile); f_unlink("usb.det"); } - return(usbEn);*/ - return(true - ); + return(usbEn); } - -//Sample CONFIG.TXT -/* -format 5 -x0_off 5732 -y0_off 34009 -x0_pp 77 -y0_pp 106 -x1_off 33955 -y1_off 6310 -x1_pp 80 -y1_pp 104 -x_mid 31986 -dMode0 4 -dMode1 2 -ledHi 0.800 -ledLo 0.100 -pollInt 300 -scale12V 16.20 -skin 0 -dtePeriod 14 -DebugMode 0 -metric 0 -firmware 11 -showHealth 1 -*/ \ No newline at end of file