Skip to content

Commit 135b940

Browse files
committed
Untested nicer msg
1 parent 6be48d4 commit 135b940

File tree

2 files changed

+48
-52
lines changed

2 files changed

+48
-52
lines changed

esp32/modules/easydraw.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,30 @@
66

77
import ugfx, badge
88

9-
# Globals
10-
msgLineNumber = 0
11-
msgShown = False
12-
139
# Functions
14-
def msg(message, clear=False):
15-
global msgShown
16-
msgShown = True
17-
global msgLineNumber
18-
if clear:
10+
def msg(message, title = 'Still Loading Anyway...', reset = False):
11+
"""Show a terminal style loading screen with title
12+
13+
title can be optionaly set when resetting or first call
14+
"""
15+
global lineNumber
16+
if reset:
17+
del lineNumber
18+
try:
19+
lineNumber
20+
except:
1921
ugfx.clear(ugfx.WHITE)
20-
ugfx.string(0, 0, message, "PermanentMarker22", ugfx.BLACK)
21-
msgLineNumber = 0
22+
ugfx.string(0, 0, title, "PermanentMarker22", ugfx.BLACK)
23+
lineNumber = 0
2224
else:
23-
ugfx.string(0, 30 + (msgLineNumber * 15), message, "Roboto_Regular12", ugfx.BLACK)
25+
ugfx.string(0, 30 + (lineNumber * 15), message, "Roboto_Regular12", ugfx.BLACK)
2426
ugfx.flush(ugfx.LUT_FASTER)
25-
msgLineNumber += 1
27+
lineNumber += 1
2628

2729
def nickname(y = 25, font = "PermanentMarker36", color = ugfx.BLACK):
2830
nick = badge.nvs_get_str("owner", "name", 'Jan de Boer')
2931
ugfx.string_box(0,y,296,38, nick, font, color, ugfx.justifyCenter)
30-
32+
3133
def battery(vUsb, vBatt, charging):
3234
vMin = badge.nvs_get_u16('batt', 'vmin', 3700) # mV
3335
vMax = badge.nvs_get_u16('batt', 'vmax', 4200) # mV

esp32/modules/splash.py

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -30,41 +30,37 @@ def splash_draw_actions(sleeping):
3030
l = ugfx.get_string_width(info2,"Roboto_Regular12")
3131
ugfx.string(296-l, 12, info2, "Roboto_Regular12",ugfx.BLACK)
3232

33-
def splash_draw(full=False,sleeping=False):
34-
if easydraw.msgShown:
35-
easydraw.msgShown = False
36-
easydraw.msgLineNumber = 0
37-
full = True
38-
33+
def splash_draw(full=False,sleeping=False):
34+
3935
vUsb = badge.usb_volt_sense()
4036
vBatt = badge.battery_volt_sense()
4137
vBatt += vDrop
4238
charging = badge.battery_charge_status()
43-
39+
4440
if splash_power_countdown_get()<1:
4541
full= True
46-
42+
4743
if full:
4844
ugfx.clear(ugfx.WHITE)
4945
easydraw.nickname()
5046
else:
5147
ugfx.area(0,0,ugfx.width(),24,ugfx.WHITE)
5248
ugfx.area(0,ugfx.height()-64,ugfx.width(),64,ugfx.WHITE)
53-
54-
easydraw.battery(vUsb, vBatt, charging)
55-
49+
50+
easydraw.battery(vUsb, vBatt, charging)
51+
5652
global splashPowerCountdown
57-
53+
5854
if splashPowerCountdown>0:
5955
if vBatt>500:
6056
ugfx.string(52, 0, str(round(vBatt/1000, 1)) + 'v','Roboto_Regular12',ugfx.BLACK)
6157
if splashPowerCountdown>0 and splashPowerCountdown<badge.nvs_get_u8('splash', 'timer.amount', 30):
6258
ugfx.string(52, 13, "Sleeping in "+str(splashPowerCountdown)+"...",'Roboto_Regular12',ugfx.BLACK)
63-
59+
6460
splash_draw_actions(sleeping)
65-
61+
6662
services.draw()
67-
63+
6864
if full:
6965
ugfx.flush(ugfx.LUT_FULL)
7066
else:
@@ -74,21 +70,19 @@ def splash_draw(full=False,sleeping=False):
7470

7571
def splash_ota_download_info():
7672
import urequests as requests
77-
easydraw.msg("Checking for updates...", True)
73+
easydraw.msg("Checking for updates...")
7874
result = False
7975
try:
8076
data = requests.get("https://badge.sha2017.org/version")
8177
except:
82-
easydraw.msg("Error:")
83-
easydraw.msg("Could not download JSON!")
78+
easydraw.msg("Error: could not download JSON!")
8479
time.sleep(5)
8580
return False
8681
try:
8782
result = data.json()
8883
except:
8984
data.close()
90-
easydraw.msg("Error:")
91-
easydraw.msg("Could not decode JSON!")
85+
easydraw.msg("Error: could not decode JSON!")
9286
time.sleep(5)
9387
return False
9488
data.close()
@@ -98,7 +92,7 @@ def splash_ota_check():
9892
if not easywifi.status():
9993
if not easywifi.enable():
10094
return False
101-
95+
10296
info = splash_ota_download_info()
10397
if info:
10498
import version
@@ -111,10 +105,10 @@ def splash_ota_check():
111105

112106
def splash_ota_start():
113107
appglue.start_ota()
114-
108+
115109
# Resources
116110
def splash_resources_install():
117-
easydraw.msg("Installing resources...",True)
111+
easydraw.msg("Installing resources...")
118112
if not easywifi.status():
119113
if not easywifi.enable():
120114
return False
@@ -145,10 +139,10 @@ def splash_sponsors_install():
145139
if not easywifi.enable():
146140
return False
147141
print("[SPLASH] Installing sponsors...")
148-
easydraw.msg("Installing sponsors...",True)
142+
easydraw.msg("Installing sponsors...")
149143
import woezel
150144
woezel.install("sponsors")
151-
easydraw.msg("Done.")
145+
easydraw.msg("Done!")
152146

153147
def splash_sponsors_show():
154148
needToInstall = True
@@ -160,7 +154,7 @@ def splash_sponsors_show():
160154
except:
161155
print("[SPLASH] Sponsors not installed.")
162156
if version>=14:
163-
needToInstall = False
157+
needToInstall = False
164158
if needToInstall:
165159
splash_sponsors_install()
166160
try:
@@ -171,14 +165,14 @@ def splash_sponsors_show():
171165
appglue.start_app("sponsors")
172166
except:
173167
pass
174-
168+
175169

176170
# About
177171

178172
def splash_about_countdown_reset():
179173
global splashAboutCountdown
180174
splashAboutCountdown = badge.nvs_get_u8('splash', 'about.amount', 10)
181-
175+
182176
def splash_about_countdown_trigger():
183177
global splashAboutCountdown
184178
try:
@@ -191,7 +185,7 @@ def splash_about_countdown_trigger():
191185
appglue.start_app('magic', False)
192186
else:
193187
print("[SPLASH] Magic in "+str(splashAboutCountdown)+"...")
194-
188+
195189

196190
# Power management
197191

@@ -206,14 +200,14 @@ def splash_power_countdown_get():
206200
except:
207201
splash_power_countdown_reset()
208202
return splashPowerCountdown
209-
203+
210204
def splash_power_countdown_trigger():
211205
global splashPowerCountdown
212206
try:
213207
splashPowerCountdown
214208
except:
215209
splash_power_countdown_reset()
216-
210+
217211
splashPowerCountdown -= 1
218212
if badge.usb_volt_sense() > 4000:
219213
splash_power_countdown_reset()
@@ -253,7 +247,7 @@ def splash_input_select(pressed):
253247
if otaAvailable:
254248
splash_ota_start()
255249
splash_power_countdown_reset()
256-
250+
257251
#def splash_input_left(pressed):
258252
# if pressed:
259253
# appglue.start_bpp()
@@ -285,7 +279,7 @@ def splash_timer_init():
285279
splashTimer = machine.Timer(-1)
286280
splashTimer.init(period=badge.nvs_get_u16('splash', 'timer.period', 100), mode=machine.Timer.ONE_SHOT, callback=splash_timer_callback)
287281
print("[SPLASH] Timer created")
288-
282+
289283
def splash_timer_callback(tmr):
290284
try:
291285
if services.loop(splash_power_countdown_get()):
@@ -295,8 +289,8 @@ def splash_timer_callback(tmr):
295289
if not splash_power_countdown_trigger():
296290
splash_draw(False, False)
297291
tmr.init(period=badge.nvs_get_u16('splash', 'timer.period', 100), mode=machine.Timer.ONE_SHOT, callback=splash_timer_callback)
298-
299-
292+
293+
300294
### PROGRAM
301295

302296
# Load settings from NVS
@@ -316,7 +310,7 @@ def splash_timer_callback(tmr):
316310

317311
# Initialize about subsystem
318312
splash_about_countdown_reset()
319-
313+
320314
# Setup / Sponsors / OTA check / NTP clock sync
321315
setupState = badge.nvs_get_u8('badge', 'setup.state', 0)
322316
if setupState == 0: #First boot
@@ -338,7 +332,7 @@ def splash_timer_callback(tmr):
338332
otaAvailable = splash_ota_check()
339333
else:
340334
otaAvailable = badge.nvs_get_u8('badge','OTA.ready',0)
341-
335+
342336
# Download resources to fatfs
343337
splash_resources_check()
344338

@@ -348,7 +342,7 @@ def splash_timer_callback(tmr):
348342

349343
# Initialize services
350344
services.setup()
351-
345+
352346
# Disable WiFi if active
353347
easywifi.disable()
354348

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