1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-16 04:29:08 +00:00

trezor/ui: close backlight slider properly

This commit is contained in:
Jan Pochyla 2017-10-10 15:33:54 +02:00
parent 04acab723a
commit 3ea5b9c151

View File

@ -82,21 +82,26 @@ async def alert(count: int=3):
display.backlight(current) display.backlight(current)
async def backlight_slide(val: int, delay: int=20000): async def backlight_slide(val: int, delay: int=20000, step: int=1):
sleep = loop.sleep(delay) sleep = loop.sleep(delay)
current = display.backlight() current = display.backlight()
for i in range(current, val, -1 if current > val else 1): for i in range(current, val, -step if current > val else step):
display.backlight(i) display.backlight(i)
await sleep await sleep
def layout(f): def layout(f):
delay = const(1000)
step = const(3)
async def inner(*args, **kwargs): async def inner(*args, **kwargs):
slider = backlight_slide(BACKLIGHT_NORMAL, 1000) await backlight_slide(BACKLIGHT_DIM, delay, step)
loop.schedule(slider) slide = backlight_slide(BACKLIGHT_NORMAL, delay, step)
await f(*args, **kwargs) try:
slider.close() loop.schedule(slide)
await backlight_slide(BACKLIGHT_DIM, 1000) return await f(*args, **kwargs)
finally:
loop.close(slide)
return inner return inner