From 07abef7ff444ce822deb447800210774fe982053 Mon Sep 17 00:00:00 2001 From: slush0 Date: Thu, 28 Apr 2016 17:18:15 +0200 Subject: [PATCH] Added animate_pulse --- src/trezor/ui.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/trezor/ui.py b/src/trezor/ui.py index 27df7c86..d1563853 100644 --- a/src/trezor/ui.py +++ b/src/trezor/ui.py @@ -1,5 +1,10 @@ +import math +import utime + from TrezorUi import Display, Touch +from . import loop + display = Display() touch = Touch() @@ -31,3 +36,16 @@ WHITE = rgbcolor(0xFF, 0xFF, 0xFF) MONO = const(0) NORMAL = const(1) BOLD = const(2) + + +def animate_pulse(func, SPEED=200000, DELAY=30000, BASE_COLOR=(0x00, 0x00, 0x00), MIN_COLOR=0x00, MAX_COLOR=0x80): + while True: + y = 1 + math.sin(utime.ticks_us() / SPEED) + + # Normalize color from interval 0:2 to MIN_COLOR:MAX_COLOR + col = int((MAX_COLOR - MIN_COLOR) / 2 * y) + MIN_COLOR + foreground = rgbcolor(BASE_COLOR[0] + col, BASE_COLOR[1] + col, BASE_COLOR[2] + col) + + func(foreground) + yield loop.Sleep(DELAY) +