Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341

Dependencies:   SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary by Tick Tock

Revision:
35:5acbd8a64a89
Parent:
34:4751a8259b18
Child:
36:dbd39c315258
--- a/main.cpp	Wed Mar 20 13:57:00 2013 +0000
+++ b/main.cpp	Thu Mar 21 12:05:22 2013 +0000
@@ -1,7 +1,6 @@
 // main.cpp
 
 //To Do:
-// * Auto-poll cellpair data (user selectable)
 // * Log file playback (to enable testing of new passive display modes without having to drive around)
 // * USB device detect
 // * Ability to update binary from the thumb-drive (requires file timestamp)
@@ -9,7 +8,6 @@
 // * Audible friction brake feedback
 // * User-configurable watchpoint
 // * Immediately turn off when car is turned off and logging
-// * 12V monitor
 // * Better graphical DTE display with historic efficiency information considered and displayed
 // * Add 50% charge option
 // * Tire Pressure Sensor display
@@ -30,10 +28,9 @@
 LocalFileSystem local("local");
 
 // to write to USB Flash Drives, or equivalent (SD card in Reader/Writer)
-MSCFileSystem fs("fs"); // to write to a USB Flash Drive
+MSCFileSystem fs("usb"); // to write to a USB Flash Drive
 
 time_t seconds ;
-Beep spkr(p21);
 
 Ticker ticker;
 Timer timer;
@@ -43,15 +40,15 @@
 DigitalOut led3(LED3);
 DigitalOut led4(LED4);
 
-PwmOut dled(p23);
-
 InterruptIn touchpad(p17);
 CAN can1(p9, p10);      // CAN1 (EV) uses pins 9 and 10 (rx, tx) and pin 8 (rs)
 DigitalOut can1SleepMode(p8);     // Use pin 8 to control the sleep mode of can2
 CAN can2(p30, p29);     // CAN2 (CAR) uses pins 30 and 29 (rx, tx) and pin 28 (rs)
 DigitalOut can2SleepMode(p28);     // Use pin 28 to control the sleep mode of can1
-
+AnalogIn mon12V(p15);
 TOUCH_TFTx2 tt(p16, p17, p19, p20, p11, p12, p13, p6, p7, p5, "TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs0, cs1, reset
+PwmOut dled(p23);
+Beep spkr(p21);
 
 bool logEn = false,logOpen = false;
 FILE *cfile;
@@ -82,6 +79,12 @@
 bool repeatPoll = false;
 bool headlights = false;
 bool tick = false;
+float ledHi = 0.8; // Bright LED value (until config file read)
+float ledLo = 0.1; // Dim LED value (until config file read)
+unsigned short pollInt = 300; // polling interval=5 minutes (until config file read)
+bool accOn = false; // Accessories on
+float scale12V = 16.2; // R1:R2 ratio
+float accV = 0;
 
 int main() {
     int readPointer=0;
@@ -131,7 +134,7 @@
 
     // Look for new binary on thumbdrive
     // 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");
+    /*cfile = fopen("/usb/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);
@@ -158,7 +161,7 @@
             }
         fclose(cfile);
         fclose(file);
-        remove("/fs/CANary.bin"); // delete original
+        remove("/usb/CANary.bin"); // delete original
         mbed_reset(); //restart
         }
     }*/
@@ -176,7 +179,7 @@
             if(logEn){ //logging enable
                 seconds = time(NULL);
                 t = *localtime(&seconds) ;
-                strftime(fileName, 32, "/fs/%m%d%H%M.alc", &t); //mmddhhmm.alc
+                strftime(fileName, 32, "/usb/%m%d%H%M.alc", &t); //mmddhhmm.alc
                 //sprintf(sTemp,"Using file %s\n",fileName);
                 //logMsg(sTemp);
                 file = fopen(fileName, "ab");
@@ -332,7 +335,7 @@
                                 if (dMode[i]==config1Screen) {
                                     repeatPoll = !repeatPoll&&logEn;
                                     if (repeatPoll) {
-                                        ticker.attach(&tickerISR,300);
+                                        ticker.attach(&tickerISR,pollInt);
                                     } else {
                                         ticker.detach();
                                     }
@@ -355,7 +358,6 @@
                             case 12:
                             case 42:
                                 secsNoTouch = userTimeout; // immediately exit config mode
-                                if (dMode[i]==config1Screen) mbed_reset();
                                 break;
                             case 22:
                             case 52:
@@ -394,10 +396,14 @@
         }
         
         if(tick){ // Executes once a second
-            if(!headlights){
-                dled = 0.75;
+            accV=mon12V*scale12V;
+            accOn=(accV>5)?true:false;
+            if(!accOn&&!logEn&&userIdle){
+                dled = 0; // turn off display if car off and logging disabled and no user activity
+            }else if(!headlights){
+                dled = ledHi;
             }else{
-                dled = 0.1;
+                dled = ledLo;
             }
             tick=false;
         }