Last active
December 16, 2024 00:59
-
-
Save carlinigraphy/2a218f11e7f559fced35ad49dfc3f3c5 to your computer and use it in GitHub Desktop.
Print raw steno output from a serial input device
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
declare -a RAW_OUTPUT=() | |
declare -A STENO_HEX=( | |
['a00000000000']='#,1' | |
['900000000000']='#,1' | |
['800000000020']='#,1' | |
['840000000000']='#,1' | |
['804000000000']='S,2' | |
['802000000000']='S,2' | |
['801000000000']='T,3' | |
['800800000000']='K,4' | |
['800400000000']='P,5' | |
['800200000000']='W,6' | |
['800100000000']='H,7' | |
['800040000000']='R,8' | |
['800020000000']='A,9' | |
['800010000000']='O,10' | |
['800008000000']='*,11' | |
['800004000000']='*,11' | |
['800000200000']='*,11' | |
['800000100000']='*,11' | |
['800000080000']='E,12' | |
['800000040000']='U,13' | |
['800000020000']='F,14' | |
['800000010000']='R,15' | |
['800000004000']='P,16' | |
['800000002000']='B,17' | |
['800000001000']='L,18' | |
['800000000800']='G,19' | |
['800000000400']='T,20' | |
['800000000200']='S,21' | |
['800000000100']='D,22' | |
['800000000001']='Z,23' | |
) | |
stty -F /dev/ttyACM0 9600 | |
stty -F /dev/ttyACM0 raw | |
stdbuf --output=0 \ | |
xxd -ps -c6 /dev/ttyACM0 \ | |
| while read -r input ; do | |
if (( (0x$input & 0x800000000000) != 0x800000000000 )) ; then | |
printf '(UNEXPECTED MSB: %s)\n' "$input" | |
exit 1 | |
fi | |
for i in {1..23} ; do | |
RAW_OUTPUT[i]=" " | |
done | |
declare -i match=0 | |
for letter in "${!STENO_HEX[@]}" ; do | |
if (( (0x$input & 0x$letter) == 0x$letter )) ; then | |
IFS=, read -r output position <<< "${STENO_HEX[$letter]}" | |
RAW_OUTPUT[position]="$output" | |
match=1 | |
fi | |
done | |
if (( match )) ; then | |
printf '%s' "${RAW_OUTPUT[@]}" | |
printf '\n' | |
else | |
printf '(NO MATCH: %s)\n' "$input" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment