mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 22:38:08 +00:00
Playground
This commit is contained in:
parent
dc20152afe
commit
a42b654eba
@ -12,6 +12,7 @@ class EventLoop:
|
||||
def __init__(self):
|
||||
self.q = []
|
||||
self.cnt = 0
|
||||
self.last_sleep = 0 # For performance stats
|
||||
#self.button_cb = None
|
||||
|
||||
'''
|
||||
@ -25,14 +26,13 @@ class EventLoop:
|
||||
self.call_at(0, callback, *args)
|
||||
|
||||
def call_later(self, delay, callback, *args):
|
||||
self.call_at(utime.time() + delay, callback, *args)
|
||||
self.call_at(utime.ticks_us() + delay * 1000000, callback, *args)
|
||||
|
||||
def call_at(self, time, callback, *args):
|
||||
# Including self.cnt is a workaround per heapq docs
|
||||
if __debug__:
|
||||
log.debug("Scheduling %s", (time, self.cnt, callback, args))
|
||||
uheapq.heappush(self.q, (time, self.cnt, callback, args))
|
||||
# print(self.q)
|
||||
self.cnt += 1
|
||||
|
||||
def wait(self, delay):
|
||||
@ -40,7 +40,8 @@ class EventLoop:
|
||||
# with IO scheduling
|
||||
if __debug__:
|
||||
log.debug("Sleeping for: %s", delay)
|
||||
utime.sleep(delay)
|
||||
self.last_sleep = delay / 1000000.
|
||||
utime.sleep(delay / 1000000.)
|
||||
|
||||
def run_forever(self):
|
||||
while True:
|
||||
@ -49,7 +50,7 @@ class EventLoop:
|
||||
if __debug__:
|
||||
log.debug("Next coroutine to run: %s", (t, cnt, cb, args))
|
||||
# __main__.mem_info()
|
||||
tnow = utime.time()
|
||||
tnow = utime.ticks_us()
|
||||
delay = t - tnow
|
||||
if delay > 0:
|
||||
self.wait(delay)
|
||||
@ -58,7 +59,9 @@ class EventLoop:
|
||||
# Assuming IO completion scheduled some tasks
|
||||
continue
|
||||
if callable(cb):
|
||||
cb(*args)
|
||||
ret = cb(*args)
|
||||
if __debug__ and isinstance(ret, type_gen):
|
||||
log.warning("Callback produced generator, which will never run.")
|
||||
else:
|
||||
delay = 0
|
||||
try:
|
||||
@ -167,11 +170,3 @@ def get_event_loop():
|
||||
if _event_loop is None:
|
||||
_event_loop = _event_loop_class()
|
||||
return _event_loop
|
||||
|
||||
def sleep(secs):
|
||||
yield Sleep(secs)
|
||||
|
||||
'''
|
||||
def coroutine(f):
|
||||
return f
|
||||
'''
|
||||
|
@ -2,7 +2,7 @@
|
||||
import sys
|
||||
sys.path.append('lib')
|
||||
|
||||
import logging
|
||||
import utime
|
||||
import math
|
||||
import gc
|
||||
|
||||
@ -11,27 +11,33 @@ from trezor import ui
|
||||
|
||||
from .import utils
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
if __debug__:
|
||||
import logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
loop = core.get_event_loop()
|
||||
|
||||
def meminfo():
|
||||
def perf_info():
|
||||
mem_free = gc.mem_free()
|
||||
collected = gc.collect()
|
||||
print("free_mem: %s/%s, collect: %s" % (mem_free, gc.mem_free(), collected))
|
||||
loop.call_later(1, meminfo)
|
||||
# gc.collect()
|
||||
print("free_mem: %s/%s, last_sleep: %.06f" % \
|
||||
(mem_free, gc.mem_free(), loop.last_sleep))
|
||||
loop.call_later(1, perf_info)
|
||||
|
||||
def animate():
|
||||
col = 0
|
||||
f = open('../assets/lock.toi', 'r')
|
||||
# hawcons gesture
|
||||
f = open('playground/tap_64.toi', 'r')
|
||||
|
||||
while True:
|
||||
col %= 0xff
|
||||
col += 0x0f
|
||||
|
||||
ui.display.icon(190, 170, f.read(), utils.rgb2color(col, 0, 0), 0xffff)
|
||||
ui.display.icon(170, 170, f.read(), 0xffff, utils.rgb2color(col, 0, 0))
|
||||
# ui.display.icon(100, 100, f.read(), 0xffff, utils.rgb2color(col, 0, 0))
|
||||
f.seek(0)
|
||||
|
||||
yield from core.sleep(0.5)
|
||||
yield core.Sleep(0.5)
|
||||
|
||||
sec = 0
|
||||
event = None
|
||||
@ -65,6 +71,9 @@ def tap_to_confirm():
|
||||
MAX_COLOR = 0xB0
|
||||
|
||||
_background = utils.rgb2color(255, 255, 255)
|
||||
|
||||
f = open('playground/tap_64.toi', 'r')
|
||||
|
||||
x = math.pi
|
||||
while True:
|
||||
x += STEP_X
|
||||
@ -72,21 +81,28 @@ def tap_to_confirm():
|
||||
x -= 2 * math.pi
|
||||
y = 1 + math.sin(x)
|
||||
|
||||
# ui.display.bar(0, 170, 240, 70, _background)
|
||||
|
||||
# Normalize color from interval 0:2 to MIN_COLOR:MAX_COLOR
|
||||
col = int((MAX_COLOR - MIN_COLOR) / 2 * y) + MIN_COLOR
|
||||
foreground = utils.rgb2color(BASE_COLOR[0] + col, BASE_COLOR[1] + col, BASE_COLOR[2] + col)
|
||||
|
||||
ui.display.text(10, 220, 'TAP TO CONFIRM', 2, foreground, _background)
|
||||
ui.display.text(68, 212, 'TAP TO CONFIRM', 2, foreground, _background)
|
||||
|
||||
yield from core.sleep(DELAY)
|
||||
f.seek(0)
|
||||
ui.display.icon(3, 170, f.read(), _background, foreground)
|
||||
# ui.display.icon(165, 50, f.read(), _background, foreground)
|
||||
|
||||
|
||||
yield core.Sleep(DELAY)
|
||||
|
||||
def run():
|
||||
# sekunda(3)
|
||||
# loop.call_soon(wait_for())
|
||||
|
||||
loop.call_soon(meminfo)
|
||||
loop.call_soon(perf_info)
|
||||
loop.call_soon(tap_to_confirm())
|
||||
loop.call_soon(animate())
|
||||
# loop.call_soon(animate())
|
||||
|
||||
loop.run_forever()
|
||||
loop.close()
|
||||
|
Loading…
Reference in New Issue
Block a user