mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2025-03-16 13:59:13 +00:00
68 lines
1.5 KiB
Bash
Executable File
68 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
shopt -s extglob
|
|
|
|
function list_usb()
|
|
{
|
|
while IFS=: read key value; do
|
|
key="${key##+( )}"
|
|
value="${value##+( )}"
|
|
case "$key" in
|
|
"Product ID")
|
|
p="${value% *}"
|
|
;;
|
|
"Vendor ID")
|
|
v="${value%% *}"
|
|
;;
|
|
"Manufacturer")
|
|
m="${value}"
|
|
;;
|
|
"Location ID")
|
|
l="${value}"
|
|
printf "%s:%s %s (%s)\n" "$v" "$p" "$l" "$m"
|
|
;;
|
|
esac
|
|
done < <( system_profiler SPUSBDataType )
|
|
}
|
|
|
|
function leaf_status()
|
|
{
|
|
this_leaf_status=$(echo "$(list_usb)" | grep "1eaf" | awk '{ print $1}')
|
|
# Find the mode of the leaf bootloader
|
|
case $this_leaf_status in
|
|
"0x1eaf:0x0003")
|
|
echo "dfu"
|
|
;;
|
|
"0x1eaf:0x0004")
|
|
echo "ttyACMx"
|
|
;;
|
|
*)
|
|
# echo "$this_leaf_status"
|
|
echo "unknown"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# Get the directory where the script is running.
|
|
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
|
|
|
# Check to see if a maple compatible board is attached
|
|
LEAF_STATUS=$(leaf_status)
|
|
|
|
# Board not found, or no boot loader on board.
|
|
if [[ $(leaf_status) = "unknown" ]]
|
|
then
|
|
# No maple board detected
|
|
echo "Maple device not found. Attempting serial upload."
|
|
SERIAL_UPLOAD=${DIR}/serial_upload_inc_bootloader
|
|
echo "${SERIAL_UPLOAD}" $1 0x8000000 $2 $3
|
|
"${SERIAL_UPLOAD}" $1 0x8000000 $2 $3
|
|
|
|
else
|
|
# Maple board detected
|
|
echo "Maple device found. Attempting USB upload."
|
|
|
|
MAPLE_UPLOAD=${DIR}/maple_upload
|
|
echo "${MAPLE_UPLOAD}" $1 2 1eaf:0003 $2
|
|
"${MAPLE_UPLOAD}" $1 2 1eaf:0003 $2
|
|
fi
|