Skip to content

Instantly share code, notes, and snippets.

@singpolyma
Created April 22, 2015 14:19
Show Gist options
  • Select an option

  • Save singpolyma/77004677bffbe1cbfeb2 to your computer and use it in GitHub Desktop.

Select an option

Save singpolyma/77004677bffbe1cbfeb2 to your computer and use it in GitHub Desktop.

Revisions

  1. singpolyma created this gist Apr 22, 2015.
    33 changes: 33 additions & 0 deletions autorotate.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    #!/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