Dual CANbus monitor and instrumentation cluster

Dependencies:   SPI_TFTx2 TFT_fonts TOUCH_TFTx2 beep mbed

Fork of CANary by Tick Tock

Revision:
17:e32324a2678d
Parent:
16:2a6ca248e1cb
Child:
18:999401f359a5
--- a/main.cpp	Sun Mar 03 18:25:50 2013 +0000
+++ b/main.cpp	Mon Mar 04 04:41:24 2013 +0000
@@ -8,7 +8,7 @@
 // * Date entry config screen (keypad)
 // * auto-poll option for cellpair data
 // * cellpair histogram
-// * 
+// * config screen (with ts cal, data, time, autopoll, enable/disable logging
 
 #include "mbed.h"
 #include "CAN.h"
@@ -60,7 +60,7 @@
 volatile bool canIdle = false, userIdle = false;
 bool touched=0; //flag to read touchscreen
 char counter = 0;
-unsigned char dMode[2] = {7,2}; //display mode
+unsigned char dMode[2] = {1,2}; //display mode
 unsigned char sMode = 0; // setup mode
 unsigned char lastDMode[2] = {0,0}; //last screen mode
 char displayLog[20][40];
@@ -137,10 +137,36 @@
         //    printf("%s\n", sTemp); // DAY MM/DD/YYYY HH:MM:SS
     }
 
+    // Look for new binary 
+    // Can't make this work right now since USB doesn't attach the right timestamp (so new binary isn't loaded)
+    cfile = fopen("/fs/CANary.bin", "rb");
+    if (cfile!=NULL){ //found a new binary on the thumbdrive so copy it over
+        sprintf(sTemp,"New binary found.\n");
+        logMsg(sTemp);
+        file = fopen("/local/CANary.bin", "wb");
+        if (file==NULL){ //failed to open destination
+            sprintf(sTemp,"Unable to open destination file.\n");
+            logMsg(sTemp);
+        } else {
+            while ( int size = fread( writeBuffer, sizeof(char), maxBufLen*13, cfile )){
+                fwrite( writeBuffer, sizeof(char), size, file );
+            }
+        fclose(cfile);
+        fclose(file);
+        remove("/fs/CANary.bin"); // delete original
+        mbed_reset(); //restart
+        }
+    } else {
+        sprintf(sTemp,"No binary found.\n");
+        logMsg(sTemp);
+    }
+
     // Look for config file
     cfile = fopen("/local/config.txt", "r");
     if (cfile==NULL){ // if doesn't exist --> create
-        sprintf(sTemp,"No config file found.\nCalibrating touch screen.\n");
+        sprintf(sTemp,"No config file found.\n");
+        logMsg(sTemp);
+        sprintf(sTemp,"Calibrating touch screen.\n");
         logMsg(sTemp);
         tt.calibrate();
         cfile = fopen("/local/config.txt", "w");