Hi,

I'm using various ELO touchscreens(mainly AccuTouch series) and I was in 
troubles with it's calibration with DirectFB driver. I have never got normal 
results.
So, this night I've inspected ELO driver and have rewritten some code.

First, I was guided by "Touch System Programmer's Guide" by Carrol 
Touch(http://www.elotouch.com/pdfs/manuals/program.pdf). I turned off 
ELO_M_CALIB parameter, which caused hardware controller recalibration. Next, 
I set scale range strictly from 0 to SCREENWIDTH and from 0 to SCREENHEIGHT 
on both axis. And then I use floating point calibration algorithm, described 
in the manual, mentioned above, to recalculate right coordinates. 
It works great now. I've tested on two devices and really want to hear success 
stories from other people, who use ELO touchscreens, to be absolutely sure. 

Second, I moved all ELO configuration stuff in dfb_config. There are 5 new 
parameters: elo-device, elo-minx, elo-maxx, elo-miny and elo-maxy.

Third, I've written simple calibration tool for ELO touchscreen, that uses 
DirectFB as GUI and communicate with touchscreen directly. It determines 
calibration parameters and produce output in directfbrc config format. So, 
only thing you have to do to configure ELO touchscreen is to run:
# ./dfb_elocal /dev/ttySx > ~/.directfbrc
and touch screen two times in marked points.

Patch was made against 0.9.22(and correct win current CVS as well).
Patch and tool is available here:
http://infostore.org/info/129544/directfb-cvs-elo.patch
http://infostore.org/info/129544/dfb_elocal-0.4.tar.gz

Patch attached as well.

Any suggestions and feedback are hardly welcome.
Especially, I want to discuss old calibration behavior with Byron and Brandon, 
to make some things clean and comprehensible.

Regards,
-- 
Ivan Daniluk,
software engineer,
Kiev, Ukraine.
diff -urN DirectFB-0.9.22-orig/inputdrivers/elo/elo.c DirectFB-0.9.22/inputdrivers/elo/elo.c
--- DirectFB-0.9.22-orig/inputdrivers/elo/elo.c	2004-11-23 04:14:15.000000000 +0200
+++ DirectFB-0.9.22/inputdrivers/elo/elo.c	2005-07-13 09:17:59.000000000 +0300
@@ -61,12 +61,6 @@
 
 #define elo_REPORT_SIZE		5
 #define elo_PACKET_SIZE		10
-#define elo_DEVICE		"/dev/ttyS0"
-#define elo_SCREENWIDTH		800
-#define elo_SCREENHEIGHT	600
-#define elo_MINX		0
-#define elo_MINY		0
-
 
 /* Mode 1 Bit Definitions */
 #define ELO_M_INITIAL 0x01  /* Enables initial pressing detection */
@@ -94,6 +88,7 @@
   unsigned char action;
 } eloData;
 
+static float elo_scalex, elo_scaley;
 
 // Write a 10-byte character packet to the touch device.
 //
@@ -277,12 +272,12 @@
   /* Set the proper mode of operation:
       Initial Touch, Range Checking, Calibration, Scaling, and Trim. */
 
-  elo_set_mode(fd,ELO_M_INITIAL|ELO_M_UNTOUCH|ELO_M_RANGECK,
-                  ELO_M_CALIB|ELO_M_SCALE|ELO_M_TRIM);
+  elo_set_mode(fd,ELO_M_INITIAL|ELO_M_UNTOUCH|ELO_M_RANGECK,ELO_M_TRIM|ELO_M_SCALE);
 
   /* Set scaling to 80 x 25 */
-  elo_set_scale(fd, 'X', elo_MINX, elo_SCREENWIDTH-1);
-  elo_set_scale(fd, 'Y', elo_MINY, elo_SCREENHEIGHT-1);
+  elo_set_scale(fd, 'X', 0, dfb_config->mode.width);
+  elo_set_scale(fd, 'Y', 0, dfb_config->mode.height);
+
 
   return 0;
 }
@@ -324,9 +319,9 @@
     return -1;
 
   /* Get touch coordinates */
-  event->x = ptr[2]+(ptr[3] << 8);
-  event->y = ptr[4]+(ptr[5] << 8);
-
+  event->x = elo_scalex * (ptr[2]+(ptr[3] << 8) - dfb_config->elo_minx);
+  event->y = elo_scaley * (ptr[4]+(ptr[5] << 8) - dfb_config->elo_miny);
+  
   /* Check for invalid range -- reset touch device if so */
   if(event->x >= event->screen_width
      || event->y >= event->screen_height) {
@@ -385,8 +380,10 @@
 static int driver_get_available( void )
 {
   int fd;
+  if (!dfb_config->elo_device)
+    return 0;
 
-  fd = eloOpenDevice (elo_DEVICE);
+  fd = eloOpenDevice (dfb_config->elo_device);
   if (fd < 0)
     return 0;
 
@@ -415,10 +412,13 @@
   int fd;
   eloData *data;
 
+  if (!dfb_config->elo_device)
+    return 0;
+
   /* open device */
-  fd = eloOpenDevice(elo_DEVICE);
+  fd = eloOpenDevice(dfb_config->elo_device);
   if(fd < 0) {
-    D_PERROR("DirectFB/elo: Error opening '"elo_DEVICE"'!\n");
+    D_PERROR("DirectFB/elo: Error opening '%s'!\n", dfb_config->elo_device);
     return DFB_INIT;
   }
 
@@ -428,14 +428,18 @@
   data->device = device;
 
   /* Must define the correct resolution of screen */
-  data->screen_width  = elo_SCREENWIDTH;
-  data->screen_height = elo_SCREENHEIGHT;
-
+  data->screen_width  = dfb_config->mode.width;
+  data->screen_height = dfb_config->mode.height;
+  
+  /* Calculate scale coefficients for calibration */
+  elo_scalex = (float)dfb_config->mode.width / (float)(dfb_config->elo_maxx - dfb_config->elo_minx);
+  elo_scaley = (float)dfb_config->mode.height / (float)(dfb_config->elo_maxy - dfb_config->elo_miny);
+  
   /* The following variable are defined to adjust the orientation of
    * the touchscreen. Variables are either max screen height/width or 0.
    */
-  data->min_x = elo_MINX;
-  data->min_y = elo_MINY;
+  data->min_x = dfb_config->elo_minx;
+  data->min_y = dfb_config->elo_miny;
 
   /* fill device info structure */
   snprintf(info->desc.name, DFB_INPUT_DEVICE_DESC_NAME_LENGTH,
diff -urN DirectFB-0.9.22-orig/src/misc/conf.c DirectFB-0.9.22/src/misc/conf.c
--- DirectFB-0.9.22-orig/src/misc/conf.c	2005-02-23 12:40:06.000000000 +0200
+++ DirectFB-0.9.22/src/misc/conf.c	2005-07-13 09:21:53.000000000 +0300
@@ -114,6 +114,11 @@
      "                                 Matrox cable type (default=composite)\n"
      "  h3600-device=<device>          Use this device for the H3600 TS driver\n"
      "  mut-device=<device>            Use this device for the MuTouch driver\n"
+     "  elo-device=<device>            Use this device for the ELO Touchscreen driver\n"
+     "    elo-minx=<amount>            Minimum X position for ELO Touchscreen\n"
+     "    elo-maxx=<amount>            Maximum X position for ELO Touchscreen\n"
+     "    elo-miny=<amount>            Minimum Y position for ELO Touchscreen\n"
+     "    elo-maxy=<amount>            Maximum Y position for ELO Touchscreen\n"
      "\n"
      " Window surface swapping policy:\n"
      "  window-surface-policy=(auto|videohigh|videolow|systemonly|videoonly)\n"
@@ -927,6 +932,82 @@
                D_ERROR( "DirectFB/Config: No MuTouch device specified!\n" );
                return DFB_INVARG;
           }
+     } else
+     if (strcmp (name, "elo-device" ) == 0) {
+          if (value) {
+               if (dfb_config->elo_device)
+                    D_FREE( dfb_config->elo_device );
+
+               dfb_config->elo_device = D_STRDUP( value );
+          }
+          else {
+               D_ERROR( "DirectFB/Config: No ELO Touchscreen device specified!\n" );
+               return DFB_INVARG;
+          }
+     } else
+     if (strcmp (name, "elo-minx" ) == 0 && dfb_config->elo_device) {
+          if (value) {
+               int pos;
+
+               if (sscanf( value, "%d", &pos ) < 1) {
+                    D_ERROR("DirectFB/Config 'elo_minx': Could not parse value!\n");
+                    return DFB_INVARG;
+               }
+
+               dfb_config->elo_minx = pos;
+          }
+          else {
+               D_ERROR("DirectFB/Config 'elo_minx': No value specified!\n");
+               return DFB_INVARG;
+          }
+     } else
+     if (strcmp (name, "elo-maxx" ) == 0 && dfb_config->elo_device) {
+          if (value) {
+               int pos;
+
+               if (sscanf( value, "%d", &pos ) < 1) {
+                    D_ERROR("DirectFB/Config 'elo_maxx': Could not parse value!\n");
+                    return DFB_INVARG;
+               }
+
+               dfb_config->elo_maxx = pos;
+          }
+          else {
+               D_ERROR("DirectFB/Config 'elo_maxx': No value specified!\n");
+               return DFB_INVARG;
+          }
+     } else
+     if (strcmp (name, "elo-miny" ) == 0 && dfb_config->elo_device) {
+          if (value) {
+               int pos;
+
+               if (sscanf( value, "%d", &pos ) < 1) {
+                    D_ERROR("DirectFB/Config 'elo_miny': Could not parse value!\n");
+                    return DFB_INVARG;
+               }
+
+               dfb_config->elo_miny = pos;
+          }
+          else {
+               D_ERROR("DirectFB/Config 'elo_miny': No value specified!\n");
+               return DFB_INVARG;
+          }
+     } else
+     if (strcmp (name, "elo-maxy" ) == 0 && dfb_config->elo_device) {
+          if (value) {
+               int pos;
+
+               if (sscanf( value, "%d", &pos ) < 1) {
+                    D_ERROR("DirectFB/Config 'elo_maxy': Could not parse value!\n");
+                    return DFB_INVARG;
+               }
+
+               dfb_config->elo_maxy = pos;
+          }
+          else {
+               D_ERROR("DirectFB/Config 'elo_maxy': No value specified!\n");
+               return DFB_INVARG;
+          }
      }
      else
           return DFB_UNSUPPORTED;
diff -urN DirectFB-0.9.22-orig/src/misc/conf.h DirectFB-0.9.22/src/misc/conf.h
--- DirectFB-0.9.22-orig/src/misc/conf.h	2005-02-23 12:36:02.000000000 +0200
+++ DirectFB-0.9.22/src/misc/conf.h	2005-07-13 07:18:36.000000000 +0300
@@ -132,6 +132,12 @@
      char      *h3600_device;                     /* H3600 Touchscreen Device */
 
      char      *mut_device;                       /* MuTouch Device */
+ 
+     char      *elo_device;                       /* ELO Touchscreen Device */
+     int        elo_minx;                         /* MinimumXPosition for ELO calibration */
+     int        elo_maxx;                         /* MaximumXPosition for ELO calibration  */
+     int        elo_miny;                         /* MinimumYPosition for ELO calibration  */
+     int        elo_maxy;                         /* MaximumYPosition for ELO calibration  */
 } DFBConfig;
 
 extern DFBConfig *dfb_config;
_______________________________________________
directfb-dev mailing list
directfb-dev@directfb.org
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-dev

Reply via email to