Initial commit
[profile/ivi/xinput_calibrator.git] / scripts / xinput_calibrator_get_hal_calibration.sh
1 #!/bin/sh
2 # Get running 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