Dual CANbus monitor and instrumentation cluster supporting ILI9341 display controller

Dependencies:   SPI_TFTx2_ILI9341 TOUCH_TFTx2_ILI9341 TFT_fonts mbed

Fork of CANary by Tick Tock

Revision:
3:3e879b043bc5
Parent:
2:71b1999a8ea5
Child:
4:8d7759f4fe7a
--- a/main.cpp	Mon Feb 11 02:22:04 2013 +0000
+++ b/main.cpp	Tue Feb 12 04:08:05 2013 +0000
@@ -75,10 +75,11 @@
 #include "MSCFileSystem.h"
 #include "SPI_TFTx2.h"
 #include "Arial12x12.h"
+#include "Arial12x12_prop.h"
 #include "Arial28x28.h"
 #include "TOUCH_TFTx2.h"
 #define upLine "\033[1A"
-#define maxBufLen 2048
+#define maxBufLen 1536
 #define canTimeout 5
 
 // write and read the Mode Data
@@ -108,7 +109,10 @@
 FILE *rfile;
 FILE *file;
 char fileName[35] = "" ;
-char writeBuffer[maxBufLen][13];
+char writeBuffer[maxBufLen][13]; // buffer for USB write
+char indexLastMsg[0x800]={0}; // index table for last message
+CANMessage lastMsg[100]; // table to store last message of eachtype
+char ii = 0; // indexindex
 char c;
 volatile int writePointer = 0;
 volatile int secsIdle = 0;
@@ -171,6 +175,22 @@
     fclose(file);
 }
 
+void printLast (){
+    char i;
+    CANMessage msg;
+    tt.set_display(1);     // select right display
+    tt.locate(0,6);
+    tt.background(Yellow);
+    tt.foreground(Red);
+    for(i=0; i<19; i++){
+        msg = lastMsg[i+1];
+        printf("%03x : %02x %02x %02x %02x %02x %02x %02x %02x    \n",msg.id,msg.data[0],msg.data[1],msg.data[2],msg.data[3],msg.data[4],msg.data[5],msg.data[6],msg.data[7]);
+    }
+    tt.set_display(0);     // select left display
+    tt.background(Black);
+    tt.foreground(Cyan);
+}
+
 void logCan (char mtype, CANMessage canRXmsg) {
     unsigned short ts = getTimeStamp();
     unsigned long secs = time(NULL); // seconds past 12:00:00 AM 1 Jan 1900
@@ -187,6 +207,13 @@
             writePointer = 0;
             led4 = !led4;
         }
+        if(indexLastMsg[canRXmsg.id]==0) { //Check if no entry
+            indexLastMsg[canRXmsg.id]=++ii; //Create entry if first message
+            if(ii>99) {
+                ii=0;
+            }
+        }
+        lastMsg[indexLastMsg[canRXmsg.id]]=canRXmsg; //Store in table
     }
 }
 
@@ -254,15 +281,18 @@
     can1_SleepMode = 1;         // Turn on Monitor_only Mode
     can2_SleepMode = 1;         // Turn on Monitor_only Mode
     //ticker.attach(&send1, 0.5);
+    ticker.attach(&printLast, 0.5); // Display messages
     can1.attach(&recieve1);
     can2.attach(&recieve2);
-    tt.set_display(2);       // select both displays
+    tt.set_orientation(1);
+    tt.set_font((unsigned char*) Arial12x12_prop);  // select the font
+    tt.set_display(1);     // select right display
+    tt.background(Yellow);
+    tt.cls();
+    tt.set_display(0);       // select left display
     tt.background(Black);    // set background to black
-    tt.foreground(White);    // set chars to white
+    tt.foreground(Cyan);    // set chars to white
     tt.cls();                // clear the screen
-    tt.set_font((unsigned char*) Arial12x12);  // select the font
-    tt.set_orientation(1);
-    tt.set_display(1);     // select left display
 
     //tt.calibrate();           // calibrate the touch
     tt.claim(stdout);        // send stdout to the TFT display
@@ -273,9 +303,9 @@
     seconds = time(NULL);
     t = *localtime(&seconds) ;
     strftime(sTemp, 32, "%a %m/%d/%Y %X", &t);
-    tt.locate(0,0);
-    printf("\nCurrent time : %s\n", sTemp); // DAY MM/DD/YYYY HH:MM:SS
-    tt.set_display(1);     // select right display
+    //tt.locate(0,0);
+    //printf("\nCurrent time : %s\n", sTemp); // DAY MM/DD/YYYY HH:MM:SS
+    tt.set_display(0);     // select left display
     tt.locate(0,0);
 
     // is it a date before 2012 ?