-
Notifications
You must be signed in to change notification settings - Fork 122
/
homescreen.py
60 lines (43 loc) · 1.67 KB
/
homescreen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""Shared functionality for home screen apps
Apps in the "homescreen" should behave in a similar manner to not confuse users.
In particular, they *should*:
* Call "homescreen.init()" at the beginning. This will initiate ugfx, clear the screen and
initiate button handline.
* Use "sleep.wfi()" as much as possible to avoid draining the battery.
* Not use
They also *may*:
* Display a name, returned by "homescreen.name()"
* Display network strength "homescreen.wifi_strength()" (0-1, might return "None" if not connected)
* Display remaining battery "homescreen.battery()" (0-1)
"""
___license___ = "MIT"
___dependencies___ = ["database", "buttons", "random", "app", "sleep", "ugfx_helper"]
import database, ugfx, random, buttons, tilda, sleep, ugfx_helper
from app import App
_state = None
def init(enable_menu_button = True):
global _state
_state = {"menu": False}
ugfx_helper.init()
if enable_menu_button:
pass
#buttons.enable_interrupt("BTN_MENU", lambda t: set_state("menu"), on_release = True)
def set_state(key, value = True):
# we can't allocate memory in interrupts, so make sure all keys are set beforehand and
# you're only using numbers and booleans
global _state
_state[key] = value
def clean_up():
pass
def sleep_or_exit(interval = 0.5):
# todo: do this better - check button multiple times and sleep for only a short while
if buttons.is_triggered(tilda.Buttons.BTN_Menu):
clean_up()
App("launcher").boot()
sleep.sleep(interval)
def name(default = None):
return database.get("homescreen.name", default)
def wifi_strength():
return random.random()
def battery():
return random.random()