~mil/sxmo-utils

ref: dbc3b1ab509aab5f1db72c5cece2ee2a6eb521e8 sxmo-utils/scripts/core/sxmo_rotateautotoggle.sh -rwxr-xr-x 1.1 KiB
dbc3b1abStacy Harper Allow the sendnewtextmenu to be used with a number as arg 1 year, 4 months ago
                                                                                
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
#!/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 -r 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" ] && sxmo_rotate.sh isrotated ; then
			sxmo_rotate.sh rotnormal
		elif [ "$y_raw" -le "$UPSIDE_DOWN" ] && [ "$(sxmo_rotate.sh isrotated)" != "right" ]; then
			sxmo_rotate.sh rotright
		elif [ "$y_raw" -ge "$RIGHT_SIDE_UP" ] && [ "$(sxmo_rotate.sh isrotated)" != "left" ]; 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