Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 55ad29d

Browse files
committed
ATLEDGE-452 sketchUploader misses the DFU window on OSX
1 parent 6c384c6 commit 55ad29d

File tree

1 file changed

+59
-38
lines changed

1 file changed

+59
-38
lines changed

clupload/cluploadArduino101_osx.sh

Lines changed: 59 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,60 @@
11
#!/bin/sh
2-
echo "starting download script"
3-
echo "Args to shell:" $*
4-
#
5-
# ARG 1: Path to lsz executable.
6-
# ARG 2: Elf File to download
7-
# ARG 3: TTY port to use.
8-
#
9-
#path may contain \ need to change all to /
10-
path_to_exe=$1
11-
fixed_path=${path_to_exe//\\/\/}
12-
tty_port_id=$3
13-
14-
#Download the file.
15-
host_file_name=$2
16-
bin_file_name=${host_file_name/elf/bin}
17-
echo "BIN FILE" $bin_file_name
18-
19-
#DFU=DYNLD_LIBRARY_PATH=$fixed_path $fixed_path/dfu-util
20-
DYLD_LIBRARY_PATH=$fixed_path
21-
DFU="$fixed_path/dfu-util -d,8087:0ABA"
22-
23-
echo "wating for device... "
24-
COUNTER=0
25-
f=`DYLD_LIBRARY_PATH=$fixed_path $DFU -l | grep sensor_core | cut -f 1 -d ' '`
26-
while [ "x$f" = "x" ] && [ $COUNTER -lt 10 ]
27-
do
28-
let COUNTER=COUNTER+1
29-
sleep 1
30-
echo $DFU
31-
f=`DYLD_LIBRARY_PATH=$fixed_path $DFU -l | grep sensor_core | cut -f 1 -d ' '`
32-
done
33-
34-
if [ "x$f" != "x" ] ; then
35-
echo "Using dfu-util to send " $bin_file_name
36-
DYLD_LIBRARY_PATH=$fixed_path $DFU -D $bin_file_name -v --alt 7 -R
37-
else
38-
echo "ERROR: Timed out waiting for Arduino 101."
39-
fi
2+
3+
setup() {
4+
# ARG 1: Path to directory which contains dfu-util executable
5+
dfu_util_dir=$1
6+
# ARG 2: Elf file to upload
7+
payload_elf=$2
8+
# ARG 3: TTY port to use
9+
tty_port_id=$3
10+
11+
# Upload the .bin instead of .elf
12+
payload_bin=${payload_elf/elf/bin}
13+
echo "Payload:" $payload_bin
14+
15+
export DYLD_LIBRARY_PATH=$dfu_util_dir:$DYLD_LIBRARY_PATH
16+
DFU="$dfu_util_dir/dfu-util -d,8087:0ABA"
17+
}
18+
19+
trap_to_dfu() {
20+
dfu_lock=$TMPDIR/dfu_lock
21+
22+
# If dfu_lock already exists, clean up before starting the loop
23+
[ -f $dfu_lock ] && rm -f $dfu_lock
24+
25+
# Loop to read from 101 so that it stays on DFU mode afterwards.
26+
counter=0
27+
until $DFU -a 4 -U $dfu_lock > /dev/null 2>&1
28+
do
29+
sleep 0.1
30+
31+
# Wait in loop only up to 50 times
32+
let counter=counter+1
33+
if [ "$counter" -gt "50" ]; then
34+
echo "ERROR: Timed out waiting for Arduino 101."
35+
exit 1
36+
fi
37+
done
38+
39+
# Clean up
40+
[ -f $dfu_lock ] && rm -f $dfu_lock
41+
}
42+
43+
upload() {
44+
$DFU -a 7 -R -D $payload_bin
45+
}
46+
47+
main() {
48+
echo "Starting upload script"
49+
setup "$@"
50+
51+
echo "Waiting for device... "
52+
trap_to_dfu
53+
54+
echo "Using dfu-util to send " $payload_bin
55+
upload
56+
57+
exit 0
58+
}
59+
60+
main "$@"

0 commit comments

Comments
 (0)