1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 14:58:09 +00:00

Added animate_pulse

This commit is contained in:
slush0 2016-04-28 17:18:15 +02:00 committed by Pavol Rusnak
parent 4f90848c0a
commit 07abef7ff4
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -1,5 +1,10 @@
import math
import utime
from TrezorUi import Display, Touch from TrezorUi import Display, Touch
from . import loop
display = Display() display = Display()
touch = Touch() touch = Touch()
@ -31,3 +36,16 @@ WHITE = rgbcolor(0xFF, 0xFF, 0xFF)
MONO = const(0) MONO = const(0)
NORMAL = const(1) 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):
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)