forked from hiveeyes/terkin-datalogger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
265 lines (210 loc) · 6.92 KB
/
Makefile
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# ***********************
# The MicroTerkin sandbox
# ***********************
# See also https://community.hiveeyes.org/t/terkin-for-micropython/233/21
# =============
# Initial setup
# =============
#
# Refresh sources and dependencies::
#
# git pull
# make setup
#
# Establish network connectivity::
#
# export MCU_PORT=/dev/cu.usbmodemPy001711
# make connect-wifi ssid=YourNetwork password=YourPassword
#
# Transfer files::
#
# export MCU_PORT=192.168.178.33
# make install-ftp
#
# Watch log output::
#
# make console
#
# Start over::
#
# -- Press reset button
# -- Have fun
# ================
# Maintenance mode
# ================
#
# When the device is already running, it is already attached to a network.
# So, to make it stay connected and pull it out of deep sleep, you might
# want to adjust one step in the procedure above.
#
# Establish network connectivity::
#
# make terkin-agent action=maintain
#
# =============
# Main Makefile
# =============
# Conditionally load "presets.mk".
MAKE_PRESETS := $(shell test -e "presets.mk" && echo "yes")
ifeq ($(MAKE_PRESETS),yes)
include presets.mk
endif
# Load modules
include tools/help.mk
include tools/base.mk
include tools/setup.mk
include tools/build.mk
include tools/docs.mk
include tools/release.mk
include tools/terkin.mk
include tools/pycom.mk
include tools/micropython.mk
include tools/bluetooth.mk
include tools/cpython.mk
# ----
# Help
# ----
.DEFAULT_GOAL := help
help: show-rules
@echo "$$(tput bold)Documentation:$$(tput sgr0)"
@echo
@echo "Please check https://community.hiveeyes.org/t/operate-the-terkin-datalogger-sandbox/2332 "
@echo "in order to get an idea how to operate this software sandbox."
@echo
@echo "Have fun!"
@echo
# -----
# Setup
# -----
## Prepare sandbox environment and download requirements
setup: setup-environment download-requirements mpy-cross-setup
# -----------------------------
# File compilation and transfer
# -----------------------------
## Compile all library files using mpy-cross
mpy-compile: check-mpy-version check-mpy-target
@echo "$(INFO) Ahead-of-time compiling to .mpy $(MPY_TARGET)"
$(eval mpy_path := lib-mpy)
@echo "$(INFO) Populating folder \"$(mpy_path)\""
@rm -rf $(mpy_path)
@$(MAKE) mpy-cross what="--out $(mpy_path) dist-packages"
@$(MAKE) mpy-cross what="--out $(mpy_path) src/lib"
@echo "$(INFO) Size of $(mpy_path):"
@du -sch $(mpy_path)
## Upload framework, program and settings and restart attached to REPL
recycle: install-framework install-sketch reset-device-attached
## Upload framework, program and settings and restart device
recycle-ng: install-ng
@# Restart device after prompting the user for confirmation.
@echo
@echo "$(WARNING) It is crucial all files have been transferred successfully before restarting the device."
@echo " Otherwise, chances are high the program will crash after restart."
@echo
@echo "$(ADVICE) You might want to check the output of the file transfer process above for any errors."
@echo
@if test "${mcu_port_type}" = "ip"; then \
$(MAKE) confirm text="Restart device using the HTTP API?" && \
$(MAKE) restart-device-http; \
elif test "${mcu_port_type}" = "usb"; then \
$(MAKE) confirm text="Restart device using the REPL?" && \
$(MAKE) reset-device; \
$(MAKE) console; \
fi
## Upload program and settings and restart attached to REPL
sketch-and-run: install-sketch reset-device-attached
## Pyboard-D transfer
pyboard-install: check-mpy-version check-mpy-target
@$(MAKE) mpy-compile
# Inactive
@#rsync -auv dist-packages lib-mpy src/boot.py src/main.py src/settings.py /Volumes/PYBFLASH; \
@if test -e "/Volumes/PYBFLASH"; then \
rsync -auv src/lib/umal.py src/lib/mininet.py /Volumes/PYBFLASH/lib; \
rsync -auv lib-mpy /Volumes/PYBFLASH; \
rsync -auv src/boot.py src/main.py /Volumes/PYBFLASH; \
cp src/settings.pybd.py /Volumes/PYBFLASH/settings.py; \
else \
echo "ERROR: Could not find /Volumes/PYBFLASH, exiting"; \
exit 1; \
fi
pyboard-reset: check-mcu-port-strict
@diskutil unmount /Volumes/PYBFLASH || true
@$(MAKE) reset-device
@sleep 2
@$(MAKE) console
pyboard-recycle: pyboard-install pyboard-reset
# ------------------
# File transfer solo
# ------------------
## Install all files to the device, using rshell
install: install-requirements install-framework install-sketch
## Install all files to the device, using FTP
install-ftp:
@if test "${mpy_cross}" = "true"; then \
$(MAKE) mpy-compile && \
$(MAKE) lftp lftp_recipe=tools/upload-mpy-$(MPY_TARGET).lftprc; \
else \
$(MAKE) lftp lftp_recipe=tools/upload-all.lftprc; \
fi
## Install all files to the device, using USB (rshell)
install-rshell:
@if test "${mpy_cross}" = "true"; then \
$(MAKE) mpy-compile && \
if test "${MPY_TARGET}" = "pycom"; then \
$(rshell) $(rshell_options) --file tools/upload-mpy-pycom.rshell; \
else \
$(rshell) $(rshell_options) --file tools/upload-mpy-genuine.rshell; \
fi; \
else \
$(MAKE) install; \
fi
## Install all files to the device, using best method
install-ng: check-mcu-port
@if test "${mcu_port_type}" = "ip"; then \
$(MAKE) notify status=INFO status_ansi="$(INFO)" message="Uploading MicroPython code to device using FTP" && \
$(MAKE) install-ftp; \
elif test "${mcu_port_type}" = "usb"; then \
$(MAKE) notify status=INFO status_ansi="$(INFO)" message="Uploading MicroPython code to device using USB" && \
$(MAKE) install-rshell; \
fi
@# User notification
@$(MAKE) notify status=OK status_ansi="$(OK)" message="MicroPython code upload finished"
install-requirements: check-mcu-port
@if test "${MPY_TARGET}" = "pycom"; then \
$(rshell) $(rshell_options) mkdir /flash/dist-packages; \
$(rshell) $(rshell_options) rsync --mirror dist-packages /flash/dist-packages; \
else \
$(rshell) $(rshell_options) mkdir /pyboard/dist-packages; \
$(rshell) $(rshell_options) rsync --mirror dist-packages /pyboard/dist-packages; \
fi
install-framework: check-mcu-port
@if test "${MPY_TARGET}" = "pycom"; then \
$(rshell) $(rshell_options) --file tools/upload-framework-pycom.rshell; \
else \
$(rshell) $(rshell_options) --file tools/upload-framework-genuine.rshell; \
fi
install-sketch: check-mcu-port
@if test "${MPY_TARGET}" = "pycom"; then \
$(rshell) $(rshell_options) --file tools/upload-sketch-pycom.rshell; \
else \
$(rshell) $(rshell_options) --file tools/upload-sketch-genuine.rshell; \
fi
refresh-requirements: check-mcu-port
@rm -r dist-packages
$(MAKE) download-requirements
@if test "${MPY_TARGET}" = "pycom"; then \
$(rshell) $(rshell_options) rm -r /flash/dist-packages; \
$(rshell) $(rshell_options) ls /flash/dist-packages; \
else; \
$(rshell) $(rshell_options) rm -r /pyboard/dist-packages; \
$(rshell) $(rshell_options) ls /pyboard/dist-packages; \
fi
$(MAKE) install-requirements
# ------------
# Applications
# ------------
terkin-and-run: check-mcu-port
$(MAKE) install-framework
$(MAKE) reset-device-attached
ratrack-and-run: check-mcu-port
$(MAKE) install-framework
$(MAKE) reset-device-attached