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
- Branch:
- Metric
- Revision:
- 111:d1559bb25c43
- Parent:
- 110:ffddff3ad2f2
- Child:
- 112:b41b35401eb6
--- a/utility.cpp Sun Jun 30 19:52:38 2013 +0000 +++ b/utility.cpp Sun Jun 30 23:04:56 2013 +0000 @@ -276,8 +276,8 @@ k=j; } //interpolate from lookup table - unsigned short temp_adc[6] = { 1000, 589, 487, 401, 365, 000}; - float temp_C[6] = {-27.0, 13.0, 23.0, 32.0, 36.0, 76.0}; + unsigned short temp_adc[7] = { 1000, 589, 487, 401, 365, 309, 000}; + float temp_C[7] = {-27.0, 13.0, 23.0, 32.0, 36.0, 43.0, 76.0}; char ii=0; while(k<=temp_adc[++ii]) { } // Find section in table maxTemp=(float)(k-temp_adc[ii]); @@ -488,7 +488,7 @@ fclose(cfile); } - void readConfig(){ +void readConfig(){ FILE *cfile; int ff; char sTemp[40]; @@ -709,7 +709,7 @@ FIL bfile; FRESULT bfr; - bfr = f_open(&bfile,"batvolt.txt",FA_WRITE|FA_OPEN_ALWAYS); + bfr = f_open(&bfile,"triplog.txt",FA_WRITE|FA_OPEN_ALWAYS); if(bfr==FR_OK) { f_lseek(&bfile,0xffffffff); // go to end of file to append strftime(sTemp, 40, "%a %m/%d/%Y %X", &t); @@ -731,10 +731,12 @@ //the CANary into a computer for updates. void updateFirmware() { - /*char sTemp[40]; - FILE *srcFile; - srcFile = fopen("/usb/firmware.bin", "rb"); - if(srcFile ==NULL) + FIL sfile; // external usb file + FRESULT sfr; // external file access flags + unsigned int bytesRW; + char sTemp[40]; + sfr = f_open(&sfile,"firmware.bin",FA_READ|FA_OPEN_EXISTING); + if(sfr != FR_OK) { sprintf(sTemp,"Couldn't find firmware.bin\n"); printf(sTemp); @@ -793,29 +795,29 @@ } char buffer[bufSize]; - while (!feof(srcFile)) + while (!f_eof(&sfile)) { - int n = fread(buffer, 1, bufSize, srcFile); - fwrite(buffer, 1, n, destFile); + sfr=f_read(&sfile,&buffer,bufSize,&bytesRW); + fwrite(buffer, 1, bytesRW, destFile); } fflush(destFile); fclose(destFile); - fclose(srcFile); + f_close(&sfile); tt.cls(); printf("Succesful\n\n"); printf("Rebooting in 3 seconds\n"); wait(3); //Now run new firmware - mbed_reset();*/ + mbed_reset(); } bool detectUSB(void){ - bool usbEn=true; // for now assume presence - /*FILE *tfile = fopen("/usb/presence.det", "w"); - usbEn=(tfile==NULL)?false:true; + FIL tfile; // external usb file + bool usbEn = (f_open(&tfile,"usb.det",FA_WRITE|FA_OPEN_ALWAYS)==FR_OK); if(usbEn){ - fclose(tfile); - }*/ + f_close(&tfile); + f_unlink("usb.det"); + } return(usbEn); }