-
Notifications
You must be signed in to change notification settings - Fork 36
/
upload_to_device.sh
executable file
·78 lines (67 loc) · 1.42 KB
/
upload_to_device.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
COMPILED='no'
PORT=/dev/ttyUSB0
BAUD=115200
if [ -e "/dev/ttyUSB0" ]; then
PORT=/dev/ttyUSB0 # esp8266
elif [ -e "/dev/ttyACM0" ]; then
PORT=/dev/ttyACM0 # esp32
else
echo "ERROR: Device not connected."
exit 1
fi
[ "$1" != "" ] && COMPILED=$1
[ "$2" != "" ] && PORT=$2
[ "$3" != "" ] && BAUD=$3
function a() {
echo "RUN: $*"
ampy -d1 --baud "${BAUD}" --port "${PORT}" $*
}
files_on_device=$(a ls)
function copy_compiled() {
a mkdir /umqtt
a put ./build_port/umqtt/errno.mpy /umqtt/errno.mpy
a put ./build_port/umqtt/simple2.mpy /umqtt/simple2.mpy
a put ./build_port/umqtt/__init__.mpy /umqtt/__init__.mpy
a put ./build_port/tests.mpy
a put ./main.py
}
function _rm_dir() {
[ $(echo -e "$files_on_device" | grep $1) ] && a rmdir $1
}
function _rm_file() {
[ $(echo -e "$files_on_device" | grep $1) ] && a rm $1
}
function delete_compiled() {
_rm_dir /umqtt
_rm_file /tests.mpy
_rm_file /main.mpy
}
function copy_normal() {
a mkdir /umqtt
a put ./src/umqtt/errno.py /umqtt/errno.py
a put ./src/umqtt/simple2.py /umqtt/simple2.py
a put ./src/umqtt/__init__.py /umqtt/__init__.py
a put ./tests.py
a put ./main.py
}
function delete_normal() {
_rm_dir /umqtt
_rm_file /tests.py
_rm_file /main.mpy
}
case "$COMPILED" in
"yes" | "y")
delete_normal
./compile.sh r
copy_compiled
;;
"no" | "n")
delete_compiled
copy_normal
;;
*)
echo "Error: No agruments"
exit 1
;;
esac