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:
Sun Mar 03 18:06:53 2013 +0000
Parent:
14:736a5e9650c5
Child:
16:2a6ca248e1cb
Commit message:
Added config file (just touch cal values for now)

Changed in this revision

TOUCH_TFTx2.lib 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
--- a/TOUCH_TFTx2.lib	Sun Mar 03 17:14:15 2013 +0000
+++ b/TOUCH_TFTx2.lib	Sun Mar 03 18:06:53 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/TickTock/code/TOUCH_TFTx2/#ce7ae1584207
+http://mbed.org/users/TickTock/code/TOUCH_TFTx2/#b7fb9d3ae5ea
--- a/main.cpp	Sun Mar 03 17:14:15 2013 +0000
+++ b/main.cpp	Sun Mar 03 18:06:53 2013 +0000
@@ -47,7 +47,7 @@
 TOUCH_TFTx2 tt(p16, p17, p19, p20, p11, p12, p13, p6, p7, p5, "TFT"); // x+,x-,y+,y-,mosi, miso, sclk, cs0, cs1, reset
 
 bool logEn = true,logOpen = false;
-FILE *rfile;
+FILE *cfile;
 FILE *file;
 char fileName[35] = "" ;
 char writeBuffer[maxBufLen][13]; // buffer for USB write
@@ -92,11 +92,11 @@
     tt.background(Black);
     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();   
-    }
+    //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
@@ -137,6 +137,34 @@
         //    strftime(sTemp, 32, "%a %m/%d/%Y %X", localtime(&seconds));
         //    printf("%s\n", sTemp); // DAY MM/DD/YYYY HH:MM:SS
     }
+
+    // Look for config file
+    cfile = fopen("/local/config.txt", "r");
+    if (cfile==NULL){ // if doesn't exist --> create
+        tt.calibrate();
+        cfile = fopen("/local/config.txt", "w");
+        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);
+        fprintf(cfile,"y0_pp %d\r\n",tt.y0_pp);
+        fprintf(cfile,"x1_off %d\r\n",tt.x1_off);
+        fprintf(cfile,"y1_off %d\r\n",tt.y1_off);
+        fprintf(cfile,"x1_pp %d\r\n",tt.x1_pp);
+        fprintf(cfile,"y1_pp %d\r\n",tt.y1_pp);
+        fprintf(cfile,"x_mid %d\r\n",tt.x_mid);
+    } else { // read params
+       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);    
+
     //ticker.attach(&tickerISR, 60);  //poll cellpair data every minute
     while (true) {
         if (!logOpen) { // Open new file if one is not already open
@@ -162,7 +190,7 @@
                     spkr.beep(2000,0.2);
                 }
             }//logging enabled
-        } else { // if (!logOpen)
+        } else { // if (logOpen)
             if (((writePointer+maxBufLen-readPointer)%maxBufLen)>(maxBufLen/16)||canIdle) {
                 // Dump buffer if > 1/16 full or canbus has stopped
                 if (file == NULL) {
@@ -217,11 +245,12 @@
             }
         } // if idle
         
-        if(touched){
+        if(touched){ // call touchscreen procedure if touch interrupt detected
             lastTouch = tt.get_touch();       
             lastTouch = tt.to_pixel(lastTouch);          // convert to pixel pos
             touched = false; // clear interrupt flag
         }
+
         if (!userIdle) {
             if (secsNoTouch<2) {// Recently touched
                 secsNoTouch +=2; // increment to prevent double touch
@@ -265,7 +294,8 @@
                 lastDMode[1]=99;
             }
         }
-        if(pollCP){
+
+        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
@@ -273,8 +303,8 @@
             pollCP=false;
             showCP=true;
         }
+
         display=display<1?display+1:0; // toggle display
         updateDisplay(display);
-        //wait(0.1); // We get >2K messages per second
     } //while (true)
 }
\ No newline at end of file