3
* Copyright 2004 by Kenan Esau <kenan.esau@conan.de>, Baltmannsweiler,
6
* Permission to use, copy, modify, distribute, and sell this software and its
7
* documentation for any purpose is hereby granted without fee, provided that
8
* the above copyright notice appear in all copies and that both that
9
* copyright notice and this permission notice appear in supporting
10
* documentation, and that the names of copyright holders not be
11
* used in advertising or publicity pertaining to distribution of the
12
* software without specific, written prior permission. The copyright holders
13
* make no representations about the suitability of this
14
* software for any purpose. It is provided "as is" without express or
17
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
18
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
19
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
21
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
22
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
23
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
31
#define _evdev_touch_C_
33
#include <xorgVersion.h>
36
/*****************************************************************************
38
****************************************************************************/
48
#include <sys/types.h>
51
#include <sys/ioctl.h>
54
#define EVIOCGRAB _IOW('E', 0x90, int)
59
#include <X11/Xproto.h>
64
#include <X11/extensions/XI.h>
65
#include <X11/extensions/XIproto.h>
66
#include "extnsionst.h"
72
#include "xf86_OSproc.h"
73
#include "xf86Xinput.h"
77
#ifndef NEED_XF86_TYPES
78
#define NEED_XF86_TYPES /* for xisb.h when !XFree86LOADER */
81
#define DBG(lvl, f) {if ((lvl) <= debug_level) f;}
86
#include <linux/input.h>
88
/*****************************************************************************
90
****************************************************************************/
94
/*****************************************************************************
95
* Variables without includable headers
96
****************************************************************************/
98
/*****************************************************************************
100
****************************************************************************/
104
EVTouchPreInit(InputDriverPtr drv, IDevPtr dev, int flags);
106
EVTouchPtrCtrl(DeviceIntPtr device, PtrCtrl *ctrl);
108
ConvertProc ( LocalDevicePtr local,
120
static int debug_level = 0;
122
InputDriverRec EVTOUCH = {
127
/*EVTouchUnInit*/ NULL,
133
static XF86ModuleVersionInfo VersionRec =
139
XORG_VERSION_CURRENT,
144
{0, 0, 0, 0} /* signature, to be patched into the file by
150
Plug( pointer module,
155
xf86AddInputDriver(&EVTOUCH, module, 0);
163
DBGOUT(1, "EVTouch: Unplug\n");
167
XF86ModuleData evtouchModuleData = {&VersionRec, Plug, Unplug };
169
#endif /* XFree86LOADER */
172
static const char *default_options[] =
180
"FlowControl", "None"
184
ControlProc(LocalDevicePtr device, xDeviceCtl *ctrl);
186
/*****************************************************************************
187
* Function Definitions
188
****************************************************************************/
192
emulate3Timer(OsTimerPtr timer, CARD32 now, pointer _local)
196
DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
198
LocalDevicePtr local = (LocalDevicePtr)_local;
199
EVTouchPrivatePtr priv = (EVTouchPrivatePtr) local->private;
201
sigstate = xf86BlockSIGIO();
203
xf86PostMotionEvent(local->dev, TRUE, 0, 2,
208
* Emit a button press -- release is handled in EVTouchLBRBEvent
210
if ( ( priv->touch_flags & LB_STAT ) &&
211
!( priv->touch_flags & RB_STAT ) ) {
212
DBGOUT(2, "EVTouch: Left Press\n");
213
xf86PostButtonEvent (local->dev, TRUE,
219
if ( ( priv->touch_flags & RB_STAT ) &&
220
!( priv->touch_flags & LB_STAT ) ) {
221
DBGOUT(2, "EVTouch: Right Press\n");
222
xf86PostButtonEvent (local->dev, TRUE,
229
Handling "middle" button press
231
if ( ( priv->touch_flags & RB_STAT ) &&
232
( priv->touch_flags & LB_STAT ) ) {
233
DBGOUT(2, "EVTouch: Middle Press\n");
234
xf86PostButtonEvent (local->dev, TRUE,
240
priv->emulate3_timer_expired = TRUE;
241
xf86UnblockSIGIO(sigstate);
246
static void DoBtnAction(EVTouchPrivatePtr priv)
249
LocalDevicePtr local = priv->local;
250
DBGOUT(2, "EVTouch: %s btn_count=%d\n", __FUNCTION__, priv->btn_count);
252
for (btn = 0; btn < priv->btn_count; btn++) {
253
DBGOUT(9, "EVTouch: %s do_it = %d \n",
254
__FUNCTION__, priv->btn_actions[btn].do_it);
255
if (priv->btn_actions[btn].do_it != 0) {
256
if (priv->emulate3_timer != NULL)
258
TimerFree(priv->emulate3_timer);
259
priv->emulate3_timer=NULL;
260
priv->emulate3_timer_expired = FALSE;
263
DBGOUT(2, "EVTouch: %s btn = %d action = %d\n",
265
priv->btn_actions[btn].action);
267
xf86PostButtonEvent (local->dev, TRUE, btn,
268
priv->btn_actions[btn].action,
273
priv->btn_actions[btn].do_it = 0;
274
priv->btn_actions[btn].action = 0;
279
static void SetBtnAction(EVTouchPrivatePtr priv, int btn, int action)
281
DBGOUT(2, "EVTouch: %s btn = %d action = %d\n", __FUNCTION__,
283
if (btn < priv->btn_count) {
284
priv->btn_actions[btn].do_it = 1;
285
priv->btn_actions[btn].action = action;
289
void EVTouchProcessAbs(EVTouchPrivatePtr priv)
291
struct input_event *ev; /* packet being/just read */
295
if ( (ev->code == ABS_X) || (ev->code == ABS_Z) ) {
296
priv->raw_x = ev->value;
300
if ( (ev->code == ABS_Y) || (ev->code == ABS_RX) ) {
301
priv->raw_y = ev->value;
305
if (pos_changed == 1) {
306
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 2
307
ConvertProc(priv->local, 0, 2,
308
priv->raw_x, priv->raw_y,
310
&priv->cur_x, &priv->cur_y);
313
libtouchSetPos(priv->libtouch, priv->cur_x, priv->cur_y);
317
if (ev->code == ABS_WHEEL) {
318
LocalDevicePtr local = priv->local;
321
for (; ev->value > 0; ev->value--) {
322
xf86PostButtonEvent (local->dev, TRUE,
326
xf86PostButtonEvent (local->dev, TRUE,
331
} else if (ev->value < 0) {
332
for (ev->value = -ev->value; ev->value > 0; ev->value--) {
333
xf86PostButtonEvent (local->dev, TRUE,
337
xf86PostButtonEvent (local->dev, TRUE,
349
void EVTouchProcessRel(EVTouchPrivatePtr priv)
351
struct input_event *ev; /* packet being/just read */
354
if ( ev->code == REL_X ) {
355
priv->raw_x += ev->value;
356
if (priv->raw_x > priv->max_x)
357
priv->raw_x = priv->max_x;
358
if (priv->raw_x < priv->min_x)
359
priv->raw_x = priv->min_x;
361
if ( ev->code == REL_Y ) {
362
priv->raw_y += ev->value;
363
if (priv->raw_y > priv->max_y)
364
priv->raw_y = priv->max_y;
365
if (priv->raw_y < priv->min_y)
366
priv->raw_y = priv->min_y;
369
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 2
370
ConvertProc(priv->local, 0, 2,
371
priv->raw_x, priv->raw_y,
373
&priv->cur_x, &priv->cur_y);
376
libtouchSetPos(priv->libtouch, priv->cur_x, priv->cur_y);
382
void EVTouchLBRBEvent(EVTouchPrivatePtr priv)
384
struct input_event *ev; /* packet being/just read */
385
LocalDevicePtr local = priv->local;
388
DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
390
if (priv->emulate3) {
391
if ( (ev->value==1) && (priv->emulate3_timer==NULL) )
392
priv->emulate3_timer = TimerSet(priv->emulate3_timer,
394
priv->emulate3_timeout,
398
if ( (ev->value == 1) && (ev->code == BTN_LEFT) ) {
399
priv->touch_flags |= LB_STAT;
401
if ( (ev->value == 1) && (ev->code == BTN_RIGHT) ) {
402
priv->touch_flags |= RB_STAT;
405
if ( (ev->value == 0) &&
406
(priv->touch_flags & RB_STAT) &&
407
(priv->touch_flags & LB_STAT) ) {
408
DBGOUT(2, "EVTouch: Middle Release\n");
409
priv->touch_flags &= ~LB_STAT;
410
priv->touch_flags &= ~RB_STAT;
411
SetBtnAction(priv, 2, BTN_RELEASE);
412
} else if ( (ev->value == 0) && (ev->code == BTN_LEFT) &&
413
(priv->touch_flags & LB_STAT) ) {
414
DBGOUT(2, "EVTouch: Left Release\n");
415
priv->touch_flags &= ~LB_STAT;
416
SetBtnAction(priv, 1, BTN_RELEASE);
417
} else if ( (ev->value == 0) && (ev->code == BTN_RIGHT) &&
418
(priv->touch_flags & RB_STAT) ) {
419
DBGOUT(2, "EVTouch: Right Release\n");
420
priv->touch_flags &= ~RB_STAT;
421
SetBtnAction(priv, 3, BTN_RELEASE);
424
if (ev->code == BTN_LEFT) {
425
SetBtnAction(priv, 1, ev->value);
428
if (ev->code == BTN_MIDDLE) {
429
SetBtnAction(priv, 2, ev->value);
432
if (ev->code == BTN_RIGHT) {
433
SetBtnAction(priv, 3, ev->value);
441
void EVTouchProcessKey(EVTouchPrivatePtr priv)
443
struct input_event *ev; /* packet being/just read */
445
DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
447
if ( (ev->code == BTN_LEFT) ||
448
(ev->code == BTN_RIGHT) ||
449
(ev->code == BTN_MIDDLE) ) {
451
/* give lb and rb-events some special treatment
452
(emulate3 or not, ...) */
453
EVTouchLBRBEvent(priv);
472
xf86PostButtonEvent(local->dev, TRUE,
473
btn, ev->value, 0, 2,
485
QueryHardware (LocalDevicePtr local)
487
DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
496
DeviceOn (DeviceIntPtr dev)
498
LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
499
EVTouchPrivatePtr priv = (EVTouchPrivatePtr) (local->private);
501
local->fd = xf86OpenSerial(local->options);
503
DBGOUT(2, "EVTouch: %s\n", __FUNCTION__ );
507
xf86Msg(X_WARNING, "%s: cannot open input device\n", local->name);
511
priv->buffer = XisbNew(local->fd, 64);
513
DBG (9, XisbTrace (priv->buffer, 1));
518
xf86CloseSerial(local->fd);
523
if (QueryHardware(local) != Success)
525
ErrorF ("Unable to query/initialize EVTouch hardware.\n");
529
xf86FlushInput(local->fd);
531
if (ioctl(local->fd, EVIOCGRAB, (void *)1))
532
xf86Msg(X_ERROR, "%s: Unable to grab device (%s).\n", local->name, strerror(errno));
536
xf86AddEnabledDevice(local);
538
AddEnabledDevice(local->fd);
541
dev->public.on = TRUE;
550
DeviceOff (DeviceIntPtr dev)
552
LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
553
EVTouchPrivatePtr priv = (EVTouchPrivatePtr) (local->private);
555
DBGOUT(2, "EVTouch: %s\n", __FUNCTION__ );
559
ioctl(local->fd, EVIOCGRAB, (void *)0);
560
xf86RemoveEnabledDevice (local);
563
XisbFree(priv->buffer);
566
xf86CloseSerial(local->fd);
570
dev->public.on = FALSE;
572
if ( (priv->calibrate) && (priv->fifo>0) ){
583
DeviceInit (DeviceIntPtr dev)
585
DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
586
LocalDevicePtr local = (LocalDevicePtr) dev->public.devicePrivate;
587
EVTouchPrivatePtr priv = (EVTouchPrivatePtr) (local->private);
588
unsigned char map[EV_MAX_BUTTONS];
591
for (i = 0; i < EV_MAX_BUTTONS; i++)
594
priv->btn_count = EV_MAX_BUTTONS;
597
* these have to be here instead of in the SetupProc, because when the
598
* SetupProc is run at server startup, screenInfo is not setup yet
601
ScrnInfoPtr pScrn = xf86Screens[priv->screen_num];
602
priv->screen_width = pScrn->virtualX; /* It's the virtual screen size ! */
603
priv->screen_height = pScrn->virtualY;
604
priv->pViewPort_X0 = &(pScrn->frameX0); /* initialize the pointers to the viewport coords */
605
if ( (priv->screen_width != priv->phys_width) ||
606
(priv->screen_height != priv->phys_height) )
611
priv->pViewPort_Y0 = &(pScrn->frameY0);
612
priv->pViewPort_X1 = &(pScrn->frameX1);
613
priv->pViewPort_Y1 = &(pScrn->frameY1);
615
DBGOUT(2, "EVTouch: Display X,Y: %d %d\n", priv->phys_width, priv->phys_height);
616
DBGOUT(2, "EVTouch: Virtual X,Y: %d %d\n", priv->screen_width, priv->screen_height);
617
DBGOUT(2, "EVTouch: DriverName, Rev.: %s %d\n", pScrn->driverName, pScrn->driverVersion);
618
DBGOUT(2, "EVTouch: Viewport X0,Y0: %d %d\n", *priv->pViewPort_X0, *priv->pViewPort_Y0);
619
DBGOUT(2, "EVTouch: Viewport X1,Y1: %d %d\n", *priv->pViewPort_X1, *priv->pViewPort_Y1);
620
DBGOUT(2, "EVTouch: MaxValue H,V: %d %d\n", pScrn->maxHValue, pScrn->maxVValue);
622
priv->screen_width = screenInfo.screens[priv->screen_num]->width;
623
priv->screen_height = screenInfo.screens[priv->screen_num]->height;
626
* Device reports button press for 5 buttons.
628
if (InitButtonClassDeviceStruct (dev, EV_MAX_BUTTONS, map) == FALSE)
630
ErrorF("Unable to allocate EVTouch touchscreen ButtonClassDeviceStruct\n");
634
DBGOUT(2, "EVTouch: %s btn_count=%d\n", __FUNCTION__,
636
priv->btn_actions = xcalloc(priv->btn_count, sizeof(BtnAction));
637
memset(priv->btn_actions, 0,
638
priv->btn_count * sizeof(BtnAction));
640
DBGOUT(2, "EVTouch: %s btn_count=%d\n", __FUNCTION__,
643
if (InitFocusClassDeviceStruct(dev) == FALSE) {
644
ErrorF("Unable to allocate EVTouch touchscreen FocusClassDeviceStruct\n");
649
* Device reports motions on 2 axes in absolute coordinates.
650
* Axes min and max values are reported in raw coordinates.
652
if (InitValuatorClassDeviceStruct(dev, 2,
653
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) == 0
656
local->history_size, Absolute) == FALSE)
658
ErrorF ("Unable to allocate EVTouch touchscreen ValuatorClassDeviceStruct\n");
662
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 2
663
xf86InitValuatorAxisStruct(dev, 0, 0, priv->screen_width,
665
EV_AXIS_MIN_RES /* min_res */ ,
666
EV_AXIS_MAX_RES /* max_res */ );
667
xf86InitValuatorDefaults(dev, 0);
668
xf86InitValuatorAxisStruct(dev, 1, 0, priv->screen_height,
670
EV_AXIS_MIN_RES /* min_res */ ,
671
EV_AXIS_MAX_RES /* max_res */ );
672
xf86InitValuatorDefaults(dev, 1);
674
xf86InitValuatorAxisStruct(dev, 0, priv->min_x, priv->max_x,
675
xf86InitValuatorDefaults(dev, 1);
678
/* Initial position of pointer on screen: Centered */
679
priv->cur_x=(priv->max_x - priv->min_x)/2;
680
priv->cur_y=(priv->max_y - priv->min_y)/2;
681
priv->raw_x=priv->cur_x;
682
priv->raw_y=priv->cur_y;
683
libtouchSetPos(priv->libtouch, priv->cur_x, priv->cur_y);
686
if (InitProximityClassDeviceStruct (dev) == FALSE)
688
ErrorF ("Unable to allocate EVTouch touchscreen ProximityClassDeviceStruct\n");
692
if (InitPtrFeedbackClassDeviceStruct(dev, EVTouchPtrCtrl) == FALSE)
694
ErrorF ("unable to allocate EVTouch touchscreen PtrFeedbackClassDeviceStruct\n");
699
* Allocate the motion events buffer.
701
xf86MotionHistoryAllocate (local);
709
DeviceControl (DeviceIntPtr dev,
717
RetValue = DeviceInit(dev);
720
RetValue = DeviceOn(dev);
724
RetValue = DeviceOff(dev);
737
EVTouchNewPacket (EVTouchPrivatePtr priv)
739
memset(&priv->ev, 0, sizeof(struct input_event));
741
priv->binary_pkt = FALSE;
748
EVTouchGetPacket (EVTouchPrivatePtr priv)
750
static int count = 0;
754
if (count==0) EVTouchNewPacket(priv);
756
while ((c = XisbRead(priv->buffer)) >= 0) {
758
now = GetTimeInMillis();
759
libtouchSetTime(priv->libtouch, now);
762
((char *)&priv->ev)[count] = c;
765
if (sizeof(priv->ev) == count) {
767
EVTouchDumpPacketToLog(priv);
778
static void ReadInput (LocalDevicePtr local)
780
struct input_event *ev; /* packet being/just read */
782
EVTouchPrivatePtr priv = (EVTouchPrivatePtr) (local->private);
785
* set blocking to -1 on the first call because we know there is data to
786
* read. Xisb automatically clears it after one successful read so that
787
* succeeding reads are preceeded buy a select with a 0 timeout to prevent
788
* read from blocking infinately.
790
XisbBlockDuration (priv->buffer, -1);
791
while (EVTouchGetPacket (priv) == Success)
794
DBGOUT(2, "EVTouch: %s type:%0.2x code: 0x%0.4x value:%d\n",
795
__FUNCTION__, ev->type, ev->code, ev->value);
797
xf86XInputSetScreen(local,
802
xf86PostProximityEvent(local->dev, 1, 0, 2,
808
EVTouchProcessAbs(priv);
811
EVTouchProcessRel(priv);
814
xf86PostMotionEvent (local->dev, TRUE, 0, 2,
818
if (priv->ev.code == BTN_TOUCH) {
819
if (priv->ev.value == 1) {
820
priv->touch_flags |= TOUCHED;
821
DBGOUT(2, "EVTouch: TOUCHED\n");
824
priv->touch_flags &= ~TOUCHED;
825
DBGOUT(2, "EVTouch: UNTOUCHED\n");
828
EVTouchProcessKey(priv);
831
xf86PostMotionEvent (local->dev, TRUE, 0, 2,
835
if ( priv->touch_flags & TOUCHED )
836
libtouchTriggerSM(priv->libtouch, PEN_TOUCHED);
838
libtouchTriggerSM(priv->libtouch, PEN_UNTOUCHED);
844
DBGOUT( 2, "EVTouch: setting (x/y)=(%d/%d)\n",
845
priv->cur_x, priv->cur_y);
854
ControlProc(LocalDevicePtr device, xDeviceCtl *ctrl)
856
DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
858
/* xDeviceTSCalibrationCtl *c = (xDeviceTSCalibrationCtl *) ctrl; */
859
/* EVTouchPrivatePtr priv = (EVTouchPrivatePtr) (local->private); */
861
/* priv->min_x = c->min_x; */
862
/* priv->max_x = c->max_x; */
863
/* priv->min_y = c->min_y; */
864
/* priv->max_y = c->max_y; */
872
CloseProc (LocalDevicePtr local)
874
DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
881
SwitchMode (ClientPtr client, DeviceIntPtr dev, int mode)
883
DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
892
ConvertProc ( LocalDevicePtr local,
904
DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
906
correction factors depending on current position of pointer
910
float dx = 0, dy = 0;
914
int screen_width = 0;
915
int screen_height = 0;
920
EVTouchPrivatePtr priv = (EVTouchPrivatePtr) (local->private);
921
ScrnInfoPtr pScrn = xf86Screens[priv->screen_num];
922
Rotation rotation = RRGetRotation(pScrn->pScreen);
924
DBGOUT(2, "EVTouch: FIRST: v0=%d v1=%d\n", v0, v1);
926
/*write raw coordinates to fifo for calibration programm*/
927
if ( (priv->fifo > 0) && (priv->calibrate) ){
928
DBGOUT(2, "EVTouch: writing to FIFO\n");
929
write (priv->fifo, &v0, sizeof(v0));
930
write (priv->fifo, &v1, sizeof(v1));
933
/*correction of raw coordinates*/
934
if (!priv->calibrate) {
935
DBGOUT(2, "EVTouch: Scaling coordinates\n");
936
xc = v0 - priv->min_x;
937
yc = v1 - priv->min_y;
939
max_x = priv->max_x - priv->min_x;
940
max_y = priv->max_y - priv->min_y;
942
if (priv->rotate == EV_ROTATE_NONE) {
943
screen_width = pScrn->currentMode->HDisplay;
944
screen_height = pScrn->currentMode->VDisplay;
946
screen_width = pScrn->currentMode->VDisplay;
947
screen_height = pScrn->currentMode->HDisplay;
950
if ( rotation == RR_Rotate_90 || rotation == RR_Rotate_270 ) {
951
int tmp = screen_width; screen_width = screen_height;
955
if (xc < (max_x / 2)) {
959
if (yc>(max_y / 2)) {
963
cx[1] = ((float) xc / (max_x / 2) );
964
cx[0] = (float) 1 - cx[1];
965
cy[0] = ((float) (yc-(max_y/2)) / (max_y/2) );
966
cy[1] = (float) 1 - cy[0];
968
dx = ((float) (cx[1] * cy[0] * priv->diff[1][0]) +
969
(float)(cx[0] * cy[0] * priv->diff[0][0]) +
970
(float)(cx[1] * cy[1] * priv->diff[4][0]) +
971
(float)(cx[0] * cy[1] * priv->diff[3][0]));
973
dy = ((float) (cx[1] * cy[0] * priv->diff[1][1]) +
974
(float)(cx[0] * cy[0] * priv->diff[0][1]) +
975
(float)(cx[1] * cy[1] * priv->diff[4][1]) +
976
(float)(cx[0] * cy[1] * priv->diff[3][1]));
982
cx[1] = ((float) xc / (max_x/2) );
983
cx[0] = (float) 1 - cx[1];
984
cy[0] = ((float) yc / (max_y/2) );
985
cy[1] = (float) 1 - cy[0];
987
dx = ((float) (cx[1] * cy[0] * priv->diff[4][0]) +
988
(float)(cx[0] * cy[0] * priv->diff[3][0]) +
989
(float)(cx[1] * cy[1] * priv->diff[7][0]) +
990
(float)(cx[0] * cy[1] * priv->diff[6][0]));
992
dy = ((float) (cx[1] * cy[0] * priv->diff[4][1]) +
993
(float)(cx[0] * cy[0] * priv->diff[3][1]) +
994
(float)(cx[1] * cy[1] * priv->diff[7][1]) +
995
(float)(cx[0] * cy[1] * priv->diff[6][1]));
1006
cx[1] = ((float) (xc-(max_x/2)) / (max_x/2) );
1007
cx[0] = (float)1 - cx[1];
1008
cy[0] = ((float) (yc-(max_y/2)) / (max_y/2) );
1009
cy[1] = (float)1 - cy[0];
1011
dx = ((float) (cx[1] * cy[0] * priv->diff[2][0]) +
1012
(float)(cx[0] * cy[0] * priv->diff[1][0]) +
1013
(float)(cx[1] * cy[1] * priv->diff[5][0]) +
1014
(float)(cx[0] * cy[1] * priv->diff[4][0]));
1016
dy = ((float) (cx[1] * cy[0] * priv->diff[2][1]) +
1017
(float)(cx[0] * cy[0] * priv->diff[1][1]) +
1018
(float)(cx[1] * cy[1] * priv->diff[5][1]) +
1019
(float)(cx[0] * cy[1] * priv->diff[4][1]));
1025
cx[1] = ((float) (xc-(max_x/2)) / (max_x/2) );
1026
cx[0] = (float) 1 - cx[1];
1027
cy[0] = ((float) yc / (max_y/2) );
1028
cy[1] = (float) 1 - cy[0];
1030
dx = ((float) (cx[1] * cy[0] * priv->diff[5][0]) +
1031
(float)(cx[0] * cy[0] * priv->diff[4][0]) +
1032
(float)(cx[1] * cy[1] * priv->diff[8][0]) +
1033
(float)(cx[0] * cy[1] * priv->diff[7][0]));
1035
dy = ((float) (cx[1] * cy[0] * priv->diff[5][1]) +
1036
(float)(cx[0] * cy[0] * priv->diff[4][1]) +
1037
(float)(cx[1] * cy[1] * priv->diff[8][1]) +
1038
(float)(cx[0] * cy[1] * priv->diff[7][1]));
1045
xf86ErrorFVerb(2, "cx[%d]=%f cy[%d]=%f\n", i, cx[i]
1048
DBGOUT(2, "EVTouch: ViewPort_X0=%d ViewPort_Y0=%d\n",
1049
*(priv->pViewPort_X0),
1050
*(priv->pViewPort_Y0));
1051
DBGOUT(2, "EVTouch: dx=%f dy=%f\n", dx, dy);
1054
xc = ( ((float)xc / max_x) * screen_width ) + dx;
1055
yc = ( ((float)yc / max_y) * screen_height) + dy;
1057
if (priv->swap_y == TRUE)
1058
yc = screen_height - yc;
1060
/* ususally we DON'T swap x -- but if swap_x is 1
1061
=> go on and swap */
1062
if (priv->swap_x == TRUE)
1063
xc = screen_width - xc;
1066
/* rotation mixes x and y up a bit */
1067
if (priv->rotate == EV_ROTATE_CW) {
1070
yc = screen_width - tmp;
1071
} else if (priv->rotate == EV_ROTATE_CCW) {
1073
xc = screen_height - yc;
1075
} else if (priv->rotate == EV_ROTATE_UD) {
1076
xc = screen_width - xc;
1077
yc = screen_height - yc;
1086
v0 = screen_width - xc;
1087
v1 = screen_height - yc;
1091
v0 = screen_height - yc;
1097
v1 = screen_width - tmp;
1104
DBGOUT(2, "EVTouch: FINAL: v0=%d v1=%d\n", v0, v1);
1116
EVTouchPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
1118
/* LocalDevicePtr local; */
1120
EVTouchPrivatePtr priv;
1128
DBGOUT(2, "EVTouch: %s\n", __FUNCTION__);
1130
priv = xcalloc (1, sizeof (EVTouchPrivateRec));
1134
local = xf86AllocateInput(drv, 0);
1140
local->name = xstrdup(dev->identifier);
1141
local->type_name = XI_TOUCHSCREEN;
1142
local->device_control = DeviceControl;
1143
local->read_input = ReadInput;
1144
local->control_proc = ControlProc;
1145
local->close_proc = CloseProc;
1146
local->switch_mode = SwitchMode;
1147
local->conversion_proc = ConvertProc;
1148
local->reverse_conversion_proc = NULL;
1151
local->private = priv;
1152
priv->local = local;
1153
local->private_flags = 0;
1154
local->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS;
1155
local->conf_idev = dev;
1157
xf86CollectInputOptions(local, default_options, NULL);
1159
xf86OptionListReport(local->options);
1161
priv->libtouch = xcalloc(1, sizeof(LibTouchRec));
1162
libtouchInit(priv->libtouch, local);
1164
priv->screen_num = xf86SetIntOption(local->options, "ScreenNumber", 0 );
1166
priv->calibrate = xf86SetIntOption(local->options, "Calibrate", 0);
1168
pScrn = xf86Screens[priv->screen_num];
1169
priv->phys_width = pScrn->currentMode->HDisplay; /* physical screen resolution */
1170
priv->phys_height = pScrn->currentMode->VDisplay;
1172
priv->min_x = xf86SetIntOption(local->options, "MinX", 0 );
1173
priv->max_x = xf86SetIntOption(local->options, "MaxX", priv->phys_width );
1174
priv->min_y = xf86SetIntOption(local->options, "MinY", 0 );
1175
priv->max_y = xf86SetIntOption(local->options, "MaxY", priv->phys_height );
1177
priv->button_number = xf86SetIntOption(local->options, "ButtonNumber", 2 );
1179
priv->emulate3 = xf86SetBoolOption(local->options, "Emulate3Buttons", TRUE);
1180
priv->emulate3_timeout = xf86SetIntOption(local->options,
1181
"Emulate3Timeout", 50);
1183
debug_level = xf86SetIntOption(local->options, "DebugLevel", 0);
1184
libtouchSetDebugLevel(debug_level);
1186
timeo = xf86SetIntOption(local->options, "TapTimer", 90);
1187
libtouchSetTapTimeo(priv->libtouch, timeo);
1189
timeo = xf86SetIntOption(local->options, "LongtouchTimer", 160);
1190
libtouchSetLongtouchTimeo(priv->libtouch, timeo);
1192
libtouchSetMoveLimit(priv->libtouch,
1193
xf86SetIntOption( local->options,
1194
"MoveLimit", 180 ));
1196
priv->rotate = EV_ROTATE_NONE;
1197
s = xf86FindOptionValue(local->options, "Rotate");
1199
if (xf86NameCmp(s, "CW") == 0) {
1200
priv->rotate = EV_ROTATE_CW;
1201
} else if (xf86NameCmp(s, "CCW") == 0 ) {
1202
priv->rotate = EV_ROTATE_CCW;
1206
if (priv->rotate == EV_ROTATE_NONE) {
1207
priv->max_rel_x = priv->max_x;
1208
priv->max_rel_y = priv->max_y;
1209
priv->min_rel_x = priv->min_x;
1210
priv->min_rel_y = priv->min_y;
1212
priv->max_rel_x = priv->max_y;
1213
priv->max_rel_y = priv->max_x;
1214
priv->min_rel_x = priv->min_y;
1215
priv->min_rel_y = priv->min_x;
1218
priv->swap_y = xf86SetBoolOption(local->options, "SwapY", FALSE);
1219
priv->swap_x = xf86SetBoolOption(local->options, "SwapX", FALSE);
1222
get calibration parameters from XF86Config
1224
for (i = 0; i < 9; i++){
1225
sprintf(tmp_str, "x%d", i);
1226
priv->diff[i][0] = xf86SetIntOption( local->options,
1228
sprintf(tmp_str, "y%d", i);
1229
priv->diff[i][1] = xf86SetIntOption( local->options,
1231
DBGOUT(2, "(diff[%d][0]/diff[%d][1])=(%d/%d)\n", i, i,
1232
priv->diff[i][0], priv->diff[i][1]);
1235
priv->touch_flags = 0;
1236
local->history_size = xf86SetIntOption( local->options, "HistorySize", 0 );
1238
/* prepare to process touch packets */
1239
EVTouchNewPacket (priv);
1242
if started in calibration-mode:
1245
if (priv->calibrate) {
1246
priv->fifo = open("/tmp/ev_calibrate", O_RDWR, 0);
1248
xf86ErrorFVerb(2, "open FIFO FAILED\n");
1251
/* this results in an xstrdup that must be freed later */
1252
local->name = xf86SetStrOption( local->options, "DeviceName", "EVTouch TouchScreen" );
1253
xf86ProcessCommonOptions(local, local->options);
1254
local->flags |= XI86_CONFIGURED;
1256
xf86CloseSerial(local->fd);
1265
EVTouchPtrCtrl(DeviceIntPtr device, PtrCtrl *ctrl)
1267
/* I have no clue what this does, except that registering it stops the
1268
X server segfaulting in ProcGetPointerMapping()