-
Notifications
You must be signed in to change notification settings - Fork 0
/
boot.py
56 lines (44 loc) · 1.34 KB
/
boot.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
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
# Configures board on boot:
# - Disables transmit pins
# - Checks if config button is pressed
# - If pressed, enables USB drive and console
# - If not pressed, disables USB drive and enables console
# - Remounts filesystem as read-only
# - Sets USB drive name if enabled
import os
import board
import storage
import usb_cdc
from digitalio import DigitalInOut, Direction, Pull
# 5v biasT
biast = DigitalInOut(board.GP1)
biast.direction = Direction.OUTPUT
biast.value = False
# config button
btn = DigitalInOut(board.GP15)
btn.direction = Direction.INPUT
btn.pull = Pull.UP
def file_or_dir_exists(filename):
try:
os.stat(filename)
return True
except OSError:
return False
# default disable usb drive
if btn.value is True:
print("boot: button not pressed, disabling drive")
storage.disable_usb_drive()
storage.remount("/", readonly=False)
usb_cdc.enable(console=True, data=False)
if file_or_dir_exists("ota.py"):
print("boot: installing new release")
os.remove("code.py")
os.rename("ota.py", "code.py")
else:
print("boot: button pressed, enable console, enabling drive")
usb_cdc.enable(console=True, data=False)
new_name = "APRSGATE"
storage.remount("/", readonly=False)
m = storage.getmount("/")
m.label = new_name
storage.remount("/", readonly=True)