mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-18 21:48:13 +00:00
add ui.blend
This commit is contained in:
parent
904127f263
commit
de83114dc7
@ -91,7 +91,7 @@ def tap_to_confirm(address, amount, currency):
|
|||||||
f.seek(0)
|
f.seek(0)
|
||||||
ui.display.icon(3, 170, f.read(), _background, foreground)
|
ui.display.icon(3, 170, f.read(), _background, foreground)
|
||||||
|
|
||||||
yield from ui.animate_pulse(func) # , DELAY=10000)
|
yield from ui.animate_pulse(func, ui.BLACK, ui.GREY) # , delay=10000)
|
||||||
|
|
||||||
'''
|
'''
|
||||||
def on_read():
|
def on_read():
|
||||||
@ -130,8 +130,7 @@ def homescreen():
|
|||||||
def func(foreground):
|
def func(foreground):
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
ui.display.icon(0, 0, f.read(), foreground, ui.BLACK)
|
ui.display.icon(0, 0, f.read(), foreground, ui.BLACK)
|
||||||
|
yield from ui.animate_pulse(func, ui.WHITE, ui.GREY, speed=400000)
|
||||||
yield from ui.animate_pulse(func, SPEED=400000, BASE_COLOR=(0xff, 0xff, 0xff), MIN_COLOR=0xaa, MAX_COLOR=0xff)
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
ui.touch.start(lambda x, y: print('touch start %d %d\n' % (x, y)))
|
ui.touch.start(lambda x, y: print('touch start %d %d\n' % (x, y)))
|
||||||
|
@ -38,14 +38,20 @@ NORMAL = const(1)
|
|||||||
BOLD = const(2)
|
BOLD = const(2)
|
||||||
|
|
||||||
|
|
||||||
def animate_pulse(func, SPEED=200000, DELAY=30000, BASE_COLOR=(0x00, 0x00, 0x00), MIN_COLOR=0x00, MAX_COLOR=0x80):
|
def lerpi(a: int, b: int, t: float) -> int:
|
||||||
|
return int(a + t * (b - a))
|
||||||
|
|
||||||
|
|
||||||
|
def blend(ca: int, cb: int, t: float) -> int:
|
||||||
|
return rgbcolor(lerpi((ca >> 8) & 0xF8, (cb >> 8) & 0xF8, t),
|
||||||
|
lerpi((ca >> 3) & 0xFC, (cb >> 3) & 0xFC, t),
|
||||||
|
lerpi((ca << 3) & 0xF8, (cb << 3) & 0xF8, t))
|
||||||
|
|
||||||
|
|
||||||
|
def animate_pulse(func, ca, cb, speed=200000, delay=30000):
|
||||||
while True:
|
while True:
|
||||||
y = 1 + math.sin(utime.ticks_us() / SPEED)
|
# normalize sin from interval -1:1 to 0:1
|
||||||
|
y = 0.5 + 0.5 * math.sin(utime.ticks_us() / speed)
|
||||||
# Normalize color from interval 0:2 to MIN_COLOR:MAX_COLOR
|
c = blend(ca, cb, y)
|
||||||
col = int((MAX_COLOR - MIN_COLOR) / 2 * y) + MIN_COLOR
|
func(c)
|
||||||
foreground = rgbcolor(BASE_COLOR[0] + col, BASE_COLOR[1] + col, BASE_COLOR[2] + col)
|
yield loop.Sleep(delay)
|
||||||
|
|
||||||
func(foreground)
|
|
||||||
yield loop.Sleep(DELAY)
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user