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():
|
||||
original = ui.display.backlight()
|
||||
try:
|
||||
await loop.Sleep(5 * 1000000)
|
||||
await ui.backlight_slide(ui.BACKLIGHT_DIM)
|
||||
while True:
|
||||
await loop.Sleep(1000000)
|
||||
finally:
|
||||
ui.display.backlight(original)
|
||||
|
||||
|
||||
def display_homescreen():
|
||||
|
@ -58,8 +58,12 @@ BTN_RADIUS = const(2)
|
||||
|
||||
BACKLIGHT_NORMAL = const(60)
|
||||
BACKLIGHT_DIM = const(5)
|
||||
BACKLIGHT_NONE = const(2)
|
||||
BACKLIGHT_MAX = const(255)
|
||||
|
||||
# display width and height
|
||||
SCREEN = const(240)
|
||||
|
||||
# icons
|
||||
ICON_RESET = 'trezor/res/header_icons/reset.toig'
|
||||
ICON_WIPE = 'trezor/res/header_icons/wipe.toig'
|
||||
|
@ -1,9 +1,8 @@
|
||||
import utime
|
||||
from micropython import const
|
||||
from trezor import loop
|
||||
from trezor import loop, ui
|
||||
from . import in_area, rotate_coords
|
||||
|
||||
|
||||
_SWIPE_DISTANCE_THRESHOLD = const(20) # Min pixels in the primary direction
|
||||
_SWIPE_VELOCITY_THRESHOLD = const(200) # Min pixels per second
|
||||
_SWIPE_RATIO_THRESHOLD = const(30) # Max ratio or directions in %
|
||||
@ -15,31 +14,53 @@ SWIPE_RIGHT = const(270)
|
||||
|
||||
|
||||
class Swipe():
|
||||
|
||||
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.start_pos = None
|
||||
self.start_time = 0
|
||||
self.end_pos = None
|
||||
self.end_time = 0
|
||||
self.light_origin = None
|
||||
self.light_target = ui.BACKLIGHT_NONE
|
||||
|
||||
def send(self, event, pos):
|
||||
|
||||
if not self.absolute:
|
||||
pos = rotate_coords(pos)
|
||||
|
||||
if event == loop.TOUCH_START and in_area(pos, self.area):
|
||||
# TODO: do not use floats here
|
||||
self.start_time = utime.ticks_ms() / 1000
|
||||
temp_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.light_origin = ui.BACKLIGHT_NORMAL
|
||||
ui.display.backlight(self.light_origin)
|
||||
|
||||
elif event == loop.TOUCH_END and self.start_pos is not None:
|
||||
self.end_time = utime.ticks_ms() / 1000
|
||||
self.end_pos = pos
|
||||
td = self.end_time - self.start_time
|
||||
pdx = self.end_pos[0] - self.start_pos[0]
|
||||
pdy = self.end_pos[1] - self.start_pos[1]
|
||||
td = temp_time - self.start_time
|
||||
pdx = pos[0] - self.start_pos[0]
|
||||
pdy = pos[1] - self.start_pos[1]
|
||||
pdxa = abs(pdx)
|
||||
pdya = abs(pdy)
|
||||
if pdxa > pdya:
|
||||
@ -57,12 +78,13 @@ class Swipe():
|
||||
if (velya >= _SWIPE_VELOCITY_THRESHOLD
|
||||
and pdya >= _SWIPE_DISTANCE_THRESHOLD
|
||||
and ratio <= _SWIPE_RATIO_THRESHOLD):
|
||||
if pdy < 0:
|
||||
ui.display.backlight(self.light_origin)
|
||||
return SWIPE_DOWN if pdy > 0 else SWIPE_UP
|
||||
# No swipe, reset the state
|
||||
self.start_pos = None
|
||||
self.start_time = 0
|
||||
self.end_pos = None
|
||||
self.end_time = 0
|
||||
ui.display.backlight(self.light_origin)
|
||||
|
||||
def __iter__(self):
|
||||
while True:
|
||||
|
Loading…
Reference in New Issue
Block a user