1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-27 01:48:17 +00:00

src/apps/homescreen: rework backlight animations

This commit is contained in:
Jan Pochyla 2018-02-19 16:50:58 +01:00
parent b659f1b29c
commit 0592cfe356
3 changed files with 24 additions and 28 deletions

View File

@ -9,15 +9,7 @@ async def swipe_to_rotate():
ui.display.orientation(degrees(swipe))
async def dim_screen():
await loop.sleep(5 * 1000000)
await ui.backlight_slide(ui.BACKLIGHT_DIM)
while True:
await loop.sleep(10000000)
@ui.layout
async def display_homescreen():
def display_homescreen():
from apps.common import storage
if not storage.is_initialized():
@ -34,10 +26,11 @@ async def display_homescreen():
ui.display.avatar((ui.SCREEN - 144) // 2, (ui.SCREEN - 144) // 2 - 10, image, ui.WHITE, ui.BLACK)
ui.display.text_center(ui.SCREEN // 2, ui.SCREEN - 20, label, ui.BOLD, ui.FG, ui.BG)
await dim_screen()
@unimport
async def layout_homescreen():
while True:
await loop.wait(swipe_to_rotate(), display_homescreen())
await ui.backlight_slide(ui.BACKLIGHT_DIM)
display_homescreen()
await ui.backlight_slide(ui.BACKLIGHT_NORMAL)
await swipe_to_rotate()

View File

@ -9,6 +9,7 @@ from trezorui import Display
from trezor import io
from trezor import loop
from trezor import res
from trezor import workflow
display = Display()
@ -95,7 +96,7 @@ async def click() -> tuple:
return pos
async def backlight_slide(val: int, delay: int=20000, step: int=1):
async def backlight_slide(val: int, delay: int=35000, step: int=20):
sleep = loop.sleep(delay)
current = display.backlight()
for i in range(current, val, -step if current > val else step):
@ -104,17 +105,17 @@ async def backlight_slide(val: int, delay: int=20000, step: int=1):
def layout(f):
delay = const(35000) # 35ms
step = const(20)
async def inner(*args, **kwargs):
await backlight_slide(BACKLIGHT_DIM, delay, step)
slide = backlight_slide(BACKLIGHT_NORMAL, delay, step)
await backlight_slide(BACKLIGHT_DIM)
slide = backlight_slide(BACKLIGHT_NORMAL)
try:
layout = f(*args, **kwargs)
workflow.onlayoutstart(layout)
loop.schedule(slide)
return await f(*args, **kwargs)
return await layout
finally:
loop.close(slide)
workflow.onlayoutclose(layout)
return inner

View File

@ -5,20 +5,16 @@ from trezor import ui
started = []
default = None
default_handler = None
layouts = []
def onstart(w):
closedefault()
started.append(w)
ui.display.backlight(ui.BACKLIGHT_NORMAL)
log.debug(__name__, 'onstart: %s', w)
def onclose(w):
started.remove(w)
log.debug(__name__, 'onclose: %s', w)
if not started and default_handler:
if not started and not layouts and default_handler:
startdefault(default_handler)
@ -28,7 +24,6 @@ def closedefault():
if default:
loop.close(default)
default = None
log.debug(__name__, 'closedefault')
def startdefault(handler):
@ -39,5 +34,12 @@ def startdefault(handler):
default_handler = handler
default = handler()
loop.schedule(default)
ui.display.backlight(ui.BACKLIGHT_NORMAL)
log.debug(__name__, 'startdefault')
def onlayoutstart(l):
closedefault()
layouts.append(l)
def onlayoutclose(l):
layouts.remove(l)