From ffd359165e2c7611a9bbcf70876bddc5d3835490 Mon Sep 17 00:00:00 2001 From: Miles Alan Date: Fri, 28 Aug 2020 19:34:59 -0500 Subject: [PATCH] Style fixes for autorotate script for consistency with other scripts Seperate autorotate enable/disable into fns. Also show which state you're toggling from/to for autorotate in Config menu --- scripts/core/sxmo_appmenu.sh | 7 ++++-- scripts/core/sxmo_autorotate.sh | 36 --------------------------- scripts/core/sxmo_rotateautotoggle.sh | 36 +++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 38 deletions(-) delete mode 100755 scripts/core/sxmo_autorotate.sh create mode 100755 scripts/core/sxmo_rotateautotoggle.sh diff --git a/scripts/core/sxmo_appmenu.sh b/scripts/core/sxmo_appmenu.sh index c292fee..89517de 100755 --- a/scripts/core/sxmo_appmenu.sh +++ b/scripts/core/sxmo_appmenu.sh @@ -66,8 +66,11 @@ programchoicesinit() { Bar Toggle ^ 1 ^ key Alt+b Invert Colors ^ 1 ^ xcalib -a -invert Change Timezone ^ 1 ^ sxmo_timezonechange.sh - Toggle Autorotate ^ 0 ^ sxmo_autorotate.sh - Rotate ^ 1 ^ sxmo_rotate.sh rotate + Autorotate $( + pgrep -f "$(command -v sxmo_rotateautotoggle.sh)" > /dev/null && + printf %b "On → Off ^ 0 ^ sxmo_rotateautotoggle.sh &" || printf %b "Off → On ^ 0 ^ sxmo_rotateautotoggle.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 deleted file mode 100755 index c693dec..0000000 --- a/scripts/core/sxmo_autorotate.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/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_rotateautotoggle.sh b/scripts/core/sxmo_rotateautotoggle.sh new file mode 100755 index 0000000..67bbdfb --- /dev/null +++ b/scripts/core/sxmo_rotateautotoggle.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env sh +GRAVITY="16374" +THRESHOLD="400" +POLL_TIME=1 +RIGHT_SIDE_UP="$(echo "$GRAVITY - $THRESHOLD" | bc)" +UPSIDE_DOWN="$(echo "-$GRAVITY + $THRESHOLD" | bc)" +FILE_Y="$(find /sys/bus/iio/devices/iio\:device*/ -iname in_accel_y_raw)" +FILE_X="$(find /sys/bus/iio/devices/iio\:device*/ -iname in_accel_x_raw)" + +autorotatedisable() { + notify-send "Autorotate disabled" + pgrep -f "$(command -v sxmo_rotateautotoggle.sh)" | grep -Ev "^${$}$" | xargs kill -9 + exit 0 +} + +autorotateenable() { + notify-send "Autorotate enabled" + while true; do + y_raw="$(cat "$FILE_Y")" + x_raw="$(cat "$FILE_X")" + 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 +} + +if pgrep -f "$(command -v sxmo_rotateautotoggle.sh)" | grep -Ev "^${$}$"; then + autorotatedisable +else + autorotateenable +fi