2 * Copyright (c) 2009 Tias Guns
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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
23 #include "calibrator/Evdev.hpp"
24 #include "calibrator/EvdevTester.hpp"
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)
31 //printf("Starting test driver\n");
34 bool CalibratorEvdevTester::finish_data(const XYinfo axis)
41 XYinfo CalibratorEvdevTester::emulate_driver(const XYinfo& raw, bool useNewAxis, const XYinfo& screen, const XYinfo& device) {
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);
54 XYinfo result(mins[0], maxs[0], mins[1], maxs[1]);
57 // the last step is usually done by the X server,
58 // or transparently somewhere on the way
59 result.do_xf86ScaleAxis(screen, device);
64 void CalibratorEvdevTester::evdev_270_processvaluator(const XYinfo& devAxis, const XYinfo& axis, int* vals)
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};
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
76 * All valuator_mask_isset() test can be skipped here:
77 * its a requirement to have both X and Y coordinates
81 // if (pEvdev->swap_axes) {
83 int swapped_isset[2] = {0, 0};
84 int swapped_values[2];
86 for(i = 0; i <= 1; i++) {
87 //if (valuator_mask_isset(pEvdev->vals, i)) {
88 swapped_isset[1 - i] = 1;
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.
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],
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];
115 // valuator_mask_unset(pEvdev->vals, i);
119 for (i = 0; i <= 1; i++) {
124 //if (!valuator_mask_isset(pEvdev->vals, i))
127 //val = valuator_mask_get(pEvdev->vals, i);
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;
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;
142 //if (pEvdev->flags & EVDEV_CALIBRATED)
144 //val = xf86ScaleAxis(val, pEvdev->absinfo[i].maximum,
145 // pEvdev->absinfo[i].minimum, calib_max,
147 val = xf86ScaleAxis(val, absinfo_max[i],
148 absinfo_min[i], calib_max,
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 +
158 //valuator_mask_set(pEvdev->vals, i, val);