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:
- 147:e0f1c84c62a6
- Parent:
- 144:b0c9d30dd346
- Child:
- 148:6e3b9135fad2
diff -r 88f7bda79d8e -r e0f1c84c62a6 utility.cpp --- a/utility.cpp Wed Aug 07 12:35:04 2013 +0000 +++ b/utility.cpp Wed Aug 07 13:36:13 2013 +0000 @@ -507,7 +507,14 @@ } void saveConfig(){ + printMsg("Saving local config file.\n"); // no config file FILE *cfile; + FIL efile; // external usb file + FRESULT sfr; // external file access flags + unsigned int bytesRW; + const int bufSize = 2048; + char buffer[bufSize]; + cfile = fopen("/local/config.txt", "w"); fprintf(cfile,"format 7\r\n"); fprintf(cfile,"x0_off %d\r\n",tt.x0_off); @@ -519,13 +526,13 @@ fprintf(cfile,"x1_pp %d\r\n",tt.x1_pp); fprintf(cfile,"y1_pp %d\r\n",tt.y1_pp); fprintf(cfile,"x_mid %d\r\n",tt.x_mid); - //if (dMode[0]==configScreen) - // fprintf(cfile,"dMode0 %d\r\n",mainScreen); - //else + if (dMode[0]==configScreen) + fprintf(cfile,"dMode0 %d\r\n",mainScreen); + else fprintf(cfile,"dMode0 %d\r\n",dMode[0]); - //if (dMode[1]==configScreen) - // fprintf(cfile,"dMode1 %d\r\n",mainScreen); - //else + if (dMode[1]==configScreen) + fprintf(cfile,"dMode1 %d\r\n",mainScreen); + else fprintf(cfile,"dMode1 %d\r\n",dMode[1]); fprintf(cfile,"ledHi %4.3f\r\n",ledHi); fprintf(cfile,"ledLo %4.3f\r\n",ledLo); @@ -541,6 +548,22 @@ fprintf(cfile,"brkMonRate %d\r\n", brkMonRate ); fprintf(cfile,"brkMonThr %d\r\n", brkMonThr ); fclose(cfile); + + // Make copy of CONFIG.TXT + cfile = fopen("/local/CONFIG.TXT", "r"); + sfr = f_open(&efile,"CONFIG.BAK",FA_WRITE|FA_CREATE_NEW); + if((cfile != NULL)&&(sfr == FR_OK)){ + printMsg("Copy config file to USB\n"); + while (!feof(cfile)) + { + bytesRW=fread(buffer, 1, bufSize, cfile); + sfr=f_write(&efile,&buffer,bytesRW,&bytesRW); + } + fflush(cfile); + fclose(cfile); + f_close(&efile); + } + wait(2); } void readConfig(){ @@ -820,27 +843,19 @@ { printf("Copy config file from USB\n"); lfile = fopen("/local/CONFIG.TXT", "w"); - while (!f_eof(&efile)) - { - sfr=f_read(&efile,&buffer,bufSize,&bytesRW); - fwrite(buffer, 1, bytesRW, lfile); + if(lfile != NULL) { + while (!f_eof(&efile)) + { + sfr=f_read(&efile,&buffer,bufSize,&bytesRW); + fwrite(buffer, 1, bytesRW, lfile); + } + fflush(lfile); + fclose(lfile); } - fflush(lfile); - fclose(lfile); f_close(&efile); - }else{ // No config file found so put one there - sfr = f_open(&efile,"CONFIG.TXT",FA_WRITE|FA_CREATE_NEW); - printf("Copy config file to USB\n"); - lfile = fopen("/local/CONFIG.TXT", "r"); - while (!feof(lfile)) - { - bytesRW=fread(buffer, 1, bufSize, lfile); - sfr=f_write(&efile,&buffer,bytesRW,&bytesRW); - } - fflush(lfile); - fclose(lfile); - f_close(&efile); + wait(2); } + sfr = f_open(&efile,"firmware.bin",FA_READ|FA_OPEN_EXISTING); if(sfr != FR_OK) {