From b86b152e6ed661454c5b0623e3ce582ebdd63340 Mon Sep 17 00:00:00 2001 From: Anjandev Momi Date: Thu, 20 Aug 2020 01:02:17 -0700 Subject: [PATCH] Added autorotate using accelerometer script --- scripts/core/sxmo_appmenu.sh | 3 ++- scripts/core/sxmo_autorotate.sh | 36 +++++++++++++++++++++++++++++++++ scripts/core/sxmo_rotate.sh | 11 +++++++++- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100755 scripts/core/sxmo_autorotate.sh diff --git a/scripts/core/sxmo_appmenu.sh b/scripts/core/sxmo_appmenu.sh index c82788f..c292fee 100755 --- a/scripts/core/sxmo_appmenu.sh +++ b/scripts/core/sxmo_appmenu.sh @@ -66,7 +66,8 @@ programchoicesinit() { Bar Toggle ^ 1 ^ key Alt+b Invert Colors ^ 1 ^ xcalib -a -invert Change Timezone ^ 1 ^ sxmo_timezonechange.sh - Rotate ^ 1 ^ sxmo_rotate.sh + Toggle Autorotate ^ 0 ^ sxmo_autorotate.sh + Rotate ^ 1 ^ sxmo_rotate.sh rotate Upgrade Pkgs ^ 0 ^ st -e sxmo_upgrade.sh " WINNAME=Config diff --git a/scripts/core/sxmo_autorotate.sh b/scripts/core/sxmo_autorotate.sh new file mode 100755 index 0000000..c693dec --- /dev/null +++ b/scripts/core/sxmo_autorotate.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env sh + +RUNNING_AUTO="$(ps aux | grep "sh /usr/bin/sxmo_autorotate.sh" | grep -v grep | cut -f1 -d' ' | grep -v "$$")" + +[ "$(echo "$RUNNING_AUTO" | wc -l)" -ge "2" ] && echo "$RUNNING_AUTO" | tr '\n' ' ' | xargs kill -9 +[ "$(echo "$RUNNING_AUTO" | wc -l)" -ge "2" ] && notify-send "Turning autorotate off" && exit 1 + +notify-send "Turning autorotate on" + +GRAVITY="16374" +THRESHOLD="400" +POLL_TIME=1 + +RIGHT_SIDE_UP="$(echo "$GRAVITY - $THRESHOLD" | bc)" +UPSIDE_DOWN="$(echo "-$GRAVITY + $THRESHOLD" | bc)" +y_file="$(find /sys/bus/iio/devices/iio\:device*/ -iname in_accel_y_raw)" +x_file="$(find /sys/bus/iio/devices/iio\:device*/ -iname in_accel_x_raw)" + +while : +do + + y_raw="$(cat "$y_file")" + x_raw="$(cat "$x_file")" + + if [ "$x_raw" -ge "$RIGHT_SIDE_UP" ] + then + sxmo_rotate.sh rotnormal + elif [ "$y_raw" -le "$UPSIDE_DOWN" ] + then + sxmo_rotate.sh rotright + elif [ "$y_raw" -ge "$RIGHT_SIDE_UP" ] + then + sxmo_rotate.sh rotleft + fi + sleep "$POLL_TIME" +done diff --git a/scripts/core/sxmo_rotate.sh b/scripts/core/sxmo_rotate.sh index 9023b06..02f99bc 100755 --- a/scripts/core/sxmo_rotate.sh +++ b/scripts/core/sxmo_rotate.sh @@ -28,8 +28,17 @@ rotright() { exit 0 } +rotleft() { + xrandr -o left + applyptrmatrix 0 -1 1 1 0 0 0 0 1 + pkill lisgd + sxmo_lisgdstart.sh -o -1 & + exit 0 +} + + rotate() { if isrotated; then rotnormal; else rotright; fi } -rotate +"$1"