From 8493da5f9743ad1d743f8a317f893bffe38eb89b Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Thu, 31 Mar 2016 18:45:15 +0200 Subject: [PATCH] introduce trezor module --- emu.sh | 2 +- extmod/modTrezorUi/modTrezorUi.c | 7 ++----- src/layout.py | 23 +++++++++-------------- src/main.py | 6 ++++-- src/trezor/__init__.py | 0 src/trezor/ui.py | 3 +++ 6 files changed, 19 insertions(+), 22 deletions(-) create mode 100644 src/trezor/__init__.py create mode 100644 src/trezor/ui.py diff --git a/emu.sh b/emu.sh index 4217190414..6f933ab0cd 100755 --- a/emu.sh +++ b/emu.sh @@ -1,3 +1,3 @@ #!/bin/bash cd `dirname $0`/src -../vendor/micropython/unix/micropython -m main +../vendor/micropython/unix/micropython main.py diff --git a/extmod/modTrezorUi/modTrezorUi.c b/extmod/modTrezorUi/modTrezorUi.c index 794c976d21..11ad8ba049 100644 --- a/extmod/modTrezorUi/modTrezorUi.c +++ b/extmod/modTrezorUi/modTrezorUi.c @@ -155,11 +155,8 @@ typedef struct _mp_obj_Display_t { // def Display.__init__(self): STATIC mp_obj_t mod_TrezorUi_Display_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { - static mp_obj_Display_t *o = 0; // singleton - if (!o) { - display_init(); - o = m_new_obj(mp_obj_Display_t); - } + display_init(); + mp_obj_Display_t *o = m_new_obj(mp_obj_Display_t); o->base.type = type; return MP_OBJ_FROM_PTR(o); } diff --git a/src/layout.py b/src/layout.py index 0d2683335f..64a2e7a9d4 100644 --- a/src/layout.py +++ b/src/layout.py @@ -1,4 +1,4 @@ -from TrezorUi import Display +from trezor import ui def rgb2color(r, g, b): return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3) @@ -29,16 +29,11 @@ MONO = 0 NORMAL = 1 BOLD = 2 -d = Display() - -class Layout(object): - - @staticmethod - def show_send(address, amount, currency='BTC'): - d.bar(0, 0, 240, 40, GREEN) - d.bar(0, 40, 240, 200, WHITE) - d.text(10, 28, 'Sending', BOLD, WHITE, GREEN) - d.text(10, 80, '%f %s' % (amount, currency), BOLD, BLACK, WHITE) - d.text(10, 110, 'to this address:', NORMAL, BLACK, WHITE) - d.text(10, 140, address[:18], MONO, BLACK, WHITE) - d.text(10, 160, address[18:], MONO, BLACK, WHITE) +def show_send(address, amount, currency='BTC'): + ui.display.bar(0, 0, 240, 40, GREEN) + ui.display.bar(0, 40, 240, 200, WHITE) + ui.display.text(10, 28, 'Sending', BOLD, WHITE, GREEN) + ui.display.text(10, 80, '%f %s' % (amount, currency), BOLD, BLACK, WHITE) + ui.display.text(10, 110, 'to this address:', NORMAL, BLACK, WHITE) + ui.display.text(10, 140, address[:18], MONO, BLACK, WHITE) + ui.display.text(10, 160, address[18:], MONO, BLACK, WHITE) diff --git a/src/main.py b/src/main.py index 7de86ae70d..d3bdc06450 100644 --- a/src/main.py +++ b/src/main.py @@ -1,3 +1,5 @@ -from layout import Layout +import layout -Layout.show_send('1BitkeyP2nDd5oa64x7AjvBbbwST54W5Zmx2', 110.126967) +layout.show_send('1BitkeyP2nDd5oa64x7AjvBbbwST54W5Zmx2', 110.126967) + +while True: pass diff --git a/src/trezor/__init__.py b/src/trezor/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/trezor/ui.py b/src/trezor/ui.py new file mode 100644 index 0000000000..88a3ff5bfb --- /dev/null +++ b/src/trezor/ui.py @@ -0,0 +1,3 @@ +from TrezorUi import Display + +display = Display()