Thread: Aura H2O AutoShelf beta
View Single Post
Old 12-27-2021, 04:31 PM   #197
vdanjean
Junior Member
vdanjean began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Dec 2021
Device: none
Hi,
fbink from https://www.mobileread.com/forums/sh...d.php?t=299110 is not recent enough for Kobo Sage. But recompiling it from github sources works ;-) You can see my messages at the end of the just cited thread.

I've been hit by another problem with AutoShelf. To detect user action, it monitors /dev/input/event1. But, on Kobo Sage, this is not (always?) the good file.
I wrote a patch to detect the good eventX file based on /proc/bus/input/devices.
To be fully correct, we must know the name of the touch screen. I put the one I know in the script (ie for Kobo Sage and Kobo Forma).
If nothing is found, it failback to /dev/input/event1 as before but also generate a file in /mnt/onboard/AutoShelf-bugreport.txt (with the contents of /proc/bus/input/devices) so that my patch can be improved.

I put my patch below, feel free to use it as you want.

I can also give you the full updated KoboRoot.tgz if you wish to quickly update the package.

Regards,

Code:
diff --git a/usr/local/AutoShelf/autoshelf.sh b/usr/local/AutoShelf/autoshelf.sh
index 8f09d7a..7a433a6 100755
--- a/usr/local/AutoShelf/autoshelf.sh
+++ b/usr/local/AutoShelf/autoshelf.sh
@@ -15,6 +15,77 @@ config() {
     [ "$value" != "" ] && echo "$value" || echo "$2"
 }
 
+#
+# touchscreen input file
+#
+TS_GUESS=
+ts_input() {
+    local l
+    local FOUND=
+    local CANDIDATE=/dev/input/event1
+    local EVENT
+    local tempdir="$(mktemp -d)"
+    mkfifo "$tempdir/fifo"
+    cat /proc/bus/input/devices > "$tempdir/fifo" &
+    while read l; do
+	case "$l" in
+        'N: Name="cyttsp5_mt"') FOUND=1;;
+	'N: Name="Elan Touchscreen"') FOUND=1;;
+	'N: Name='*[Tt]ouch[Ss]creen*) FOUND=2;;
+        'H: Handlers='*) EVENT="$(echo "$l" | sed -e 's/.*\(event[0-9]\+\).*/\1/')" ;;
+	'')
+	    case "$FOUND" in
+	    1)
+		echo /dev/input/"$EVENT"
+		rm -rf "$tempdir"
+		return ;;
+	    2)
+		CANDIDATE="/dev/input/$EVENT"
+		;;
+	    esac
+	    FOUND= ;;
+        *) ;;
+	esac
+    done < "$tempdir/fifo"
+    rm -rf "$tempdir"
+    TS_GUESS=1
+    echo "CANDIDATE=$CANDIDATE"
+}
+
+ts_warn() {
+    if [ "$TS_GUESS" != 1 ]; then
+	return
+    fi
+
+    for i in $(seq 1 60)
+    do
+        if [ -e /mnt/onboard/.kobo/KoboReader.sqlite ]
+        then
+            break
+        fi
+
+        sleep 1
+	break
+    done
+
+    if [ ! -e /mnt/onboard/.kobo/KoboReader.sqlite ]; then
+	: return
+    fi
+
+cat > /mnt/onboard/AutoShelf-bugreport.txt <<EOF
+The touchscreen have not been exactly detected.
+To improve AutoShelf, please send the following information to the developpers:
+
+Input devices on the machine:
+$(cat /proc/bus/input/devices)
+
+Machine version:
+$(cat /mnt/onboard/.kobo/version)
+$(uname -a)
+
+EOF
+}
+
 # database escapes
 escape() {
     echo -n "${1//"'"/"''"}"
@@ -241,7 +312,8 @@ then
     grep /mnt/onboard /proc/mounts && exit
     fbink -g file="/usr/local/AutoShelf/autoshelf-off.png"
 
-    while cat /dev/input/event1 | dd bs=1 count=1
+    TS_INPUT="$(ts_input)"
+    while cat "$TS_INPUT" | dd bs=1 count=1
     do
         grep /mnt/onboard /proc/mounts && exit
 
@@ -267,6 +339,7 @@ then
     exit
 elif [ ! -e /tmp/autoshelf-on ]
 then
+    ts_warn
     # disabled mode
     exit
 fi
@@ -285,6 +358,8 @@ do
     sleep 1
 done
 
+ts_warn
+
 if [ -e /mnt/onboard/.kobo/KoboReader.sqlite ]
 then
     cfg_logfile="$BASE"/$(config logfile '')
vdanjean is offline   Reply With Quote