Skip to content

Commit

Permalink
addon: update Volume-Key-Selector
Browse files Browse the repository at this point in the history
  • Loading branch information
ahkehra committed Dec 4, 2021
1 parent 0e4032d commit c94f704
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 22 deletions.
2 changes: 1 addition & 1 deletion addon/Volume-Key-Selector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ Ex:
* Each volume key selector method will timeout after 3 seconds in the event of incompatibility or error

## Included Binaries/Credits:
* [keycheck binary](https://github.com/sonyxperiadev/device-sony-common-init/tree/master/keycheck) compiled by me [here](https://github.com/Zackptg5/Keycheck)
* [keycheck binary](https://github.com/sonyxperiadev/device-sony-common-init/tree/master/keycheck) compiled by me [here](https://github.com/Zackptg5/Keycheck)
61 changes: 40 additions & 21 deletions addon/Volume-Key-Selector/install.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,56 @@
# External Tools
chmod -R 0755 $MODPATH/common/addon/Volume-Key-Selector/tools

chmod -R 0755 $MODPATH/addon/Volume-Key-Selector/tools

chooseport() {
chooseport_legacy() {
# Keycheck binary by someone755 @Github, idea for code below by Zappo @xda-developers
# Calling it first time detects previous input. Calling it second time will do what we want
[ "$1" ] && local delay=$1 || local delay=3
local error=false
while true; do
if [ "$ARCH" = "x86" ]; then
timeout 0 $MODPATH/addon/Volume-Key-Selector/tools/x86/keycheck
timeout $delay $MODPATH/addon/Volume-Key-Selector/tools/x86/keycheck
elif [ "$ARCH" = "arm64" ]; then
timeout 0 $MODPATH/addon/Volume-Key-Selector/tools/arm/keycheck
timeout $delay $MODPATH/addon/Volume-Key-Selector/tools/arm/keycheck
elif [ "$ARCH" = "x64" ]; then
timeout 0 $MODPATH/addon/Volume-Key-Selector/tools/x86/keycheck
timeout $delay $MODPATH/addon/Volume-Key-Selector/tools/x86/keycheck
elif [ "$ARCH" = "arm" ]; then
timeout 0 $MODPATH/addon/Volume-Key-Selector/tools/arm/keycheck
timeout $delay $MODPATH/addon/Volume-Key-Selector/tools/arm/keycheck
fi
local SEL=$?
if [ $SEL -eq 42 ]; then
timeout 0 $MODPATH/common/addon/Volume-Key-Selector/tools/$ARCH32/keycheck
timeout $delay $MODPATH/common/addon/Volume-Key-Selector/tools/$ARCH32/keycheck
local sel=$?
if [ $sel -eq 42 ]; then
return 0
elif [ $SEL -eq 41 ]; then
elif [ $sel -eq 41 ]; then
return 1
elif $error; then
abort "Volume key not detected!"
else
error=true
echo "Volume key not detected. Try again"
fi
done
}

chooseport() {
# Original idea by chainfire and ianmacd @xda-developers
[ "$1" ] && local delay=$1 || local delay=3
local error=false
while true; do
local count=0
while true; do
timeout $delay /system/bin/getevent -lqc 1 2>&1 > $TMPDIR/events &
sleep 0.5; count=$((count + 1))
if (`grep -q 'KEY_VOLUMEUP *DOWN' $TMPDIR/events`); then
return 0
elif (`grep -q 'KEY_VOLUMEDOWN *DOWN' $TMPDIR/events`); then
return 1
fi
[ $count -gt 6 ] && break
done
if $error; then
# abort "Volume key not detected!"
echo "Volume key not detected. Trying keycheck method"
export chooseport=chooseport_legacy VKSEL=chooseport_legacy
chooseport_legacy $delay
return $?
else
$error && abort "Volume key error!"
error=true
echo "Volume key not detected. Try again"
fi
done
}

# Keep old variable from previous versions of this
VKSEL=chooseport
VKSEL=chooseport

0 comments on commit c94f704

Please sign in to comment.