Skip to content

Commit

Permalink
inputdrivers: tslib: add support for ts_read_mt()
Browse files Browse the repository at this point in the history
First of all, ts_read_mt() is available in newer version of tslib. With
those, also their ABI changed and we need to check for it in configure.
We drop checking for tslib-0.0 which is ancient and historic at best in
favor of the up-to-date tslib.

If supported by the libts library, ts_read_mt() is now used instead of
ts_read(). This would make it trivially easy to add real multitouch support
of it can be used inside of DirectFB.

Signed-off-by: Martin Kepplinger <martink@posteo.de>
  • Loading branch information
merge committed Sep 6, 2017
1 parent 80a5778 commit 011444b
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 1 deletion.
2 changes: 1 addition & 1 deletion configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -2563,7 +2563,7 @@ enable_tslib=no
if test "$checkfor_tslib" = "yes"; then
PKG_CHECK_MODULES([TSLIB], [tslib-1.0 >= 1.0], [enable_tslib=yes], [enable_tslib=no])
if test "$enable_tslib" = "no"; then
PKG_CHECK_MODULES([TSLIB], [tslib-0.0], [enable_tslib=yes], [enable_tslib=no
PKG_CHECK_MODULES([TSLIB], [tslib >= 1.10], [enable_tslib=yes], [enable_tslib=no
AC_MSG_WARN([*** no tslib -- tslib driver will not be built.])])
fi
fi
Expand Down
103 changes: 103 additions & 0 deletions inputdrivers/tslib/tslib.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,86 @@ typedef struct {
CoreInputDevice *device;
DirectThread *thread;
struct tsdev *ts;
#ifdef TSLIB_VERSION_MT
struct ts_sample_mt **ts_events;
#endif
} tslibData;

#define MAX_TSLIB_DEVICES 16
#define TSLIB_SLOTS 1 /* only 1 supported! FIXME if MT usable in directfb */
#define TSLIB_SAMPLES 1 /* we open blocking, so 1 */

static int num_devices = 0;
static char *device_names[MAX_TSLIB_DEVICES];

#ifdef TSLIB_VERSION_MT
static void *
tslibEventThread( DirectThread *thread, void *driver_data )
{
tslibData *data = (tslibData *) driver_data;
int readlen;
/* as soon as we have TSLIB_SLOTS > 1, we need to allocate an array here */
int old_x = -1;
int old_y = -1;
unsigned int old_pressure = 0;
int i, j;

while ((readlen = ts_read_mt( data->ts, data->ts_events, TSLIB_SLOTS, TSLIB_SAMPLES )) >= 0) {
DFBInputEvent evt;

direct_thread_testcancel( thread );

if (readlen < 1)
continue;

for (i = 0; i < readlen; i++) {
for (j = 0; j < TSLIB_SLOTS; j++) {
if (data->ts_events[i][j].valid != 1)
continue;

if (data->ts_events[i][j].pressure) {
if (data->ts_events[i][j].x != old_x) {
evt.type = DIET_AXISMOTION;
evt.flags = DIEF_AXISABS;
evt.axis = DIAI_X;
evt.axisabs = data->ts_events[i][j].x;

dfb_input_dispatch( data->device, &evt );

old_x = data->ts_events[i][j].x;
}

if (data->ts_events[i][j].y != old_y) {
evt.type = DIET_AXISMOTION;
evt.flags = DIEF_AXISABS;
evt.axis = DIAI_Y;
evt.axisabs = data->ts_events[i][j].y;

dfb_input_dispatch( data->device, &evt );

old_y = data->ts_events[i][j].y;
}
}

if (!data->ts_events[i][j].pressure != !old_pressure) {
evt.type = data->ts_events[i][j].pressure ? DIET_BUTTONPRESS : DIET_BUTTONRELEASE;
evt.flags = DIEF_NONE;
evt.button = DIBI_LEFT;

dfb_input_dispatch( data->device, &evt );

old_pressure = data->ts_events[i][j].pressure;
}
}
}
}

if (readlen < 0)
D_ERROR( "tslib Input thread died\n" );

return NULL;
}
#else /* use the old ts_read() interface */
static void *
tslibEventThread( DirectThread *thread, void *driver_data )
{
Expand Down Expand Up @@ -125,6 +198,7 @@ tslibEventThread( DirectThread *thread, void *driver_data )

return NULL;
}
#endif /* TSLIB_VERSION_MT */

static bool
check_device( const char *device )
Expand Down Expand Up @@ -257,6 +331,24 @@ driver_open_device( CoreInputDevice *device,
data->ts = ts;
data->device = device;

#ifdef TSLIB_VERSION_MT
int i;

data->ts_events = malloc(TSLIB_SAMPLES * sizeof(struct ts_sample_mt *));
if (!data->ts_events) {
ts_close(ts);
return D_OOM();
}

for (i = 0; i < TSLIB_SAMPLES; i++) {
data->ts_events[i] = calloc(TSLIB_SLOTS, sizeof(struct ts_sample_mt));
if (!data->ts_events[i]) {
ts_close(ts);
return D_OOM();
}
}
#endif /* TSLIB_VERSION_MT */

/* start input thread */
data->thread = direct_thread_create( DTT_INPUT, tslibEventThread, data, "tslib Input" );

Expand Down Expand Up @@ -287,6 +379,17 @@ driver_close_device( void *driver_data )
direct_thread_join( data->thread );
direct_thread_destroy( data->thread );

#ifdef TSLIB_VERSION_MT
int i;

for (i = 0; i < TSLIB_SAMPLES; i++) {
if (data->ts_events[i])
free(data->ts_events[i]);
}
if (data->ts_events)
free(data->ts_events);
#endif /* TSLIB_VERSION_MT */

/* close device */
ts_close( data->ts );

Expand Down

0 comments on commit 011444b

Please sign in to comment.