Dual CANbus monitor and instrumentation cluster supporting ILI9341 display controller

Dependencies:   SPI_TFTx2_ILI9341 TOUCH_TFTx2_ILI9341 TFT_fonts mbed

Fork of CANary by Tick Tock

Files at this revision

API Documentation at this revision

Comitter:
TickTock
Date:
Wed Aug 07 13:36:13 2013 +0000
Parent:
146:88f7bda79d8e
Child:
148:6e3b9135fad2
Commit message:
Changed CONFIG.TXT copy on thumbdrive to CONFIG.BAK to avoid unwanted restore. Also copy to thumbdrive happens when saveConfig is selected instead of on fw update.;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
utility.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Aug 07 12:35:04 2013 +0000
+++ b/main.cpp	Wed Aug 07 13:36:13 2013 +0000
@@ -12,7 +12,8 @@
 // * Add temperature to efficiency lookup table
 // * Add debug screen
 
-// rev146
+// rev147
+// Changed CONFIG.TXT copy on thumbdrive to CONFIG.BAK to avoid unwanted restore
 
 #include "mbed.h"
 #include "CAN.h"
@@ -23,7 +24,7 @@
 #include "utility.h"
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
-char revStr[7] = "146"; // gg - revision string, max 6 characters
+char revStr[7] = "147"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -471,7 +472,6 @@
                                     dMode[whichTouched] = effScreen ; // GoTo EFF Screen
                                     sMode=0;
                                 } else if (dMode[whichTouched]==configScreen) {
-                                    printMsg("Saving config file.\n"); // saving config
                                     dMode[whichTouched]=mainScreen;
                                     saveConfig();
                                     spkr.beep(2000,0.25);
--- 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)
     {