A generic touchscreen calibration program for X.Org
Revision | 59ffb806a423791ef615a77ad6a20d531b6bfe73 (tree) |
---|---|
Zeit | 2009-11-29 23:13:10 |
Autor | Tias <tias@kata...> |
Commiter | Tias |
Add support for providing the current calibration on the command line
(with --precalib), add help information (-h or --help).
Included a script that reads the current calibration data from lshal,
and runs the calibration program with the right --precalib data
@@ -0,0 +1,74 @@ | ||
1 | +#!/bin/sh | |
2 | +# Get running EVTOUCH calibration data from lshal | |
3 | +# (needed to recalibrate it, most easily fetchable from lshal) | |
4 | + | |
5 | +export PATH=".:$PATH" | |
6 | +#FIND="hal-find-by-property" | |
7 | +CAPAB="hal-find-by-capability" | |
8 | +GET="hal-get-property" | |
9 | +BINARY="xinput_calibrator" | |
10 | + | |
11 | +if [ "$(which $CAPAB)" = "" ]; then | |
12 | + echo "Error: Can not find executable $CAPAB" | |
13 | + exit 1 | |
14 | +fi | |
15 | +if [ "$(which $GET)" = "" ]; then | |
16 | + echo "Error: Can not find executable $GET" | |
17 | + exit 1 | |
18 | +fi | |
19 | + | |
20 | + | |
21 | +#udis=$($FIND --key input.x11_driver --string evtouch) | |
22 | +udis=$($CAPAB --capability input) | |
23 | + | |
24 | +if [ "$udis" = "" ]; then | |
25 | + echo "HAL Error: No input devices found (tested: info.capabilities 'input'))" | |
26 | + exit 1 | |
27 | +fi | |
28 | + | |
29 | + | |
30 | +echo "Trying all available input devices:" | |
31 | +# possibly multiple screens, iterate over each possibility | |
32 | +count=0 | |
33 | +cmd="" | |
34 | +for udi in $udis; do | |
35 | + name=$($GET --udi $udi --key info.product) | |
36 | + minx=$($GET --udi $udi --key input.x11_options.minx 2> /dev/null) | |
37 | + maxx=$($GET --udi $udi --key input.x11_options.maxx 2> /dev/null) | |
38 | + miny=$($GET --udi $udi --key input.x11_options.miny 2> /dev/null) | |
39 | + maxy=$($GET --udi $udi --key input.x11_options.maxy 2> /dev/null) | |
40 | + | |
41 | + # missing values ? | |
42 | + if [ "$minx" = "" ] || [ "$maxx" = "" ] || | |
43 | + [ "$miny" = "" ] || [ "$maxy" = "" ]; then | |
44 | + if [ "$minx" = "" ] && [ "$maxx" = "" ] && | |
45 | + [ "$miny" = "" ] && [ "$maxy" = "" ]; then | |
46 | + # no calibration data available | |
47 | + echo "\t'$name': no calibration data available" | |
48 | + else | |
49 | + # partial calibration data available ??? | |
50 | + echo "Error: '$name', only partial calibration data available (MinX='$minx' MaxX='$maxx' MinY='$miny' MaxY='$maxy'). All 4 current calibration values are need to recalibrate the device !" | |
51 | + fi | |
52 | + else | |
53 | + count=$((count += 1)) | |
54 | + cmd="$BINARY --precalib $minx $maxx $miny $maxy" | |
55 | + echo "\t'$name': values found, calibrate by running:" | |
56 | + echo "$cmd" | |
57 | + fi | |
58 | +done | |
59 | + | |
60 | +if [ $count -gt 1 ]; then | |
61 | + echo "Found multiple calibratable touchscreen devices, select one from above and execute the calibration program with the given parameters." | |
62 | +else | |
63 | + if [ $count -eq 0 ]; then | |
64 | + echo "Warning: No existing calibration data found, no parameters used." | |
65 | + cmd="$BINARY" | |
66 | + fi | |
67 | + | |
68 | + if [ "$(which $BINARY)" = "" ]; then | |
69 | + echo "Error: can not find calibration program ($BINARY), please run it with the above parameters yourself." | |
70 | + else | |
71 | + echo "\nRunning calibration program..." | |
72 | + $cmd | |
73 | + fi | |
74 | +fi |
@@ -282,8 +282,9 @@ public: | ||
282 | 282 | CalibratorXorgPrint::CalibratorXorgPrint (const char* drivername0, int min_x, int max_x, int min_y, int max_y) |
283 | 283 | : Calibrator (drivername0, min_x, max_x, min_y, max_y) |
284 | 284 | { |
285 | - printf ("Calibrating unknown driver \"%s\" (having min_x=%d, max_x=%d and min_y=%d, max_y=%d)\n", | |
285 | + printf ("Calibrating unknown driver \"%s\" (currently having min_x=%d, max_x=%d and min_y=%d, max_y=%d)\n", | |
286 | 286 | drivername, oldcalib_min_x, oldcalib_max_x, oldcalib_min_y, oldcalib_max_y); |
287 | + printf("\tIf the current calibration data is estimated wrong then either supply it manually with --precalib <minx> <maxx> <miny> <maxy> or run the 'get_precalib.sh' script to automatically get it from your current Xorg configuration (through hal).\n"); | |
287 | 288 | } |
288 | 289 | |
289 | 290 | void CalibratorXorgPrint::finish_data ( |
@@ -855,7 +856,7 @@ void CalibratorUsbts::finish_data ( | ||
855 | 856 | class CalibrationArea : public Gtk::DrawingArea |
856 | 857 | { |
857 | 858 | public: |
858 | - CalibrationArea (); | |
859 | + CalibrationArea (int argc, char** argv); | |
859 | 860 | |
860 | 861 | protected: |
861 | 862 | /* Helper functions */ |
@@ -873,7 +874,7 @@ protected: | ||
873 | 874 | int time_elapsed; |
874 | 875 | }; |
875 | 876 | |
876 | -CalibrationArea::CalibrationArea () | |
877 | +CalibrationArea::CalibrationArea (int argc, char** argv) | |
877 | 878 | : num_clicks (0), time_elapsed (0) |
878 | 879 | { |
879 | 880 | /* Not sure this is the right place for this, but here we go |
@@ -943,6 +944,22 @@ CalibrationArea::CalibrationArea () | ||
943 | 944 | XFreeDeviceList(slist); |
944 | 945 | XCloseDisplay(display); |
945 | 946 | |
947 | + // override min/maxX/Y from command line ? | |
948 | + if (argc > 1) { | |
949 | + for (int i=1; i!=argc; i++) { | |
950 | + if (strcmp("--precalib", argv[i]) == 0) { | |
951 | + if (argc > i+1) | |
952 | + min_x = atoi(argv[i+1]); | |
953 | + if (argc > i+2) | |
954 | + max_x = atoi(argv[i+2]); | |
955 | + if (argc > i+3) | |
956 | + min_y = atoi(argv[i+3]); | |
957 | + if (argc > i+4) | |
958 | + max_y = atoi(argv[i+4]); | |
959 | + } | |
960 | + } | |
961 | + } | |
962 | + | |
946 | 963 | if (found == 0) { |
947 | 964 | fprintf (stderr, "Error: No calibratable devices found.\n"); |
948 | 965 | quit (1); |
@@ -956,6 +973,7 @@ CalibrationArea::CalibrationArea () | ||
956 | 973 | else { |
957 | 974 | // unable to know device driver from its name alone |
958 | 975 | // either its EVDEV or an unknown driver |
976 | + // evtouch has: "EVTouch TouchScreen" | |
959 | 977 | if (CalibratorEvdev::check_driver(drivername)) |
960 | 978 | W = new CalibratorEvdev(drivername, |
961 | 979 | min_x, max_x, min_y, max_y); |
@@ -1097,15 +1115,32 @@ bool CalibrationArea::on_timeout () | ||
1097 | 1115 | return true; |
1098 | 1116 | } |
1099 | 1117 | |
1118 | +static void | |
1119 | +usage(char* cmd) | |
1120 | +{ | |
1121 | + fprintf(stderr, "usage: %s [-h|--help] [--precalib <minx> <maxx> <miny> <maxy>]\n", cmd); | |
1122 | + fprintf(stderr, "\t--precalib: manually provide the current calibration setting (eg the values in xorg.conf)\n"); | |
1123 | +} | |
1100 | 1124 | |
1101 | 1125 | int main(int argc, char** argv) |
1102 | 1126 | { |
1127 | + // Display help ? | |
1128 | + if (argc > 1) { | |
1129 | + for (int i=1; i!=argc; i++) { | |
1130 | + if (strcmp("-h", argv[i]) == 0 || | |
1131 | + strcmp("--help", argv[i]) == 0) { | |
1132 | + usage(argv[0]); | |
1133 | + return 0; | |
1134 | + } | |
1135 | + } | |
1136 | + } | |
1137 | + | |
1103 | 1138 | Gtk::Main kit(argc, argv); |
1104 | 1139 | |
1105 | 1140 | Gtk::Window win; |
1106 | 1141 | win.fullscreen (); |
1107 | 1142 | |
1108 | - CalibrationArea area; | |
1143 | + CalibrationArea area(argc, argv); | |
1109 | 1144 | win.add (area); |
1110 | 1145 | area.show (); |
1111 | 1146 |