-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
29 lines (28 loc) · 964 Bytes
/
tasks.py
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
from invoke import task, run
from termcolor import colored
'''
This task compiles an arduino sketch file (*.ino) and uploads to
the Arduino in the given port.
'''
@task
def upload(context, module=1, device='USB0'):
modules = range(1,8)
ARDUINO_PATH = '~/Software/arduino-1.8.7/'
SKETCH_PATH = 'ESP32/module/module.ino'
ARDUINO_PORT = f'/dev/tty{device}'
if not module:
print(colored('Module number (1-7) must be specified', 'red'))
return
if not module in modules:
print(colored(f"Unknown module '{module}'", 'yellow'))
return
# Change module ID sketch
command = (f"sed -i 's/MOD_ID = .*/MOD_ID = \"{module}\";/g'"
f" {SKETCH_PATH}")
print(colored("Changing sketch module id . . .", 'yellow'))
run(command)
# Upload scketch
command = (f'{ARDUINO_PATH}./arduino '
f'--upload {SKETCH_PATH} '
f'--port {ARDUINO_PORT}')
print(run(command))