|
|
|
#!/usr/bin/env bash
|
etc/makefiles: Call bin/focus-send to do the device reset
Instead of simply echoing "device.reset" into the device port, call
`bin/focus-send`, which sets the `raw` setting on the port, before writing into
it. Without that, the command is not recognised by the firmware.
We could do the stty call in the makefile directly, but to support macOS, we'd
need to treat that specially, and at that point, it's easier to just call
`bin/focus-send`. The sketch relies on having the Kaleidoscope repo available
anyway, so we can safely rely on `bin/focus-send` being there, too.
Because we're now using the tool in the makefiles, `focus-test` was renamed to
`focus-send`.
Signed-off-by: Gergely Nagy <algernon@keyboard.io>
2 years ago
|
|
|
# focus-send - Trivial Focus testing tool
|
|
|
|
# Copyright (C) 2018-2022 Keyboard.io, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify it under
|
|
|
|
# the terms of the GNU General Public License as published by the Free Software
|
|
|
|
# Foundation, version 3.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
# this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
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
|
|
|
|
Linux)
|
|
|
|
DEVICE="${DEVICE:-/dev/ttyACM0}"
|
|
|
|
;;
|
|
|
|
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}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Error Unknown OS : ${OS}" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
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
|
|
|
|
|
|
|
|
read_reply () {
|
|
|
|
while read -r line; do
|
|
|
|
if [ "${line}" = "." ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
echo "${line}"
|
|
|
|
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
|