Modified to work with two displays

Dependents:   touch2 default CANary_9341_test CANary_merge

Fork of Touch_tft by Peter Drescher

Revision:
11:ce7ae1584207
Parent:
10:fd7ae99850a9
Child:
13:220e3da2dd00
--- a/TOUCH_TFTx2.cpp	Sun Mar 03 15:49:34 2013 +0000
+++ b/TOUCH_TFTx2.cpp	Sun Mar 03 17:13:58 2013 +0000
@@ -193,152 +193,140 @@
     int ulx1 = 0, uly1 = 0, brx1 = 0, bry1 = 0;
     int pos_x, pos_y;
     point p;
-    if(true){ //skip cal for me
-        x0_off = 5570;
-        y0_off = 34030;
-        x0_pp = 80;
-        y0_pp = 108;
-        x1_off = 33700;
-        y1_off = 5780;
-        x1_pp = 82;
-        y1_pp = 108;
-        x_mid = 32500;
-    } else {
-        seldisp=1;       // select right display
-        cls();
-        line(0,3,6,3,White);
-        line(3,0,3,6,White);
-    
-        // get the center of the screen
-        pos_x = columns() / 2 - 3;
-        pos_x = pos_x * font[1];
-        pos_y = (rows() / 2) - 1;
-        pos_y = pos_y * font[2];
-        
-        //calibrate right screen
-        locate(pos_x,pos_y);
-        printf("press cross");
-        locate(pos_x,pos_y + font[2]);
-        printf("to calibrate");
-        do {
-            wait(0.1);
-        } while (!is_touched()); //Wait for touch
-        for (i=0; i<5; i++) {
-            do {
-                p = get_touch();
-            } while (p.x==0 && p.y==0);
-            ulx1 += p.x;
-            uly1 += p.y;
-        }
-        ulx1 /= 5;
-        uly1 /= 5;
-        locate(pos_x,pos_y);
-        printf("OK         ");
-        printf("           ");
-        do {
-            wait(0.1);
-        } while (is_touched()); //Wait for no touch
-    
-        cls();
-        line(width() -1, height() - 4,width() - 7,height() -4,White);   // paint cross
-        line(width() - 4,height() - 1,width() - 4,height() - 7,White);
-        locate(pos_x,pos_y);
-        printf("press cross");
-        locate(pos_x,pos_y + font[2]);
-        printf("to calibrate");
-        do {
-            wait(0.1);
-        } while (!is_touched()); //Wait for touch
-        for (i=0; i<5; i++) {
-            do {
-                p = get_touch();
-            } while (p.x==0 && p.y==0);        p  = get_touch();
-            brx1 += p.x;
-            bry1 += p.y;
-        }
-        brx1 /= 5;
-        bry1 /= 5;
-    
-        locate(pos_x, pos_y);
-        printf("OK         ");
-        printf("           ");
-        do {
-            wait(0.1);
-        } while (is_touched()); //Wait for no touch
+    seldisp=1;       // select right display
+    cls();
+    line(0,3,6,3,White);
+    line(3,0,3,6,White);
+
+    // get the center of the screen
+    pos_x = columns() / 2 - 3;
+    pos_x = pos_x * font[1];
+    pos_y = (rows() / 2) - 1;
+    pos_y = pos_y * font[2];
     
-        cls();
-        seldisp=0;       // select left display
-        cls();
-        line(0,3,6,3,White);
-        line(3,0,3,6,White);
-    
-        // now calibrate left screen
-        locate(pos_x,pos_y);
-        printf("press cross");
-        locate(pos_x,pos_y + font[2]);
-        printf("to calibrate");
+    //calibrate right screen
+    locate(pos_x,pos_y);
+    printf("press cross");
+    locate(pos_x,pos_y + font[2]);
+    printf("to calibrate");
+    do {
+        wait(0.1);
+    } while (!is_touched()); //Wait for touch
+    for (i=0; i<5; i++) {
         do {
-            wait(0.1);
-        } while (!is_touched()); //Wait for touch
-        for (i=0; i<5; i++) {
-            do {
-                p = get_touch();
-            } while (p.x==0 && p.y==0);
-            ulx0 += p.x;
-            uly0 += p.y;
-        }
-        ulx0 /= 5;
-        uly0 /= 5;
-        locate(pos_x,pos_y);
-        printf("OK         ");
-        printf("           ");
-        do {
-            wait(0.1);
-        } while (is_touched()); //Wait for no touch
-    
-        cls();
-        line(width() -1, height() - 4,width() - 7,height() -4,White);   // paint cross
-        line(width() - 4,height() - 1,width() - 4,height() - 7,White);
-        locate(pos_x,pos_y);
-        printf("press cross");
-        locate(pos_x,pos_y + font[2]);
-        printf("to calibrate");
+            p = get_touch();
+        } while (p.x==0 && p.y==0);
+        ulx1 += p.x;
+        uly1 += p.y;
+    }
+    ulx1 /= 5;
+    uly1 /= 5;
+    locate(pos_x,pos_y);
+    printf("OK         ");
+    printf("           ");
+    do {
+        wait(0.1);
+    } while (is_touched()); //Wait for no touch
+
+    cls();
+    line(width() -1, height() - 4,width() - 7,height() -4,White);   // paint cross
+    line(width() - 4,height() - 1,width() - 4,height() - 7,White);
+    locate(pos_x,pos_y);
+    printf("press cross");
+    locate(pos_x,pos_y + font[2]);
+    printf("to calibrate");
+    do {
+        wait(0.1);
+    } while (!is_touched()); //Wait for touch
+    for (i=0; i<5; i++) {
         do {
-            wait(0.1);
-        } while (!is_touched()); //Wait for touch
-        for (i=0; i<5; i++) {
-            do {
-                p = get_touch();
-            } while (p.x==0 && p.y==0);
-            brx0 += p.x;
-            bry0 += p.y;
-        }
-        brx0 /= 5;
-        bry0 /= 5;
-    
-        locate(pos_x, pos_y);
-        printf("OK         ");
-        printf("           ");
+            p = get_touch();
+        } while (p.x==0 && p.y==0);        p  = get_touch();
+        brx1 += p.x;
+        bry1 += p.y;
+    }
+    brx1 /= 5;
+    bry1 /= 5;
+
+    locate(pos_x, pos_y);
+    printf("OK         ");
+    printf("           ");
+    do {
+        wait(0.1);
+    } while (is_touched()); //Wait for no touch
+
+    cls();
+    seldisp=0;       // select left display
+    cls();
+    line(0,3,6,3,White);
+    line(3,0,3,6,White);
+
+    // now calibrate left screen
+    locate(pos_x,pos_y);
+    printf("press cross");
+    locate(pos_x,pos_y + font[2]);
+    printf("to calibrate");
+    do {
+        wait(0.1);
+    } while (!is_touched()); //Wait for touch
+    for (i=0; i<5; i++) {
         do {
-            wait(0.1);
-        } while (is_touched()); //Wait for no touch
+            p = get_touch();
+        } while (p.x==0 && p.y==0);
+        ulx0 += p.x;
+        uly0 += p.y;
+    }
+    ulx0 /= 5;
+    uly0 /= 5;
+    locate(pos_x,pos_y);
+    printf("OK         ");
+    printf("           ");
+    do {
+        wait(0.1);
+    } while (is_touched()); //Wait for no touch
+
+    cls();
+    line(width() -1, height() - 4,width() - 7,height() -4,White);   // paint cross
+    line(width() - 4,height() - 1,width() - 4,height() - 7,White);
+    locate(pos_x,pos_y);
+    printf("press cross");
+    locate(pos_x,pos_y + font[2]);
+    printf("to calibrate");
+    do {
+        wait(0.1);
+    } while (!is_touched()); //Wait for touch
+    for (i=0; i<5; i++) {
+        do {
+            p = get_touch();
+        } while (p.x==0 && p.y==0);
+        brx0 += p.x;
+        bry0 += p.y;
+    }
+    brx0 /= 5;
+    bry0 /= 5;
+
+    locate(pos_x, pos_y);
+    printf("OK         ");
+    printf("           ");
+    do {
+        wait(0.1);
+    } while (is_touched()); //Wait for no touch
+
+    cls();
+
+    x0_off = ulx0;
+    y0_off = uly0;
+    x0_pp = (brx0-ulx0) / (width() - 6);
+    y0_pp = (bry0-uly0) / (height() - 6);
     
-        cls();
     
-        x0_off = ulx0;
-        y0_off = uly0;
-        x0_pp = (brx0-ulx0) / (width() - 6);
-        y0_pp = (bry0-uly0) / (height() - 6);
-        
-        
-        x1_off = ulx1;
-        y1_off = uly1;
-        x1_pp = (brx1-ulx1) / (width() - 6);
-        y1_pp = (bry1-uly1) / (height() - 6);
-        x_mid = (brx0 + ulx1) / 2;
-        //debug
-        //printf("x0_off:%d y0_off:%d x0_pp:%d y0_pp:%d\n",x0_off,y0_off,x0_pp,y0_pp);
-        //printf("x1_off:%d y1_off:%d x1_pp:%d y1_pp:%d\n",x1_off,y1_off,x1_pp,y1_pp);
-        //printf("x_mid:%d\n",x_mid);
-    }
+    x1_off = ulx1;
+    y1_off = uly1;
+    x1_pp = (brx1-ulx1) / (width() - 6);
+    y1_pp = (bry1-uly1) / (height() - 6);
+    x_mid = (brx0 + ulx1) / 2;
+    //debug
+    //printf("x0_off:%d y0_off:%d x0_pp:%d y0_pp:%d\n",x0_off,y0_off,x0_pp,y0_pp);
+    //printf("x1_off:%d y1_off:%d x1_pp:%d y1_pp:%d\n",x1_off,y1_off,x1_pp,y1_pp);
+    //printf("x_mid:%d\n",x_mid);
 }