summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Bruguier <nicolas.bruguier@supersonicimagine.fr>2009-08-07 19:09:54 +0200
committerNicolas Bruguier <nicolas.bruguier@supersonicimagine.fr>2009-08-07 19:09:54 +0200
commit1bf9aec0bb7a7cdf4f58a82093306eb4b7e151c1 (patch)
tree901c76a41eaacf06d8095473fdabf4eb6d0ed1c3
parent7188350f68af36a7395cb137318fb13e33ee2f47 (diff)
Create and remove calibration pipe when is activated by XI Property
-rw-r--r--src/evtouch2.c394
1 files changed, 203 insertions, 191 deletions
diff --git a/src/evtouch2.c b/src/evtouch2.c
index eddeae7..a345c88 100644
--- a/src/evtouch2.c
+++ b/src/evtouch2.c
@@ -30,6 +30,8 @@
#include "config.h"
#endif
+#include <string.h>
+#include <errno.h>
#include <X11/extensions/XIproto.h>
#include <xf86.h>
#include <xf86_OSlib.h>
@@ -855,6 +857,7 @@ EVTouch2ConvertProc ( LocalDevicePtr local,
int xc, yc;
int screen_width = 0;
int screen_height = 0;
+ int tmp = 0;
#ifdef EVDBG
int i = 0;
#endif
@@ -877,224 +880,216 @@ EVTouch2ConvertProc ( LocalDevicePtr local,
}
/* correction of raw coordinates */
- if (!priv->calibration.enabled)
+ if (priv->swap_axes)
{
- int tmp = 0;
+ tmp = v0;
+ v0 = v1;
+ v1 = tmp;
+ }
+
+ DBGOUT(2, "EVTouch2: Scaling coordinates\n");
+ xc = v0 - priv->calibration.min_x;
+ yc = v1 - priv->calibration.min_y;
- if (priv->swap_axes)
+ max_x = priv->calibration.max_x - priv->calibration.min_x;
+ max_y = priv->calibration.max_y - priv->calibration.min_y;
+
+ if (priv->rotate == EVTOUCH2_ROTATE_NONE)
+ {
+ if (priv->pan_viewport.enabled)
{
- tmp = v0;
- v0 = v1;
- v1 = tmp;
+ screen_width = priv->pan_viewport.width;
+ screen_height = priv->pan_viewport.height;
}
-
- DBGOUT(2, "EVTouch2: Scaling coordinates\n");
- xc = v0 - priv->calibration.min_x;
- yc = v1 - priv->calibration.min_y;
-
- max_x = priv->calibration.max_x - priv->calibration.min_x;
- max_y = priv->calibration.max_y - priv->calibration.min_y;
-
- if (priv->rotate == EVTOUCH2_ROTATE_NONE)
+ else
{
- if (priv->pan_viewport.enabled)
- {
- screen_width = priv->pan_viewport.width;
- screen_height = priv->pan_viewport.height;
- }
- else
- {
- screen_width = pScrn->currentMode->HDisplay;
- screen_height = pScrn->currentMode->VDisplay;
- }
- }
+ screen_width = pScrn->currentMode->HDisplay;
+ screen_height = pScrn->currentMode->VDisplay;
+ }
+ }
+ else
+ {
+ if (priv->pan_viewport.enabled)
+ {
+ screen_width = priv->pan_viewport.height;
+ screen_height = priv->pan_viewport.width;
+ }
else
{
- if (priv->pan_viewport.enabled)
- {
- screen_width = priv->pan_viewport.height;
- screen_height = priv->pan_viewport.width;
- }
- else
- {
- screen_width = pScrn->currentMode->VDisplay;
- screen_height = pScrn->currentMode->HDisplay;
- }
+ screen_width = pScrn->currentMode->VDisplay;
+ screen_height = pScrn->currentMode->HDisplay;
}
+ }
+
+ if ( rotation == RR_Rotate_90 || rotation == RR_Rotate_270 )
+ {
+ int tmp = screen_width; screen_width = screen_height;
+ screen_height = tmp;
+ }
- if ( rotation == RR_Rotate_90 || rotation == RR_Rotate_270 )
+ if (xc < (max_x / 2))
+ {
+ /*
+ left
+ */
+ if (yc>(max_y / 2))
{
- int tmp = screen_width; screen_width = screen_height;
- screen_height = tmp;
+ /*
+ upper
+ */
+ cx[1] = ((float) xc / (max_x / 2) );
+ cx[0] = (float) 1 - cx[1];
+ cy[0] = ((float) (yc-(max_y/2)) / (max_y/2) );
+ cy[1] = (float) 1 - cy[0];
+
+ dx = ((float) (cx[1] * cy[0] * priv->calibration.diff[1][0]) +
+ (float)(cx[0] * cy[0] * priv->calibration.diff[0][0]) +
+ (float)(cx[1] * cy[1] * priv->calibration.diff[4][0]) +
+ (float)(cx[0] * cy[1] * priv->calibration.diff[3][0]));
+
+ dy = ((float) (cx[1] * cy[0] * priv->calibration.diff[1][1]) +
+ (float)(cx[0] * cy[0] * priv->calibration.diff[0][1]) +
+ (float)(cx[1] * cy[1] * priv->calibration.diff[4][1]) +
+ (float)(cx[0] * cy[1] * priv->calibration.diff[3][1]));
}
-
- if (xc < (max_x / 2))
+ else
{
/*
- left
+ lower
*/
- if (yc>(max_y / 2))
- {
- /*
- upper
- */
- cx[1] = ((float) xc / (max_x / 2) );
- cx[0] = (float) 1 - cx[1];
- cy[0] = ((float) (yc-(max_y/2)) / (max_y/2) );
- cy[1] = (float) 1 - cy[0];
-
- dx = ((float) (cx[1] * cy[0] * priv->calibration.diff[1][0]) +
- (float)(cx[0] * cy[0] * priv->calibration.diff[0][0]) +
- (float)(cx[1] * cy[1] * priv->calibration.diff[4][0]) +
- (float)(cx[0] * cy[1] * priv->calibration.diff[3][0]));
-
- dy = ((float) (cx[1] * cy[0] * priv->calibration.diff[1][1]) +
- (float)(cx[0] * cy[0] * priv->calibration.diff[0][1]) +
- (float)(cx[1] * cy[1] * priv->calibration.diff[4][1]) +
- (float)(cx[0] * cy[1] * priv->calibration.diff[3][1]));
- }
- else
- {
- /*
- lower
- */
- cx[1] = ((float) xc / (max_x/2) );
- cx[0] = (float) 1 - cx[1];
- cy[0] = ((float) yc / (max_y/2) );
- cy[1] = (float) 1 - cy[0];
-
- dx = ((float) (cx[1] * cy[0] * priv->calibration.diff[4][0]) +
- (float)(cx[0] * cy[0] * priv->calibration.diff[3][0]) +
- (float)(cx[1] * cy[1] * priv->calibration.diff[7][0]) +
- (float)(cx[0] * cy[1] * priv->calibration.diff[6][0]));
-
- dy = ((float) (cx[1] * cy[0] * priv->calibration.diff[4][1]) +
- (float)(cx[0] * cy[0] * priv->calibration.diff[3][1]) +
- (float)(cx[1] * cy[1] * priv->calibration.diff[7][1]) +
- (float)(cx[0] * cy[1] * priv->calibration.diff[6][1]));
- }
+ cx[1] = ((float) xc / (max_x/2) );
+ cx[0] = (float) 1 - cx[1];
+ cy[0] = ((float) yc / (max_y/2) );
+ cy[1] = (float) 1 - cy[0];
+
+ dx = ((float) (cx[1] * cy[0] * priv->calibration.diff[4][0]) +
+ (float)(cx[0] * cy[0] * priv->calibration.diff[3][0]) +
+ (float)(cx[1] * cy[1] * priv->calibration.diff[7][0]) +
+ (float)(cx[0] * cy[1] * priv->calibration.diff[6][0]));
+
+ dy = ((float) (cx[1] * cy[0] * priv->calibration.diff[4][1]) +
+ (float)(cx[0] * cy[0] * priv->calibration.diff[3][1]) +
+ (float)(cx[1] * cy[1] * priv->calibration.diff[7][1]) +
+ (float)(cx[0] * cy[1] * priv->calibration.diff[6][1]));
+ }
+ }
+ else
+ {
+ /*
+ right
+ */
+ if (yc>(max_y/2))
+ {
+ /*
+ upper
+ */
+ cx[1] = ((float) (xc-(max_x/2)) / (max_x/2) );
+ cx[0] = (float)1 - cx[1];
+ cy[0] = ((float) (yc-(max_y/2)) / (max_y/2) );
+ cy[1] = (float)1 - cy[0];
+
+ dx = ((float) (cx[1] * cy[0] * priv->calibration.diff[2][0]) +
+ (float)(cx[0] * cy[0] * priv->calibration.diff[1][0]) +
+ (float)(cx[1] * cy[1] * priv->calibration.diff[5][0]) +
+ (float)(cx[0] * cy[1] * priv->calibration.diff[4][0]));
+
+ dy = ((float) (cx[1] * cy[0] * priv->calibration.diff[2][1]) +
+ (float)(cx[0] * cy[0] * priv->calibration.diff[1][1]) +
+ (float)(cx[1] * cy[1] * priv->calibration.diff[5][1]) +
+ (float)(cx[0] * cy[1] * priv->calibration.diff[4][1]));
}
else
{
/*
- right
+ lower
*/
- if (yc>(max_y/2))
- {
- /*
- upper
- */
- cx[1] = ((float) (xc-(max_x/2)) / (max_x/2) );
- cx[0] = (float)1 - cx[1];
- cy[0] = ((float) (yc-(max_y/2)) / (max_y/2) );
- cy[1] = (float)1 - cy[0];
-
- dx = ((float) (cx[1] * cy[0] * priv->calibration.diff[2][0]) +
- (float)(cx[0] * cy[0] * priv->calibration.diff[1][0]) +
- (float)(cx[1] * cy[1] * priv->calibration.diff[5][0]) +
- (float)(cx[0] * cy[1] * priv->calibration.diff[4][0]));
-
- dy = ((float) (cx[1] * cy[0] * priv->calibration.diff[2][1]) +
- (float)(cx[0] * cy[0] * priv->calibration.diff[1][1]) +
- (float)(cx[1] * cy[1] * priv->calibration.diff[5][1]) +
- (float)(cx[0] * cy[1] * priv->calibration.diff[4][1]));
- }
- else
- {
- /*
- lower
- */
- cx[1] = ((float) (xc-(max_x/2)) / (max_x/2) );
- cx[0] = (float) 1 - cx[1];
- cy[0] = ((float) yc / (max_y/2) );
- cy[1] = (float) 1 - cy[0];
-
- dx = ((float) (cx[1] * cy[0] * priv->calibration.diff[5][0]) +
- (float)(cx[0] * cy[0] * priv->calibration.diff[4][0]) +
- (float)(cx[1] * cy[1] * priv->calibration.diff[8][0]) +
- (float)(cx[0] * cy[1] * priv->calibration.diff[7][0]));
-
- dy = ((float) (cx[1] * cy[0] * priv->calibration.diff[5][1]) +
- (float)(cx[0] * cy[0] * priv->calibration.diff[4][1]) +
- (float)(cx[1] * cy[1] * priv->calibration.diff[8][1]) +
- (float)(cx[0] * cy[1] * priv->calibration.diff[7][1]));
- }
+ cx[1] = ((float) (xc-(max_x/2)) / (max_x/2) );
+ cx[0] = (float) 1 - cx[1];
+ cy[0] = ((float) yc / (max_y/2) );
+ cy[1] = (float) 1 - cy[0];
+
+ dx = ((float) (cx[1] * cy[0] * priv->calibration.diff[5][0]) +
+ (float)(cx[0] * cy[0] * priv->calibration.diff[4][0]) +
+ (float)(cx[1] * cy[1] * priv->calibration.diff[8][0]) +
+ (float)(cx[0] * cy[1] * priv->calibration.diff[7][0]));
+
+ dy = ((float) (cx[1] * cy[0] * priv->calibration.diff[5][1]) +
+ (float)(cx[0] * cy[0] * priv->calibration.diff[4][1]) +
+ (float)(cx[1] * cy[1] * priv->calibration.diff[8][1]) +
+ (float)(cx[0] * cy[1] * priv->calibration.diff[7][1]));
}
+ }
#ifdef EVDBG
- for (i=0; i<3; i++)
- xf86ErrorFVerb(2, "cx[%d]=%f cy[%d]=%f\n", i, cx[i]
- ,i, cy[i]);
-
- DBGOUT(2, "EVTouch2: dx=%f dy=%f\n", dx, dy);
- if (priv->pan_viewport.enabled)
- {
- DBGOUT(2, "EVTouch2: Pan Viewport Position (x/y) (%d/%d)\n",
- priv->pan_viewport.x, priv->pan_viewport.y);
- DBGOUT(2, "EVTouch2: Pan Viewport Geometry (w x h) (%d x %d)\n",
- priv->pan_viewport.width, priv->pan_viewport.height);
- }
+ for (i=0; i<3; i++)
+ xf86ErrorFVerb(2, "cx[%d]=%f cy[%d]=%f\n", i, cx[i]
+ ,i, cy[i]);
+
+ DBGOUT(2, "EVTouch2: dx=%f dy=%f\n", dx, dy);
+ if (priv->pan_viewport.enabled)
+ {
+ DBGOUT(2, "EVTouch2: Pan Viewport Position (x/y) (%d/%d)\n",
+ priv->pan_viewport.x, priv->pan_viewport.y);
+ DBGOUT(2, "EVTouch2: Pan Viewport Geometry (w x h) (%d x %d)\n",
+ priv->pan_viewport.width, priv->pan_viewport.height);
+ }
#endif
- xc = ( ((float)xc / max_x) * screen_width ) + dx;
- yc = ( ((float)yc / max_y) * screen_height) + dy;
+ xc = ( ((float)xc / max_x) * screen_width ) + dx;
+ yc = ( ((float)yc / max_y) * screen_height) + dy;
- if (priv->swap_y == TRUE)
- yc = screen_height - yc;
+ if (priv->swap_y == TRUE)
+ yc = screen_height - yc;
- if (priv->pan_viewport.enabled)
- {
- xc += priv->pan_viewport.x;
- yc += priv->pan_viewport.y;
- }
+ xc += priv->pan_viewport.x;
+ yc += priv->pan_viewport.y;
+
+ /* ususally we DON'T swap x -- but if swap_x is 1
+ => go on and swap */
+ if (priv->swap_x == TRUE)
+ xc = screen_width - xc;
- /* ususally we DON'T swap x -- but if swap_x is 1
- => go on and swap */
- if (priv->swap_x == TRUE)
- xc = screen_width - xc;
+ /* rotation mixes x and y up a bit */
+ if (priv->rotate == EVTOUCH2_ROTATE_CW)
+ {
+ tmp = xc;
+ xc = yc;
+ yc = screen_width - tmp;
+ }
+ else if (priv->rotate == EVTOUCH2_ROTATE_CCW)
+ {
+ tmp = xc;
+ xc = screen_height - yc;
+ yc = tmp;
+ }
+ else if (priv->rotate == EVTOUCH2_ROTATE_UD)
+ {
+ xc = screen_width - xc;
+ yc = screen_height - yc;
+ }
- /* rotation mixes x and y up a bit */
- if (priv->rotate == EVTOUCH2_ROTATE_CW)
- {
+ switch (rotation)
+ {
+ case RR_Rotate_0:
+ v0 = xc;
+ v1 = yc;
+ break;
+ case RR_Rotate_180:
+ v0 = screen_width - xc;
+ v1 = screen_height - yc;
+ break;
+ case RR_Rotate_90:
tmp = xc;
- xc = yc;
- yc = screen_width - tmp;
- }
- else if (priv->rotate == EVTOUCH2_ROTATE_CCW)
- {
+ v0 = screen_height - yc;
+ v1 = tmp;
+ break;
+ case RR_Rotate_270:
tmp = xc;
- xc = screen_height - yc;
- yc = tmp;
- }
- else if (priv->rotate == EVTOUCH2_ROTATE_UD)
- {
- xc = screen_width - xc;
- yc = screen_height - yc;
- }
-
- switch (rotation)
- {
- case RR_Rotate_0:
- v0 = xc;
- v1 = yc;
- break;
- case RR_Rotate_180:
- v0 = screen_width - xc;
- v1 = screen_height - yc;
- break;
- case RR_Rotate_90:
- tmp = xc;
- v0 = screen_height - yc;
- v1 = tmp;
- break;
- case RR_Rotate_270:
- tmp = xc;
- v0 = yc;
- v1 = screen_width - tmp;
- break;
- default:
- break;
- }
+ v0 = yc;
+ v1 = screen_width - tmp;
+ break;
+ default:
+ break;
}
DBGOUT(2, "EVTouch2: FINAL: v0=%d v1=%d\n", v0, v1);
@@ -1688,6 +1683,9 @@ EVTouch2SetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
if (!checkonly)
{
+ char filename[256];
+
+ snprintf(filename, 256, "/dev/evtouch2_calibrate_%d", dev->id);
priv->calibration.enabled = *((CARD8*)val->data);
if (priv->calibration.fifo > 0)
@@ -1695,15 +1693,21 @@ EVTouch2SetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
close (priv->calibration.fifo);
priv->calibration.fifo = -1;
}
+ unlink(filename);
if (priv->calibration.enabled)
{
- char filename[256];
- snprintf(filename, 256, "/tmp/evtouch2_calibrate_%d", dev->id);
+ if (mkfifo(filename, 0666) < 0)
+ {
+ xf86ErrorFVerb(2, "create FIFO FAILED : %s\n",strerror(errno));
+ priv->calibration.enabled = FALSE;
+ return !Success;
+ }
+ chmod (filename, 0666);
priv->calibration.fifo = open(filename, O_RDWR, 0);
if (priv->calibration.fifo < 0)
{
- xf86ErrorFVerb(2, "open FIFO FAILED\n");
+ xf86ErrorFVerb(2, "open FIFO FAILED : %s\n",strerror(errno));
priv->calibration.enabled = FALSE;
return !Success;
}
@@ -1726,8 +1730,12 @@ EVTouch2SetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
priv->calibration.enabled = FALSE;
if (priv->calibration.fifo > 0)
{
+ char filename[256];
+
close(priv->calibration.fifo);
priv->calibration.fifo = -1;
+ snprintf(filename, 256, "/dev/evtouch2_calibrate_%d", dev->id);
+ unlink(filename);
}
}
}
@@ -1749,8 +1757,12 @@ EVTouch2SetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
priv->calibration.enabled = FALSE;
if (priv->calibration.fifo > 0)
{
+ char filename[256];
+
close(priv->calibration.fifo);
priv->calibration.fifo = -1;
+ snprintf(filename, 256, "/dev/evtouch2_calibrate_%d", dev->id);
+ unlink(filename);
}
}
}