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:
19:d576298c46f3
Parent:
18:999401f359a5
Child:
20:3bf176d14b14
--- a/main.cpp	Mon Mar 04 14:00:49 2013 +0000
+++ b/main.cpp	Thu Mar 07 04:39:23 2013 +0000
@@ -73,7 +73,7 @@
     int readPointer=0;
     char sTemp[40];
     unsigned long secs;
-    char i,j,display=0;
+    char i,j,ff,display=0;
     point lastTouch;    
 
     can1.monitor(true); // set to snoop mode
@@ -86,16 +86,9 @@
     can2.attach(&recieve2);
     
     tt.set_orientation(1);
-    tt.set_font((unsigned char*) Arial12x12_prop);  // select the font
-    tt.set_display(2);     // select right display
     tt.background(Black);
+    tt.set_display(2);       // select both displays
     tt.cls();
-    tt.set_display(0);       // select left display
-    //if(true){ // bypass calibration
-    //    tt.setcal(5570, 34030, 80, 108, 33700, 5780, 82, 108, 32500);
-    //} else {  // calibrate the touch
-    //    tt.calibrate();   
-    //}
     tt.claim(stdout);        // send stdout to the TFT display
     touchpad.rise(&touch_ISR);
     tt.wfi();               // enable interrupt on touch
@@ -103,19 +96,17 @@
     timer.start() ;
     RTC_Init(); // start the RTC Interrupts that sync the timer
     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)
+    NVIC_SetPriority(TIMER3_IRQn, 1); //set ticker priority
+    NVIC_SetPriority(CAN_IRQn, 2); //higher than can (so RTC sync works)
     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
+    strftime(sTemp, 32, "%a %m/%d/%Y %X\n", &t);
+    logMsg(sTemp);
 
     // is it a date before 2012 ?
     if ((t.tm_year + 1900) < 2012 ) {
         // before 2012, so the RTC probably lost power
         // So, set a near-recent date in 2012
-
         // enter people-values here
         t.tm_year = 2013 ; // 28 May 2012
         t.tm_mon = 3 ; // 1 to 12
@@ -178,8 +169,10 @@
         logMsg(sTemp);
         sprintf(sTemp,"Calibrating touch screen.\n");
         logMsg(sTemp);
-        tt.calibrate();
+        //tt.setcal(5570, 34030, 80, 108, 33700, 5780, 82, 108, 32500);// bypass calibration using my values
+        tt.calibrate();   // run touchscreen calibration routine
         cfile = fopen("/local/config.txt", "w");
+        fprintf(cfile,"format 1\r\n");
         fprintf(cfile,"x0_off %d\r\n",tt.x0_off);
         fprintf(cfile,"y0_off %d\r\n",tt.y0_off);
         fprintf(cfile,"x0_pp %d\r\n",tt.x0_pp);
@@ -190,17 +183,18 @@
         fprintf(cfile,"y1_pp %d\r\n",tt.y1_pp);
         fprintf(cfile,"x_mid %d\r\n",tt.x_mid);
     } else { // read params
-       sprintf(sTemp,"Reading config file.\n");
-       logMsg(sTemp);
-       fscanf(cfile, "x0_off %d\r\n", &tt.x0_off ) ;
-       fscanf(cfile, "y0_off %d\r\n", &tt.y0_off ) ;
-       fscanf(cfile, "x0_pp %d\r\n", &tt.x0_pp ) ;
-       fscanf(cfile, "y0_pp %d\r\n", &tt.y0_pp ) ;
-       fscanf(cfile, "x1_off %d\r\n", &tt.x1_off ) ;
-       fscanf(cfile, "y1_off %d\r\n", &tt.y1_off ) ;
-       fscanf(cfile, "x1_pp %d\r\n", &tt.x1_pp ) ;
-       fscanf(cfile, "y1_pp %d\r\n", &tt.y1_pp ) ;
-       fscanf(cfile, "x_mid %d\r\n", &tt.x_mid ) ;
+        sprintf(sTemp,"Reading config file.\n");
+        logMsg(sTemp);
+        fscanf(cfile, "format %c\r\n", &ff ) ;
+        fscanf(cfile, "x0_off %d\r\n", &tt.x0_off ) ;
+        fscanf(cfile, "y0_off %d\r\n", &tt.y0_off ) ;
+        fscanf(cfile, "x0_pp %d\r\n", &tt.x0_pp ) ;
+        fscanf(cfile, "y0_pp %d\r\n", &tt.y0_pp ) ;
+        fscanf(cfile, "x1_off %d\r\n", &tt.x1_off ) ;
+        fscanf(cfile, "y1_off %d\r\n", &tt.y1_off ) ;
+        fscanf(cfile, "x1_pp %d\r\n", &tt.x1_pp ) ;
+        fscanf(cfile, "y1_pp %d\r\n", &tt.y1_pp ) ;
+        fscanf(cfile, "x_mid %d\r\n", &tt.x_mid ) ;
     }
     fclose(cfile);    
 
@@ -342,7 +336,6 @@
             pollCP=false;
             showCP=true;
         }
-
         display=display<1?display+1:0; // toggle display
         updateDisplay(display);
     } //while (true)