File: capture.sh

package info (click to toggle)
android-platform-system-extras 7.0.0%2Br33-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,136 kB
  • sloc: cpp: 28,180; ansic: 14,543; python: 5,376; sh: 2,441; java: 908; asm: 299; makefile: 19; xml: 12
file content (75 lines) | stat: -rwxr-xr-x 1,337 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Capture and display input events and coordinates
#
# Usage: ./capture.sh
#

# do a throw-away adb in case the server is out-of-date
adb devices -l 2>&1 >/dev/null

while [ $# -gt 0 ]
do
	case "$1" in
	(-d) DEVICE=$2; shift;;
	(*)
		echo Unknown option $1
		exit 1;;
	esac
	shift
done

if [ "$DEVICE" = "" ]; then
	devInfo=$(adb devices -l | grep -v ^List | head -1)
	set -- $devInfo
	echo devInfo=$devInfo
	DEVICE=$(echo $4 | sed 's/product://')
fi

function convert {
	in=$1
	max=$2
	scale=$3
	if [ $max -eq 0 ]; then
		echo $in
	else
		((out=in*scale/max))
		echo $out
	fi
}


case $DEVICE in
(shamu|hammerhead|bullhead|ariel)
	# no scaling necessary
	xmax=0
	ymax=0;;
(volantis)
	xmax=3060
	xscale=1500
	ymax=2304
	yscale=1950;;
(*)
	echo "Error: No display information available for $DEVICE"
	exit 1;;
esac

echo Capturing input for $DEVICE...
stdbuf -o0 adb shell getevent -t |
	stdbuf -o0 grep "event.: 0003" |
	stdbuf -o0 grep "0003 003[0156a9]" |
	stdbuf -o0 tr ':[]
' ' ' | while read line
do
	set -- $line
	code=$4
	value=$((16#$5))
	case $code in
	(0035) x=$(convert $value $xmax $xscale);;
	(0036) y=$(convert $value $ymax $yscale);;
	(0030) tag="majorTouch";;
	(0031) tag="minorTouch";;
	(003a) tag="pressure";;
	(0039) tag="trackingId";;
	(--) echo unknown code=$code;;
	esac
	printf "%-10s %-4d  %-4d\n" $tag $x $y
done