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 Jun 30 23:04:56 2013 +0000
Branch:
Metric
Parent:
110:ffddff3ad2f2
Child:
112:b41b35401eb6
Commit message:
Added USB insertion detect. Logging will start once usb drive is inserted.

Changed in this revision

SPI_TFTx2.lib Show annotated file Show diff for this revision Revisions of this file
USBHostLite/usbhost_lpc17xx.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
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/SPI_TFTx2.lib	Sun Jun 30 19:52:38 2013 +0000
+++ b/SPI_TFTx2.lib	Sun Jun 30 23:04:56 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/TickTock/code/SPI_TFTx2/#ff509eb02e37
+http://mbed.org/users/TickTock/code/SPI_TFTx2/#4ad7de7d2220
--- a/USBHostLite/usbhost_lpc17xx.h	Sun Jun 30 19:52:38 2013 +0000
+++ b/USBHostLite/usbhost_lpc17xx.h	Sun Jun 30 23:04:56 2013 +0000
@@ -33,7 +33,7 @@
 **************************************************************************************************************
 */
 
-#define  PRINT_ENABLE         1
+#define  PRINT_ENABLE         0
 
 #if PRINT_ENABLE
 #define  PRINT_Log(...)       printf(__VA_ARGS__)
--- a/displayModes.cpp	Sun Jun 30 19:52:38 2013 +0000
+++ b/displayModes.cpp	Sun Jun 30 23:04:56 2013 +0000
@@ -77,14 +77,14 @@
     if(force){
         tt.cls();
     }
-    if(force||lmiles!=miles_trip[0]){ //only update if changed
+    if(force||(int)lmiles!=(int)miles_trip[0]){ //only update if changed
         tt.foreground(Navy);
         tt.set_font((unsigned char*) Arial28x28);
         tt.locate(6,210);
-        printf("kWh : %s : Eff\n",distanceUnit());
+        printf("kWh :  %s : Eff\n",distanceUnit());
         for(int i=0; i<3; i++){
             tt.locate(6,20+i*60);
-            printf("%3.2f : %3.1f : %2.1f \n",kWh_trip[i],convertDistance(miles_trip[i]),convertDistance(miles_trip[i])/kWh_trip[i]);
+            printf("%3.2f : %3.1f : %2.1f\n",kWh_trip[i],convertDistance(miles_trip[i]),convertDistance(miles_trip[i])/kWh_trip[i]);
         }
         tt.set_font((unsigned char*) Arial12x12);
         tt.background(DarkCyan);
--- a/main.cpp	Sun Jun 30 19:52:38 2013 +0000
+++ b/main.cpp	Sun Jun 30 23:04:56 2013 +0000
@@ -2,7 +2,6 @@
 //
 //To Do:
 // * USB device detect
-// * Enable file timestamps
 // * Audible friction brake feedback
 // * User-configurable watchpoint
 // * Add 50% charge option
@@ -11,13 +10,9 @@
 // ** Force regen display to zero when in neutral
 // * Add coasting regen to regen/braking display
 // * Change semilog efficiency graph to linear with 10 minute values
-// * Make display updates interruptable for log writes
 // * Add additional 79b bank readouts
 // * Add ability to transfer settings config file to/from USB
-// * Add once-on-powerup/powerdown log
 // * Move log dump to ISR (but CAN RX at higher priority)
-// * Fix bug preventing setting logEn to true by default
-
 
 #include "mbed.h"
 #include "CAN.h"
@@ -29,14 +24,13 @@
 #include "displayModes.h"
 #include "TOUCH_TFTx2.h"
 
-char revStr[7] = "110"; // gg - revision string, max 6 characters
+char revStr[7] = "111"; // gg - revision string, max 6 characters
 
 FATFS USBdrive;
 LocalFileSystem local("local");
 bool waitasec = true;
 // to write to USB Flash Drives, or equivalent (SD card in Reader/Writer)
-FRESULT mfr=f_mount(0,&USBdrive);
-
+FRESULT mfr = f_mount(0,&USBdrive);
 time_t seconds ;
 
 Ticker autoPoll;
@@ -149,7 +143,6 @@
     unsigned char i,j,display=0,lwt=0;
     point lastTouch;
     float average;
-    usbEn=detectUSB();
     tt.set_orientation(1);
     tt.background(Black);
     tt.set_display(2);       // select both displays
@@ -182,6 +175,8 @@
     // revision
     sprintf(sTemp,"CANary firmware rev%s\n", revStr); // gg - for Logging the revision
     printMsg(sTemp); // revision
+    //sprintf(sTemp,"free clusters = %d\n", freeClusters);
+    //printMsg(sTemp); // revision
 
     secsNoMsg = 0;
 
@@ -292,10 +287,9 @@
             if (repeatPoll) { // stop autopolling if enabled
                 autoPoll.detach();
             }
-            //keep file open when asleep - new lseek not fast
-            //if (logOpen){
-            //    f_close(&efile);
-            //} // if (logOpen)*/
+            if (logOpen){ //close file to dump buffer
+                f_close(&efile);
+            } // if (logOpen)
             seconds = time(NULL);
             t = *localtime(&seconds) ;
             strftime(sTemp, 40, "Sleeping: %a %m/%d/%Y %X\n", &t);
@@ -331,9 +325,8 @@
                 } // if (logOpen)
                 if (secsNoTouch>100) secsNoTouch = 100; // also mostly reset user Idle counter
             } else if (logOpen){ // insert timestamp on each wake if logging enabled (disabled for now)
-                //file kept open
-                //efr = f_open(&efile,fileName,FA_WRITE|FA_OPEN_ALWAYS);
-                //f_lseek(&efile,0xffffffff); // goto end of file (append existing)
+                efr = f_open(&efile,fileName,FA_WRITE|FA_OPEN_ALWAYS);
+                f_lseek(&efile,0xffffffff); // goto end of file (append existing)
                 logEvent("WakingUp"); // gg - use messeges
                 logTS(); // Date-Time at wakeup
             }
@@ -483,12 +476,6 @@
                                     lastDMode[whichTouched]=99;//repaint to clear highlight
                                     // and re-paint the other screen too, to see new skin there
                                     lastDMode[whichTouched ^ 1]=99; // repaint other screen (^ = XOR)
-                                    
-                                    //sprintf(sTemp,"Changed Skin to %d.\n");
-                                    //printMsg(sTemp); /// changed skin - for debug
-                                    //saveConfig();
-                                    //spkr.beep(2000,0.25);
-                                    
                                 } else if (dMode[whichTouched] == indexScreen) { // gg - index
                                     dMode[whichTouched] = dteScreen ; // GoTo DTE Screen
                                     sMode=0;
@@ -685,7 +672,6 @@
         }
 
         if(tick){ // Executes once a second
-            waitasec=false; // work around to avoid hang when USB tries to init immediately
             tick=false;
             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
@@ -780,6 +766,7 @@
             if(!usbEn){
                 usbEn=detectUSB(); // Keep looking if none found
             }
+            waitasec=false; // work around to avoid hang when USB tries to init immediately
         }
 
         display=display<1?display+1:0; // toggle display
--- a/utility.cpp	Sun Jun 30 19:52:38 2013 +0000
+++ b/utility.cpp	Sun Jun 30 23:04:56 2013 +0000
@@ -276,8 +276,8 @@
                         k=j;
                         }
                     //interpolate from lookup table
-                    unsigned short temp_adc[6] = { 1000,  589,  487,  401,  365,  000};
-                    float            temp_C[6] = {-27.0, 13.0, 23.0, 32.0, 36.0, 76.0};
+                    unsigned short temp_adc[7] = { 1000,  589,  487,  401,  365,  309, 000};
+                    float            temp_C[7] = {-27.0, 13.0, 23.0, 32.0, 36.0, 43.0, 76.0};
                     char ii=0;
                     while(k<=temp_adc[++ii]) { } // Find section in table
                     maxTemp=(float)(k-temp_adc[ii]);
@@ -488,7 +488,7 @@
     fclose(cfile);
 }
 
- void readConfig(){
+void readConfig(){
     FILE *cfile;
     int ff;
     char sTemp[40];
@@ -709,7 +709,7 @@
     
     FIL bfile;
     FRESULT bfr;
-    bfr = f_open(&bfile,"batvolt.txt",FA_WRITE|FA_OPEN_ALWAYS);
+    bfr = f_open(&bfile,"triplog.txt",FA_WRITE|FA_OPEN_ALWAYS);
     if(bfr==FR_OK) {
         f_lseek(&bfile,0xffffffff); // go to end of file to append
         strftime(sTemp, 40, "%a %m/%d/%Y %X", &t);
@@ -731,10 +731,12 @@
 //the CANary into a computer for updates.
 void updateFirmware()
 {
-    /*char sTemp[40];
-    FILE *srcFile;    
-    srcFile = fopen("/usb/firmware.bin", "rb");    
-    if(srcFile ==NULL)
+    FIL sfile; // external usb file
+    FRESULT sfr; // external file access flags
+    unsigned int bytesRW;
+    char sTemp[40];
+    sfr = f_open(&sfile,"firmware.bin",FA_READ|FA_OPEN_EXISTING);    
+    if(sfr != FR_OK)
     {        
         sprintf(sTemp,"Couldn't find firmware.bin\n");
         printf(sTemp);
@@ -793,29 +795,29 @@
     }
     char buffer[bufSize];
 
-    while (!feof(srcFile))
+    while (!f_eof(&sfile))
     {
-        int n = fread(buffer, 1, bufSize, srcFile);
-        fwrite(buffer, 1, n, destFile);
+        sfr=f_read(&sfile,&buffer,bufSize,&bytesRW);
+        fwrite(buffer, 1, bytesRW, destFile);
     }
 
     fflush(destFile);
     fclose(destFile);
-    fclose(srcFile);
+    f_close(&sfile);
     tt.cls();
     printf("Succesful\n\n");
     printf("Rebooting in 3 seconds\n");
     wait(3);
     //Now run new firmware
-    mbed_reset();*/
+    mbed_reset();
 }
 
 bool detectUSB(void){
-    bool usbEn=true; // for now assume presence
-    /*FILE *tfile = fopen("/usb/presence.det", "w");
-    usbEn=(tfile==NULL)?false:true;
+    FIL tfile; // external usb file
+    bool usbEn = (f_open(&tfile,"usb.det",FA_WRITE|FA_OPEN_ALWAYS)==FR_OK);
     if(usbEn){
-        fclose(tfile);
-    }*/
+        f_close(&tfile);
+        f_unlink("usb.det");
+    }
     return(usbEn);
 }