View Single Post
Community Council | Posts: 4,920 | Thanked: 12,867 times | Joined on May 2012 @ Southerrn Finland
#39
You could experiment with this attached code, to see what kind of codes you are going to get. All the input devices return the same kind of data, "struct input_event", whether it be touchscreen, accelerometer or whatever

The important header file here, "/usr/include/linux/input.h" contains the constants that are returned in type and code fields of the input_event.

Code:
int main(int argc, char *argv[])
{
  struct input_event ievent;
  int fdev, xaxis, yaxis, flag, ret;

  if ((fdev = open("/dev/input/ts",  O_RDONLY)) < 0) {
    perror("cannot open input device");
    return -1;
  }

  while(1) {
    if((ret = read(fdev ,&ievent ,sizeof(ievent))) < sizeof(ievent)) {
      printf("\nreceived only %d bytes on read", ret);
      return -1;
    }
    printf("\n%d,\t%d,\t%d", ievent.type, ievent.code, ievent.value);
  }

  return 0;
}
---------- edit ----------

OK, so I played with it again just for the fun of it. For example, every time I set finger on the TS I get nine input events something like this;

Code:
0,	0,	0
1,	330,	1
3,	0,	657
3,	1,	327
3,	53,	657
3,	54,	327
3,	48,	22
3,	57,	0
0,	2,	0
And every time I lift up finger, I get eight events like this;

Code:
0,	0,	0
3,	53,	657
3,	54,	327
3,	48,	38
3,	57,	0
0,	2,	0
0,	0,	0
1,	330,	0
The input_event "1, 330, 1" means "EV_KEY, BTN_TOUCH, DOWN", it is the touchdown event.

The input_event "1, 330, 0" means "EV_KEY, BTN_TOUCH, UP", it is the touchup event.

Last edited by juiceme; 2012-11-02 at 22:47. Reason: added more of the same...