src/video/x11/SDL_eventtouch.c
author Jim Grandpre
Tue, 01 Jun 2010 02:54:33 -0400
changeset 4646 eea1bf53effa
parent 4645 0375d020e7e3
child 4669 62e6a6e9720b
permissions -rw-r--r--
Added include/touch.h Now reading in resolution of touch pad.
jim@4645
     1
/*
jim@4645
     2
    SDL - Simple DirectMedia Layer
jim@4645
     3
    Copyright (C) 1997-2010 Sam Lantinga
jim@4645
     4
jim@4645
     5
    This library is free software; you can redistribute it and/or
jim@4645
     6
    modify it under the terms of the GNU Lesser General Public
jim@4645
     7
    License as published by the Free Software Foundation; either
jim@4645
     8
    version 2.1 of the License, or (at your option) any later version.
jim@4645
     9
jim@4645
    10
    This library is distributed in the hope that it will be useful,
jim@4645
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
jim@4645
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
jim@4645
    13
    Lesser General Public License for more details.
jim@4645
    14
jim@4645
    15
    You should have received a copy of the GNU Lesser General Public
jim@4645
    16
    License along with this library; if not, write to the Free Software
jim@4645
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
jim@4645
    18
jim@4645
    19
    Sam Lantinga
jim@4645
    20
    slouken@libsdl.org
jim@4645
    21
*/
jim@4645
    22
#include "SDL_config.h"
jim@4645
    23
#include "SDL_x11video.h"
jim@4645
    24
#include "SDL_eventtouch.h"
jim@4645
    25
#include "../../events/SDL_touch_c.h"
jim@4645
    26
jim@4645
    27
#include <linux/input.h>
jim@4645
    28
#include <fcntl.h>
jim@4645
    29
jim@4645
    30
void
jim@4645
    31
X11_InitTouch(_THIS)
jim@4645
    32
{
jim@4645
    33
  printf("Initializing touch...\n");
jim@4645
    34
jim@4645
    35
  FILE *fd;
jim@4645
    36
  fd = fopen("/proc/bus/input/devices","r");
jim@4645
    37
  
jim@4645
    38
  char c;
jim@4645
    39
  int i = 0;
jim@4645
    40
  char line[256];
jim@4645
    41
  char tstr[256];
jim@4645
    42
  int vendor = -1,product = -1,event = -1;
jim@4645
    43
  while(!feof(fd)) {
jim@4645
    44
    if(fgets(line,256,fd) <=0) continue;
jim@4645
    45
    //printf("%s",line);
jim@4645
    46
    if(line[0] == '\n') {
jim@4645
    47
      if(vendor == 1386){
jim@4645
    48
	printf("Wacom... Assuming it is a touch device\n");
jim@4645
    49
	sprintf(tstr,"/dev/input/event%i",event);
jim@4645
    50
	printf("At location: %s\n",tstr);
jim@4645
    51
jim@4645
    52
	SDL_Touch touch;
jim@4645
    53
	touch.pressure_max = 0;
jim@4645
    54
	touch.pressure_min = 0;
jim@4645
    55
	touch.id = event; 
jim@4646
    56
jim@4646
    57
	
jim@4646
    58
jim@4645
    59
	
jim@4645
    60
jim@4645
    61
	touch.driverdata = SDL_malloc(sizeof(EventTouchData));
jim@4645
    62
	EventTouchData* data = (EventTouchData*)(touch.driverdata);
jim@4645
    63
	printf("Opening device...\n");
jim@4645
    64
	//printf("New Touch - DataPtr: %i\n",data);
jim@4645
    65
	data->eventStream = open(tstr, 
jim@4645
    66
				 O_RDONLY | O_NONBLOCK);
jim@4645
    67
	ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
jim@4645
    68
	printf ("Reading From : %s\n", tstr);
jim@4646
    69
jim@4646
    70
jim@4646
    71
jim@4646
    72
	int abs[5];
jim@4646
    73
	ioctl(data->eventStream,EVIOCGABS(0),abs);	
jim@4646
    74
	touch.x_min = abs[1];
jim@4646
    75
	touch.x_max = abs[2];
jim@4646
    76
	touch.xres = touch.x_max - touch.x_min;
jim@4646
    77
	ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);	
jim@4646
    78
	touch.y_min = abs[1];
jim@4646
    79
	touch.y_max = abs[2];
jim@4646
    80
	touch.yres = touch.y_max - touch.y_min;
jim@4646
    81
	ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);	
jim@4646
    82
	touch.pressure_min = abs[1];
jim@4646
    83
	touch.pressure_max = abs[2];
jim@4646
    84
	touch.pressureres = touch.pressure_max - touch.pressure_min;
jim@4646
    85
jim@4646
    86
jim@4645
    87
	SDL_AddTouch(&touch, tstr);
jim@4645
    88
jim@4645
    89
      }
jim@4645
    90
      vendor = -1;
jim@4645
    91
      product = -1;
jim@4645
    92
      event = -1;      
jim@4645
    93
    }
jim@4645
    94
    else if(line[0] == 'I') {
jim@4645
    95
      i = 1;
jim@4645
    96
      while(line[i]) {
jim@4645
    97
	sscanf(&line[i],"Vendor=%x",&vendor);
jim@4645
    98
	sscanf(&line[i],"Product=%x",&product);
jim@4645
    99
	i++;
jim@4645
   100
      }
jim@4645
   101
    }
jim@4645
   102
    else if(line[0] == 'H') {
jim@4645
   103
      i = 1;
jim@4645
   104
      while(line[i]) {
jim@4645
   105
	sscanf(&line[i],"event%d",&event);
jim@4645
   106
	i++;
jim@4645
   107
      }
jim@4645
   108
    }
jim@4645
   109
  }
jim@4645
   110
  
jim@4645
   111
  close(fd);
jim@4645
   112
}
jim@4645
   113
jim@4645
   114
void
jim@4645
   115
X11_QuitTouch(_THIS)
jim@4645
   116
{
jim@4645
   117
    SDL_TouchQuit();
jim@4645
   118
}
jim@4645
   119
jim@4645
   120
/* vi: set ts=4 sw=4 expandtab: */