Attempts to merge SPI_TFT2 & SPI_TFT_ILI9341

Dependencies:   SPI_TFTx2 TFT_fonts TOUCH_TFTx2 mbed

Fork of CANary by Tick Tock

Files at this revision

API Documentation at this revision

Comitter:
TickTock
Date:
Tue Mar 19 04:43:43 2013 +0000
Parent:
32:c9d9b6cb5de1
Child:
34:4751a8259b18
Commit message:
Added auto dim based on daylight sensor

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	Tue Mar 19 01:23:26 2013 +0000
+++ b/common.h	Tue Mar 19 04:43:43 2013 +0000
@@ -11,6 +11,6 @@
 #define maxScreens 9
 #define btnGap 10
 
-#define maxBufLen 512
+#define maxBufLen 768
 #define canTimeout 5
 #define userTimeout 10
--- a/displayModes.cpp	Tue Mar 19 01:23:26 2013 +0000
+++ b/displayModes.cpp	Tue Mar 19 04:43:43 2013 +0000
@@ -361,6 +361,13 @@
     }
     sprintf(sTemp2," Logging");
     showButton(0,1,sTemp1,sTemp2,3,3);
+    if (repeatPoll) {
+        sprintf(sTemp1," Disable");
+    } else {
+        sprintf(sTemp1," Enable");
+    }
+    sprintf(sTemp2," Auto CP");
+    showButton(1,1,sTemp1,sTemp2,3,3);
 }
 
 void showDateTime(bool force){
--- a/displayModes.h	Tue Mar 19 01:23:26 2013 +0000
+++ b/displayModes.h	Tue Mar 19 04:43:43 2013 +0000
@@ -18,6 +18,7 @@
 extern unsigned char battData[256];
 extern bool showCP;
 extern bool logEn;
+extern bool repeatPoll;
 extern unsigned char dMode[2];
 extern unsigned char lastDMode[2];
 extern unsigned char sMode;
--- 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
--- a/utility.cpp	Tue Mar 19 01:23:26 2013 +0000
+++ b/utility.cpp	Tue Mar 19 04:43:43 2013 +0000
@@ -11,7 +11,7 @@
     LPC_RTC->ILR |= (1<<0); // clear interrupt to prepare for next
 }
 
-void RTC_Init (void) {
+extern "C" void RTC_Init (void) {
     LPC_RTC->ILR=0x00; // set up the RTC interrupts
     LPC_RTC->CIIR=0x01; // interrupts each second
     LPC_RTC->CCR = 0x01;  // Clock enable
@@ -73,7 +73,9 @@
         msgChanged[indexLastMsg[canRXmsg.id]]=changed;
     }
     lastMsg[indexLastMsg[canRXmsg.id]]=canRXmsg; //Store in table
-    if((mType==1)&&(canRXmsg.id==0x7bb)){ // is battery data?  Need to store all responses
+    if((mType==2)&&(canRXmsg.id==0x358)){ // is daylight sensor
+        daylight = (canRXmsg.data[1]&0x80)?false:true;
+    } else if((mType==1)&&(canRXmsg.id==0x7bb)){ // is battery data?  Need to store all responses
         if(canRXmsg.data[0]<0x20){
             if(canRXmsg.data[3]==2){//cellpair data
                 bdi=0;
@@ -121,7 +123,7 @@
     logCan(0,tsMsg);
 }
 
-/*void sendCPreq() {
+void sendCPreq() {
     char i;
     char data[8] = {0x02, 0x21, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff};
     can1.monitor(false); // set to active mode
@@ -153,63 +155,17 @@
     }
     can1SleepMode = 1; // disable TX
     can1.monitor(true); // set to snoop mode
-}*/
-
-void msgSend() {
-    //char sTemp[40];
-    char data[8] = {0x02, 0x21, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff};
-    if (CPcount<30) {
-        switch (CPcount) {
-            case 0:
-                can1.monitor(false); // set to active mode
-                can1SleepMode = 0; // enable TX
-                //data[8] = {0x02, 0x21, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff};
-                data[2] = 0x02;
-                //sprintf(sTemp,"Sending cp request\n");
-                //logMsg(sTemp);
-                break;
-            default:
-                data[0]=0x30; //change to request next line message
-                data[1]=0x01;
-                data[2]=0x00;
-                break;
-        }
-        can1.write(CANMessage(0x79b, data, 8));
-        CPcount+=1;
-    } else if (Tcount<4) {
-        switch (Tcount) {
-            case 0:
-                //data[8] = {0x02, 0x21, 0x04, 0xff, 0xff, 0xff, 0xff, 0xff};
-                data[2] = 0x04;
-                //sprintf(sTemp,"Sending temp request\n");
-                //logMsg(sTemp);
-                break;
-            default:
-                data[0]=0x30; //change to request next line message
-                data[1]=0x01;
-                data[2]=0x00;
-                break;
-        }
-        can1.write(CANMessage(0x79b, data, 8));
-        Tcount+=1;
-    } else if (Tcount<5){
-        showCP=true; // Trigger display update
-        Tcount+=1;
-        can1SleepMode = 1; // disable TX
-        can1.monitor(true); // set to snoop mode
-    }
 }
 
 void tickerISR() {  //This is the ticker ISR for auto-polling
-    CPcount=0; //reset CP message counter
-    Tcount=0; //reset Temp message counter
-}
+    pollCP=true;    //Set a flag to do in main loop instead of here
+}                   //since ticker blocks other interrupts
 
 void recieve1() {
     CANMessage msg1;
     secsNoMsg=0; // reset deadman switch
     can1.read(msg1);
-    logCan(1, msg1);
+    logCan(1, msg1); //EVcan
     led1 = !led1;
 }
 
@@ -217,7 +173,7 @@
     CANMessage msg2;
     secsNoMsg=0; // reset deadman switch
     can2.read(msg2);
-    logCan(2, msg2);
+    logCan(2, msg2); //CARcan
     led2 = !led2;
 }
 
--- a/utility.h	Tue Mar 19 01:23:26 2013 +0000
+++ b/utility.h	Tue Mar 19 04:43:43 2013 +0000
@@ -24,11 +24,9 @@
 extern CANMessage lastMsg[100];
 extern CAN can1,can2;
 extern DigitalOut can1SleepMode,can2SleepMode;
-extern bool showCP;
-extern bool tick16;
+extern bool pollCP;
+extern bool daylight;
 extern TOUCH_TFTx2 tt;
-extern unsigned char CPcount;
-extern unsigned char Tcount;
 
 extern "C" {
     void mbed_reset();
@@ -39,10 +37,9 @@
     unsigned short getTimeStamp();
     void logCan (char mType, CANMessage canRXmsg);
     void logTS ();    
-    //void sendCPreq();    
-    //void sendTreq();    
+    void sendCPreq();    
+    void sendTreq();    
     void tickerISR();
-    void msgSend();
     void recieve1();
     void recieve2();
     unsigned char buttonX(unsigned short X, unsigned char columns);