Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341

Dependencies:   SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary by Tick Tock

Revision:
33:a277743ebdeb
Parent:
32:c9d9b6cb5de1
Child:
34:4751a8259b18
--- a/main.cpp	Tue Mar 19 01:23:26 2013 +0000
+++ b/main.cpp	Tue Mar 19 04:43:43 2013 +0000
@@ -1,22 +1,19 @@
 // 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)
-* Cellpair histogram
-* Audible friction brake feedback
-* User-configurable watchpoint
-* LCD Autodim
-* 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
-* CSV dump of key parameters on car on/off
-*/
+// * 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)
+// * Cellpair histogram
+// * 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
+// * CSV dump of key parameters on car on/off
 
 #include "mbed.h"
 #include "CAN.h"
@@ -73,8 +70,7 @@
 volatile bool userIdle;
 bool touched=false; //flag to read touchscreen
 char counter = 0;
-//unsigned char dMode[2] = {dteScreen,brakeScreen}; //display mode
-unsigned char dMode[2] = {cpScreen,logScreen}; //display mode
+unsigned char dMode[2] = {dteScreen,brakeScreen}; //display mode
 unsigned char sMode = 0; // setup mode
 unsigned char lastDMode[2] = {0,0}; //last screen mode
 unsigned char dtMode = 6;
@@ -82,9 +78,9 @@
 unsigned char displayLoc = 0;
 unsigned char indexOffset = 1;
 bool showCP = false;
-bool tick16 = false;
-unsigned char CPcount = 99;
-unsigned char Tcount = 99;
+bool pollCP = false;
+bool repeatPoll = false;
+bool daylight = false;
 
 int main() {
     int readPointer=0;
@@ -116,8 +112,7 @@
     struct tm t; // pointer to a static tm structure
     NVIC_SetPriority(TIMER3_IRQn, 1); //set ticker priority
     NVIC_SetPriority(CAN_IRQn, 2); //higher than can (so RTC sync works)
-    //ticker.attach(&tickerISR, 300); //Auto-request CP data every 5 minutes
-    ticker.attach(&msgSend, 0.016); //send commands at 16ms rate
+
 
     seconds = time(NULL);
     t = *localtime(&seconds) ;
@@ -305,10 +300,7 @@
                                     for(j=0;j<100;j++) msgChanged[j]=0; // clear changed data
                                     lastDMode[i]=99;//force refresh
                                 } else if (dMode[i]==cpScreen) {
-                                    if (Tcount>3){
-                                        CPcount=0; //reset CP message counter
-                                        Tcount=0; //reset Temp message counter
-                                    }
+                                    pollCP=true;
                                 } else if (dMode[i]==config1Screen) {
                                     mbed_reset();
                                 }
@@ -328,6 +320,7 @@
                             case 31:
                                 if (dMode[i]==config1Screen) {
                                     logEn = !logEn;
+                                    if (!logEn) repeatPoll=false;
                                 } else if (dMode[i]==config2Screen){
                                     dtMode=(dtMode<6)?dtMode+1:0;
                                     lastDMode[i]=99;
@@ -335,7 +328,14 @@
                                 break;
                             case 11:
                             case 41:
-                                if (dMode[i]==config2Screen){
+                                if (dMode[i]==config1Screen) {
+                                    repeatPoll = !repeatPoll&&logEn;
+                                    if (repeatPoll) {
+                                        ticker.attach(&tickerISR,300);
+                                    } else {
+                                        ticker.detach();
+                                    }
+                                } else if (dMode[i]==config2Screen){
                                     upDate(dtMode,true);
                                     lastDMode[i]=99;
                                 }
@@ -380,9 +380,21 @@
             }
         }
 
-        if (Tcount>4){
-            display=display<1?display+1:0; // update display (unless sending Consult3 requests
-            updateDisplay(display);
+        display=display<1?display+1:0; // toggle display
+        updateDisplay(display);
+        if(pollCP){ // We do this inside main loop instead of ticker so CAN RX will not be blocked
+            sendCPreq(); // send cellpair data request.
+            wait_ms(16);
+            sendTreq(); //send temperature request
+            wait_ms(16);
+            pollCP=false;
+            showCP=true;
         }
+        if(daylight){
+            dled = 0.75;
+        }else{
+            dled = 0.1;
+        }
+
     } //while (true)
 }
\ No newline at end of file