Skip to content

Commit 09d45c7

Browse files
authored
Merge pull request SHA2017-badge#180 from SHA2017-badge/exceptions
Exception reporting and post OTA update script
2 parents 90ee894 + 4dd77d6 commit 09d45c7

File tree

5 files changed

+65
-21
lines changed

5 files changed

+65
-21
lines changed

esp32/modules/create.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import uos
2+
3+
def boot():
4+
print("Updating 'boot.py'...")
5+
with open("/boot.py", "w") as f:
6+
f.write("""\
7+
# This file is executed on every boot (including wake-boot from deepsleep)
8+
import badge, machine, esp, ugfx, sys
9+
badge.init()
10+
ugfx.init()
11+
esp.rtcmem_write(0,0)
12+
esp.rtcmem_write(1,0)
13+
splash = badge.nvs_get_str('boot','splash','splash')
14+
if machine.reset_cause() != machine.DEEPSLEEP_RESET:
15+
print('[BOOT] Cold boot')
16+
else:
17+
print("[BOOT] Wake from sleep")
18+
load_me = esp.rtcmem_read_string()
19+
if load_me:
20+
splash = load_me
21+
print("starting %s" % load_me)
22+
esp.rtcmem_write_string("")
23+
try:
24+
if not splash=="shell":
25+
__import__(splash)
26+
else:
27+
ugfx.clear(ugfx.WHITE)
28+
ugfx.flush(ugfx.LUT_FULL)
29+
except BaseException as e:
30+
sys.print_exception(e)
31+
import easydraw
32+
easydraw.msg("A fatal error occured!","Still Crashing Anyway", True)
33+
easydraw.msg("")
34+
easydraw.msg("Guru meditation:")
35+
easydraw.msg(str(e))
36+
easydraw.msg("")
37+
easydraw.msg("Rebooting in 5 seconds...")
38+
import time
39+
time.sleep(5)
40+
import appglue
41+
appglue.home()
42+
""")

esp32/modules/inisetup.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,6 @@
33
def setup():
44
print("Performing initial setup")
55
vfs = uos.VfsNative(True)
6-
with open("/boot.py", "w") as f:
7-
f.write("""\
8-
# This file is executed on every boot (including wake-boot from deepsleep)
9-
import badge, machine, esp, ugfx
10-
badge.init()
11-
ugfx.init()
12-
esp.rtcmem_write(0,0)
13-
esp.rtcmem_write(1,0)
14-
splash = badge.nvs_get_str('badge','boot.splash','splash')
15-
if machine.reset_cause() != machine.DEEPSLEEP_RESET:
16-
print('[BOOT.PY] Cold boot')
17-
else:
18-
print("[BOOT.PY] Wake from sleep")
19-
load_me = esp.rtcmem_read_string()
20-
if load_me:
21-
splash = load_me
22-
print("starting %s" % load_me)
23-
esp.rtcmem_write_string("")
24-
__import__(splash)
25-
""")
6+
import create
7+
create.boot()
268
return vfs

esp32/modules/post_ota.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import badge, easydraw
2+
3+
def u0to1():
4+
import create
5+
create.boot()
6+
easydraw.msg("Applied patch 1")
7+
8+
# Read current patch level
9+
lvl = badge.nvs_get_u8('ota', 'fixlvl', 0)
10+
11+
if lvl<1:
12+
easydraw.msg("Running post OTA scripts...","Still updating anyways...",)
13+
u0to1()
14+
easydraw.msg("Post OTA update completed")
15+
badge.nvs_set_u8('ota', 'fixlvl', 1)

esp32/modules/shell.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import appglue
2+
appglue.start_app("shell")

esp32/modules/splash.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ def onSleep(idleTime):
123123
splash_input_init()
124124
splash_about_countdown_reset()
125125

126+
# post ota script
127+
import post_ota
128+
126129
setupState = badge.nvs_get_u8('badge', 'setup.state', 0)
127130
if setupState == 0: #First boot
128131
print("[SPLASH] First boot (start setup)...")
@@ -171,5 +174,5 @@ def onSleep(idleTime):
171174

172175
print("----")
173176
print("WARNING: POWER MANAGEMENT ACTIVE")
174-
print("TO USE REPL START LAUNCHER")
177+
print("To use shell type 'import shell' within 5 seconds.")
175178
print("----")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy