Skip to content

Instantly share code, notes, and snippets.

@singpolyma
Created April 22, 2015 14:19
Show Gist options
  • Save singpolyma/77004677bffbe1cbfeb2 to your computer and use it in GitHub Desktop.
Save singpolyma/77004677bffbe1cbfeb2 to your computer and use it in GitHub Desktop.
Novena Autorotate Script
#!/bin/sh
set -e
x="$(cat /sys/bus/iio/devices/iio:device0/in_accel_x_raw)"
y="$(cat /sys/bus/iio/devices/iio:device0/in_accel_y_raw)"
abs_x="$x"
[ "$x" -lt 0 ] && abs_x=$(( $x * -1 ))
abs_y="$y"
[ "$y" -lt 0 ] && abs_y=$(( $y * -1 ))
if [ "$abs_x" -lt 70 ] && [ "$abs_y" -lt 70 ]; then
# No change (lying flat)
exit
fi
current="$(xrandr -q --verbose | grep '^LVDS1 ' | cut -d' ' -f5)"
if [ "$abs_y" -gt "$abs_x" ]; then
if [ "$y" -lt 0 ]; then
[ "$current" != "inverted" ] && xrandr -o inverted
else
[ "$current" != "normal" ] && xrandr -o normal
fi
else
if [ "$x" -lt 0 ]; then
[ "$current" != "left" ] && xrandr -o left
else
[ "$current" != "right" ] && xrandr -o right
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment