#!/usr/bin/env bash # 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 . 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 wait_dot () { 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}" wait_dot echo "$@" >"${DEVICE}" wait_dot