EMF_Camp_Badge/lib/homescreen.py

56 lines
1.4 KiB
Python
Raw Normal View History

2018-07-15 06:53:48 -04:00
"""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 "pyb.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)
"""
2018-08-05 17:14:31 -04:00
___license___ = "MIT"
___dependencies___ = ["database", "buttons", "random", "app"]
2018-07-15 06:53:48 -04:00
2018-08-05 17:14:31 -04:00
import database, ugfx, random, buttons, time
from app import App
2018-07-15 06:53:48 -04:00
def init(color = 0xFFFFFF):
ugfx.init()
2018-08-05 17:14:31 -04:00
ugfx.orientation(90)
2018-07-15 06:53:48 -04:00
ugfx.clear(ugfx.html_color(color))
2018-08-05 17:14:31 -04:00
# A special loop that exits on menu being pressed
def loop(func, interval = 500):
2018-07-15 06:53:48 -04:00
buttons.init()
2018-08-05 17:14:31 -04:00
state = {"pressed": False} # This is a terrible hack
def irp(t):
state["pressed"] = True
buttons.enable_interrupt("BTN_MENU", irp, on_release = True)
while not state["pressed"]:
func()
time.sleep_ms(interval)
buttons.disable_interrupt("BTN_MENU")
App("launcher").boot()
2018-07-15 06:53:48 -04:00
def menu():
ugfx.clear()
2018-08-05 17:14:31 -04:00
def name(default = None):
return database.get("homescreen.name", default)
2018-07-15 06:53:48 -04:00
def wifi_strength():
2018-08-05 17:14:31 -04:00
return random.rand() / 256
2018-07-15 06:53:48 -04:00
def battery():
2018-08-05 17:14:31 -04:00
return random.rand() / 256
2018-07-15 06:53:48 -04:00