A generic touchscreen calibration program for X.Org
Revisão | 093054d088f47efc241c5752d5070a028ecbe849 (tree) |
---|---|
Hora | 2012-06-22 15:34:50 |
Autor | Tias Guns <tias@ulys...> |
Commiter | Tias Guns |
EvdevTester with evdev 2.7.0 emulation code
@@ -51,7 +51,7 @@ xinput_calibrator_CXXFLAGS = $(XINPUT_CFLAGS) $(GTKMM_CFLAGS) $(AM_CXXFLAGS) | ||
51 | 51 | xinput_calibrator_LDFLAGS = -Wl,--as-needed |
52 | 52 | endif |
53 | 53 | |
54 | -tester_SOURCES = tester.cpp calibrator.cpp calibrator/Tester.cpp | |
54 | +tester_SOURCES = tester.cpp calibrator.cpp calibrator/Tester.cpp calibrator/Evdev.cpp calibrator/EvdevTester.cpp | |
55 | 55 | tester_LDADD = $(XINPUT_LIBS) $(XRANDR_LIBS) $(X11_LIBS) |
56 | 56 | tester_CXXFLAGS = $(XINPUT_CFLAGS) $(X11_CFLAGS) $(XRANDR_CFLAGS) $(AM_CXXFLAGS) |
57 | 57 |
@@ -160,6 +160,14 @@ CalibratorEvdev::CalibratorEvdev(const char* const device_name0, | ||
160 | 160 | #endif // HAVE_XI_PROP |
161 | 161 | |
162 | 162 | } |
163 | +// protected pass-through constructor for subclasses | |
164 | +CalibratorEvdev::CalibratorEvdev(const char* const device_name0, | |
165 | + const XYinfo& axys0, | |
166 | + const int thr_misclick, | |
167 | + const int thr_doubleclick, | |
168 | + const OutputType output_type, | |
169 | + const char* geometry) | |
170 | + : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry) { } | |
163 | 171 | |
164 | 172 | // Destructor |
165 | 173 | CalibratorEvdev::~CalibratorEvdev () { |
@@ -38,10 +38,24 @@ private: | ||
38 | 38 | XDeviceInfo *devInfo; |
39 | 39 | XDevice *dev; |
40 | 40 | |
41 | +protected: | |
42 | + // protected constructor: should only be used by subclasses! | |
43 | + // (pass-through to Calibrator) | |
44 | + CalibratorEvdev(const char* const device_name, | |
45 | + const XYinfo& axys, | |
46 | + const int thr_misclick=0, | |
47 | + const int thr_doubleclick=0, | |
48 | + const OutputType output_type=OUTYPE_AUTO, | |
49 | + const char* geometry=0); | |
50 | + | |
41 | 51 | public: |
42 | - CalibratorEvdev(const char* const device_name, const XYinfo& axys, | |
43 | - XID device_id=(XID)-1, const int thr_misclick=0, const int thr_doubleclick=0, | |
44 | - const OutputType output_type=OUTYPE_AUTO, const char* geometry=0); | |
52 | + CalibratorEvdev(const char* const device_name, | |
53 | + const XYinfo& axys, | |
54 | + XID device_id=(XID)-1, | |
55 | + const int thr_misclick=0, | |
56 | + const int thr_doubleclick=0, | |
57 | + const OutputType output_type=OUTYPE_AUTO, | |
58 | + const char* geometry=0); | |
45 | 59 | ~CalibratorEvdev(); |
46 | 60 | |
47 | 61 | virtual bool finish_data(const XYinfo new_axys); |
@@ -0,0 +1,163 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2009 Tias Guns | |
3 | + * | |
4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | + * of this software and associated documentation files (the "Software"), to deal | |
6 | + * in the Software without restriction, including without limitation the rights | |
7 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | + * copies of the Software, and to permit persons to whom the Software is | |
9 | + * furnished to do so, subject to the following conditions: | |
10 | + * | |
11 | + * The above copyright notice and this permission notice shall be included in | |
12 | + * all copies or substantial portions of the Software. | |
13 | + * | |
14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
20 | + * THE SOFTWARE. | |
21 | + */ | |
22 | + | |
23 | +#include "calibrator/Evdev.hpp" | |
24 | +#include "calibrator/EvdevTester.hpp" | |
25 | + | |
26 | +#include <cstdio> | |
27 | + | |
28 | +CalibratorEvdevTester::CalibratorEvdevTester(const char* const device_name0, const XYinfo& axys0, const int thr_misclick, const int thr_doubleclick, const OutputType output_type, const char* geometry) | |
29 | + : CalibratorEvdev(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry) | |
30 | +{ | |
31 | + //printf("Starting test driver\n"); | |
32 | +} | |
33 | + | |
34 | +bool CalibratorEvdevTester::finish_data(const XYinfo axis) | |
35 | +{ | |
36 | + new_axis = axis; | |
37 | + | |
38 | + return true; | |
39 | +} | |
40 | + | |
41 | +XYinfo CalibratorEvdevTester::emulate_driver(const XYinfo& raw, bool useNewAxis, const XYinfo& screen, const XYinfo& device) { | |
42 | + XYinfo calibAxis; | |
43 | + if (useNewAxis) | |
44 | + calibAxis = new_axis; | |
45 | + else | |
46 | + calibAxis = old_axys; | |
47 | + | |
48 | + // call evdev's code (minimally modified to fit us) | |
49 | + int mins[2] = {raw.x.min, raw.y.min}; | |
50 | + evdev_270_processvaluator(device, calibAxis, mins); | |
51 | + int maxs[2] = {raw.x.max, raw.y.max}; | |
52 | + evdev_270_processvaluator(device, calibAxis, maxs); | |
53 | + | |
54 | + XYinfo result(mins[0], maxs[0], mins[1], maxs[1]); | |
55 | + | |
56 | + | |
57 | + // the last step is usually done by the X server, | |
58 | + // or transparently somewhere on the way | |
59 | + result.do_xf86ScaleAxis(screen, device); | |
60 | + return result; | |
61 | +} | |
62 | + | |
63 | +// return in 'vals' | |
64 | +void CalibratorEvdevTester::evdev_270_processvaluator(const XYinfo& devAxis, const XYinfo& axis, int* vals) | |
65 | +{ | |
66 | + //int vals[2] = {valX, valY}; | |
67 | + int absinfo_min[2] = {devAxis.x.min, devAxis.y.min}; | |
68 | + int absinfo_max[2] = {devAxis.x.max, devAxis.y.max}; | |
69 | + | |
70 | + /* | |
71 | + * Code from xf86-input-evdev: src/evdev.c | |
72 | + * function: static void EvdevProcessValuators(InputInfoPtr pInfo) | |
73 | + * last change: 2011-12-14 'Fix absolute events with swapped axes' | |
74 | + * last change id: 8d6dfd13b0c4177305555294218e366a6cddc83f | |
75 | + * | |
76 | + * All valuator_mask_isset() test can be skipped here: | |
77 | + * its a requirement to have both X and Y coordinates | |
78 | + */ | |
79 | + int i; | |
80 | + | |
81 | + // if (pEvdev->swap_axes) { | |
82 | + if (axis.swap_xy) { | |
83 | + int swapped_isset[2] = {0, 0}; | |
84 | + int swapped_values[2]; | |
85 | + | |
86 | + for(i = 0; i <= 1; i++) { | |
87 | + //if (valuator_mask_isset(pEvdev->vals, i)) { | |
88 | + swapped_isset[1 - i] = 1; | |
89 | + | |
90 | + /* in all sensible cases, the absinfo is the same for the | |
91 | + * X and Y axis. In that case, the below simplifies to: | |
92 | + * wapped_values[1 - i] = vals[i] | |
93 | + * However, the code below accounts for the oddball | |
94 | + * device for which this would not be the case. | |
95 | + */ | |
96 | + swapped_values[1 - i] = | |
97 | + //xf86ScaleAxis(valuator_mask_get(pEvdev->vals, i), | |
98 | + // pEvdev->absinfo[1 - i].maximum, | |
99 | + // pEvdev->absinfo[1 - i].minimum, | |
100 | + // pEvdev->absinfo[i].maximum, | |
101 | + // pEvdev->absinfo[i].minimum); | |
102 | + xf86ScaleAxis(vals[i], | |
103 | + absinfo_max[1 - i], | |
104 | + absinfo_min[1 - i], | |
105 | + absinfo_max[i], | |
106 | + absinfo_min[i]); | |
107 | + //} | |
108 | + } | |
109 | + | |
110 | + for (i = 0; i <= 1; i++) { | |
111 | + if (swapped_isset[i]) | |
112 | + //valuator_mask_set(pEvdev->vals, i, swapped_values[i]); | |
113 | + vals[i] = swapped_values[i]; | |
114 | + //else | |
115 | + // valuator_mask_unset(pEvdev->vals, i); | |
116 | + } | |
117 | + } | |
118 | + | |
119 | + for (i = 0; i <= 1; i++) { | |
120 | + int val; | |
121 | + int calib_min; | |
122 | + int calib_max; | |
123 | + | |
124 | + //if (!valuator_mask_isset(pEvdev->vals, i)) | |
125 | + // continue; | |
126 | + | |
127 | + //val = valuator_mask_get(pEvdev->vals, i); | |
128 | + val = vals[i]; | |
129 | + | |
130 | + if (i == 0) { | |
131 | + //calib_min = pEvdev->calibration.min_x; | |
132 | + calib_min = axis.x.min; | |
133 | + //calib_max = pEvdev->calibration.max_x; | |
134 | + calib_max = axis.x.max; | |
135 | + } else { | |
136 | + //calib_min = pEvdev->calibration.min_y; | |
137 | + calib_min = axis.y.min; | |
138 | + //calib_max = pEvdev->calibration.max_y; | |
139 | + calib_max = axis.y.max; | |
140 | + } | |
141 | + | |
142 | + //if (pEvdev->flags & EVDEV_CALIBRATED) | |
143 | + if (true) | |
144 | + //val = xf86ScaleAxis(val, pEvdev->absinfo[i].maximum, | |
145 | + // pEvdev->absinfo[i].minimum, calib_max, | |
146 | + // calib_min); | |
147 | + val = xf86ScaleAxis(val, absinfo_max[i], | |
148 | + absinfo_min[i], calib_max, | |
149 | + calib_min); | |
150 | + | |
151 | + //if ((i == 0 && pEvdev->invert_x) || (i == 1 && pEvdev->invert_y)) | |
152 | + if ((i == 0 && axis.x.invert) || (i == 1 && axis.y.invert)) | |
153 | + //val = (pEvdev->absinfo[i].maximum - val + | |
154 | + // pEvdev->absinfo[i].minimum); | |
155 | + val = (absinfo_max[i] - val + | |
156 | + absinfo_min[i]); | |
157 | + | |
158 | + //valuator_mask_set(pEvdev->vals, i, val); | |
159 | + vals[i] = val; | |
160 | + } | |
161 | + | |
162 | + //return vals; | |
163 | +} |
@@ -0,0 +1,65 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2009 Tias Guns | |
3 | + * | |
4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | + * of this software and associated documentation files (the "Software"), to deal | |
6 | + * in the Software without restriction, including without limitation the rights | |
7 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | + * copies of the Software, and to permit persons to whom the Software is | |
9 | + * furnished to do so, subject to the following conditions: | |
10 | + * | |
11 | + * The above copyright notice and this permission notice shall be included in | |
12 | + * all copies or substantial portions of the Software. | |
13 | + * | |
14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
20 | + * THE SOFTWARE. | |
21 | + */ | |
22 | + | |
23 | +#ifndef CALIBRATOR_EVDEV_TESTER_HPP | |
24 | +#define CALIBRATOR_EVDEV_TESTER_HPP | |
25 | + | |
26 | +#include "calibrator.hh" | |
27 | +#include "calibrator/Evdev.hpp" | |
28 | + | |
29 | +/*************************************** | |
30 | + * Class for testing the evdev | |
31 | + * calibration routine | |
32 | + ***************************************/ | |
33 | +class CalibratorEvdevTester: public CalibratorTesterInterface, public CalibratorEvdev | |
34 | +{ | |
35 | +protected: | |
36 | + // store the new axis for use in driver emulation | |
37 | + XYinfo new_axis; | |
38 | + | |
39 | +public: | |
40 | + CalibratorEvdevTester(const char* const device_name, const XYinfo& axys, | |
41 | + const int thr_misclick=0, const int thr_doubleclick=0, | |
42 | + const OutputType output_type=OUTYPE_AUTO, const char* geometry=0); | |
43 | + | |
44 | + virtual bool finish_data(const XYinfo new_axis); | |
45 | + | |
46 | + // emulate the driver processing the coordinates in 'raw' | |
47 | + virtual XYinfo emulate_driver(const XYinfo& raw, bool useNewAxis, const XYinfo& screen, const XYinfo& device); | |
48 | + | |
49 | + virtual void new_axis_print() { | |
50 | + new_axis.print(); | |
51 | + } | |
52 | + | |
53 | + //* From CalibratorEvdev | |
54 | + virtual bool add_click(int x, int y) { | |
55 | + return CalibratorEvdev::add_click(x, y); | |
56 | + } | |
57 | + virtual bool finish(int width, int height) { | |
58 | + return CalibratorEvdev::finish(width, height); | |
59 | + } | |
60 | + | |
61 | + // evdev 2.7.0 EvdevProcessValuators code, modified to fit us | |
62 | + void evdev_270_processvaluator(const XYinfo& devAxis, const XYinfo& axis, int* vals); | |
63 | +}; | |
64 | + | |
65 | +#endif |
@@ -2,4 +2,5 @@ EXTRA_DIST = \ | ||
2 | 2 | Evdev.cpp \ |
3 | 3 | Usbtouchscreen.cpp \ |
4 | 4 | XorgPrint.cpp \ |
5 | - Tester.cpp | |
5 | + Tester.cpp \ | |
6 | + EvdevTester.cpp |
@@ -4,6 +4,7 @@ | ||
4 | 4 | |
5 | 5 | #include "calibrator.hh" |
6 | 6 | #include "calibrator/Tester.hpp" |
7 | +#include "calibrator/EvdevTester.hpp" | |
7 | 8 | |
8 | 9 | int main() { |
9 | 10 | // screen dimensions |
@@ -65,7 +66,8 @@ int main() { | ||
65 | 66 | XYinfo raw(raw_coords[c]); |
66 | 67 | //printf("Raw: "); raw.print(); |
67 | 68 | |
68 | - CalibratorTesterInterface* calib = new CalibratorTester("Tester", old_axis); | |
69 | + // DO NOT COMMIT THIS | |
70 | + CalibratorTesterInterface* calib = new CalibratorEvdevTester("Tester", old_axis); | |
69 | 71 | |
70 | 72 | // clicked from raw |
71 | 73 | XYinfo clicked = calib->emulate_driver(raw, false, screen_res, dev_res);// false=old_axis |