• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No 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

Revision59ffb806a423791ef615a77ad6a20d531b6bfe73 (tree)
Time2009-11-29 23:13:10
AuthorTias <tias@kata...>
CommiterTias

Log Message

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

Change Summary

Incremental Difference

--- /dev/null
+++ b/get_precalib.sh
@@ -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
--- a/xinput_calibrator.cc
+++ b/xinput_calibrator.cc
@@ -282,8 +282,9 @@ public:
282282 CalibratorXorgPrint::CalibratorXorgPrint (const char* drivername0, int min_x, int max_x, int min_y, int max_y)
283283 : Calibrator (drivername0, min_x, max_x, min_y, max_y)
284284 {
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",
286286 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");
287288 }
288289
289290 void CalibratorXorgPrint::finish_data (
@@ -855,7 +856,7 @@ void CalibratorUsbts::finish_data (
855856 class CalibrationArea : public Gtk::DrawingArea
856857 {
857858 public:
858- CalibrationArea ();
859+ CalibrationArea (int argc, char** argv);
859860
860861 protected:
861862 /* Helper functions */
@@ -873,7 +874,7 @@ protected:
873874 int time_elapsed;
874875 };
875876
876-CalibrationArea::CalibrationArea ()
877+CalibrationArea::CalibrationArea (int argc, char** argv)
877878 : num_clicks (0), time_elapsed (0)
878879 {
879880 /* Not sure this is the right place for this, but here we go
@@ -943,6 +944,22 @@ CalibrationArea::CalibrationArea ()
943944 XFreeDeviceList(slist);
944945 XCloseDisplay(display);
945946
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+
946963 if (found == 0) {
947964 fprintf (stderr, "Error: No calibratable devices found.\n");
948965 quit (1);
@@ -956,6 +973,7 @@ CalibrationArea::CalibrationArea ()
956973 else {
957974 // unable to know device driver from its name alone
958975 // either its EVDEV or an unknown driver
976+ // evtouch has: "EVTouch TouchScreen"
959977 if (CalibratorEvdev::check_driver(drivername))
960978 W = new CalibratorEvdev(drivername,
961979 min_x, max_x, min_y, max_y);
@@ -1097,15 +1115,32 @@ bool CalibrationArea::on_timeout ()
10971115 return true;
10981116 }
10991117
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+}
11001124
11011125 int main(int argc, char** argv)
11021126 {
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+
11031138 Gtk::Main kit(argc, argv);
11041139
11051140 Gtk::Window win;
11061141 win.fullscreen ();
11071142
1108- CalibrationArea area;
1143+ CalibrationArea area(argc, argv);
11091144 win.add (area);
11101145 area.show ();
11111146