Improvements on gyro auto rotation for ACER 1825

By Christopher, February 18, 2011

In two old posts I described, how you could use the gyro sensor of the Acer 1825 for auto rotating your screen and how you could enable and disable this feature with a special button.

http://www.ceh-photo.de/blog/?p=244

http://www.ceh-photo.de/blog/?p=186

A user (perpe) from http://ubuntuforums.org/showthread.php?t=1486671&page=13 found out, that in windows the gyro sensor is enabled and disabled with some special keyboard events.

He found these keyboard events after doing a bios update to version 1.3127. Because of some problems I always did this update and could not check if the presented procedure works with older bios.

Make the special key commands usable:

You need to specify the keycodes for these commands in your /etc/rc.local

#button P
#STRG+ALT+NB_ENTF
setkeycodes e070 112
#button backup
#XF86Launch5
setkeycodes e062 184
#tablet mode key
#XF86MenuKB
setkeycodes e039 185
#laptop mode key
#0xb8
setkeycodes e001 176

Next update both old scripts:

/usr/bin/gyro-auto-rotate.run

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
#
DEBUG="" # write DEBUG="1" for debugging

#redirect stdin, stdout and stderr
[ ! "${DEBUG}" ] && exec>/dev/null 2>&1  # daemonize and exit
[ ! "${DEBUG}" ] &&  [ -z "$PPID" ] && { PPID=$$ $0 & exit 0; }

init()
{
modprobe i2c-i801 >/dev/null 2>&1
modprobe i2c-dev >/dev/null 2>&1
}

rotate()
{
xrandr -o $1
case $1 in
normal)
xinput set-prop "$id" "Evdev Axis Inversion" 0, 0
xinput set-prop "$id" "Evdev Axes Swap" 0
xinput set-prop "$id" "Evdev Axis Calibration" $calibx $caliby
;;
inverted)
xinput set-prop "$id" "Evdev Axis Inversion" 1, 1
xinput set-prop "$id" "Evdev Axes Swap" 0
xinput set-prop "$id" "Evdev Axis Calibration" $calibx $caliby
;;
left)
xinput set-prop "$id" "Evdev Axis Inversion" 1, 0
xinput set-prop "$id" "Evdev Axes Swap" 1
xinput set-prop "$id" "Evdev Axis Calibration" $caliby $calibx
;;
right)
xinput set-prop "$id" "Evdev Axis Inversion" 0, 1
xinput set-prop "$id" "Evdev Axes Swap" 1
xinput set-prop "$id" "Evdev Axis Calibration" $caliby $calibx
esac
}

get_orientation()
{
set `i2c-gsensor 0`

x=$3
y=$6
z=$9

if [[ ( $x -gt 0 ) && ( $x -lt 60 ) ]] && [[ ( $y -gt 247 ) || ( $y -lt 10 ) ]]
then
# laptop mod = normal tablet mode = inverted
new_orientation="inverted"
elif [ $y -lt 248 ] && [ $y -gt 190 ]
then
# laptop mod = right tablet mode = left
new_orientation="left"
elif [ $y -lt 60 ] && [ $y -gt 10 ]
then
# laptop mod = left tablet mode = right
new_orientation="right"
else
# laptop mod = inverted tablet mode = normal
new_orientation="normal"
fi
echo $new_orientation
}

loop()
{
while [ 1 ]
do
sleep 3
get_orientation
if [ "${new_orientation}" != "${orientation}" ]
then
rotate ${new_orientation}
orientation=${new_orientation}
fi
echo "x: $x y: $y z: $z"
done
}

# MAIN
#-----
trap - EXIT

#Initialisation
PATH="$PATH:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
prog=`basename $0`
caliby="0 10751"
calibx="0 18943"
init
[ "$id" ] || id="`xinput list | grep Cando \
| sed -n -e's/.*id=\([0-9]\+\).*/\1/p'`
"

[ "$id" ] || id="`xinput list | grep touchscreen \
| sed -n -e's/.*id=\([0-9]\+\).*/\1/p'`
"

[ "$id" ] || { echo " Touch screen not found..." & exit 1; }
orientation=`xrandr --query --verbose | awk ' ($1=="LVDS1") {print $5} '`
new_orientation="${orientation}"

#if got argument do not jump into loop
if [[ $# -gt 0 ]];then
rotate $1
else
loop
fi

exit 0

/usr/bin/gyro-key.run

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
pid=$( pgrep gyro-auto-rotat )
if [[ $1 == "activate" ]];then
#DO NOT START TWICE
if [ "$pid" == "" ] ;then
gyro-auto-rotate.run &
fi
notify-send "gyro auto rotation enabled --> tablet mode"
else

if [[ $1 == "deactivate" ]];then
if [ "$pid" != "" ] ;then
kill -9 $pid
#reset screen to default
gyro-auto-rotate.run normal
fi
notify-send "gyro auto rotation disabled --> laptop mode"
else
notify-send "No param"
fi
fi

I use a tool for displaying me desktop notifications if gyro rotations is enabled or disabled. If you want to use it, you need to install the package libnotify-bin with

sudo apt-get install libnotify-bin

if you don’t want the feature please uncomment all lines with notify-send.

After that you need to update your key-bindings in gnome-keybinding-properties.

Take a look at my configuration:

you need to call the script gyro-key.run one time with parameter deactivate and one time with activate to enable and disable the gyro auto rotation. See example on the screenshot.

The backup-button is now free for other commands. I use it as button for fullscreen-mode.