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

Revision:
169:84d790ac18a2
Parent:
161:71ac85d11f03
Child:
170:7ee98e3611bc
--- a/utility.cpp	Wed Dec 04 12:45:39 2013 +0000
+++ b/utility.cpp	Tue Dec 17 15:25:41 2013 +0000
@@ -960,46 +960,6 @@
     tt.foreground(Yellow);
     tt.locate(0,10);
     tt.cls();
-    // Check for config file on USB drive
-    sfr = f_open(&efile,"CONFIG.TXT",FA_READ|FA_OPEN_EXISTING);    
-    if(sfr == FR_OK)
-    {        
-        printf("Copy config file from USB\n");
-        lfile = fopen("/local/CONFIG.TXT", "w");
-        if(lfile != NULL) {
-            while (!f_eof(&efile))
-            {
-                sfr=f_read(&efile,&buffer,bufSize,&bytesRW);
-                fwrite(buffer, 1, bytesRW, lfile);
-            }
-            fflush(lfile);
-            fclose(lfile);
-        }
-        f_close(&efile);
-        int fwc_tmp = fwCount;
-        readConfig();
-        fwCount = fwc_tmp; // Do no overwrite fwcount when loading new config
-        //wait(2);
-    }
-
-    // Check for history file on USB drive
-    sfr = f_open(&efile,"ehist.cny",FA_READ|FA_OPEN_EXISTING);    
-    if(sfr == FR_OK)
-    {        
-        printf("Copy ehist file from USB\n");
-        lfile = fopen("/local/ehist.cny", "w");
-        if(lfile != NULL) {
-            while (!f_eof(&efile))
-            {
-                sfr=f_read(&efile,&buffer,bufSize,&bytesRW);
-                fwrite(buffer, 1, bytesRW, lfile);
-            }
-            fflush(lfile);
-            fclose(lfile);
-        }
-        f_close(&efile);
-        //wait(2);
-    }
 
     sfr = f_open(&efile,"firmware.bin",FA_READ|FA_OPEN_EXISTING);    
     if(sfr != FR_OK)
@@ -1070,6 +1030,59 @@
     mbed_reset();
 }
 
+void updateConfig()
+{
+    FIL efile; // external usb file
+    FRESULT sfr; // external file access flags
+    unsigned int bytesRW;
+    char sTemp[40];
+    const int bufSize = 2048;
+    char buffer[bufSize];
+    FILE *lfile;    
+
+    tt.set_font((unsigned char*) Arial12x12);
+    tt.background(Blue);
+    tt.foreground(Yellow);
+    tt.locate(0,10);
+    tt.cls();
+    // Check for config file on USB drive
+    sfr = f_open(&efile,"CONFIG.TXT",FA_READ|FA_OPEN_EXISTING);    
+    if(sfr == FR_OK){        
+        printf("Copy config file from USB\n");
+        lfile = fopen("/local/CONFIG.TXT", "w");
+        if(lfile != NULL) {
+            while (!f_eof(&efile)){
+                sfr=f_read(&efile,&buffer,bufSize,&bytesRW);
+                fwrite(buffer, 1, bytesRW, lfile);
+            }
+            fflush(lfile);
+            fclose(lfile);
+        }
+        f_close(&efile);
+        int fwc_tmp = fwCount;
+        readConfig();
+        fwCount = fwc_tmp; // Do no overwrite fwcount when loading new config
+    }
+
+    // Check for history file on USB drive
+    sfr = f_open(&efile,"ehist.cny",FA_READ|FA_OPEN_EXISTING);    
+    if(sfr == FR_OK){        
+        printf("Copy ehist file from USB\n");
+        lfile = fopen("/local/ehist.cny", "w");
+        if(lfile != NULL) {
+            while (!f_eof(&efile)){
+                sfr=f_read(&efile,&buffer,bufSize,&bytesRW);
+                fwrite(buffer, 1, bytesRW, lfile);
+            }
+            fflush(lfile);
+            fclose(lfile);
+        }
+        f_close(&efile);
+    }
+    printf("Succesful.\n\n");
+    wait(5);
+}
+
 bool detectUSB(void){
     FIL tfile; // external usb file
     bool usbEn = (f_open(&tfile,"usb.det",FA_WRITE|FA_OPEN_ALWAYS)==FR_OK);