• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A generic touchscreen calibration program for X.Org


Commit MetaInfo

Revision9b8708970b199397b9af49ce5f2e4efeed6365dd (tree)
Zeit2010-09-13 00:11:46
AutorTias Guns <tias@ulys...>
CommiterTias Guns

Log Message

add --output-type option to select output type (default: auto, automatically selects best option)

Ändern Zusammenfassung

Diff

--- a/src/calibrator.cpp
+++ b/src/calibrator.cpp
@@ -30,8 +30,8 @@
3030 #include "calibrator.hh"
3131
3232 Calibrator::Calibrator(const char* const device_name0, const XYinfo& axys0,
33- const bool verbose0, const int thr_misclick, const int thr_doubleclick)
34- : device_name(device_name0), old_axys(axys0), verbose(verbose0), num_clicks(0), threshold_doubleclick(thr_doubleclick), threshold_misclick(thr_misclick)
33+ const bool verbose0, const int thr_misclick, const int thr_doubleclick, const OutputType output_type0)
34+ : device_name(device_name0), old_axys(axys0), verbose(verbose0), num_clicks(0), threshold_doubleclick(thr_doubleclick), threshold_misclick(thr_misclick), output_type(output_type0)
3535 {
3636 }
3737
--- a/src/calibrator.hh
+++ b/src/calibrator.hh
@@ -34,7 +34,7 @@ public:
3434 * if the touchscreen is not of the type it supports
3535 */
3636 Calibrator(const char* const device_name, const XYinfo& axys,
37- const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0);
37+ const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0, const OutputType output_type=OUTYPE_AUTO);
3838 ~Calibrator() {}
3939
4040 // set the doubleclick treshold
@@ -82,6 +82,9 @@ protected:
8282 // Set to zero if you don't want this check
8383 int threshold_misclick;
8484
85+ // Type of output
86+ OutputType output_type;
87+
8588 // Check whether the given name is a sysfs device name
8689 bool is_sysfs_name(const char* name);
8790
--- a/src/calibrator/calibratorEvdev.cpp
+++ b/src/calibrator/calibratorEvdev.cpp
@@ -48,7 +48,8 @@ private:
4848 int old_swap_xy;
4949 public:
5050 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+ XID device_id=(XID)-1, const int thr_misclick=0, const int thr_doubleclick=0,
52+ const OutputType output_type=OUTYPE_AUTO);
5253 ~CalibratorEvdev();
5354
5455 virtual bool finish_data(const XYinfo new_axys, int swap_xy);
@@ -65,8 +66,8 @@ protected:
6566 bool output_xinput(const XYinfo new_axys, int swap_xy, int new_swap_xy);
6667 };
6768
68-CalibratorEvdev::CalibratorEvdev(const char* const device_name0, const XYinfo& axys0, const bool verbose0, XID device_id, const int thr_misclick, const int thr_doubleclick)
69- : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick), old_swap_xy(0)
69+CalibratorEvdev::CalibratorEvdev(const char* const device_name0, const XYinfo& axys0, const bool verbose0, XID device_id, const int thr_misclick, const int thr_doubleclick, const OutputType output_type)
70+ : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick, output_type), old_swap_xy(0)
7071 {
7172 // init
7273 display = XOpenDisplay(NULL);
@@ -218,11 +219,24 @@ bool CalibratorEvdev::finish_data(const XYinfo new_axys, int swap_xy)
218219
219220
220221 printf("\n\n--> Making the calibration permanent <--\n");
221- // xorg.conf.d or alternatively xinput commands
222- if (has_xorgconfd_support()) {
223- success &= output_xorgconfd(new_axys, swap_xy, new_swap_xy);
224- } else {
225- success &= output_xinput(new_axys, swap_xy, new_swap_xy);
222+ switch (output_type) {
223+ case OUTYPE_AUTO:
224+ // xorg.conf.d or alternatively xinput commands
225+ if (has_xorgconfd_support()) {
226+ success &= output_xorgconfd(new_axys, swap_xy, new_swap_xy);
227+ } else {
228+ success &= output_xinput(new_axys, swap_xy, new_swap_xy);
229+ }
230+ break;
231+ case OUTYPE_XORGCONFD:
232+ success &= output_xorgconfd(new_axys, swap_xy, new_swap_xy);
233+ break;
234+ case OUTYPE_XINPUT:
235+ success &= output_xinput(new_axys, swap_xy, new_swap_xy);
236+ break;
237+ default:
238+ fprintf(stderr, "ERROR: Evdev Calibrator does not support the supplied --output-type\n");
239+ success = false;
226240 }
227241
228242 return success;
--- a/src/calibrator/calibratorUsbtouchscreen.cpp
+++ b/src/calibrator/calibratorUsbtouchscreen.cpp
@@ -52,7 +52,8 @@ class CalibratorUsbtouchscreen: public Calibrator
5252 {
5353 public:
5454 CalibratorUsbtouchscreen(const char* const device_name, const XYinfo& axys,
55- const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0);
55+ const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0,
56+ const OutputType output_type=OUTYPE_AUTO);
5657 ~CalibratorUsbtouchscreen();
5758
5859 virtual bool finish_data(const XYinfo new_axys, int swap_xy);
@@ -133,8 +134,8 @@ protected:
133134 }
134135 };
135136
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+CalibratorUsbtouchscreen::CalibratorUsbtouchscreen(const char* const device_name0, const XYinfo& axys0, const bool verbose0, const int thr_misclick, const int thr_doubleclick, const OutputType output_type)
138+ : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick, output_type)
138139 {
139140 if (strcmp(device_name, "Usbtouchscreen") != 0)
140141 throw WrongCalibratorException("Not a usbtouchscreen device");
@@ -164,6 +165,11 @@ CalibratorUsbtouchscreen::~CalibratorUsbtouchscreen()
164165
165166 bool CalibratorUsbtouchscreen::finish_data(const XYinfo new_axys, int swap_xy)
166167 {
168+ if (output_type != OUTYPE_AUTO) {
169+ fprintf(stderr, "ERROR: Usbtouchscreen Calibrator does not support the supplied --output-type\n");
170+ return false;
171+ }
172+
167173 // New ranges
168174 const int range_x = (new_axys.x_max - new_axys.x_min);
169175 const int range_y = (new_axys.y_max - new_axys.y_min);
--- a/src/calibrator/calibratorXorgPrint.cpp
+++ b/src/calibrator/calibratorXorgPrint.cpp
@@ -28,7 +28,8 @@ class CalibratorXorgPrint: public Calibrator
2828 {
2929 public:
3030 CalibratorXorgPrint(const char* const device_name, const XYinfo& axys,
31- const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0);
31+ const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0,
32+ const OutputType output_type=OUTYPE_AUTO);
3233
3334 virtual bool finish_data(const XYinfo new_axys, int swap_xy);
3435 protected:
@@ -36,8 +37,8 @@ protected:
3637 bool output_hal(const XYinfo new_axys, int swap_xy, int new_swap_xy);
3738 };
3839
39-CalibratorXorgPrint::CalibratorXorgPrint(const char* const device_name0, const XYinfo& axys0, const bool verbose0, const int thr_misclick, const int thr_doubleclick)
40- : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick)
40+CalibratorXorgPrint::CalibratorXorgPrint(const char* const device_name0, const XYinfo& axys0, const bool verbose0, const int thr_misclick, const int thr_doubleclick, const OutputType output_type)
41+ : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick, output_type)
4142 {
4243 printf("Calibrating standard Xorg driver \"%s\"\n", device_name);
4344 printf("\tcurrent calibration values: min_x=%d, max_x=%d and min_y=%d, max_y=%d\n",
@@ -54,11 +55,24 @@ bool CalibratorXorgPrint::finish_data(const XYinfo new_axys, int swap_xy)
5455 int new_swap_xy = swap_xy;
5556
5657 printf("\n\n--> Making the calibration permanent <--\n");
57- // xorg.conf.d or alternatively hal config
58- if (has_xorgconfd_support()) {
59- success &= output_xorgconfd(new_axys, swap_xy, new_swap_xy);
60- } else {
61- success &= output_hal(new_axys, swap_xy, new_swap_xy);
58+ switch (output_type) {
59+ case OUTYPE_AUTO:
60+ // xorg.conf.d or alternatively hal config
61+ if (has_xorgconfd_support()) {
62+ success &= output_xorgconfd(new_axys, swap_xy, new_swap_xy);
63+ } else {
64+ success &= output_hal(new_axys, swap_xy, new_swap_xy);
65+ }
66+ break;
67+ case OUTYPE_XORGCONFD:
68+ success &= output_xorgconfd(new_axys, swap_xy, new_swap_xy);
69+ break;
70+ case OUTYPE_HAL:
71+ success &= output_hal(new_axys, swap_xy, new_swap_xy);
72+ break;
73+ default:
74+ fprintf(stderr, "ERROR: XorgPrint Calibrator does not support the supplied --output-type\n");
75+ success = false;
6276 }
6377
6478 return success;
--- a/src/main_common.hpp
+++ b/src/main_common.hpp
@@ -64,6 +64,14 @@ enum {
6464 LR = 3 // Lower-right
6565 };
6666
67+// Output types
68+enum OutputType {
69+ OUTYPE_AUTO,
70+ OUTYPE_XORGCONFD,
71+ OUTYPE_HAL,
72+ OUTYPE_XINPUT
73+};
74+
6775 // struct to hold min/max info of the X and Y axis
6876 struct XYinfo {
6977 int x_min;
@@ -222,7 +230,7 @@ int find_device(const char* pre_device, bool verbose, bool list_devices,
222230
223231 static void usage(char* cmd, unsigned thr_misclick)
224232 {
225- fprintf(stderr, "Usage: %s [-h|--help] [-v|--verbose] [--list] [--device <device name or id>] [--precalib <minx> <maxx> <miny> <maxy>] [--misclick <nr of pixels>] [--fake]\n", cmd);
233+ fprintf(stderr, "Usage: %s [-h|--help] [-v|--verbose] [--list] [--device <device name or id>] [--precalib <minx> <maxx> <miny> <maxy>] [--misclick <nr of pixels>] [--output-type <auto|xorg.conf.d|hal|xinput>] [--fake]\n", cmd);
226234 fprintf(stderr, "\t-h, --help: print this help message\n");
227235 fprintf(stderr, "\t-v, --verbose: print debug messages during the process\n");
228236 fprintf(stderr, "\t--list: list calibratable input devices and quit\n");
@@ -230,6 +238,7 @@ static void usage(char* cmd, unsigned thr_misclick)
230238 fprintf(stderr, "\t--precalib: manually provide the current calibration setting (eg. the values in xorg.conf)\n");
231239 fprintf(stderr, "\t--misclick: set the misclick threshold (0=off, default: %i pixels)\n",
232240 thr_misclick);
241+ fprintf(stderr, "\t--output-type <auto|xorg.conf.d|hal|xinput>: type of config to ouput (auto=automatically detect, default: auto)\n");
233242 fprintf(stderr, "\t--fake: emulate a fake device (for testing purposes)\n");
234243 }
235244
@@ -244,6 +253,7 @@ Calibrator* main_common(int argc, char** argv)
244253 const char* pre_device = NULL;
245254 unsigned thr_misclick = 15;
246255 unsigned thr_doubleclick = 7;
256+ OutputType output_type = OUTYPE_AUTO;
247257
248258 // parse input
249259 if (argc > 1) {
@@ -302,6 +312,30 @@ Calibrator* main_common(int argc, char** argv)
302312 }
303313 } else
304314
315+ // Get output type ?
316+ if (strcmp("--output-type", argv[i]) == 0) {
317+ if (argc > i+1) {
318+ i++; // eat it or exit
319+ if (strcmp("auto", argv[i]) == 0)
320+ output_type = OUTYPE_AUTO;
321+ else if (strcmp("xorg.conf.d", argv[i]) == 0)
322+ output_type = OUTYPE_XORGCONFD;
323+ else if (strcmp("hal", argv[i]) == 0)
324+ output_type = OUTYPE_HAL;
325+ else if (strcmp("xinput", argv[i]) == 0)
326+ output_type = OUTYPE_XINPUT;
327+ else {
328+ fprintf(stderr, "Error: --output-type needs one of auto|xorg.conf.d|hal|xinput.\n\n");
329+ usage(argv[0], thr_misclick);
330+ exit(1);
331+ }
332+ } else {
333+ fprintf(stderr, "Error: --output-type needs one argument.\n\n");
334+ usage(argv[0], thr_misclick);
335+ exit(1);
336+ }
337+ } else
338+
305339 // Fake calibratable device ?
306340 if (strcmp("--fake", argv[i]) == 0) {
307341 fake = true;
@@ -379,7 +413,7 @@ Calibrator* main_common(int argc, char** argv)
379413 try {
380414 // try Usbtouchscreen driver
381415 return new CalibratorUsbtouchscreen(device_name, device_axys,
382- verbose, thr_misclick, thr_doubleclick);
416+ verbose, thr_misclick, thr_doubleclick, output_type);
383417
384418 } catch(WrongCalibratorException& x) {
385419 if (verbose)
@@ -389,7 +423,7 @@ Calibrator* main_common(int argc, char** argv)
389423 try {
390424 // next, try Evdev driver (with XID)
391425 return new CalibratorEvdev(device_name, device_axys, verbose, device_id,
392- thr_misclick, thr_doubleclick);
426+ thr_misclick, thr_doubleclick, output_type);
393427
394428 } catch(WrongCalibratorException& x) {
395429 if (verbose)
@@ -398,5 +432,5 @@ Calibrator* main_common(int argc, char** argv)
398432
399433 // lastly, presume a standard Xorg driver (evtouch, mutouch, ...)
400434 return new CalibratorXorgPrint(device_name, device_axys,
401- verbose, thr_misclick, thr_doubleclick);
435+ verbose, thr_misclick, thr_doubleclick, output_type);
402436 }