1
1
import ugfx , time , badge , machine , uos , appglue , deepsleep , network , esp
2
2
3
3
# SHA2017 badge home screen
4
+ # HOTFIX VERSION 26-07-2017
4
5
# Renze Nicolai 2017
5
6
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
-
33
7
# SERVICES
34
8
def setup_services ():
35
9
global services
@@ -239,8 +213,6 @@ def draw_home(percent, cstate, status, full_clear, going_to_sleep):
239
213
draw_helper_battery (percent , cstate )
240
214
if (going_to_sleep ):
241
215
info = "[ ANY: Wake up ]"
242
- elif (status == "BPP" ):
243
- info = "[ ANY: Exit BPP ]"
244
216
else :
245
217
info = "[ START: LAUNCHER ]"
246
218
@@ -270,7 +242,6 @@ def start_launcher(pushed):
270
242
print ("[SPLASH] Starting launcher..." )
271
243
global splashTimer
272
244
splashTimer .deinit ()
273
- increment_reboot_counter ()
274
245
appglue .start_app ("launcher" )
275
246
276
247
def start_ota (pushed ):
@@ -302,14 +273,12 @@ def start_magic(pushed):
302
273
303
274
# SLEEP
304
275
def badge_sleep ():
305
- increment_reboot_counter ()
306
276
global sleep_duration
307
277
print ("[SPLASH] Going to sleep now..." )
308
278
badge .eink_busy_wait () #Always wait for e-ink
309
279
deepsleep .start_sleeping (sleep_duration * 1000 )
310
280
311
281
def badge_sleep_forever ():
312
- increment_reboot_counter ()
313
282
print ("[SPLASH] Going to sleep WITHOUT TIME WAKEUP now..." )
314
283
badge .eink_busy_wait () #Always wait for e-ink
315
284
deepsleep .start_sleeping (0 ) #Sleep until button interrupt occurs
@@ -319,8 +288,6 @@ def splashTimer_callback(tmr):
319
288
global loopCnt
320
289
global timer_loop_amount
321
290
#print("[TIMER] "+str(loopCnt))
322
- #print("[BATTERY] "+str(badge.battery_volt_sense())+" ["+str(badge.battery_charge_status())+"]")
323
-
324
291
if loopCnt < 1 :
325
292
loopCnt = timer_loop_amount
326
293
cstate = badge .battery_charge_status ()
@@ -336,12 +303,8 @@ def splashTimer_callback(tmr):
336
303
ugfx .flush ()
337
304
badge_sleep_forever ()
338
305
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 ()
345
308
else :
346
309
if (loop_services (loopCnt )):
347
310
loopCnt = timer_loop_amount
@@ -386,6 +349,7 @@ def wifi_connect():
386
349
return True
387
350
388
351
# CHECK OTA VERSION
352
+
389
353
def download_ota_info ():
390
354
import gc
391
355
import urequests as requests
@@ -409,38 +373,42 @@ def download_ota_info():
409
373
return result
410
374
411
375
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 :
419
395
disableWifi ()
420
396
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 :
430
397
disableWifi ()
398
+ return True
399
+ except :
400
+ print ("OTA CHECK EXCEPTION" )
431
401
return False
432
- disableWifi ()
433
- return True
434
402
435
403
# WELCOME (SETUP, SPONSORS OR CLOCK)
436
404
def welcome ():
437
- setupcompleted = badge .nvs_get_u8 ('badge' , 'setup.state' , 0 )
405
+ setupcompleted = int ( badge .nvs_get_str ('badge' , 'setup.state' , '0' ) )
438
406
if (setupcompleted == 0 ): # First boot (open setup)
439
407
print ("[SPLASH] Setup not completed. Running setup!" )
440
408
appglue .start_app ("setup" )
441
409
elif (setupcompleted == 1 ): # Second boot (after setup)
442
410
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
444
412
appglue .start_app ("sponsors" )
445
413
else : # Setup completed
446
414
print ("[SPLASH] Normal boot." )
@@ -453,43 +421,44 @@ def welcome():
453
421
454
422
# SETTINGS FROM NVS
455
423
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" )
493
462
494
463
# MAIN
495
464
def splash_main ():
@@ -506,7 +475,6 @@ def splash_main():
506
475
global battery_percent_empty
507
476
if (cstate ) or (percent > battery_percent_empty ) or (vbatt < 100 ):
508
477
ugfx .input_init ()
509
- welcome ()
510
478
ugfx .input_attach (ugfx .BTN_START , start_launcher )
511
479
ugfx .input_attach (ugfx .BTN_A , start_magic )
512
480
ugfx .input_attach (ugfx .BTN_B , nothing )
@@ -515,12 +483,14 @@ def splash_main():
515
483
ugfx .input_attach (ugfx .JOY_DOWN , nothing )
516
484
ugfx .input_attach (ugfx .JOY_LEFT , nothing )
517
485
ugfx .input_attach (ugfx .JOY_RIGHT , nothing )
486
+ try :
487
+ welcome ()
488
+ except :
489
+ print ("Well fuck." )
518
490
global splashTimer
519
491
setup_services ()
520
492
start_sleep_counter ()
521
493
full_clear = False
522
- if (get_reboot_counter ()== 0 ):
523
- full_clear = True
524
494
draw_home (percent , cstate , header_status_string , full_clear , False )
525
495
else :
526
496
draw_batterylow (percent )
@@ -540,7 +510,6 @@ def splash_main():
540
510
battery_volt_max = 4300
541
511
battery_percent_empty = 1
542
512
ntp_timeout = 40
543
- bpp_after_count = 5
544
513
header_status_string = ""
545
514
splash_timer_interval = 500
546
515
0 commit comments