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

Branch:
Metric
Revision:
128:25314f339565
Parent:
127:27c739fd6d71
Child:
130:1a9d2a6d99ce
--- a/utility.cpp	Sun Jul 21 11:27:43 2013 +0000
+++ b/utility.cpp	Sun Jul 21 23:44:10 2013 +0000
@@ -490,7 +490,7 @@
 void saveConfig(){
     FILE *cfile;
     cfile = fopen("/local/config.txt", "w");    
-    fprintf(cfile,"format 5\r\n");
+    fprintf(cfile,"format 6\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,12 +517,14 @@
     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
@@ -571,8 +573,13 @@
             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<4){//If not latest format, save as latest format
+        if(ff<6){//If not latest format, save as latest format
             saveConfig();
             printMsg("Config file format updated.\n"); // config forat updates
         }
@@ -768,6 +775,26 @@
     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)
     {        
@@ -812,21 +839,17 @@
     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
-    const int bufSize = 2048;
-    FILE *destFile;    
+    //The newest bin file is the one that is used by the mbed  
     sprintf(sTemp,"/local/fw%d.bin",fwCount);
     printf("Writing %s\n",sTemp);
     wait(2);
     destFile = fopen(sTemp, "wb");
     if(destFile == NULL)
     {
-        sprintf(sTemp,"Couldn't Open Destination\n");
-        printf(sTemp);
+        printf("Couldn't Open Destination\n");
         wait(3);
         return;
     }
-    char buffer[bufSize];
 
     while (!f_eof(&sfile))
     {
@@ -846,11 +869,39 @@
 }
 
 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(usbEn);*/
+    return(true
+    );
 }
+
+//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