TouchScreen prblems

"Kai.Niu" <[email protected]>
Newsgroups gmane.comp.xfree86.devel
Message-ID <[email protected]>
Hi all:

         Firstly, thank you guys who helped me get through the way of
cross-compiling tinyX server. special thanks for Joe^^  Now I had my SBC
running tinyX happily. Sadly, I got one more problem.  I have already
tweaked the touchscreen driver of my SBC so that tinyX server could read the
data exactly the same as reading from IPAQ's touch screen driver. I thought
I could fool the tinyX server, but I am failed. Now, the cursor move
randomly with little step while I am touching the screen. I guess there
maybe some problem with my driver, so I cross-compiled tinyX server from
source to my IPAQ H3955 to prove that. Unlucky, the tinyX still can't
response screen stroke correctly. Dose anyone of you know how to make the
tinyX server compiled correctly with touchscreen driver? Here is the ts.c I
modified as follow and the version of XFree86 source tree is 4.40 

=======================ts.c=================================================
=======

 

#define NEED_EVENTS

#include "X.h"

#include "Xproto.h"

#include "inputstr.h"

#include "scrnintstr.h"

#include "kdrive.h"

#include "Xpoll.h"

#include <sys/ioctl.h>

 

//kai made modification here

/*===========================================*/

#define IOC_MAGIC 't'  

 

typedef struct {

        unsigned short pressure;

        unsigned short x;

        unsigned short y;

        unsigned short pad; /* TODO TODO word boundary pad */

}TS_EVENT;

 

typedef struct {

     int Xscale;

     int xtrans;

     int Yscale;

     int ytrans;

}TS_CAL;

 

#define TS_GET_CAL _IOR(IOC_MAGIC,10,TS_CAL)

#define TS_SET_CAL _IOW(IOC_MAGIC,11,TS_CAL)

/*==================end here modification================*/

static long lastx = 0, lasty = 0;

 

int

TsReadBytes (int fd, char *buf, int len, int min)

{

    int           n, tot;

    fd_set        set;

    struct timeval  tv;

 

    tot = 0;

    while (len)

    {

     n = read (fd, buf, len);

     if (n > 0)

     {

         tot += n;

         buf += n;

         len -= n;

     }

     if (tot % min == 0)

         break;

     FD_ZERO (&set);

     FD_SET (fd, &set);

     tv.tv_sec = 0;

     tv.tv_usec = 100 * 1000;

     n = select (fd + 1, &set, 0, 0, &tv);

     if (n <= 0)

         break;

    }

    return tot;

}

 

void

TsRead (int tsPort, void *closure)

{

    KdMouseInfo        *mi = closure;

    int           fd = (int) mi->driver;

    TS_EVENT      event;

    long     buf[3];

    int           n;

    long     pressure;

    long     x, y;

    unsigned long   flags;

    unsigned long   buttons;

 

    n = TsReadBytes (tsPort, (char *) &event, sizeof (event), sizeof
(event));

    if (n == sizeof (event))  

    {

     if (event.pressure) 

     {

         /* 

          * HACK ATTACK.  (static global variables used !)

          * Here we test for the touch screen driver actually being on the

          * touch screen, if it is we send absolute coordinates. If not,

          * then we send delta's so that we can track the entire vga screen.

          */

         if (KdTsCurScreen == KdTsPhyScreen) {

         flags = KD_BUTTON_1;

         x = event.x;

         y = event.y;

         } else {

         flags = /* KD_BUTTON_1 |*/ KD_MOUSE_DELTA;

         if ((lastx == 0) || (lasty == 0)) {

             x = 0;

             y = 0;

         } else {

             x = event.x - lastx;

             y = event.y - lasty;

         }

         lastx = event.x;

         lasty = event.y;

         }

     } else {

         flags = KD_MOUSE_DELTA;

         x = 0;

         y = 0;

         lastx = 0;

         lasty = 0;

     }

     KdEnqueueMouseEvent (mi, flags, x, y);

    }

}

 

char *TsNames[] = {

  "/dev/ts",  

  "/dev/h3600_ts" /* temporary name; note this code can try

                 to open more than one device */

};

 

#define NUM_TS_NAMES   (sizeof (TsNames) / sizeof (TsNames[0]))

 

int TsInputType;

 

int

TsInit (void)

{

    int       i;

    int       fd;

    KdMouseInfo    *mi, *next;

    int       n = 0;

 

    if (!TsInputType)

     TsInputType = KdAllocInputType ();

    

    for (mi = kdMouseInfo; mi; mi = next)

    {

     next = mi->next;

     if (mi->inputType)

         continue;

     if (!mi->name)

     {

         for (i = 0; i < NUM_TS_NAMES; i++)    

         {

         fd = open (TsNames[i], 0);

         if (fd >= 0) 

         {

             mi->name = KdSaveString (TsNames[i]);

             break;

         }

         }

     }

     else

         fd = open (mi->name, 0);

     if (fd >= 0)

     {

         TS_CAL cal;    //kai made modification here

         /*

          * Check to see if this is a touch screen

          */

         if (ioctl (fd, TS_GET_CAL, &cal) != -1)

         {

         mi->driver = (void *) fd;

         mi->inputType = TsInputType;

         if (KdRegisterFd (TsInputType, fd, TsRead, (void *) mi))

             n++;

         }

         else

         close (fd);

     }

    }

}

 

void

TsFini (void)

{

    KdMouseInfo    *mi;

 

    KdUnregisterFds (TsInputType, TRUE);

    for (mi = kdMouseInfo; mi; mi = mi->next)

    {

     if (mi->inputType == TsInputType)

     {

         mi->driver = 0;

         mi->inputType = 0;

     }

    }

}

 

KdMouseFuncs TsFuncs = {

    TsInit,

    TsFini

};

==================================end of
ts.c=====================================================

 

 

Thank you all in advanced!!!!!

 

                                   Kai@15th June 2005
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.