~mil/sxmo-devel

sxmo-utils: fix unreliable sxmo_proximitylock.sh v1 PROPOSED

Willow Barraco: 1
 fix unreliable sxmo_proximitylock.sh

 1 files changed, 9 insertions(+), 39 deletions(-)
#1180726 test.yml success
Hey Aren! Thanks for pushing this forward. Let's hope this get
accepted soon enough :)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~mil/sxmo-devel/patches/50494/mbox | git am -3
Learn more about email & git

[PATCH sxmo-utils] fix unreliable sxmo_proximitylock.sh Export this patch

Most of the time, this feature just does not works on my phone. No event
are triggered. So let's got back to the good old manual probing.
Signed-off-by: Willow Barraco <contact@willowbarraco.fr>
---
 scripts/core/sxmo_proximitylock.sh | 48 ++++++------------------------
 1 file changed, 9 insertions(+), 39 deletions(-)

diff --git a/scripts/core/sxmo_proximitylock.sh b/scripts/core/sxmo_proximitylock.sh
index e0af8c8c..cef75fdf 100755
--- a/scripts/core/sxmo_proximitylock.sh
+++ b/scripts/core/sxmo_proximitylock.sh
@@ -9,16 +9,6 @@
# This hook enables the proximity lock.

finish() {
	kill "$EVENTMONITORPID"
	kill "$TAILPID"
	rm "$tmp"

	# De-activate thresholds
	printf 0 > "$prox_path/events/in_proximity_thresh_falling_value"
	# The in_proximity_scale affects the maximum threshold value
	# (see static const int stk3310_ps_max[4])
	printf 6553 > "$prox_path/events/in_proximity_thresh_rising_value"

	sxmo_wakelock.sh unlock sxmo_proximity_lock_running

	if [ -n "$INITIALSTATE" ]; then
@@ -46,7 +36,7 @@ far() {
	sxmo_state.sh set unlock
}

trap 'finish' TERM INT
trap 'finish' TERM INT EXIT

sxmo_wakelock.sh lock sxmo_proximity_lock_running infinite

@@ -56,35 +46,15 @@ if [ -z "$SXMO_PROX_RAW_BUS" ]; then
else
	prox_raw_bus="$SXMO_PROX_RAW_BUS"
fi
prox_path="$(dirname "$prox_raw_bus")"
prox_name="$(cat "$prox_path/name")" # e.g. stk3310

# set some sane defaults
printf "%d" "${SXMO_PROX_FALLING:-50}" > "$prox_path/events/in_proximity_thresh_falling_value"
printf "%d" "${SXMO_PROX_RISING:-100}" > "$prox_path/events/in_proximity_thresh_rising_value"

tmp="$(mktemp)"

# TODO: stdbuf not needed with linux-tools-iio >=5.17
stdbuf -o L iio_event_monitor "$prox_name" >> "$tmp" &
EVENTMONITORPID=$!

tail -f "$tmp" | while read -r line; do
	if echo "$line" | grep -q rising; then
while : ; do
	value="$(cat "$prox_raw_bus")"
	if [ "$value" -gt 100 ] && [ "$last" != "near" ]; then
		near
	elif echo "$line" | grep -q falling; then
		last=near
	elif [ "$value" -lt 100 ] && [ "$last" != "far" ]; then
		far
		last=far
	fi
done &
TAILPID=$!

initial_distance="$(cat "$prox_raw_bus")"
if [ "$initial_distance" -gt "${SXMO_PROX_FALLING:-50}" ]; then
	near
elif [ "$initial_distance" -lt "${SXMO_PROX_RISING:-100}" ]; then
	far
fi

wait

finish
	sleep 0.5
done
-- 
2.44.0
sxmo-utils/patches/test.yml: SUCCESS in 23s

[fix unreliable sxmo_proximitylock.sh][0] from [Willow Barraco][1]

[0]: https://lists.sr.ht/~mil/sxmo-devel/patches/50494
[1]: mailto:contact@willowbarraco.fr

✓ #1180726 SUCCESS sxmo-utils/patches/test.yml https://builds.sr.ht/~mil/job/1180726