nested loops in macros, testbuttons macro, updated aliases

This commit is contained in:
2025-06-26 22:24:01 +02:00
parent f97156f503
commit 0df9a11c2d
3 changed files with 89 additions and 20 deletions
+51
View File
@@ -0,0 +1,51 @@
jc() {
screen -S joycontrol -X stuff "$1^M"
}
jcupdate() {
cd ~/joycontrol
git pull --ff-only
cd
cp -f ~/joycontrol/.jc_aliases ~
}
jcstart() {
jcupdate
screen -dmS ~/joycontrol sudo python3 ~/run_controller_cli.py PRO_CONTROLLER -r 98:E2:55:92:E8:81
}
jcstop() {
screen -S joycontrol -X quit
}
jcrestart() {
jcstop
jcstart
}
jcmacro() {
buttonDelay='0.01'
if [[ ! -z $2 ]]; then
buttonDelay=$2
fi
macro=$(~/joycontrol/expand_nested_loops.sh "~/joycontrol/macro/$1")
echo "$macro"
while read -r line; do
if [[ ${line:0:1} != "#" ]]; then
jc "$line"
jc "sleep $buttonDelay"
fi
done <<< $macro
}
jclist() {
ls ~/joycontrol/macro
}
if screen -ls | grep joycontrol; then
echo "joycontrol already running, restart id needed"
else
jcstart
fi
+32
View File
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -euo pipefail
# Recursively read lines until EOF or a "loopend" is encountered.
# Prints everything it reads, expanding any nested loops.
expand() {
local line repeat body
# Read one line at a time
while IFS= read -r line; do
# If this is the start of a loop, grab the count
if [[ $line =~ ^[[:space:]]*loop[[:space:]]+([0-9]+)[[:space:]]*$ ]]; then
repeat=${BASH_REMATCH[1]}
# Recursively collect inner block into an array
mapfile -t body < <( expand )
# Print that block "repeat" times
for ((i=0; i<repeat; i++)); do
printf '%s\n' "${body[@]}"
done
# If this is the end of the current loop, return to caller
elif [[ $line =~ ^[[:space:]]*loopend[[:space:]]*$ ]]; then
return
# Otherwise, just print the line verbatim
else
printf '%s\n' "$line"
fi
done
}
# Kick it off: read from file if given, otherwise stdin
expand < "${1:-/dev/stdin}"
+6 -20
View File
@@ -9,29 +9,15 @@ left
a a
sleep 1.2 sleep 1.2
#go to controller settings #go to controller settings
down loop 8
down down
down loopend
down
down
down
down
down
a a
sleep 1.2 sleep 1.2
# go to test inputs # go to test inputs
down loop 12jc res
down down
down loopend
down
down
down
down
down
down
down
down
down
a a
sleep 1.2 sleep 1.2
a a