Merge pull request #1227 from tlyu/focus-send

improve focus-send
pull/799/merge
Jesse Vincent 2 years ago committed by GitHub
commit f3fe7c9023
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,14 +17,22 @@ set -e
OS=$(uname -s) OS=$(uname -s)
# igncr absorbs CR from Focus CRLF line endings
# -echo is needed because raw doesn't turn it off on Linux
STTY_ARGS="9600 raw igncr -echo"
case ${OS} in case ${OS} in
Linux) Linux)
DEVICE="${DEVICE:-/dev/ttyACM0}" DEVICE="${DEVICE:-/dev/ttyACM0}"
stty -F "${DEVICE}" 9600 raw -echo
;; ;;
Darwin) Darwin)
# bash on macOS has a bug that randomly drops serial input
if [ -n "$BASH_VERSION" ] && [ -x /bin/dash ]; then
# Prevent loop in case someone exported it
export -n BASH_VERSION
exec /bin/dash "$0" "$@"
fi
DEVICE="${DEVICE:-/dev/cu.usbmodemCkbio01E}" DEVICE="${DEVICE:-/dev/cu.usbmodemCkbio01E}"
stty -f "${DEVICE}" 9600 raw -echo
;; ;;
*) *)
echo "Error Unknown OS : ${OS}" >&2 echo "Error Unknown OS : ${OS}" >&2
@ -32,14 +40,24 @@ case ${OS} in
;; ;;
esac esac
# Redirect prior to running stty, because macOS sometimes resets termios
# state upon last close of a terminal device.
exec < "${DEVICE}"
# shellcheck disable=SC2086 # intentional word splitting
stty $STTY_ARGS
exec 3<"${DEVICE}" read_reply () {
echo "$@" >"${DEVICE}" while read -r line; do
if [ "${line}" = "." ]; then
while read -r line <&3; do
line="$(echo -n "${line}" | tr -d '\r')"
if [ "${line}" == "." ]; then
break break
fi fi
echo "${line}" echo "${line}"
done done
}
# Flush any invalid commands out of input buffer.
# This could happen after a failed upload.
echo ' ' > "${DEVICE}"
read_reply > /dev/null
echo "$@" >"${DEVICE}"
read_reply

Loading…
Cancel
Save