mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-26 01:18:28 +00:00
trezor.ui: fading on swipe up
This commit is contained in:
parent
5e69cbe69f
commit
3daa18a5f1
@ -10,14 +10,10 @@ async def swipe_to_rotate():
|
|||||||
|
|
||||||
|
|
||||||
async def dim_screen():
|
async def dim_screen():
|
||||||
original = ui.display.backlight()
|
await loop.Sleep(5 * 1000000)
|
||||||
try:
|
await ui.backlight_slide(ui.BACKLIGHT_DIM)
|
||||||
await loop.Sleep(5 * 1000000)
|
while True:
|
||||||
await ui.backlight_slide(ui.BACKLIGHT_DIM)
|
await loop.Sleep(1000000)
|
||||||
while True:
|
|
||||||
await loop.Sleep(1000000)
|
|
||||||
finally:
|
|
||||||
ui.display.backlight(original)
|
|
||||||
|
|
||||||
|
|
||||||
def display_homescreen():
|
def display_homescreen():
|
||||||
|
@ -58,8 +58,12 @@ BTN_RADIUS = const(2)
|
|||||||
|
|
||||||
BACKLIGHT_NORMAL = const(60)
|
BACKLIGHT_NORMAL = const(60)
|
||||||
BACKLIGHT_DIM = const(5)
|
BACKLIGHT_DIM = const(5)
|
||||||
|
BACKLIGHT_NONE = const(2)
|
||||||
BACKLIGHT_MAX = const(255)
|
BACKLIGHT_MAX = const(255)
|
||||||
|
|
||||||
|
# display width and height
|
||||||
|
SCREEN = const(240)
|
||||||
|
|
||||||
# icons
|
# icons
|
||||||
ICON_RESET = 'trezor/res/header_icons/reset.toig'
|
ICON_RESET = 'trezor/res/header_icons/reset.toig'
|
||||||
ICON_WIPE = 'trezor/res/header_icons/wipe.toig'
|
ICON_WIPE = 'trezor/res/header_icons/wipe.toig'
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import utime
|
import utime
|
||||||
from micropython import const
|
from micropython import const
|
||||||
from trezor import loop
|
from trezor import loop, ui
|
||||||
from . import in_area, rotate_coords
|
from . import in_area, rotate_coords
|
||||||
|
|
||||||
|
|
||||||
_SWIPE_DISTANCE_THRESHOLD = const(20) # Min pixels in the primary direction
|
_SWIPE_DISTANCE_THRESHOLD = const(20) # Min pixels in the primary direction
|
||||||
_SWIPE_VELOCITY_THRESHOLD = const(200) # Min pixels per second
|
_SWIPE_VELOCITY_THRESHOLD = const(200) # Min pixels per second
|
||||||
_SWIPE_RATIO_THRESHOLD = const(30) # Max ratio or directions in %
|
_SWIPE_RATIO_THRESHOLD = const(30) # Max ratio or directions in %
|
||||||
@ -15,31 +14,53 @@ SWIPE_RIGHT = const(270)
|
|||||||
|
|
||||||
|
|
||||||
class Swipe():
|
class Swipe():
|
||||||
|
|
||||||
def __init__(self, area=None, absolute=False):
|
def __init__(self, area=None, absolute=False):
|
||||||
self.area = area or (0, 0, 240, 240)
|
self.area = area or (0, 0, ui.SCREEN, ui.SCREEN)
|
||||||
self.absolute = absolute
|
self.absolute = absolute
|
||||||
self.start_pos = None
|
self.start_pos = None
|
||||||
self.start_time = 0
|
self.start_time = 0
|
||||||
self.end_pos = None
|
self.light_origin = None
|
||||||
self.end_time = 0
|
self.light_target = ui.BACKLIGHT_NONE
|
||||||
|
|
||||||
def send(self, event, pos):
|
def send(self, event, pos):
|
||||||
|
|
||||||
if not self.absolute:
|
if not self.absolute:
|
||||||
pos = rotate_coords(pos)
|
pos = rotate_coords(pos)
|
||||||
|
|
||||||
if event == loop.TOUCH_START and in_area(pos, self.area):
|
temp_time = utime.ticks_ms() / 1000
|
||||||
# TODO: do not use floats here
|
|
||||||
self.start_time = utime.ticks_ms() / 1000
|
# primary now for fading purposes
|
||||||
|
if event == loop.TOUCH_MOVE and self.start_pos is not None:
|
||||||
|
pdx = pos[0] - self.start_pos[0]
|
||||||
|
pdy = pos[1] - self.start_pos[1]
|
||||||
|
td = temp_time - self.start_time
|
||||||
|
|
||||||
|
pdxa = abs(pdx)
|
||||||
|
pdya = abs(pdy)
|
||||||
|
if pdxa < pdya and pdy < 0:
|
||||||
|
# check if its vertical scroll up
|
||||||
|
velya = abs(pdy / td) if td > 0 else 1
|
||||||
|
ratio = int(pdxa / pdya * 100) if pdya > 0 else 100
|
||||||
|
if (velya >= _SWIPE_VELOCITY_THRESHOLD
|
||||||
|
and pdya >= _SWIPE_DISTANCE_THRESHOLD
|
||||||
|
and ratio <= _SWIPE_RATIO_THRESHOLD):
|
||||||
|
light = ui.display.backlight()
|
||||||
|
if light > self.light_target:
|
||||||
|
light -= 5
|
||||||
|
ui.display.backlight(light)
|
||||||
|
else:
|
||||||
|
ui.display.backlight(self.light_target)
|
||||||
|
|
||||||
|
elif event == loop.TOUCH_START and in_area(pos, self.area):
|
||||||
|
self.start_time = temp_time
|
||||||
self.start_pos = pos
|
self.start_pos = pos
|
||||||
|
self.light_origin = ui.BACKLIGHT_NORMAL
|
||||||
|
ui.display.backlight(self.light_origin)
|
||||||
|
|
||||||
elif event == loop.TOUCH_END and self.start_pos is not None:
|
elif event == loop.TOUCH_END and self.start_pos is not None:
|
||||||
self.end_time = utime.ticks_ms() / 1000
|
td = temp_time - self.start_time
|
||||||
self.end_pos = pos
|
pdx = pos[0] - self.start_pos[0]
|
||||||
td = self.end_time - self.start_time
|
pdy = pos[1] - self.start_pos[1]
|
||||||
pdx = self.end_pos[0] - self.start_pos[0]
|
|
||||||
pdy = self.end_pos[1] - self.start_pos[1]
|
|
||||||
pdxa = abs(pdx)
|
pdxa = abs(pdx)
|
||||||
pdya = abs(pdy)
|
pdya = abs(pdy)
|
||||||
if pdxa > pdya:
|
if pdxa > pdya:
|
||||||
@ -47,22 +68,23 @@ class Swipe():
|
|||||||
velxa = abs(pdx / td)
|
velxa = abs(pdx / td)
|
||||||
ratio = int(pdya / pdxa * 100) if pdxa > 0 else 100
|
ratio = int(pdya / pdxa * 100) if pdxa > 0 else 100
|
||||||
if (velxa >= _SWIPE_VELOCITY_THRESHOLD
|
if (velxa >= _SWIPE_VELOCITY_THRESHOLD
|
||||||
and pdxa >= _SWIPE_DISTANCE_THRESHOLD
|
and pdxa >= _SWIPE_DISTANCE_THRESHOLD
|
||||||
and ratio <= _SWIPE_RATIO_THRESHOLD):
|
and ratio <= _SWIPE_RATIO_THRESHOLD):
|
||||||
return SWIPE_RIGHT if pdx > 0 else SWIPE_LEFT
|
return SWIPE_RIGHT if pdx > 0 else SWIPE_LEFT
|
||||||
else:
|
else:
|
||||||
# Vertical direction
|
# Vertical direction
|
||||||
velya = abs(pdy / td)
|
velya = abs(pdy / td)
|
||||||
ratio = int(pdxa / pdya * 100) if pdya > 0 else 100
|
ratio = int(pdxa / pdya * 100) if pdya > 0 else 100
|
||||||
if (velya >= _SWIPE_VELOCITY_THRESHOLD
|
if (velya >= _SWIPE_VELOCITY_THRESHOLD
|
||||||
and pdya >= _SWIPE_DISTANCE_THRESHOLD
|
and pdya >= _SWIPE_DISTANCE_THRESHOLD
|
||||||
and ratio <= _SWIPE_RATIO_THRESHOLD):
|
and ratio <= _SWIPE_RATIO_THRESHOLD):
|
||||||
|
if pdy < 0:
|
||||||
|
ui.display.backlight(self.light_origin)
|
||||||
return SWIPE_DOWN if pdy > 0 else SWIPE_UP
|
return SWIPE_DOWN if pdy > 0 else SWIPE_UP
|
||||||
# No swipe, reset the state
|
# No swipe, reset the state
|
||||||
self.start_pos = None
|
self.start_pos = None
|
||||||
self.start_time = 0
|
self.start_time = 0
|
||||||
self.end_pos = None
|
ui.display.backlight(self.light_origin)
|
||||||
self.end_time = 0
|
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
while True:
|
while True:
|
||||||
|
Loading…
Reference in New Issue
Block a user