From cf38b58a7344077314b0df5ff6de134d8b041d5d Mon Sep 17 00:00:00 2001 From: slush0 Date: Sat, 8 Oct 2016 11:47:28 +0200 Subject: [PATCH] Reworked homescreen (no blinking, only diming) Added ui.alert() --- src/apps/homescreen/layout_homescreen.py | 23 ++++++++++++++++++++--- src/trezor/ui/__init__.py | 23 +++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/apps/homescreen/layout_homescreen.py b/src/apps/homescreen/layout_homescreen.py index be6a76720e..f4feed1a83 100644 --- a/src/apps/homescreen/layout_homescreen.py +++ b/src/apps/homescreen/layout_homescreen.py @@ -1,7 +1,6 @@ from trezor import ui, loop, res from trezor.utils import unimport - async def swipe_to_rotate(): from trezor.ui.swipe import Swipe @@ -10,14 +9,32 @@ async def swipe_to_rotate(): ui.display.orientation(degrees) +''' async def animate_logo(): image = res.load('apps/homescreen/res/trezor.toig') def render(fg): ui.display.icon(0, 0, image, fg, ui.BLACK) - await ui.animate_pulse(render, ui.WHITE, ui.DARK_GREY, speed=400000) + await ui.animate_pulse(render, ui.WHITE, ui.DARK_GREY, speed=800000) +''' +async def dim_screen(): + current = ui.display.backlight() + + await loop.Sleep(5*1000000) + await ui.backlight_slide(ui.BACKLIGHT_DIM) + + try: + while True: + await loop.Sleep(1000000) + except: + # Return back to original brightness + ui.display.backlight(current) @unimport async def layout_homescreen(): - await loop.Wait([swipe_to_rotate(), animate_logo()]) + image = res.load('apps/homescreen/res/trezor.toig') + ui.display.icon(0, 0, image, ui.WHITE, ui.BLACK) + + ui.display.backlight(ui.BACKLIGHT_NORMAL) + await loop.Wait([swipe_to_rotate(), dim_screen()]) \ No newline at end of file diff --git a/src/trezor/ui/__init__.py b/src/trezor/ui/__init__.py index db6cbd5813..e42ed76bec 100644 --- a/src/trezor/ui/__init__.py +++ b/src/trezor/ui/__init__.py @@ -45,6 +45,10 @@ MONO = Display.FONT_MONO NORMAL = Display.FONT_NORMAL BOLD = Display.FONT_BOLD +BACKLIGHT_NORMAL = const(127) +BACKLIGHT_DIM = const(70) +BACKLIGHT_MAX = const(255) + # icons ICON_RESET = 'trezor/res/reset.toig' ICON_WIPE = 'trezor/res/wipe.toig' @@ -66,6 +70,25 @@ def blend(ca: int, cb: int, t: float) -> int: lerpi((ca << 3) & 0xF8, (cb << 3) & 0xF8, t)) +def alert(count=3): + current = display.backlight() + for i in range(count*2): + if i % 2 == 0: + display.backlight(BACKLIGHT_MAX) + yield loop.Sleep(20000) + else: + display.backlight(BACKLIGHT_NORMAL) + yield loop.Sleep(80000) + + display.backlight(current) + +def backlight_slide(val, speed=20000): + current = display.backlight() + + for i in range(current, val, -1 if current > val else 1): + display.backlight(i) + await loop.Sleep(speed) + def animate_pulse(func, ca, cb, speed=200000, delay=30000): while True: # normalize sin from interval -1:1 to 0:1