A generic touchscreen calibration program for X.Org
Revisión | 552ff156c5a993afa8471f197beedb869054f580 (tree) |
---|---|
Tiempo | 2012-06-19 06:33:52 |
Autor | Tias Guns <tias@ulys...> |
Commiter | Tias Guns |
driver emulation implementation
@@ -30,6 +30,9 @@ | ||
30 | 30 | #include <stdio.h> |
31 | 31 | #include <vector> |
32 | 32 | |
33 | +int xf86ScaleAxis(int Cx, int to_max, int to_min, int from_max, int from_min); | |
34 | +int scaleAxis(int Cx, int to_max, int to_min, int from_max, int from_min); | |
35 | + | |
33 | 36 | /* |
34 | 37 | * Number of blocks. We partition the screen into 'num_blocks' x 'num_blocks' |
35 | 38 | * rectangles of equal size. We then ask the user to press points that are |
@@ -93,6 +96,13 @@ struct XYinfo { | ||
93 | 96 | swap_xy = !swap_xy; |
94 | 97 | } |
95 | 98 | |
99 | + void do_xf86ScaleAxis(XYinfo& to, XYinfo& from) { | |
100 | + x.min = xf86ScaleAxis(x.min, to.x.max, to.x.min, from.x.max, from.x.min); | |
101 | + x.max = xf86ScaleAxis(x.max, to.x.max, to.x.min, from.x.max, from.x.min); | |
102 | + y.min = xf86ScaleAxis(y.min, to.y.max, to.y.min, from.y.max, from.y.min); | |
103 | + y.max = xf86ScaleAxis(y.max, to.y.max, to.y.min, from.y.max, from.y.min); | |
104 | + } | |
105 | + | |
96 | 106 | void print(const char* xtra="\n") { |
97 | 107 | printf("XYinfo: x.min=%i, x.max=%i, y.min=%i, y.max=%i, swap_xy=%i, invert_x=%i, invert_y=%i%s", |
98 | 108 | x.min, x.max, y.min, y.max, swap_xy, x.invert, y.invert, xtra); |
@@ -122,9 +132,6 @@ class WrongCalibratorException : public std::invalid_argument { | ||
122 | 132 | std::invalid_argument(msg) {} |
123 | 133 | }; |
124 | 134 | |
125 | -int xf86ScaleAxis(int Cx, int to_max, int to_min, int from_max, int from_min); | |
126 | -int scaleAxis(int Cx, int to_max, int to_min, int from_max, int from_min); | |
127 | - | |
128 | 135 | /// Base class for calculating new calibration parameters |
129 | 136 | class Calibrator |
130 | 137 | { |
@@ -37,7 +37,36 @@ bool CalibratorTester::finish_data(const XYinfo axis) | ||
37 | 37 | return true; |
38 | 38 | } |
39 | 39 | |
40 | -XYinfo CalibratorTester::emulate_driver(XYinfo raw, bool useNewAxis) { | |
41 | - // filler | |
42 | - return XYinfo(0,0,0,0); | |
40 | +XYinfo CalibratorTester::emulate_driver(XYinfo& raw, bool useNewAxis, XYinfo screen, XYinfo device) { | |
41 | + XYinfo calibAxis; | |
42 | + if (useNewAxis) | |
43 | + calibAxis = new_axis; | |
44 | + else | |
45 | + calibAxis = old_axys; | |
46 | + | |
47 | + /** | |
48 | + * The most simple and intuitive calibration implementation | |
49 | + * if only all drivers sticked to this... | |
50 | + * Note that axis inversion is automatically supported | |
51 | + * by the ScaleAxis implementation (swapping max/min on | |
52 | + * one axis will result in the inversion being calculated) | |
53 | + */ | |
54 | + | |
55 | + // placeholder for the new coordinates | |
56 | + XYinfo result(raw); | |
57 | + | |
58 | + // swap coordinates if asked | |
59 | + if (calibAxis.swap_xy) { | |
60 | + result.x.min = raw.y.min; | |
61 | + result.x.max = raw.y.max; | |
62 | + result.y.min = raw.x.min; | |
63 | + result.y.max = raw.x.max; | |
64 | + } | |
65 | + | |
66 | + result.do_xf86ScaleAxis(device, calibAxis); | |
67 | + | |
68 | + // the last step is usually done by the X server, | |
69 | + // or transparently somewhere on the way | |
70 | + result.do_xf86ScaleAxis(screen, device); | |
71 | + return result; | |
43 | 72 | } |
@@ -43,7 +43,7 @@ public: | ||
43 | 43 | virtual bool finish_data(const XYinfo new_axis); |
44 | 44 | |
45 | 45 | // emulate the driver processing the coordinates in 'raw' |
46 | - XYinfo emulate_driver(XYinfo raw, bool useNewAxis); | |
46 | + XYinfo emulate_driver(XYinfo& raw, bool useNewAxis, XYinfo screen, XYinfo device); | |
47 | 47 | }; |
48 | 48 | |
49 | 49 | #endif |
@@ -35,15 +35,15 @@ int main() { | ||
35 | 35 | raw_coords.push_back( XYinfo(883, 233, 105, 783) ); |
36 | 36 | raw_coords.push_back( XYinfo(883, 233, 783, 105) ); |
37 | 37 | |
38 | - CalibratorTester calib("Tester", old_axis); | |
39 | - | |
40 | 38 | for (unsigned c=0; c != raw_coords.size(); c++) { |
39 | + CalibratorTester calib("Tester", old_axis); | |
40 | + | |
41 | 41 | XYinfo raw(raw_coords[c]); |
42 | 42 | printf("Raw: "); raw.print(); |
43 | 43 | |
44 | 44 | // clicked from raw |
45 | - XYinfo clicked = calib.emulate_driver(raw, false);//false=old_axis, screen_res, dev_res); | |
46 | - printf("Clicked: "); clicked.print(); | |
45 | + XYinfo clicked = calib.emulate_driver(raw, false, screen_res, dev_res);// false=old_axis | |
46 | + //printf("\tClicked: "); clicked.print(); | |
47 | 47 | |
48 | 48 | // emulate screen clicks |
49 | 49 | calib.add_click(clicked.x.min, clicked.y.min); |
@@ -53,7 +53,7 @@ int main() { | ||
53 | 53 | calib.finish(width, height); |
54 | 54 | |
55 | 55 | // test result |
56 | - XYinfo result = calib.emulate_driver(raw, true); // true=new_axis | |
56 | + XYinfo result = calib.emulate_driver(raw, true, screen_res, dev_res); // true=new_axis | |
57 | 57 | |
58 | 58 | if (abs(target.x.min - result.x.min) > slack || |
59 | 59 | abs(target.x.max - result.x.max) > slack || |