From 7fe60435bce6595a9c58a9bfd8244d74b5320e96 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Tue, 15 Jan 2013 08:46:13 +0100 Subject: Import DirectFB141_2k11R3_beta5 --- Source/DirectFB/inputdrivers/h3600_ts/h3600_ts.c | 239 +++++++++++++++++++++++ 1 file changed, 239 insertions(+) create mode 100755 Source/DirectFB/inputdrivers/h3600_ts/h3600_ts.c (limited to 'Source/DirectFB/inputdrivers/h3600_ts/h3600_ts.c') diff --git a/Source/DirectFB/inputdrivers/h3600_ts/h3600_ts.c b/Source/DirectFB/inputdrivers/h3600_ts/h3600_ts.c new file mode 100755 index 0000000..6a6b1af --- /dev/null +++ b/Source/DirectFB/inputdrivers/h3600_ts/h3600_ts.c @@ -0,0 +1,239 @@ +/* + (c) Copyright 2001-2009 The world wide DirectFB Open Source Community (directfb.org) + (c) Copyright 2000-2004 Convergence (integrated media) GmbH + + All rights reserved. + + Written by Denis Oliver Kropp , + Andreas Hundt , + Sven Neumann , + Ville Syrjälä and + Claudio Ciccani . + + 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 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., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include + +#include +#include + +#include + +#include + +#include +#include +#include +#include + +#include + + +DFB_INPUT_DRIVER( h3600_ts ) + +typedef struct { + CoreInputDevice *device; + DirectThread *thread; + + int fd; +} H3600TSData; + +static void * +h3600tsEventThread( DirectThread *thread, void *driver_data ) +{ + H3600TSData *data = (H3600TSData*) driver_data; + + TS_EVENT ts_event; + + int readlen; + + unsigned short old_x = -1; + unsigned short old_y = -1; + unsigned short old_pressure = 0; + + while ((readlen = read(data->fd, &ts_event, sizeof(TS_EVENT))) > 0 || + errno == EINTR) + { + DFBInputEvent evt; + + direct_thread_testcancel( thread ); + + if (readlen < 1) + continue; + + if (ts_event.pressure) { + if (ts_event.x != old_x) { + evt.type = DIET_AXISMOTION; + evt.flags = DIEF_AXISABS; + evt.axis = DIAI_X; + evt.axisabs = ts_event.x; + + dfb_input_dispatch( data->device, &evt ); + + old_x = ts_event.x; + } + + if (ts_event.y != old_y) { + evt.type = DIET_AXISMOTION; + evt.flags = DIEF_AXISABS; + evt.axis = DIAI_Y; + evt.axisabs = ts_event.y; + + dfb_input_dispatch( data->device, &evt ); + + old_y = ts_event.y; + } + } + + if ((ts_event.pressure && !old_pressure) || + (!ts_event.pressure && old_pressure)) { + evt.type = (ts_event.pressure ? + DIET_BUTTONPRESS : DIET_BUTTONRELEASE); + evt.flags = DIEF_NONE; + evt.button = DIBI_LEFT; + + dfb_input_dispatch( data->device, &evt ); + + old_pressure = ts_event.pressure; + } + } + + if (readlen <= 0) + D_PERROR ("H3600 Touchscreen thread died\n"); + + return NULL; +} + + +/* exported symbols */ + +static int driver_get_available( void ) +{ + int fd; + + fd = open( dfb_config->h3600_device ? : "/dev/ts", O_RDONLY | O_NOCTTY ); + if (fd < 0) + return 0; + + close( fd ); + + return 1; +} + +static void +driver_get_info( InputDriverInfo *info ) +{ + /* fill driver info structure */ + snprintf( info->name, + DFB_INPUT_DRIVER_INFO_NAME_LENGTH, "H3600 Touchscreen Driver" ); + + snprintf( info->vendor, + DFB_INPUT_DRIVER_INFO_VENDOR_LENGTH, "directfb.org" ); + + info->version.major = 0; + info->version.minor = 2; +} + +static DFBResult +driver_open_device( CoreInputDevice *device, + unsigned int number, + InputDeviceInfo *info, + void **driver_data ) +{ + int fd; + H3600TSData *data; + + /* open device */ + fd = open( dfb_config->h3600_device ? : "/dev/ts", O_RDONLY | O_NOCTTY ); + if (fd < 0) { + D_PERROR( "DirectFB/H3600: Error opening `%s'!\n", dfb_config->h3600_device ? : "/dev/ts" ); + return DFB_INIT; + } + + /* fill device info structure */ + snprintf( info->desc.name, + DFB_INPUT_DEVICE_DESC_NAME_LENGTH, "H3600 Touchscreen" ); + + snprintf( info->desc.vendor, + DFB_INPUT_DEVICE_DESC_VENDOR_LENGTH, "Unknown" ); + + info->prefered_id = DIDID_MOUSE; + + info->desc.type = DIDTF_MOUSE; + info->desc.caps = DICAPS_AXES | DICAPS_BUTTONS; + info->desc.max_axis = DIAI_Y; + info->desc.max_button = DIBI_LEFT; + + /* allocate and fill private data */ + data = D_CALLOC( 1, sizeof(H3600TSData) ); + if (!data) { + close( fd ); + return D_OOM(); + } + + data->fd = fd; + data->device = device; + + /* start input thread */ + data->thread = direct_thread_create( DTT_INPUT, h3600tsEventThread, data, "H3600 TS Input" ); + + /* set private data pointer */ + *driver_data = data; + + return DFB_OK; +} + +/* + * Fetch one entry from the device's keymap if supported. + */ +static DFBResult +driver_get_keymap_entry( CoreInputDevice *device, + void *driver_data, + DFBInputDeviceKeymapEntry *entry ) +{ + return DFB_UNSUPPORTED; +} + +static void +driver_close_device( void *driver_data ) +{ + H3600TSData *data = (H3600TSData*) driver_data; + + /* stop input thread */ + direct_thread_cancel( data->thread ); + direct_thread_join( data->thread ); + direct_thread_destroy( data->thread ); + + /* close device */ + if (close( data->fd ) < 0) + D_PERROR( "DirectFB/H3600: Error closing `%s'!\n", dfb_config->h3600_device ? : "/dev/ts" ); + + /* free private data */ + D_FREE( data ); +} + -- cgit