Skip to content

Commit

Permalink
Merge pull request #62 from emfcamp/boot-improvements
Browse files Browse the repository at this point in the history
Emergency boot, OTA and POST improvements
  • Loading branch information
MatthewWilkes authored Jun 1, 2022
2 parents b552e41 + 8ab1cd1 commit 6f83044
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 17 deletions.
4 changes: 2 additions & 2 deletions modules/bootmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ def reset_firstrun():
class BootMenu:

TITLE = "Recovery Menu"
BG = RED
BG = BRAND_ORANGE
FG = WHITE
FOCUS_FG = RED
FOCUS_FG = ADDITIONAL_DEEP_ORANGE
FOCUS_BG = WHITE

# Note, the text for each choice needs to be <= 16 characters in order to fit on screen
Expand Down
13 changes: 10 additions & 3 deletions modules/otaupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def supports_rotation(self):
return False

def on_start(self):
self.window = textwindow.TextWindow(MAGENTA, WHITE, "Firmware Update")
self.window = textwindow.TextWindow(BRAND_PINK, WHITE, "Firmware Update")

def wait_for_a(self):
while True:
Expand All @@ -60,10 +60,17 @@ def on_activate(self):
window.println("USB flash needed")
return

lines = window.flow_lines("OTA requires a charged battery.USB power is insufficient.")
for line in lines:
window.println(line)
window.println("")

version = ota.get_version()
if version == "HEAD-HASH-NOTFOUND":
version = "Custom"
window.println("Boot: " + current.info()[4])
window.println("Next: " + nxt.info()[4])
window.println("Version:")
window.println(ota.get_version())
window.println("Version: " + version)
window.println()
line = window.get_next_line()
window.println("Press [A] to")
Expand Down
61 changes: 49 additions & 12 deletions modules/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class PowerOnSelfTest:

title = "POST"

BG = tidal.BLUE
FG = tidal.WHITE
BG = tidal.BRAND_ORANGE
FG = tidal.BLACK


def run_sync(self):
Expand All @@ -32,6 +32,8 @@ def on_start(self):
self.window.cls()
self.i2c_addresses = tidal.i2cs.scan()
self.connecting = False
self.error_found = False
self.buttons_seen = {repr(button):False for button in tidal.ALL_BUTTONS}
self.adc = ADC(tidal.BUTTON_A)
self.adc.atten(ADC.ATTN_11DB)
self.adc.width(ADC.WIDTH_12BIT)
Expand All @@ -40,6 +42,7 @@ def update_screen(self):
win = self.window
reading = self.read_battery_state()
if reading[2] < 0.8:
self.buttons_seen[repr(tidal.BUTTON_A)] = True
nan = float('nan')
win.println(" Raw: {:0.3g}".format(nan))
win.println(" Voltage: {:0.3g}".format(nan))
Expand Down Expand Up @@ -76,38 +79,72 @@ def on_activate(self):
#window.cls()
window.set_next_line(0)

i2c = self.i2c_addresses == [18, 44, 96]
if not i2c and self.window.bg != tidal.ADDITIONAL_RED:
self.window.bg = tidal.ADDITIONAL_RED
self.window.fg = tidal.WHITE
self.window.cls()

self.update_screen()

window.println("")
window.println("")

window.println(f"I2C: {self.i2c_addresses}")
#tidal.enable_peripheral_I2C()
#p_i2c_addresses = tidal.i2cp.scan() if tidal.i2cp else None
#window.println(f"I2Cp: {p_i2c_addresses}")

window.println("")

tidal.led_power_on()
tidal.led[0] = (255, 128, 0)
tidal.led.write()

buttons = [btn.value() for btn in tidal.ALL_BUTTONS]

window.println("")
window.println("")

buttons = []
for button in tidal.ALL_BUTTONS:
val = button.value()
if val == 0 and button != tidal.BUTTON_A:
self.buttons_seen[repr(button)] = True
buttons.append('X' if self.buttons_seen[repr(button)] else '.')
buttons = "".join(map(str, buttons))
window.println(f"BTN: {buttons}")
buttons = all(self.buttons_seen.values())

window.println("")
window.println("")

wifi_state = False
if self.timer:
if tidal.BUTTON_B.value() == 0:
self.timer -= 1
else:
self.timer = min(self.timer + 1, 10)
window.println(f"Wifi: Hold B {self.timer:2}")
self.timer -= 1
window.println(f"Wifi: Wait for {self.timer:2}")
window.println("IP: N/A")
else:
if not self.connecting:
wifi.connect()
self.connecting = True
window.println(f"Wifi: {wifi.get_sta_status()}")
window.println(f"IP: {wifi.get_ip()}")
if wifi.get_sta_status() == 1010:
wifi_state = True
try:
x,y,z = accelerometer.get_xyz()
except OSError:
x = y = z = None

window.println("")
window.println("")

window.println("Accel")
window.println(f"X: {x}")
window.println(f"Y: {y}")
window.println(f"Z: {z}")

accel = x != 0 or y != 0 or z != 0

print(f"{buttons}, {accel}, {wifi_state}, {i2c}")
if buttons and accel and wifi_state and i2c:
if self.window.bg != tidal.BRAND_NAVY:
self.window.bg = tidal.BRAND_NAVY
self.window.fg = tidal.WHITE
self.window.cls()

0 comments on commit 6f83044

Please sign in to comment.