Skip to content
This repository was archived by the owner on Oct 28, 2023. It is now read-only.

Commit 3d81d93

Browse files
authored
Merge pull request SHA2017-badge#116 from SHA2017-badge/rstd-batterymanagement
Major python code change
2 parents e6a654a + 767902e commit 3d81d93

File tree

6 files changed

+277
-498
lines changed

6 files changed

+277
-498
lines changed

esp32/modules/_boot.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
try:
44
uos.mount(uos.VfsNative(True), '/')
55
open("/boot.py", "r")
6-
76
except OSError:
87
import inisetup
98
vfs = inisetup.setup()

esp32/modules/appglue.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import ugfx, esp, badge, deepsleep
22

3-
def start_app(app):
4-
ugfx.clear(ugfx.WHITE)
5-
ugfx.string(0, 0, "Please wait...", "PermanentMarker22", ugfx.BLACK)
6-
if (app==""):
7-
ugfx.string(0, 25, "Returning to homescreen...","Roboto_Regular12",ugfx.BLACK)
8-
else:
9-
ugfx.string(0, 25, "Starting "+app+"...","Roboto_Regular12",ugfx.BLACK)
10-
ugfx.flush()
3+
def start_app(app, display = True):
4+
if display:
5+
ugfx.clear(ugfx.WHITE)
6+
ugfx.string(0, 0, "Loading...", "PermanentMarker22", ugfx.BLACK)
7+
if app:
8+
ugfx.string(0, 25, "Starting "+app+"...","Roboto_Regular12",ugfx.BLACK)
9+
else:
10+
ugfx.string(0, 25, "Returning to homescreen...","Roboto_Regular12",ugfx.BLACK)
11+
ugfx.flush(ugfx.LUT_FASTER)
1112
esp.rtcmem_write_string(app)
1213
badge.eink_busy_wait()
1314
deepsleep.reboot()

esp32/modules/deepsleep.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import machine as m
1+
import machine
22

3-
p = m.Pin(25)
4-
r = m.RTC()
5-
r.wake_on_ext0(pin = p, level = 0)
3+
pin = machine.Pin(25)
4+
rtc = machine.RTC()
5+
rtc.wake_on_ext0(pin = pin, level = 0)
66

77
def start_sleeping(time=0):
8-
m.deepsleep(time)
8+
machine.deepsleep(time)
99

1010
def reboot():
11-
m.deepsleep(1)
11+
machine.deepsleep(1)

esp32/modules/inisetup.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@ def setup():
1111
ugfx.init()
1212
esp.rtcmem_write(0,0)
1313
esp.rtcmem_write(1,0)
14+
splash = badge.nvs_get_str('badge','boot.splash','splash')
1415
if machine.reset_cause() != machine.DEEPSLEEP_RESET:
15-
print("cold boot")
16-
import splash
16+
print('[BOOT.PY] Cold boot')
1717
else:
18-
print("wake from sleep")
18+
print("[BOOT.PY] Wake from sleep")
1919
load_me = esp.rtcmem_read_string()
20-
if load_me != "":
20+
if load_me:
21+
splash = load_me
2122
print("starting %s" % load_me)
2223
esp.rtcmem_write_string("")
23-
__import__(load_me)
24-
else:
25-
import splash
24+
__import__(splash)
2625
""")
2726
return vfs

esp32/modules/services.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import uos
2+
3+
# SHA2017 badge services
4+
# Renze Nicolai
5+
# Thomas Roos
6+
7+
def setup():
8+
global services
9+
try:
10+
apps = uos.listdir('lib')
11+
except OSError:
12+
print("[SERVICES] Can't setup services: no lib folder!")
13+
return False
14+
found = False
15+
for app in apps:
16+
try:
17+
files = uos.listdir('lib/'+app)
18+
except OSError:
19+
print("[SERVICES] Listing app files for app '"+app+"' failed!")
20+
21+
for f in files:
22+
if (f=="service.py"):
23+
found = True
24+
print("[SERVICES] Found service "+app+"...")
25+
try:
26+
srv = __import__('lib/'+app+'/service')
27+
services.append(srv) #Add to global list
28+
srv.setup()
29+
except BaseException as msg:
30+
print("Exception in service setup "+app+": ", msg)
31+
break
32+
return found
33+
34+
def loop(lcnt):
35+
noSleep = False
36+
global services
37+
for srv in services:
38+
try:
39+
if (srv.loop(lcnt)):
40+
noSleep = True
41+
except BaseException as msg:
42+
print("[SERVICES] Service loop exception: ", msg)
43+
return noSleep
44+
45+
def draw():
46+
global services
47+
x = 0
48+
y = 114
49+
for srv in services:
50+
try:
51+
space_used = srv.draw(x,y)
52+
if (space_used>0):
53+
y = y - abs(space_used)
54+
except BaseException as msg:
55+
print("[SERVICES] Service draw exception: ", msg)
56+
57+
services = []

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