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

Commit e6a654a

Browse files
committed
HOTFIX
1 parent f6c0902 commit e6a654a

File tree

1 file changed

+70
-101
lines changed

1 file changed

+70
-101
lines changed

esp32/modules/splash.py

Lines changed: 70 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,9 @@
11
import ugfx, time, badge, machine, uos, appglue, deepsleep, network, esp
22

33
# SHA2017 badge home screen
4+
# HOTFIX VERSION 26-07-2017
45
# Renze Nicolai 2017
56

6-
# Reboot counter (Used for BPP)
7-
def get_reboot_counter():
8-
return esp.rtcmem_read(1023)
9-
10-
def set_reboot_counter(value):
11-
esp.rtcmem_write(1023, value)
12-
13-
def increment_reboot_counter():
14-
val = get_reboot_counter()
15-
if (val<255):
16-
val = val + 1
17-
set_reboot_counter(val)
18-
19-
# BPP
20-
def bpp_execute():
21-
print("[SPLASH] Executing BPP...")
22-
set_reboot_counter(0)
23-
esp.rtcmem_write(0,2)
24-
esp.rtcmem_write(0,~2)
25-
deepsleep.reboot()
26-
27-
def bpp_check():
28-
global bpp_after_count
29-
if (get_reboot_counter()>bpp_after_count):
30-
return True
31-
return False
32-
337
# SERVICES
348
def setup_services():
359
global services
@@ -239,8 +213,6 @@ def draw_home(percent, cstate, status, full_clear, going_to_sleep):
239213
draw_helper_battery(percent, cstate)
240214
if (going_to_sleep):
241215
info = "[ ANY: Wake up ]"
242-
elif (status=="BPP"):
243-
info = "[ ANY: Exit BPP ]"
244216
else:
245217
info = "[ START: LAUNCHER ]"
246218

@@ -270,7 +242,6 @@ def start_launcher(pushed):
270242
print("[SPLASH] Starting launcher...")
271243
global splashTimer
272244
splashTimer.deinit()
273-
increment_reboot_counter()
274245
appglue.start_app("launcher")
275246

276247
def start_ota(pushed):
@@ -302,14 +273,12 @@ def start_magic(pushed):
302273

303274
# SLEEP
304275
def badge_sleep():
305-
increment_reboot_counter()
306276
global sleep_duration
307277
print("[SPLASH] Going to sleep now...")
308278
badge.eink_busy_wait() #Always wait for e-ink
309279
deepsleep.start_sleeping(sleep_duration*1000)
310280

311281
def badge_sleep_forever():
312-
increment_reboot_counter()
313282
print("[SPLASH] Going to sleep WITHOUT TIME WAKEUP now...")
314283
badge.eink_busy_wait() #Always wait for e-ink
315284
deepsleep.start_sleeping(0) #Sleep until button interrupt occurs
@@ -319,8 +288,6 @@ def splashTimer_callback(tmr):
319288
global loopCnt
320289
global timer_loop_amount
321290
#print("[TIMER] "+str(loopCnt))
322-
#print("[BATTERY] "+str(badge.battery_volt_sense())+" ["+str(badge.battery_charge_status())+"]")
323-
324291
if loopCnt<1:
325292
loopCnt = timer_loop_amount
326293
cstate = badge.battery_charge_status()
@@ -336,12 +303,8 @@ def splashTimer_callback(tmr):
336303
ugfx.flush()
337304
badge_sleep_forever()
338305
else:
339-
if (bpp_check()):
340-
draw_home(percent, cstate, "BPP", False, True)
341-
bpp_execute()
342-
else:
343-
draw_home(percent, cstate, "Zzz...", False, True)
344-
badge_sleep()
306+
draw_home(percent, cstate, "Zzz...", False, True)
307+
badge_sleep()
345308
else:
346309
if (loop_services(loopCnt)):
347310
loopCnt = timer_loop_amount
@@ -386,6 +349,7 @@ def wifi_connect():
386349
return True
387350

388351
# CHECK OTA VERSION
352+
389353
def download_ota_info():
390354
import gc
391355
import urequests as requests
@@ -409,38 +373,42 @@ def download_ota_info():
409373
return result
410374

411375
def check_ota_available():
412-
import wifi
413-
import network
414-
global update_available
415-
global update_name
416-
global update_build
417-
if not wifi.sta_if.isconnected():
418-
if not wifi_connect():
376+
try:
377+
import wifi
378+
import network
379+
global update_available
380+
global update_name
381+
global update_build
382+
if not wifi.sta_if.isconnected():
383+
if not wifi_connect():
384+
disableWifi()
385+
return False
386+
json = download_ota_info()
387+
if (json):
388+
import version
389+
if (json["build"]>version.build):
390+
update_available = True
391+
update_name = json["name"]
392+
update_build = json["build"]
393+
ugfx.input_attach(ugfx.BTN_B, start_ota)
394+
else:
419395
disableWifi()
420396
return False
421-
json = download_ota_info()
422-
if (json):
423-
import version
424-
if (json["build"]>version.build):
425-
update_available = True
426-
update_name = json["name"]
427-
update_build = json["build"]
428-
ugfx.input_attach(ugfx.BTN_B, start_ota)
429-
else:
430397
disableWifi()
398+
return True
399+
except:
400+
print("OTA CHECK EXCEPTION")
431401
return False
432-
disableWifi()
433-
return True
434402

435403
# WELCOME (SETUP, SPONSORS OR CLOCK)
436404
def welcome():
437-
setupcompleted = badge.nvs_get_u8('badge', 'setup.state', 0)
405+
setupcompleted = int(badge.nvs_get_str('badge', 'setup.state', '0'))
438406
if (setupcompleted==0): # First boot (open setup)
439407
print("[SPLASH] Setup not completed. Running setup!")
440408
appglue.start_app("setup")
441409
elif (setupcompleted==1): # Second boot (after setup)
442410
print("[SPLASH] Showing sponsors once...")
443-
badge.nvs_set_u8('badge', 'setup.state', 2) # Only force show sponsors once
411+
badge.nvs_set_str('badge', 'setup.state', '2') # Only force show sponsors once
444412
appglue.start_app("sponsors")
445413
else: # Setup completed
446414
print("[SPLASH] Normal boot.")
@@ -453,43 +421,44 @@ def welcome():
453421

454422
# SETTINGS FROM NVS
455423
def load_settings():
456-
header_inv = badge.nvs_get_u8('splash', 'header.invert', 0)
457-
if (header_inv>0):
458-
global header_fg
459-
global header_bg
460-
header_fg = ugfx.WHITE
461-
header_bg = ugfx.BLACK
462-
header_hws = badge.nvs_get_u8('splash', 'header.hws', 0) #Hide While Sleeping
463-
if (header_hws>0):
464-
global header_hide_while_sleeping
465-
header_hide_while_sleeping = True
466-
header_hbws = badge.nvs_get_u8('splash', 'header.hbws', 0) #Hide Battery While Sleeping
467-
if (header_hbws>0):
468-
global header_hide_battery_while_sleeping
469-
header_hide_battery_while_sleeping = True
470-
global sleep_duration
471-
sleep_duration = badge.nvs_get_u8('splash', 'sleep.duration', 60)
472-
if (sleep_duration<30):
473-
print("[SPLASH] Sleep duration set to less than 30 seconds. Forcing 30 seconds.")
474-
sleep_duration = 30
475-
#if (sleep_duration>120):
476-
# print("[SPLASH] Sleep duration set to more than 120 seconds. Forcing 120 seconds.")
477-
global battery_volt_min
478-
battery_volt_min = badge.nvs_get_u16('splash', 'batt.vmin', 3700) # mV
479-
global battery_volt_max
480-
battery_volt_max = badge.nvs_get_u16('splash', 'batt.vmax', 4200) # mV
481-
global battery_percent_empty
482-
battery_percent_empty = badge.nvs_get_u8('splash', 'batt.pempty', 1) # %
483-
global ntp_timeout
484-
ntp_timeout = badge.nvs_get_u8('splash', 'ntp.timeout', 40) #amount of tries
485-
global bpp_after_count
486-
bpp_after_count = badge.nvs_get_u8('splash', 'bpp.count', 5)
487-
global splash_timer_interval
488-
splash_timer_interval = badge.nvs_get_u16('splash', 'tmr.interval', 200)
489-
global timer_loop_amount
490-
timer_loop_amount = badge.nvs_get_u8('splash', 'tmr.amount', 25)
491-
global loopCnt
492-
loopCnt = timer_loop_amount
424+
try:
425+
header_inv = badge.nvs_get_u8('splash', 'header.invert', 0)
426+
if (header_inv>0):
427+
global header_fg
428+
global header_bg
429+
header_fg = ugfx.WHITE
430+
header_bg = ugfx.BLACK
431+
header_hws = badge.nvs_get_u8('splash', 'header.hws', 0) #Hide While Sleeping
432+
if (header_hws>0):
433+
global header_hide_while_sleeping
434+
header_hide_while_sleeping = True
435+
header_hbws = badge.nvs_get_u8('splash', 'header.hbws', 0) #Hide Battery While Sleeping
436+
if (header_hbws>0):
437+
global header_hide_battery_while_sleeping
438+
header_hide_battery_while_sleeping = True
439+
global sleep_duration
440+
sleep_duration = badge.nvs_get_u8('splash', 'sleep.duration', 60)
441+
if (sleep_duration<30):
442+
print("[SPLASH] Sleep duration set to less than 30 seconds. Forcing 30 seconds.")
443+
sleep_duration = 30
444+
#if (sleep_duration>120):
445+
# print("[SPLASH] Sleep duration set to more than 120 seconds. Forcing 120 seconds.")
446+
global battery_volt_min
447+
battery_volt_min = badge.nvs_get_u16('splash', 'bat.volt.min', 3500) # mV
448+
global battery_volt_max
449+
battery_volt_max = badge.nvs_get_u16('splash', 'bat.volt.max', 4200) # mV
450+
global battery_percent_empty
451+
battery_percent_empty = badge.nvs_get_u8('splash', 'bat.perc.empty', 1) # %
452+
global ntp_timeout
453+
ntp_timeout = badge.nvs_get_u8('splash', 'ntp.timeout', 40) #amount of tries
454+
global splash_timer_interval
455+
splash_timer_interval = badge.nvs_get_u16('splash', 'timer.interval', 200)
456+
global timer_loop_amount
457+
timer_loop_amount = badge.nvs_get_u8('splash', 'timer.amount', 25)
458+
global loopCnt
459+
loopCnt = timer_loop_amount
460+
except:
461+
print("SETTINGS LOAD ERROR")
493462

494463
# MAIN
495464
def splash_main():
@@ -506,7 +475,6 @@ def splash_main():
506475
global battery_percent_empty
507476
if (cstate) or (percent>battery_percent_empty) or (vbatt<100):
508477
ugfx.input_init()
509-
welcome()
510478
ugfx.input_attach(ugfx.BTN_START, start_launcher)
511479
ugfx.input_attach(ugfx.BTN_A, start_magic)
512480
ugfx.input_attach(ugfx.BTN_B, nothing)
@@ -515,12 +483,14 @@ def splash_main():
515483
ugfx.input_attach(ugfx.JOY_DOWN, nothing)
516484
ugfx.input_attach(ugfx.JOY_LEFT, nothing)
517485
ugfx.input_attach(ugfx.JOY_RIGHT, nothing)
486+
try:
487+
welcome()
488+
except:
489+
print("Well fuck.")
518490
global splashTimer
519491
setup_services()
520492
start_sleep_counter()
521493
full_clear = False
522-
if (get_reboot_counter()==0):
523-
full_clear = True
524494
draw_home(percent, cstate, header_status_string, full_clear, False)
525495
else:
526496
draw_batterylow(percent)
@@ -540,7 +510,6 @@ def splash_main():
540510
battery_volt_max = 4300
541511
battery_percent_empty = 1
542512
ntp_timeout = 40
543-
bpp_after_count = 5
544513
header_status_string = ""
545514
splash_timer_interval = 500
546515

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