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

Commit 7db308d

Browse files
committed
Handling verbose option in upload script
JIRA: ATLEDGE-453
1 parent c084f8a commit 7db308d

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

clupload/cluploadArduino101_osx.sh

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,38 @@
11
#!/bin/sh
22

3+
dbg_print() {
4+
if [ "x$verbosity" == "xverbose" ]; then
5+
echo "$@"
6+
fi
7+
}
8+
9+
error_out() {
10+
echo "$@"
11+
exit 1
12+
}
13+
314
setup() {
415
# ARG 1: Path to directory which contains dfu-util executable
516
dfu_util_dir=$1
617
# ARG 2: Elf file to upload
718
payload_elf=$2
819
# ARG 3: TTY port to use
920
tty_port_id=$3
21+
# ARG 4: quiet/verbose
22+
verbosity=$4
1023

1124
# Upload the .bin instead of .elf
12-
payload_bin=${payload_elf/elf/bin}
13-
echo "Payload:" $payload_bin
25+
payload_bin=${payload_elf/.elf/.bin}
26+
dbg_print "Payload:" $payload_bin
1427

1528
export DYLD_LIBRARY_PATH=$dfu_util_dir:$DYLD_LIBRARY_PATH
16-
DFU="$dfu_util_dir/dfu-util -d,8087:0ABA"
29+
dfu_cmd="$dfu_util_dir/dfu-util -d,8087:0ABA"
30+
31+
if [ "x$verbosity" == "xverbose" ] ; then
32+
dfu_download="$dfu_cmd -D $payload_bin -v --alt 7 -R"
33+
else
34+
dfu_download="$dfu_cmd -D $payload_bin --alt 7 -R >/dev/null 2>&1"
35+
fi
1736
}
1837

1938
trap_to_dfu() {
@@ -24,7 +43,7 @@ trap_to_dfu() {
2443

2544
# Loop to read from 101 so that it stays on DFU mode afterwards.
2645
counter=0
27-
until $DFU -a 4 -U $dfu_lock > /dev/null 2>&1
46+
until $dfu_cmd -a 4 -U $dfu_lock > /dev/null 2>&1
2847
do
2948
sleep 0.1
3049

@@ -41,18 +60,18 @@ trap_to_dfu() {
4160
}
4261

4362
upload() {
44-
$DFU -a 7 -R -D $payload_bin
45-
echo "Sketch will execute in about 5 seconds."
63+
eval $dfu_download || error_out "ERROR: DFU transfer failed"
64+
echo "SUCCESS: Sketch will execute in about 5 seconds."
4665
}
4766

4867
main() {
4968
echo "Starting upload script"
5069
setup "$@"
5170

52-
echo "Waiting for device... "
71+
dbg_print "Waiting for device... "
5372
trap_to_dfu
5473

55-
echo "Using dfu-util to send " $payload_bin
74+
dbg_print "Using dfu-util to send " $payload_bin
5675
upload
5776

5877
exit 0

0 commit comments

Comments
 (0)