test fork

Dependencies:   SPI_TFTx2 SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary_9341 by Tick Tock

Files at this revision

API Documentation at this revision

Comitter:
TickTock
Date:
Sun Jul 21 23:44:10 2013 +0000
Branch:
Metric
Parent:
127:27c739fd6d71
Child:
129:8991d0de01ab
Commit message:
Kills thumbdrives on contact!

Changed in this revision

common.h Show annotated file Show diff for this revision Revisions of this file
displayModes.cpp Show annotated file Show diff for this revision Revisions of this file
displayModes.h Show annotated file Show diff for this revision Revisions of this file
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
utility.h Show annotated file Show diff for this revision Revisions of this file
--- a/common.h	Sun Jul 21 11:27:43 2013 +0000
+++ b/common.h	Sun Jul 21 23:44:10 2013 +0000
@@ -35,4 +35,4 @@
 #define BatDataBaseG7 0x3A
 #define BatDataBufMax 0x196 // 7 x 3A bytes
 
-#define VP230Sleep 1 // Set to 0 if using VP231 (sleep disables RX)
\ No newline at end of file
+#define VP230Sleep 0 // Set to 0 if using VP231 (sleep disables RX)
\ No newline at end of file
--- a/displayModes.cpp	Sun Jul 21 11:27:43 2013 +0000
+++ b/displayModes.cpp	Sun Jul 21 23:44:10 2013 +0000
@@ -572,7 +572,7 @@
         showButton(3,1," GoTo"," Config",4,4);               
         // bottom (not Nav) row        
         showButton(0,2," GoTo","Playback",4,4);               
-        showButton(1,2," GoTo","Set Time",4,4);             
+        //showButton(1,2," GoTo","Set Time",4,4);             
         showButton(2,2," GoTo"," Log",4,4);     
         showButton(3,2," GoTo"," Trip",4,4);     
     
@@ -844,7 +844,7 @@
     //-------- top row --------
     showButton(0,0,"Calibrate"," Touch",4,4); // gg - 4x4
     showButton(1,0," Reset","",4,4);
-    showButton(2,0," Save"," Config",4,4);
+    showButton(2,0,"  Save"," Config",4,4);
            
     // a button to step to the next skin
     unsigned int nextSkin = skin + 1 ;
@@ -854,7 +854,7 @@
     else if( nextSkin == ggSkin ) sprintf(sTemp1,"Skin GG");
     else sprintf(sTemp1,"Skin %d",nextSkin);
 
-    showButton(3,0," Use",sTemp1,4,4);
+    showButton(3,0,"  Use",sTemp1,4,4);
     
     //------- second row -----
     if (logEn&&usbEn) {
@@ -881,9 +881,9 @@
     
     // add Enable/Disable Debug - debugMode
     if (debugMode) {
-        sprintf(sTemp1,"Disable");
+        sprintf(sTemp1," Disable");
     } else {
-        sprintf(sTemp1,"Enable");
+        sprintf(sTemp1," Enable");
     }
     showButton(3,1,sTemp1," Debug",4,4);    
     
@@ -892,6 +892,13 @@
     else
        showButton(0,2,"Metric","",4,4);
     
+    showButton(1,2,"  Set"," Time",4,4);
+    if (showHealth) {
+        sprintf(sTemp1," Hide");
+    } else {
+        sprintf(sTemp1," Show");
+    }
+    showButton(2,2,sTemp1," Health",4,4);
     showButton(3,2,"Update","Firmware",4,4);
     
 }
@@ -959,9 +966,6 @@
                 case 5:
                     sprintf(sTemp1,"Second");
                     break;
-                case 6:
-                    sprintf(sTemp1,"Select");
-                    break;
                 default:
                     break;
             }
--- a/displayModes.h	Sun Jul 21 11:27:43 2013 +0000
+++ b/displayModes.h	Sun Jul 21 23:44:10 2013 +0000
@@ -57,6 +57,7 @@
 extern bool shunt[96];
 extern float unloadedV_x2,Resr,curRmax,curRmin,redRmax,redRmin,incRmax,incRmin;
 extern signed short Imax, Imin;
+extern bool showHealth;
 
 extern "C" {
     void printLast (bool force, bool showButtons);
--- a/main.cpp	Sun Jul 21 11:27:43 2013 +0000
+++ b/main.cpp	Sun Jul 21 23:44:10 2013 +0000
@@ -20,7 +20,7 @@
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
 
-char revStr[7] = "127"; // gg - revision string, max 6 characters
+char revStr[7] = "128b"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
@@ -53,7 +53,7 @@
 
 bool debugMode = false;
 bool usbEn = false;
-bool logEn = true;
+bool logEn = false;
 bool logOpen = false; 
 bool yesBattLog = true; // gg - Batt Log
 unsigned char tNavRow = 3; // gg - 4x4 touch
@@ -83,7 +83,7 @@
 unsigned char dMode[2] = {mainScreen,brakeScreen}; //display mode
 unsigned char sMode = 0; // setup mode
 unsigned char lastDMode[2] = {0,0}; //last screen mode
-unsigned char dtMode = 6;
+unsigned char dtMode = 0;
 char displayLog[20][40];
 unsigned char displayLoc = 0;
 unsigned int fwCount=1;
@@ -138,6 +138,9 @@
 bool metric = false;
 bool shunt[96]={0};
 bool charging=false;
+bool showHealth=false;
+unsigned char saveDmode=99;
+bool moving=false;
 
 int main() {
     //can1SleepMode.mode(OpenDrain);
@@ -223,7 +226,7 @@
     secsNoTouch=2;
     while (true) {
         if (!logOpen) { // Open new file if one is not already open
-            if(logEn&&usbEn){ //logging enables and USB device detected
+            if(logEn&&usbEn){ //logging enabled and USB device detected
                 strftime(fileName, 32, "%m%d%H%M.alc", &t); //mmddhhmm.alc
                 efr = f_open(&efile,fileName,FA_WRITE|FA_OPEN_ALWAYS);
                 seconds = time(NULL);
@@ -491,7 +494,7 @@
                                     dMode[whichTouched] = cpScreen ; // GoTo CP Data Screen                                
                                     sMode=0;
                                 } else if (dMode[whichTouched]==dateScreen){
-                                    dtMode=(dtMode<6)?dtMode+1:0;
+                                    dtMode=(dtMode<5)?dtMode+1:0;
                                     lastDMode[whichTouched]=99;
                                 } else {
                                     lastDMode[whichTouched]=99;//repaint to clear highlight
@@ -593,7 +596,7 @@
                                 break;
                                 
                              case 12: // left-middle col, bottom row (not nav)
-                                if (dMode[whichTouched] == indexScreen) { // gg - index
+                                if (dMode[whichTouched] == configScreen) { // gg - index
                                     dMode[whichTouched] = dateScreen ; // GoTo Set Date/Time Screen  
                                 } else {
                                     lastDMode[whichTouched]=99;//repaint to clear highlight
@@ -603,6 +606,8 @@
                              case 22: // right-middle col, bottom row (not nav)
                                 if (dMode[whichTouched] == indexScreen) { // gg - index
                                     dMode[whichTouched] = logScreen ;    
+                                } else if (dMode[whichTouched]==configScreen) {
+                                    showHealth = !showHealth;
                                 } else {
                                     lastDMode[whichTouched]=99;//repaint to clear highlight
                                 } 
@@ -674,7 +679,8 @@
             headlights = (lastMsg[indexLastMsg[0x358]].data[1]&0x80)?true:false;  // headlight/turn signal indicator
             accV=floor(mon12V*scale12V*10+0.5)/10; //Round to nearest 10th
             accOn=(accV>5)?true:false;
-            charging=(mph[0]<0.1)&&(kW[0]<-1); // not moving and generating energy so much be charging
+            moving=(mph[0]>0.1);
+            charging=!moving&&(kW[0]<-1); // not moving and generating energy so must be charging
             if(laccOn&&!accOn){ // Car turned off
                 if (repeatPoll) { // Log on shutdown if autopoll enabled
                     tripLog(); // Write trip log on powerdown
@@ -692,6 +698,10 @@
                 miles_trip[0]=0;
                 kWh_trip[0]=0;
                 wait5secs=5;
+                if(showHealth){
+                    saveDmode=dMode[0];
+                    dMode[0]=healthScreen;
+                }
             }
             laccOn=accOn;
             if(!accOn&&!logEn&&userIdle&&!playbackEn){ // Car off and logging disabled and no user activity
@@ -709,6 +719,10 @@
                     msgReq.attach(&sendReq,0.015);
                 }
             }
+            if(moving&&(saveDmode<99)&&(wait5secs==0)){
+                dMode[0]=saveDmode;
+                saveDmode=99;
+            }
 
             //compute historic efficiency
             if(numSsamples>0){ // Avoid div0
--- 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
--- a/utility.h	Sun Jul 21 11:27:43 2013 +0000
+++ b/utility.h	Sun Jul 21 23:44:10 2013 +0000
@@ -66,6 +66,7 @@
 extern bool debugMode;
 extern bool shunt[96];
 extern float accV;
+extern bool showHealth;
 
 extern "C" {
     void mbed_reset();