Added include/touch.h Now reading in resolution of touch pad.
authorJim Grandpre <jim.tla@gmail.com>
Tue, 01 Jun 2010 02:54:33 -0400
changeset 4646eea1bf53effa
parent 4645 0375d020e7e3
child 4647 be2250bb482b
child 4651 86c171888eee
Added include/touch.h Now reading in resolution of touch pad.
include/SDL_touch.h
src/events/SDL_touch.c
src/events/SDL_touch_c.h
src/video/x11/SDL_eventtouch.c
src/video/x11/SDL_x11events.c
touchTest/parseDevicesTest.c
touchTest/touchTest.c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/include/SDL_touch.h	Tue Jun 01 02:54:33 2010 -0400
     1.3 @@ -0,0 +1,118 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997-2010 Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Lesser General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2.1 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Lesser General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Lesser General Public
    1.19 +    License along with this library; if not, write to the Free Software
    1.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@libsdl.org
    1.24 +*/
    1.25 +
    1.26 +/**
    1.27 + *  \file SDL_touch.h
    1.28 + *  
    1.29 + *  Include file for SDL mouse event handling.
    1.30 + */
    1.31 +
    1.32 +#ifndef _SDL_touch_h
    1.33 +#define _SDL_touch_h
    1.34 +
    1.35 +#include "SDL_stdinc.h"
    1.36 +#include "SDL_error.h"
    1.37 +#include "SDL_video.h"
    1.38 +
    1.39 +#include "begin_code.h"
    1.40 +/* Set up for C function definitions, even when using C++ */
    1.41 +#ifdef __cplusplus
    1.42 +/* *INDENT-OFF* */
    1.43 +extern "C" {
    1.44 +/* *INDENT-ON* */
    1.45 +#endif
    1.46 +
    1.47 +typedef struct SDL_Touch SDL_Touch;
    1.48 +typedef struct SDL_Finger SDL_Finger;
    1.49 +
    1.50 +struct SDL_Finger {
    1.51 +  int id;
    1.52 +  int x;
    1.53 +  int y;
    1.54 +  int z;                      /* for future use */
    1.55 +  int xdelta;
    1.56 +  int ydelta;
    1.57 +  int last_x, last_y,last_pressure;  /* the last reported coordinates */
    1.58 +  int pressure;
    1.59 +};
    1.60 +
    1.61 +
    1.62 +struct SDL_Touch
    1.63 +{
    1.64 +  
    1.65 +  /* Free the touch when it's time */
    1.66 +  void (*FreeTouch) (SDL_Touch * touch);
    1.67 +  
    1.68 +  /* data common for tablets */
    1.69 +  int pressure_max, pressure_min;
    1.70 +  int x_max,x_min;
    1.71 +  int y_max,y_min;
    1.72 +  int xres,yres,pressureres;
    1.73 +  int tilt;                   /* for future use */
    1.74 +  int rotation;               /* for future use */
    1.75 +  
    1.76 +  /* Data common to all touch */
    1.77 +  int id;
    1.78 +  SDL_Window *focus;
    1.79 +  
    1.80 +  char *name;
    1.81 +  Uint8 buttonstate;
    1.82 +  SDL_bool relative_mode;
    1.83 +  SDL_bool flush_motion;
    1.84 +
    1.85 +  int num_fingers;
    1.86 +  int max_fingers;
    1.87 +  SDL_Finger** fingers;
    1.88 +    
    1.89 +  void *driverdata;
    1.90 +};
    1.91 +
    1.92 +
    1.93 +/* Function prototypes */
    1.94 +
    1.95 +/**
    1.96 + *  \brief Get the touch object at the given id.
    1.97 + *
    1.98 + *
    1.99 + */
   1.100 +  extern DECLSPEC SDL_Touch* SDLCALL SDL_GetTouch(int id);
   1.101 +
   1.102 +
   1.103 +
   1.104 +/**
   1.105 + *  \brief Get the finger object of the given touch, at the given id.
   1.106 + *
   1.107 + *
   1.108 + */
   1.109 +  extern DECLSPEC SDL_Finger* SDLCALL SDL_GetFinger(SDL_Touch *touch, int id);
   1.110 +
   1.111 +/* Ends C function definitions when using C++ */
   1.112 +#ifdef __cplusplus
   1.113 +/* *INDENT-OFF* */
   1.114 +}
   1.115 +/* *INDENT-ON* */
   1.116 +#endif
   1.117 +#include "close_code.h"
   1.118 +
   1.119 +#endif /* _SDL_mouse_h */
   1.120 +
   1.121 +/* vi: set ts=4 sw=4 expandtab: */
     2.1 --- a/src/events/SDL_touch.c	Mon May 31 00:24:37 2010 -0400
     2.2 +++ b/src/events/SDL_touch.c	Tue Jun 01 02:54:33 2010 -0400
     2.3 @@ -133,9 +133,9 @@
     2.4      SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1);   
     2.5  
     2.6      SDL_touchPads[index]->num_fingers = 0;
     2.7 -    SDL_touchPads[index]->max_fingers = 0;
     2.8 -    SDL_touchPads[index]->fingers = NULL;
     2.9 -    
    2.10 +    SDL_touchPads[index]->max_fingers = 1;
    2.11 +    SDL_touchPads[index]->fingers = (SDL_Finger **) SDL_malloc(sizeof(SDL_Finger*));
    2.12 +    SDL_touchPads[index]->fingers[0] = NULL;
    2.13      SDL_touchPads[index]->buttonstate = 0;
    2.14      SDL_touchPads[index]->relative_mode = SDL_FALSE;
    2.15      SDL_touchPads[index]->flush_motion = SDL_FALSE;
    2.16 @@ -253,39 +253,37 @@
    2.17      int index;
    2.18      SDL_Finger **fingers;
    2.19      size_t length;
    2.20 -    
    2.21 +    //printf("Adding Finger...\n");
    2.22      if (SDL_GetFingerIndexId(touch,finger->id) != -1) {
    2.23          SDL_SetError("Finger ID already in use");
    2.24  	}
    2.25  
    2.26      /* Add the touch to the list of touch */
    2.27 -    if(touch->num_fingers >= touch->max_fingers){
    2.28 -      if(fingers == NULL) {
    2.29 -	touch->max_fingers = 1;
    2.30 -	fingers = (SDL_Finger **) SDL_malloc(sizeof(finger));
    2.31 -      }
    2.32 -      else {
    2.33 -	fingers = (SDL_Finger **) SDL_realloc(touch->fingers,
    2.34 -				     (touch->num_fingers + 1) * sizeof(finger));
    2.35 +    if(touch->num_fingers  >= touch->max_fingers){
    2.36 +	printf("Making room for it!\n");
    2.37 +     	fingers = (SDL_Finger **) SDL_realloc(touch->fingers,
    2.38 +  		               (touch->num_fingers + 1) * sizeof(SDL_Finger *));
    2.39  	touch->max_fingers = touch->num_fingers+1;
    2.40 -      }
    2.41 -
    2.42 +	if (!fingers) {
    2.43 +	    SDL_OutOfMemory();
    2.44 +	    return -1;
    2.45 +	} 
    2.46 +	else {
    2.47 +	    touch->max_fingers = touch->num_fingers+1;
    2.48 +	    touch->fingers = fingers;
    2.49 +	}
    2.50      }
    2.51  
    2.52 -    if (!fingers) {
    2.53 -        SDL_OutOfMemory();
    2.54 -        return -1;
    2.55 -    }
    2.56 +    index = touch->num_fingers;
    2.57 +    //printf("Max_Fingers: %i Index: %i\n",touch->max_fingers,index);
    2.58  
    2.59 -    touch->fingers = fingers;
    2.60 -    index = touch->num_fingers;
    2.61 -    touch->num_fingers++;
    2.62 -    touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(*(touch->fingers[index])));
    2.63 +    touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(SDL_Finger));
    2.64      if (!touch->fingers[index]) {
    2.65          SDL_OutOfMemory();
    2.66          return -1;
    2.67      }
    2.68 -    *touch->fingers[index] = *finger;    
    2.69 +    *(touch->fingers[index]) = *finger;
    2.70 +    touch->num_fingers++;
    2.71  
    2.72      return index;
    2.73  }
    2.74 @@ -323,6 +321,7 @@
    2.75  	nf.ydelta = 0;
    2.76  	nf.last_x = x;
    2.77  	nf.last_y = y;
    2.78 +	nf.last_pressure = pressure;
    2.79  	SDL_AddFinger(touch,&nf);
    2.80  
    2.81  	posted = 0;
    2.82 @@ -383,6 +382,7 @@
    2.83  	} else {
    2.84  	    if(x < 0) x = finger->last_x; /*If movement is only in one axis,*/
    2.85  	    if(y < 0) y = finger->last_y; /*The other is marked as -1*/
    2.86 +	    if(pressure < 0) pressure = finger->last_pressure;
    2.87  	    xrel = x - finger->last_x;
    2.88  	    yrel = y - finger->last_y;
    2.89  	}
    2.90 @@ -418,8 +418,8 @@
    2.91  	  touch->y = 0;
    2.92  	  }
    2.93  	*/
    2.94 -	finger->xdelta += xrel;
    2.95 -	finger->ydelta += yrel;
    2.96 +	finger->xdelta = xrel;
    2.97 +	finger->ydelta = yrel;
    2.98  	finger->pressure = pressure;
    2.99  	
   2.100  	
   2.101 @@ -440,6 +440,7 @@
   2.102  	}
   2.103  	finger->last_x = finger->x;
   2.104  	finger->last_y = finger->y;
   2.105 +	finger->last_pressure = finger->pressure;
   2.106  	return posted;
   2.107      }
   2.108  }
     3.1 --- a/src/events/SDL_touch_c.h	Mon May 31 00:24:37 2010 -0400
     3.2 +++ b/src/events/SDL_touch_c.h	Tue Jun 01 02:54:33 2010 -0400
     3.3 @@ -20,52 +20,11 @@
     3.4      slouken@libsdl.org
     3.5  */
     3.6  #include "SDL_config.h"
     3.7 +#include "../../include/SDL_touch.h"
     3.8  
     3.9  #ifndef _SDL_touch_c_h
    3.10  #define _SDL_touch_c_h
    3.11  
    3.12 -typedef struct SDL_Touch SDL_Touch;
    3.13 -typedef struct SDL_Finger SDL_Finger;
    3.14 -
    3.15 -struct SDL_Finger {
    3.16 -  int id;
    3.17 -  int x;
    3.18 -  int y;
    3.19 -  int z;                      /* for future use */
    3.20 -  int xdelta;
    3.21 -  int ydelta;
    3.22 -  int last_x, last_y;         /* the last reported x and y coordinates */
    3.23 -  int pressure;
    3.24 -};
    3.25 -
    3.26 -
    3.27 -struct SDL_Touch
    3.28 -{
    3.29 -  
    3.30 -  /* Free the touch when it's time */
    3.31 -  void (*FreeTouch) (SDL_Touch * touch);
    3.32 -  
    3.33 -  /* data common for tablets */
    3.34 -  int pressure_max;
    3.35 -  int pressure_min;
    3.36 -  int tilt;                   /* for future use */
    3.37 -  int rotation;               /* for future use */
    3.38 -  
    3.39 -  /* Data common to all touch */
    3.40 -  int id;
    3.41 -  SDL_Window *focus;
    3.42 -  
    3.43 -  char *name;
    3.44 -  Uint8 buttonstate;
    3.45 -  SDL_bool relative_mode;
    3.46 -  SDL_bool flush_motion;
    3.47 -
    3.48 -  int num_fingers;
    3.49 -  int max_fingers;
    3.50 -  SDL_Finger** fingers;
    3.51 -    
    3.52 -  void *driverdata;
    3.53 -};
    3.54  
    3.55  
    3.56  /* Initialize the touch subsystem */
     4.1 --- a/src/video/x11/SDL_eventtouch.c	Mon May 31 00:24:37 2010 -0400
     4.2 +++ b/src/video/x11/SDL_eventtouch.c	Tue Jun 01 02:54:33 2010 -0400
     4.3 @@ -53,7 +53,9 @@
     4.4  	touch.pressure_max = 0;
     4.5  	touch.pressure_min = 0;
     4.6  	touch.id = event; 
     4.7 -    
     4.8 +
     4.9 +	
    4.10 +
    4.11  	
    4.12  
    4.13  	touch.driverdata = SDL_malloc(sizeof(EventTouchData));
    4.14 @@ -64,6 +66,24 @@
    4.15  				 O_RDONLY | O_NONBLOCK);
    4.16  	ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
    4.17  	printf ("Reading From : %s\n", tstr);
    4.18 +
    4.19 +
    4.20 +
    4.21 +	int abs[5];
    4.22 +	ioctl(data->eventStream,EVIOCGABS(0),abs);	
    4.23 +	touch.x_min = abs[1];
    4.24 +	touch.x_max = abs[2];
    4.25 +	touch.xres = touch.x_max - touch.x_min;
    4.26 +	ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);	
    4.27 +	touch.y_min = abs[1];
    4.28 +	touch.y_max = abs[2];
    4.29 +	touch.yres = touch.y_max - touch.y_min;
    4.30 +	ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);	
    4.31 +	touch.pressure_min = abs[1];
    4.32 +	touch.pressure_max = abs[2];
    4.33 +	touch.pressureres = touch.pressure_max - touch.pressure_min;
    4.34 +
    4.35 +
    4.36  	SDL_AddTouch(&touch, tstr);
    4.37  
    4.38        }
     5.1 --- a/src/video/x11/SDL_x11events.c	Mon May 31 00:24:37 2010 -0400
     5.2 +++ b/src/video/x11/SDL_x11events.c	Tue Jun 01 02:54:33 2010 -0400
     5.3 @@ -449,6 +449,7 @@
     5.4  			    break;
     5.5  			case ABS_PRESSURE:
     5.6  			    data->pressure = ev[i].value;
     5.7 +			    if(data->pressure < 0) data->pressure = 0;
     5.8  			    break;
     5.9  			case ABS_MISC:
    5.10  			    data->up = SDL_TRUE;
    5.11 @@ -461,7 +462,7 @@
    5.12  			data->finger = ev[i].value;
    5.13  		    break;
    5.14  		case EV_SYN:
    5.15 -  		    printf("Id: %i\n",touch->id); 
    5.16 +		  //printf("Id: %i\n",touch->id); 
    5.17  		    if(data->x >= 0 || data->y >= 0)
    5.18  			SDL_SendTouchMotion(touch->id,data->finger, 
    5.19  					    SDL_FALSE,data->x,data->y,
     6.1 --- a/touchTest/parseDevicesTest.c	Mon May 31 00:24:37 2010 -0400
     6.2 +++ b/touchTest/parseDevicesTest.c	Tue Jun 01 02:54:33 2010 -0400
     6.3 @@ -1,6 +1,7 @@
     6.4  #include <stdio.h>
     6.5  #include <stdlib.h>
     6.6  #include <linux/input.h>
     6.7 +#include <fcntl.h>
     6.8  
     6.9  
    6.10  int main(int agrc,char **argv)
    6.11 @@ -22,7 +23,23 @@
    6.12  	sprintf(tstr,"/dev/input/event%i",event);
    6.13  	printf("At location: %s\n",tstr);
    6.14  		
    6.15 +	int inFile = open(tstr,O_RDONLY);
    6.16  	
    6.17 +	unsigned long bits[4];
    6.18 +	int abs[5];
    6.19 +	ioctl(inFile,EVIOCGABS(ABS_X),abs);	
    6.20 +	int minx,maxx,miny,maxy,minp,maxp;
    6.21 +	minx = abs[1];
    6.22 +	maxx = abs[2];
    6.23 +	ioctl(inFile,EVIOCGABS(ABS_Y),abs);	
    6.24 +	miny = abs[1];
    6.25 +	maxy = abs[2];
    6.26 +	ioctl(inFile,EVIOCGABS(ABS_PRESSURE),abs);	
    6.27 +	minp = abs[1];
    6.28 +	maxp = abs[2];
    6.29 +	
    6.30 +
    6.31 +	close(inFile);
    6.32        }
    6.33        vendor = -1;
    6.34        product = -1;
     7.1 --- a/touchTest/touchTest.c	Mon May 31 00:24:37 2010 -0400
     7.2 +++ b/touchTest/touchTest.c	Tue Jun 01 02:54:33 2010 -0400
     7.3 @@ -1,7 +1,7 @@
     7.4  #include <stdio.h>
     7.5  #include <SDL.h>
     7.6  #include <math.h>
     7.7 -#include "../src/events/SDL_touch_c.h" //BAD!!!
     7.8 +#include <SDL_touch.h>
     7.9  
    7.10  #define PI 3.1415926535897
    7.11  #define WIDTH 640
    7.12 @@ -19,12 +19,12 @@
    7.13  
    7.14  
    7.15  typedef struct {
    7.16 -  int x,y;
    7.17 +  float x,y;
    7.18  } Point;
    7.19  
    7.20  typedef struct {
    7.21    Point p;
    7.22 -  int pressure;
    7.23 +  float pressure;
    7.24  } Finger;
    7.25  
    7.26  
    7.27 @@ -32,7 +32,7 @@
    7.28  
    7.29  void handler (int sig)
    7.30  {
    7.31 -  printf ("\nexiting...(%d)\n", sig);
    7.32 +  printf ("\exiting...(%d)\n", sig);
    7.33    exit (0);
    7.34  }
    7.35  
    7.36 @@ -61,8 +61,17 @@
    7.37  {
    7.38  
    7.39    float a;
    7.40 -  for(a=0;a<PI/2;a+=1.f/(float)r)
    7.41 +  int tx;
    7.42 +  for(a=0;a<PI/2;a+=1.f/(float)abs(r))
    7.43    {
    7.44 +    if(r > 0) { //r<0 ==> unfilled circle
    7.45 +      for(tx=x-r*cos(a);tx<x+r*cos(a);tx++) {
    7.46 +	setpix(screen,tx,(int)(y+r*sin(a)),c);
    7.47 +	setpix(screen,tx,(int)(y-r*sin(a)),c);
    7.48 +      }
    7.49 +    }
    7.50 +    
    7.51 +    //Always Draw Outline
    7.52      setpix(screen,(int)(x+r*cos(a)),(int)(y+r*sin(a)),c);
    7.53      setpix(screen,(int)(x-r*cos(a)),(int)(y+r*sin(a)),c);
    7.54      setpix(screen,(int)(x+r*cos(a)),(int)(y-r*sin(a)),c);
    7.55 @@ -89,12 +98,17 @@
    7.56  	  setpix(screen,x,y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255);
    7.57          }
    7.58      }
    7.59 -  drawCircle(screen,mousx,mousy,30,0xFFFFFF);
    7.60 +  drawCircle(screen,mousx,mousy,-30,0xFFFFFF);
    7.61    
    7.62    int i;
    7.63    for(i=0;i<MAXFINGERS;i++)
    7.64      if(finger[i].p.x >= 0 && finger[i].p.y >= 0)
    7.65 -      drawCircle(screen,finger[i].p.x,finger[i].p.y,20,0xFF6600-finger[i].pressure);
    7.66 +      if(finger[i].pressure > 0)
    7.67 +	drawCircle(screen,finger[i].p.x*screen->w,finger[i].p.y*screen->h
    7.68 +		   ,20,0xFF*finger[i].pressure);
    7.69 +      else
    7.70 +	drawCircle(screen,finger[i].p.x*screen->w,finger[i].p.y*screen->h
    7.71 +		   ,20,0xFF);
    7.72    
    7.73    if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
    7.74    
    7.75 @@ -162,14 +176,28 @@
    7.76  	    bstatus &= ~(1<<(event.button.button-1));
    7.77  	    break;
    7.78  	  case SDL_FINGERMOTION:    
    7.79 -	    
    7.80 +	    ;
    7.81  	    //printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId,
    7.82  	    //	   event.tfinger.x,event.tfinger.y);
    7.83 -	    finger[event.tfinger.fingerId].p.x = event.tfinger.x;
    7.84 -	    finger[event.tfinger.fingerId].p.y = event.tfinger.y;
    7.85 -	    finger[event.tfinger.fingerId].pressure = event.tfinger.pressure;
    7.86 -	    printf("Finger: %i, pressure: %i\n",event.tfinger.fingerId,
    7.87 -		   event.tfinger.pressure);
    7.88 +	    SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId);
    7.89 +	    SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId);
    7.90 +	    
    7.91 +	    finger[event.tfinger.fingerId].p.x = ((float)event.tfinger.x)/
    7.92 +	      inTouch->xres;
    7.93 +	    finger[event.tfinger.fingerId].p.y = ((float)event.tfinger.y)/
    7.94 +	      inTouch->yres;
    7.95 +
    7.96 +	    finger[event.tfinger.fingerId].pressure = 
    7.97 +	      ((float)event.tfinger.pressure)/inTouch->pressureres;
    7.98 +
    7.99 +	    printf("Finger: %i, Pressure: %f Pressureres: %i\n",
   7.100 +		   event.tfinger.fingerId,
   7.101 +		   finger[event.tfinger.fingerId].pressure,
   7.102 +		   inTouch->pressureres);
   7.103 +	    //printf("Finger: %i, pressure: %f\n",event.tfinger.fingerId,
   7.104 +	    //   finger[event.tfinger.fingerId].pressure);
   7.105 +
   7.106 +	    
   7.107  	    break;	    
   7.108  	  case SDL_FINGERDOWN:
   7.109  	    printf("Figner: %i down - x: %i, y: %i\n",event.tfinger.fingerId,