A generic touchscreen calibration program for X.Org
修订版 | 898c61f1aee6aac352d49fdb25342a7bc61deb04 (tree) |
---|---|
时间 | 2010-07-07 05:16:18 |
作者 | Tias Guns <tias@ulys...> |
Commiter | Tias Guns |
support common setting of thresholds for doubleclick and misclick detection
@@ -23,8 +23,9 @@ | ||
23 | 23 | #include <algorithm> |
24 | 24 | #include "calibrator.hh" |
25 | 25 | |
26 | -Calibrator::Calibrator(const char* const device_name0, const XYinfo& axys0, const bool verbose0) | |
27 | - : device_name(device_name0), old_axys(axys0), verbose(verbose0), num_clicks(0), threshold_doubleclick(7), threshold_misclick(15) | |
26 | +Calibrator::Calibrator(const char* const device_name0, const XYinfo& axys0, | |
27 | + const bool verbose0, const int thr_misclick, const int thr_doubleclick) | |
28 | + : device_name(device_name0), old_axys(axys0), verbose(verbose0), num_clicks(0), threshold_doubleclick(thr_doubleclick), threshold_misclick(thr_misclick) | |
28 | 29 | { |
29 | 30 | } |
30 | 31 |
@@ -66,7 +67,7 @@ bool Calibrator::add_click(int x, int y) | ||
66 | 67 | bool misclick = true; |
67 | 68 | |
68 | 69 | if (num_clicks == 1) { |
69 | - // check that along one axis of first pointV | |
70 | + // check that along one axis of first point | |
70 | 71 | if (along_axis(x,clicked_x[0],clicked_y[0]) || |
71 | 72 | along_axis(y,clicked_x[0],clicked_y[0])) |
72 | 73 | misclick = false; |
@@ -88,7 +89,12 @@ bool Calibrator::add_click(int x, int y) | ||
88 | 89 | |
89 | 90 | if (misclick) { |
90 | 91 | if (verbose) { |
91 | - printf("DEBUG: Mis-click detected, click %i (X=%i, Y=%i) not aligned with click 0 (X=%i, Y=%i) (threshold=%i)\n", num_clicks, x, y, clicked_x[0], clicked_y[0], threshold_misclick); | |
92 | + if (num_clicks == 1) | |
93 | + printf("DEBUG: Mis-click detected, click %i (X=%i, Y=%i) not aligned with click 0 (X=%i, Y=%i) (threshold=%i)\n", num_clicks, x, y, clicked_x[0], clicked_y[0], threshold_misclick); | |
94 | + else if (num_clicks == 2) | |
95 | + printf("DEBUG: Mis-click detected, click %i (X=%i, Y=%i) not aligned with click 0 (X=%i, Y=%i) or click 1 (X=%i, Y=%i) (threshold=%i)\n", num_clicks, x, y, clicked_x[0], clicked_y[0], clicked_x[1], clicked_y[1], threshold_misclick); | |
96 | + else if (num_clicks == 3) | |
97 | + printf("DEBUG: Mis-click detected, click %i (X=%i, Y=%i) not aligned with click 1 (X=%i, Y=%i) or click 2 (X=%i, Y=%i) (threshold=%i)\n", num_clicks, x, y, clicked_x[1], clicked_y[1], clicked_x[2], clicked_y[2], threshold_misclick); | |
92 | 98 | } |
93 | 99 | |
94 | 100 | num_clicks = 0; |
@@ -33,7 +33,8 @@ public: | ||
33 | 33 | * The constructor will throw an exception, |
34 | 34 | * if the touchscreen is not of the type it supports |
35 | 35 | */ |
36 | - Calibrator(const char* const device_name, const XYinfo& axys, const bool verbose); | |
36 | + Calibrator(const char* const device_name, const XYinfo& axys, | |
37 | + const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0); | |
37 | 38 | ~Calibrator() {} |
38 | 39 | |
39 | 40 | // set the doubleclick treshold |
@@ -70,7 +71,8 @@ protected: | ||
70 | 71 | int threshold_doubleclick; |
71 | 72 | |
72 | 73 | // Threshold to detect mis-clicks (clicks not along axes) |
73 | - // Set to zero to ignore, lower is more precise calibration | |
74 | + // A lower value forces more precise calibration | |
75 | + // Set to zero if you don't want this check | |
74 | 76 | int threshold_misclick; |
75 | 77 | }; |
76 | 78 |
@@ -47,7 +47,8 @@ private: | ||
47 | 47 | |
48 | 48 | int old_swap_xy; |
49 | 49 | public: |
50 | - CalibratorEvdev(const char* const device_name, const XYinfo& axys, const bool verbose, XID device_id=(XID)-1); | |
50 | + CalibratorEvdev(const char* const device_name, const XYinfo& axys, const bool verbose, | |
51 | + XID device_id=(XID)-1, const int thr_misclick=0, const int thr_doubleclick=0); | |
51 | 52 | ~CalibratorEvdev(); |
52 | 53 | |
53 | 54 | virtual bool finish_data(const XYinfo new_axys, int swap_xy); |
@@ -61,8 +62,8 @@ public: | ||
61 | 62 | int xinput_do_set_prop(Display *display, Atom type, int format, int argc, char* argv[]); |
62 | 63 | }; |
63 | 64 | |
64 | -CalibratorEvdev::CalibratorEvdev(const char* const device_name0, const XYinfo& axys0, const bool verbose0, XID device_id) | |
65 | - : Calibrator(device_name0, axys0, verbose0), old_swap_xy(0) | |
65 | +CalibratorEvdev::CalibratorEvdev(const char* const device_name0, const XYinfo& axys0, const bool verbose0, XID device_id, const int thr_misclick, const int thr_doubleclick) | |
66 | + : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick), old_swap_xy(0) | |
66 | 67 | { |
67 | 68 | // init |
68 | 69 | display = XOpenDisplay(NULL); |
@@ -51,7 +51,8 @@ const char *p_swap_xy = "swap_xy"; | ||
51 | 51 | class CalibratorUsbtouchscreen: public Calibrator |
52 | 52 | { |
53 | 53 | public: |
54 | - CalibratorUsbtouchscreen(const char* const device_name, const XYinfo& axys, const bool verbose); | |
54 | + CalibratorUsbtouchscreen(const char* const device_name, const XYinfo& axys, | |
55 | + const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0); | |
55 | 56 | ~CalibratorUsbtouchscreen(); |
56 | 57 | |
57 | 58 | virtual bool finish_data(const XYinfo new_axys, int swap_xy); |
@@ -132,8 +133,8 @@ protected: | ||
132 | 133 | } |
133 | 134 | }; |
134 | 135 | |
135 | -CalibratorUsbtouchscreen::CalibratorUsbtouchscreen(const char* const device_name0, const XYinfo& axys0, const bool verbose0) | |
136 | - : Calibrator(device_name0, axys0, verbose0) | |
136 | +CalibratorUsbtouchscreen::CalibratorUsbtouchscreen(const char* const device_name0, const XYinfo& axys0, const bool verbose0, const int thr_misclick, const int thr_doubleclick) | |
137 | + : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick) | |
137 | 138 | { |
138 | 139 | if (strcmp(device_name, "Usbtouchscreen") != 0) |
139 | 140 | throw WrongCalibratorException("Not a usbtouchscreen device"); |
@@ -27,13 +27,14 @@ | ||
27 | 27 | class CalibratorXorgPrint: public Calibrator |
28 | 28 | { |
29 | 29 | public: |
30 | - CalibratorXorgPrint(const char* const device_name, const XYinfo& axys, const bool verbose); | |
30 | + CalibratorXorgPrint(const char* const device_name, const XYinfo& axys, | |
31 | + const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0); | |
31 | 32 | |
32 | 33 | virtual bool finish_data(const XYinfo new_axys, int swap_xy); |
33 | 34 | }; |
34 | 35 | |
35 | -CalibratorXorgPrint::CalibratorXorgPrint(const char* const device_name0, const XYinfo& axys0, const bool verbose0) | |
36 | - : Calibrator(device_name0, axys0, verbose0) | |
36 | +CalibratorXorgPrint::CalibratorXorgPrint(const char* const device_name0, const XYinfo& axys0, const bool verbose0, const int thr_misclick, const int thr_doubleclick) | |
37 | + : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick) | |
37 | 38 | { |
38 | 39 | printf("Calibrating standard Xorg driver \"%s\"\n", device_name); |
39 | 40 | printf("\tcurrent calibration values: min_x=%d, max_x=%d and min_y=%d, max_y=%d\n", |
@@ -240,6 +240,8 @@ Calibrator* main_common(int argc, char** argv) | ||
240 | 240 | bool precalib = false; |
241 | 241 | XYinfo pre_axys; |
242 | 242 | const char* pre_device = NULL; |
243 | + unsigned thr_misclick = 15; | |
244 | + unsigned thr_doubleclick = 7; | |
243 | 245 | |
244 | 246 | // parse input |
245 | 247 | if (argc > 1) { |
@@ -363,7 +365,8 @@ Calibrator* main_common(int argc, char** argv) | ||
363 | 365 | // Different device/driver, different ways to apply the calibration values |
364 | 366 | try { |
365 | 367 | // try Usbtouchscreen driver |
366 | - return new CalibratorUsbtouchscreen(device_name, device_axys, verbose); | |
368 | + return new CalibratorUsbtouchscreen(device_name, device_axys, | |
369 | + verbose, thr_misclick, thr_doubleclick); | |
367 | 370 | |
368 | 371 | } catch(WrongCalibratorException& x) { |
369 | 372 | if (verbose) |
@@ -372,7 +375,8 @@ Calibrator* main_common(int argc, char** argv) | ||
372 | 375 | |
373 | 376 | try { |
374 | 377 | // next, try Evdev driver (with XID) |
375 | - return new CalibratorEvdev(device_name, device_axys, verbose, device_id); | |
378 | + return new CalibratorEvdev(device_name, device_axys, verbose, device_id, | |
379 | + thr_misclick, thr_doubleclick); | |
376 | 380 | |
377 | 381 | } catch(WrongCalibratorException& x) { |
378 | 382 | if (verbose) |
@@ -380,5 +384,6 @@ Calibrator* main_common(int argc, char** argv) | ||
380 | 384 | } |
381 | 385 | |
382 | 386 | // lastly, presume a standard Xorg driver (evtouch, mutouch, ...) |
383 | - return new CalibratorXorgPrint(device_name, device_axys, verbose); | |
387 | + return new CalibratorXorgPrint(device_name, device_axys, | |
388 | + verbose, thr_misclick, thr_doubleclick); | |
384 | 389 | } |