LIB for resistiv touchscreen connected to 4 mbed pins Use SPI_TFT lib

Dependents:   touch LCD_Grapher Mandelbrot Tactile ... more

Revision:
2:ef7972c29c0e
Parent:
1:1745fdf054b5
--- a/touch_tft.cpp	Thu Jul 14 21:27:19 2011 +0000
+++ b/touch_tft.cpp	Sun Sep 04 21:23:31 2011 +0000
@@ -110,16 +110,22 @@
 void touch_tft::calibrate(void) {
     int i;
     int a = 0,b = 0,c = 0, d = 0;
-    int pos;
+    int pos_x, pos_y;
     point p;
 
     cls();
     line(0,3,6,3,White);
     line(3,0,3,6,White);
-    pos = columns() / 2 - 5;
-    locate(pos,5);
+
+    // 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];
+
+    locate(pos_x,pos_y);
     printf("press cross");
-    locate(pos,6);
+    locate(pos_x,pos_y + font[2]);
     printf("to calibrate");
     for (i=0; i<5; i++) {
         do {
@@ -130,7 +136,7 @@
     }
     a = a / 5;
     b = b / 5;
-    locate(pos,5);
+    locate(pos_x,pos_y);
     printf("OK         ");
     do {
         p = get_touch();
@@ -139,9 +145,9 @@
     cls();
     line(width() -5, height() - 8,width() - 5,height() -1,White);   // paint cross
     line(width() - 8,height() - 5,width() - 1,height() - 5,White);
-    locate(pos,5);
+    locate(pos_x,pos_y);
     printf("press cross");
-    locate(pos,6);
+    locate(pos_x,pos_y + font[2]);
     printf("to calibrate");
     for (i=0; i<5; i++) {
         do {
@@ -153,7 +159,7 @@
     c = c / 5;
     d = d / 5;
 
-    locate(pos,5);
+    locate(pos_x, pos_y);
     printf("OK         ");
     do {
         p = get_touch();
@@ -176,13 +182,13 @@
     point p;
 
     p.x = (a_point.x - x_off) / pp_tx;
-    if(p.x > width()) p.x = 0;
+    if (p.x > width()) p.x = width();
     p.y = (a_point.y - y_off) / pp_ty;
-    if(p.y > height()) p.y = 0; 
+    if (p.y > height()) p.y = height();
     return (p);
 }
 
-bool touch_tft::is_touched(point a){
-  if (a.x > threshold & a.y > threshold) return(true);
-  else return(false);
+bool touch_tft::is_touched(point a) {
+    if (a.x > threshold & a.y > threshold) return(true);
+    else return(false);
 }