Skip to content

Commit

Permalink
UI cleanup: 1) added macros for populating widgets, page information …
Browse files Browse the repository at this point in the history
…and double-click that takes from view to transcation menus
  • Loading branch information
brejski committed Mar 22, 2018
1 parent 12a8e6b commit 8ca5bc2
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 73 deletions.
Binary file modified src/ledger/.DS_Store
Binary file not shown.
Binary file added src/ledger/src/.DS_Store
Binary file not shown.
96 changes: 96 additions & 0 deletions src/ledger/src/UI_templates.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*******************************************************************************
* (c) 2016 Ledger
* (c) 2018 ZondaX GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
#pragma once

#define UI_FillRectangle(x, y, w, h, fgcolor, bgcolor) \
{ \
{ \
BAGL_RECTANGLE, /* type */ \
0x00, /* usedid */ \
x, /* x */ \
y, /* y */ \
w, /* width */ \
h, /* height */ \
0, /* stroke */ \
0, /* radius */ \
BAGL_FILL, /* fill */ \
fgcolor, /* fgcolor */ \
bgcolor, /* bgcolor */ \
0, /* font_id */ \
0 /* icon_id */ \
}, \
NULL, /* text */ \
0, /* touch_area_brim */ \
0, /* overfgcolor */ \
0, /* overbgcolor */ \
NULL, /* tap */ \
NULL, /* out */ \
NULL, /* over */ \
}

#define UI_LabelLine(x, y, w, h, fgcolor, bgcolor, text) \
{ \
{ \
BAGL_LABELINE, /* type */ \
0x00, /* usedid */ \
x, /* x */ \
y, /* y */ \
w, /* width */ \
h, /* height */ \
0, /* stroke */ \
0, /* radius */ \
0, /* fill */ \
fgcolor, /* fgcolor */ \
bgcolor, /* bgcolor */ \
UI_CENTER11PX, /* font_id */ \
0 /* icon_id */ \
}, \
text, /* text */ \
0, /* touch_area_brim */ \
0, /* overfgcolor */ \
0, /* overbgcolor */ \
NULL, /* tap */ \
NULL, /* out */ \
NULL, /* over */ \
}


#define UI_Icon(x, y, w, h, icon) \
{ \
{ \
BAGL_ICON, /* type */ \
0x00, /* usedid */ \
x, /* x */ \
y, /* y */ \
w, /* width */ \
h, /* height */ \
0, /* stroke */ \
0, /* radius */ \
0, /* fill */ \
0xFFFFFF, /* fgcolor */ \
0x000000, /* bgcolor */ \
0, /* font_id */ \
icon /* icon_id */ \
}, \
NULL, /* text */ \
0, /* touch_area_brim */ \
0, /* overfgcolor */ \
0, /* overbgcolor */ \
NULL, /* tap */ \
NULL, /* out */ \
NULL, /* over */ \
}
1 change: 1 addition & 0 deletions src/ledger/src/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
if (process_json(tx, rx))
{
ui_display_transaction(update_transaction_ui_data(0, 0, 0, 0, -1));

*flags |= IO_ASYNCH_REPLY;
}
else {
Expand Down
129 changes: 56 additions & 73 deletions src/ledger/src/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,64 @@
* limitations under the License.
********************************************************************************/
#include <string.h>
#include <stdio.h>
#include "ui.h"
#include "glyphs.h"
#include "ui_templates.h"

ux_state_t ux;
enum UI_STATE uiState;

volatile char transactionDataName[32];
volatile char transactionDataValue[32];
volatile char pageInfo[10];

int transactionDetailsCurrentPage;
int transactionDetailsPageCount;

void start_transaction_info_display(unsigned int unused);
void sign_transaction(unsigned int unused);
void reject(unsigned int unused);

const ux_menu_entry_t menu_main[];
const ux_menu_entry_t menu_about[];

const ux_menu_entry_t menu_transaction_info[] = {
{NULL, start_transaction_info_display, 0, NULL, "View transaction", NULL, 0, 0},
{NULL, sign_transaction, 0, NULL, "Sign transaction", NULL, 0, 0},
{NULL, reject, 0, &C_icon_back, "Reject", NULL, 60, 40},
UX_MENU_END
};

const ux_menu_entry_t menu_main[] = {
{NULL, NULL, 0, &C_icon_tendermint, "Tendermint", "Cosmos Demo", 33, 12},
{menu_about, NULL, 0, NULL, "About", NULL, 0, 0},
{NULL, os_sched_exit, 0, &C_icon_dashboard, "Quit app", NULL, 50, 29},
UX_MENU_END
};

const ux_menu_entry_t menu_about[] = {
{NULL, NULL, 0, NULL, "Version", APPVERSION, 0, 0},
{menu_main, NULL, 2, &C_icon_back, "Back", NULL, 61, 40},
UX_MENU_END
};

static const bagl_element_t bagl_ui_sign_transaction[] = {
UI_FillRectangle(0, 0, 128, 32, 0x000000, 0xFFFFFF),
UI_LabelLine(0, 12, 128, 11, 0xFFFFFF, 0x000000, "Sign transaction"),
UI_LabelLine(0, 23, 128, 11, 0xFFFFFF, 0x000000, "Not implemented yet"),
UI_Icon(3, 32 / 2 - 4, 7, 7, BAGL_GLYPH_ICON_CROSS),
};

static const bagl_element_t bagl_ui_transaction_info[] = {
UI_FillRectangle(0, 0, 128, 32, 0x000000, 0xFFFFFF),
UI_Icon(0, 0, 7, 7, BAGL_GLYPH_ICON_LEFT),
UI_Icon(128-7, 0, 7, 7, BAGL_GLYPH_ICON_RIGHT),
UI_LabelLine(0, 8, 128, 11, 0xFFFFFF, 0x000000,(const char*)pageInfo),
UI_LabelLine(0, 21, 128, 11, 0xFFFFFF, 0x000000,(const char*)transactionDataName),
UI_LabelLine(0, 32, 128, 11, 0xFFFFFF, 0x000000,(const char*)transactionDataValue),
};

UpdateTxDataPtr updateTxDataPtr = NULL;
RejectPtr rejectPtr = NULL;

Expand All @@ -39,70 +86,24 @@ void set_reject_transaction_callback(RejectPtr ptr)
rejectPtr = ptr;
}

const ux_menu_entry_t menu_main[];

// {{type, userid, x, y, width, height, stroke, radius, fill, fgcolor, bgcolor, font_id, icon_id},
// text, touch_area_brim, overfgcolor, overbgcolor, tap, out, over, },
static const bagl_element_t bagl_ui_sign_transaction[] =
{
{
{BAGL_RECTANGLE, 0x00, 0, 0, 128, 32, 0, 0, BAGL_FILL, 0x000000, 0xFFFFFF, 0, 0},
NULL, 0, 0, 0, NULL, NULL, NULL,
},
{
{BAGL_LABELINE, 0x02, 0, 12, 128, 11, 0, 0, 0, 0xFFFFFF, 0x000000, UI_CENTER11PX, 0},
"Sign transaction", 0, 0, 0, NULL, NULL, NULL,
},
{
{BAGL_LABELINE, 0x02, 0, 23, 128, 11, 0, 0, 0, 0xFFFFFF, 0x000000, UI_CENTER11PX, 0},
"Not implemented yet", 0, 0, 0, NULL, NULL, NULL,
},
{
{BAGL_ICON, 0x00, 3, 12, 7, 7, 0, 0, 0, 0xFFFFFF, 0x000000, 0, BAGL_GLYPH_ICON_CROSS},
NULL, 0, 0, 0, NULL, NULL, NULL,
},
};

static unsigned int bagl_ui_sign_transaction_button(unsigned int button_mask,
unsigned int button_mask_counter) {
unsigned int button_mask_counter)
{
switch (button_mask) {
default:
ui_display_transaction(0);
}
return 0;
}

// {{type, userid, x, y, width, height, stroke, radius, fill, fgcolor, bgcolor, font_id, icon_id},
// text, touch_area_brim, overfgcolor, overbgcolor, tap, out, over, },
static const bagl_element_t bagl_ui_transaction_info[] =
{
{
{BAGL_RECTANGLE, 0x00, 0, 0, 128, 32, 0, 0, BAGL_FILL, 0x000000, 0xFFFFFF, 0, 0},
NULL, 0, 0, 0, NULL, NULL, NULL,
},
{
{BAGL_LABELINE, 0x02, 0, 12, 128, 11, 0, 0, 0, 0xFFFFFF, 0x000000, UI_CENTER11PX, 0},
(const char*)transactionDataName, 0, 0, 0, NULL, NULL, NULL,
},
{
{BAGL_LABELINE, 0x02, 0, 23, 128, 11, 0, 0, 0, 0xFFFFFF, 0x000000, UI_CENTER11PX, 0},
(const char*)transactionDataValue, 0, 0, 0, NULL, NULL, NULL,
},
{
{BAGL_ICON, 0x00, 3, 15, 7, 7, 0, 0, 0, 0xFFFFFF, 0x000000, 0, BAGL_GLYPH_ICON_LEFT},
NULL, 0, 0, 0, NULL, NULL, NULL,
},
{
{BAGL_ICON, 0x00, 100, 15, 7, 7, 0, 0, 0, 0xFFFFFF, 0x000000, 0, BAGL_GLYPH_ICON_RIGHT},
NULL, 0, 0, 0, NULL, NULL, NULL,
},
};


static unsigned int bagl_ui_transaction_info_button(unsigned int button_mask,
unsigned int button_mask_counter)
{
switch (button_mask) {
case BUTTON_EVT_RELEASED | BUTTON_LEFT | BUTTON_RIGHT:
ui_display_transaction(0);
break;

case BUTTON_EVT_RELEASED | BUTTON_LEFT:
if (transactionDetailsCurrentPage > 0) {
transactionDetailsCurrentPage--;
Expand Down Expand Up @@ -141,6 +142,8 @@ void update_transaction_page_info()
(char*)transactionDataValue,
sizeof(transactionDataValue),
transactionDetailsCurrentPage);

snprintf((char*)pageInfo, sizeof(pageInfo), "%d/%d", transactionDetailsCurrentPage+1, transactionDetailsPageCount);
}

void sign_transaction(unsigned int unused)
Expand All @@ -151,31 +154,11 @@ void sign_transaction(unsigned int unused)

void reject(unsigned int unused)
{
if (rejectPtr != NULL){
if (rejectPtr != NULL) {
rejectPtr();
}
}

const ux_menu_entry_t menu_transaction_info[] = {
{NULL, start_transaction_info_display, 0, NULL, "View transaction", NULL, 0, 0},
{NULL, sign_transaction, 0, NULL, "Sign transaction", NULL, 0, 0},
{NULL, reject, 0, &C_icon_back, "Reject", NULL, 60, 40},
UX_MENU_END
};

const ux_menu_entry_t menu_about[] = {
{NULL, NULL, 0, NULL, "Version", APPVERSION, 0, 0},
{menu_main, NULL, 2, &C_icon_back, "Back", NULL, 61, 40},
UX_MENU_END
};

const ux_menu_entry_t menu_main[] = {
{NULL, NULL, 0, &C_icon_tendermint, "Tendermint", "Cosmos Demo", 33, 12},
{menu_about, NULL, 0, NULL, "About", NULL, 0, 0},
{NULL, os_sched_exit, 0, &C_icon_dashboard, "Quit app", NULL, 50, 29},
UX_MENU_END
};

void io_seproxyhal_display(const bagl_element_t *element)
{
io_seproxyhal_display_default((bagl_element_t *) element);
Expand Down

0 comments on commit 8ca5bc2

Please sign in to comment.