Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added include/touch.h Now reading in resolution of touch pad.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimtla committed Jun 1, 2010
1 parent e36fc80 commit 02f0a3b
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 82 deletions.
118 changes: 118 additions & 0 deletions include/SDL_touch.h
@@ -0,0 +1,118 @@
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2010 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/

/**
* \file SDL_touch.h
*
* Include file for SDL mouse event handling.
*/

#ifndef _SDL_touch_h
#define _SDL_touch_h

#include "SDL_stdinc.h"
#include "SDL_error.h"
#include "SDL_video.h"

#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif

typedef struct SDL_Touch SDL_Touch;
typedef struct SDL_Finger SDL_Finger;

struct SDL_Finger {
int id;
int x;
int y;
int z; /* for future use */
int xdelta;
int ydelta;
int last_x, last_y,last_pressure; /* the last reported coordinates */
int pressure;
};


struct SDL_Touch
{

/* Free the touch when it's time */
void (*FreeTouch) (SDL_Touch * touch);

/* data common for tablets */
int pressure_max, pressure_min;
int x_max,x_min;
int y_max,y_min;
int xres,yres,pressureres;
int tilt; /* for future use */
int rotation; /* for future use */

/* Data common to all touch */
int id;
SDL_Window *focus;

char *name;
Uint8 buttonstate;
SDL_bool relative_mode;
SDL_bool flush_motion;

int num_fingers;
int max_fingers;
SDL_Finger** fingers;

void *driverdata;
};


/* Function prototypes */

/**
* \brief Get the touch object at the given id.
*
*
*/
extern DECLSPEC SDL_Touch* SDLCALL SDL_GetTouch(int id);



/**
* \brief Get the finger object of the given touch, at the given id.
*
*
*/
extern DECLSPEC SDL_Finger* SDLCALL SDL_GetFinger(SDL_Touch *touch, int id);

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"

#endif /* _SDL_mouse_h */

/* vi: set ts=4 sw=4 expandtab: */
51 changes: 26 additions & 25 deletions src/events/SDL_touch.c
Expand Up @@ -133,9 +133,9 @@ SDL_AddTouch(const SDL_Touch * touch, char *name)
SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1);

SDL_touchPads[index]->num_fingers = 0;
SDL_touchPads[index]->max_fingers = 0;
SDL_touchPads[index]->fingers = NULL;

SDL_touchPads[index]->max_fingers = 1;
SDL_touchPads[index]->fingers = (SDL_Finger **) SDL_malloc(sizeof(SDL_Finger*));
SDL_touchPads[index]->fingers[0] = NULL;
SDL_touchPads[index]->buttonstate = 0;
SDL_touchPads[index]->relative_mode = SDL_FALSE;
SDL_touchPads[index]->flush_motion = SDL_FALSE;
Expand Down Expand Up @@ -253,39 +253,37 @@ SDL_AddFinger(SDL_Touch* touch,SDL_Finger* finger)
int index;
SDL_Finger **fingers;
size_t length;

//printf("Adding Finger...\n");
if (SDL_GetFingerIndexId(touch,finger->id) != -1) {
SDL_SetError("Finger ID already in use");
}

/* Add the touch to the list of touch */
if(touch->num_fingers >= touch->max_fingers){
if(fingers == NULL) {
touch->max_fingers = 1;
fingers = (SDL_Finger **) SDL_malloc(sizeof(finger));
}
else {
fingers = (SDL_Finger **) SDL_realloc(touch->fingers,
(touch->num_fingers + 1) * sizeof(finger));
if(touch->num_fingers >= touch->max_fingers){
printf("Making room for it!\n");
fingers = (SDL_Finger **) SDL_realloc(touch->fingers,
(touch->num_fingers + 1) * sizeof(SDL_Finger *));
touch->max_fingers = touch->num_fingers+1;
}

}

if (!fingers) {
SDL_OutOfMemory();
return -1;
if (!fingers) {
SDL_OutOfMemory();
return -1;
}
else {
touch->max_fingers = touch->num_fingers+1;
touch->fingers = fingers;
}
}

touch->fingers = fingers;
index = touch->num_fingers;
touch->num_fingers++;
touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(*(touch->fingers[index])));
//printf("Max_Fingers: %i Index: %i\n",touch->max_fingers,index);

touch->fingers[index] = (SDL_Finger *) SDL_malloc(sizeof(SDL_Finger));
if (!touch->fingers[index]) {
SDL_OutOfMemory();
return -1;
}
*touch->fingers[index] = *finger;
*(touch->fingers[index]) = *finger;
touch->num_fingers++;

return index;
}
Expand Down Expand Up @@ -323,6 +321,7 @@ SDL_SendFingerDown(int id, int fingerid, SDL_bool down, int x, int y, int pressu
nf.ydelta = 0;
nf.last_x = x;
nf.last_y = y;
nf.last_pressure = pressure;
SDL_AddFinger(touch,&nf);

posted = 0;
Expand Down Expand Up @@ -383,6 +382,7 @@ SDL_SendTouchMotion(int id, int fingerid, int relative,
} else {
if(x < 0) x = finger->last_x; /*If movement is only in one axis,*/
if(y < 0) y = finger->last_y; /*The other is marked as -1*/
if(pressure < 0) pressure = finger->last_pressure;
xrel = x - finger->last_x;
yrel = y - finger->last_y;
}
Expand Down Expand Up @@ -418,8 +418,8 @@ SDL_SendTouchMotion(int id, int fingerid, int relative,
touch->y = 0;
}
*/
finger->xdelta += xrel;
finger->ydelta += yrel;
finger->xdelta = xrel;
finger->ydelta = yrel;
finger->pressure = pressure;


Expand All @@ -440,6 +440,7 @@ SDL_SendTouchMotion(int id, int fingerid, int relative,
}
finger->last_x = finger->x;
finger->last_y = finger->y;
finger->last_pressure = finger->pressure;
return posted;
}
}
Expand Down
43 changes: 1 addition & 42 deletions src/events/SDL_touch_c.h
Expand Up @@ -20,52 +20,11 @@
slouken@libsdl.org
*/
#include "SDL_config.h"
#include "../../include/SDL_touch.h"

#ifndef _SDL_touch_c_h
#define _SDL_touch_c_h

typedef struct SDL_Touch SDL_Touch;
typedef struct SDL_Finger SDL_Finger;

struct SDL_Finger {
int id;
int x;
int y;
int z; /* for future use */
int xdelta;
int ydelta;
int last_x, last_y; /* the last reported x and y coordinates */
int pressure;
};


struct SDL_Touch
{

/* Free the touch when it's time */
void (*FreeTouch) (SDL_Touch * touch);

/* data common for tablets */
int pressure_max;
int pressure_min;
int tilt; /* for future use */
int rotation; /* for future use */

/* Data common to all touch */
int id;
SDL_Window *focus;

char *name;
Uint8 buttonstate;
SDL_bool relative_mode;
SDL_bool flush_motion;

int num_fingers;
int max_fingers;
SDL_Finger** fingers;

void *driverdata;
};


/* Initialize the touch subsystem */
Expand Down
22 changes: 21 additions & 1 deletion src/video/x11/SDL_eventtouch.c
Expand Up @@ -53,7 +53,9 @@ X11_InitTouch(_THIS)
touch.pressure_max = 0;
touch.pressure_min = 0;
touch.id = event;






touch.driverdata = SDL_malloc(sizeof(EventTouchData));
Expand All @@ -64,6 +66,24 @@ X11_InitTouch(_THIS)
O_RDONLY | O_NONBLOCK);
ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
printf ("Reading From : %s\n", tstr);



int abs[5];
ioctl(data->eventStream,EVIOCGABS(0),abs);
touch.x_min = abs[1];
touch.x_max = abs[2];
touch.xres = touch.x_max - touch.x_min;
ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);
touch.y_min = abs[1];
touch.y_max = abs[2];
touch.yres = touch.y_max - touch.y_min;
ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);
touch.pressure_min = abs[1];
touch.pressure_max = abs[2];
touch.pressureres = touch.pressure_max - touch.pressure_min;


SDL_AddTouch(&touch, tstr);

}
Expand Down
3 changes: 2 additions & 1 deletion src/video/x11/SDL_x11events.c
Expand Up @@ -449,6 +449,7 @@ X11_PumpEvents(_THIS)
break;
case ABS_PRESSURE:
data->pressure = ev[i].value;
if(data->pressure < 0) data->pressure = 0;
break;
case ABS_MISC:
data->up = SDL_TRUE;
Expand All @@ -461,7 +462,7 @@ X11_PumpEvents(_THIS)
data->finger = ev[i].value;
break;
case EV_SYN:
printf("Id: %i\n",touch->id);
//printf("Id: %i\n",touch->id);
if(data->x >= 0 || data->y >= 0)
SDL_SendTouchMotion(touch->id,data->finger,
SDL_FALSE,data->x,data->y,
Expand Down
17 changes: 17 additions & 0 deletions touchTest/parseDevicesTest.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <linux/input.h>
#include <fcntl.h>


int main(int agrc,char **argv)
Expand All @@ -22,7 +23,23 @@ int main(int agrc,char **argv)
sprintf(tstr,"/dev/input/event%i",event);
printf("At location: %s\n",tstr);

int inFile = open(tstr,O_RDONLY);

unsigned long bits[4];
int abs[5];
ioctl(inFile,EVIOCGABS(ABS_X),abs);
int minx,maxx,miny,maxy,minp,maxp;
minx = abs[1];
maxx = abs[2];
ioctl(inFile,EVIOCGABS(ABS_Y),abs);
miny = abs[1];
maxy = abs[2];
ioctl(inFile,EVIOCGABS(ABS_PRESSURE),abs);
minp = abs[1];
maxp = abs[2];


close(inFile);
}
vendor = -1;
product = -1;
Expand Down

0 comments on commit 02f0a3b

Please sign in to comment.