improve homescreen lib
parent
7936cbf3a7
commit
8904484cb9
|
@ -37,10 +37,8 @@ ugfx.set_default_font(ugfx.FONT_MEDIUM)
|
||||||
status = ugfx.Label(0, 130, ugfx.width(), 40, "", justification=ugfx.Label.CENTERTOP)
|
status = ugfx.Label(0, 130, ugfx.width(), 40, "", justification=ugfx.Label.CENTERTOP)
|
||||||
|
|
||||||
# update loop
|
# update loop
|
||||||
def tick():
|
while True:
|
||||||
status.text("wifi: %s%%\nbattery: %s%%" % (int(wifi_strength() * 100), int(battery() * 100)))
|
status.text("wifi: %s%%\nbattery: %s%%" % (int(wifi_strength() * 100), int(battery() * 100)))
|
||||||
time.sleep_ms(500)
|
sleep(500)
|
||||||
|
|
||||||
loop(tick)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,30 +19,39 @@ They also *may*:
|
||||||
___license___ = "MIT"
|
___license___ = "MIT"
|
||||||
___dependencies___ = ["database", "buttons", "random", "app"]
|
___dependencies___ = ["database", "buttons", "random", "app"]
|
||||||
|
|
||||||
import database, ugfx, random, buttons, time
|
import database, ugfx, random, buttons, time, select
|
||||||
from app import App
|
from app import App
|
||||||
|
|
||||||
def init(color = 0xFFFFFF):
|
_state = None
|
||||||
|
def init(enable_menu_button = True):
|
||||||
|
global _state
|
||||||
|
_state = {"menu": False}
|
||||||
ugfx.init()
|
ugfx.init()
|
||||||
ugfx.orientation(90)
|
ugfx.orientation(90)
|
||||||
ugfx.clear(ugfx.html_color(color))
|
|
||||||
|
|
||||||
# A special loop that exits on menu being pressed
|
|
||||||
def loop(func, interval = 500):
|
|
||||||
buttons.init()
|
|
||||||
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()
|
|
||||||
|
|
||||||
|
|
||||||
def menu():
|
|
||||||
ugfx.clear()
|
if enable_menu_button:
|
||||||
|
buttons.init()
|
||||||
|
buttons.enable_interrupt("BTN_MENU", lambda t: set_state("menu"), on_release = True)
|
||||||
|
|
||||||
|
def set_state(key, value = True):
|
||||||
|
global _state
|
||||||
|
_state[key] = value
|
||||||
|
|
||||||
|
def clean_up():
|
||||||
|
buttons.disable_all_interrupt()
|
||||||
|
|
||||||
|
def check():
|
||||||
|
global _state
|
||||||
|
if _state["menu"]:
|
||||||
|
clean_up()
|
||||||
|
App("launcher").boot()
|
||||||
|
|
||||||
|
def sleep(interval = 500):
|
||||||
|
check()
|
||||||
|
time.sleep_ms(interval) # todo: deep sleep
|
||||||
|
check()
|
||||||
|
|
||||||
def name(default = None):
|
def name(default = None):
|
||||||
return database.get("homescreen.name", default)
|
return database.get("homescreen.name", default)
|
||||||
|
|
Loading…
Reference in New Issue