Skip to content

Commit b9cc4c2

Browse files
committed
qr: Show brightness controls when displaying animated qrcodes
Simplify the associated code since we no longer display a help button outside of the options section.
1 parent 7cb95d4 commit b9cc4c2

File tree

4 files changed

+27
-41
lines changed

4 files changed

+27
-41
lines changed

main/button_events.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ typedef enum {
259259
BTN_QR_OPTIONS_FRAMERATE,
260260
BTN_QR_OPTIONS_HELP,
261261
BTN_QR_OPTIONS_EXIT,
262-
BTN_QR_DISPLAY_HELP,
263262
BTN_QR_DISPLAY_EXIT,
264263

265264
// NOTE: Always leave these ones last as keyboard buttons use

main/qrmode.c

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ gui_activity_t* make_search_address_options_activity(
6767
bool show_account, gui_view_node_t** account_textbox, gui_view_node_t** change_textbox);
6868

6969
gui_activity_t* make_show_qr_activity(const char* message[], size_t message_size, Icon* icons, size_t num_icons,
70-
size_t frames_per_qr_icon, bool show_options_button, bool show_help_btn);
70+
size_t frames_per_qr_icon, bool show_options_button);
7171
gui_activity_t* make_qr_options_activity(gui_view_node_t** density_textbox, gui_view_node_t** framerate_textbox);
7272

7373
bool import_mnemonic(const uint8_t* bytes, size_t bytes_len, char* buf, size_t buf_len, size_t* written);
@@ -905,14 +905,13 @@ static bool handle_qr_options(uint32_t* qr_flags, const char* help_url)
905905

906906
// Create activity to display (potentially multi-frame/animated) qr
907907
static gui_activity_t* create_display_bcur_qr_activity(const char* message[], const size_t message_size,
908-
const char* bcur_type, const uint8_t* cbor, const size_t cbor_len, const uint32_t qr_flags, const char* help_url)
908+
const char* bcur_type, const uint8_t* cbor, const size_t cbor_len, const uint32_t qr_flags)
909909
{
910910
JADE_ASSERT(message);
911911
JADE_ASSERT(message_size);
912912
JADE_ASSERT(bcur_type);
913913
JADE_ASSERT(cbor);
914914
JADE_ASSERT(cbor_len);
915-
// help_url is optional
916915

917916
// Map BCUR cbor into a series of QR-code icons
918917
Icon* icons = NULL;
@@ -923,10 +922,10 @@ static gui_activity_t* create_display_bcur_qr_activity(const char* message[], co
923922
// Create qr activity for those icons
924923
const bool show_options_button = true;
925924
const uint8_t frames_per_qr = qr_framerate_from_flags(qr_flags);
926-
return make_show_qr_activity(message, message_size, icons, num_icons, frames_per_qr, show_options_button, help_url);
925+
return make_show_qr_activity(message, message_size, icons, num_icons, frames_per_qr, show_options_button);
927926
}
928927

929-
// Display a QR code, with access to size_speed options
928+
// Display a QR code, with access to size/speed options
930929
static void display_bcur_qr(const char* message[], const size_t message_size, const char* bcur_type,
931930
const uint8_t* cbor, const size_t cbor_len, const char* help_url)
932931
{
@@ -944,8 +943,7 @@ static void display_bcur_qr(const char* message[], const size_t message_size, co
944943
idletimer_set_min_timeout_secs(BCUR_QR_DISPLAY_MIN_TIMEOUT_SECS);
945944

946945
// Create show psbt activity for those icons
947-
gui_activity_t* act
948-
= create_display_bcur_qr_activity(message, message_size, bcur_type, cbor, cbor_len, qr_flags, help_url);
946+
gui_activity_t* act = create_display_bcur_qr_activity(message, message_size, bcur_type, cbor, cbor_len, qr_flags);
949947

950948
while (true) {
951949
// Show, and await button click
@@ -954,13 +952,13 @@ static void display_bcur_qr(const char* message[], const size_t message_size, co
954952
const int32_t ev_id = gui_activity_wait_button(act, BTN_QR_DISPLAY_EXIT);
955953
if (ev_id == BTN_QR_OPTIONS) {
956954
if (handle_qr_options(&qr_flags, help_url)) {
957-
// Options were updated - re-create psbt qr screen
955+
// Options were updated - re-create bcur qr screen
958956
display_processing_message_activity();
959-
act = create_display_bcur_qr_activity(
960-
message, message_size, bcur_type, cbor, cbor_len, qr_flags, help_url);
957+
act = create_display_bcur_qr_activity(message, message_size, bcur_type, cbor, cbor_len, qr_flags);
961958
}
962-
} else if (ev_id == BTN_QR_DISPLAY_HELP) {
963-
await_qr_help_activity(help_url);
959+
} else if (ev_id == BTN_QR_BRIGHTNESS) {
960+
gui_next_qrcode_color();
961+
gui_repaint(act->root_node);
964962
} else if (ev_id == BTN_QR_DISPLAY_EXIT) {
965963
// Done
966964
break;
@@ -1001,7 +999,7 @@ static bool handle_qr_bytes(const uint8_t* bytes, const size_t bytes_len)
1001999
JADE_ASSERT(sig[written - 1] == '\0');
10021000

10031001
const char* message[] = { "Scan QR", "signature" };
1004-
await_single_qr_activity(message, 2, sig, written - 1, NULL);
1002+
await_single_qr_activity(message, 2, sig, written - 1);
10051003
return true;
10061004
}
10071005

@@ -1380,23 +1378,20 @@ bool display_bcur_bytes_qr(
13801378
return true;
13811379
}
13821380

1383-
// Display screen with help url and qr code
1384-
// Handles up to v6. codes - ie text up to 134 bytes
1385-
// help_url is optional
13861381
void await_single_qr_activity(
1387-
const char* message[], const size_t message_size, const uint8_t* data, const size_t data_len, const char* help_url)
1382+
const char* message[], const size_t message_size, const uint8_t* data, const size_t data_len)
13881383
{
13891384
JADE_ASSERT(message);
13901385
JADE_ASSERT(message_size);
13911386
JADE_ASSERT(data);
13921387
JADE_ASSERT(data_len);
1393-
// help_url is optional
13941388

13951389
Icon* const qr_icon = JADE_MALLOC(sizeof(Icon));
13961390
bytes_to_qr_icon(data, data_len, qr_icon);
13971391

13981392
// Show, and await button click - note gui takes ownership of icon
1399-
gui_activity_t* const act = make_show_qr_activity(message, message_size, qr_icon, 1, 0, false, help_url);
1393+
const bool show_options_button = false;
1394+
gui_activity_t* const act = make_show_qr_activity(message, message_size, qr_icon, 1, 0, show_options_button);
14001395

14011396
while (true) {
14021397
gui_set_current_activity(act);
@@ -1405,8 +1400,9 @@ void await_single_qr_activity(
14051400
if (ev_id == BTN_QR_DISPLAY_EXIT) {
14061401
// Done
14071402
break;
1408-
} else if (ev_id == BTN_QR_DISPLAY_HELP) {
1409-
await_qr_help_activity(help_url);
1403+
} else if (ev_id == BTN_QR_BRIGHTNESS) {
1404+
gui_next_qrcode_color();
1405+
gui_repaint(act->root_node);
14101406
}
14111407
}
14121408
}

main/qrmode.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ void handle_scan_qr(void);
1515
bool display_bcur_bytes_qr(
1616
const char* message[], size_t message_size, const uint8_t* data, size_t data_len, const char* help_url);
1717

18-
// Display screen with single arbitrary qr code
19-
// Handles up to v6 codes - ie. text up to 134 bytes
20-
// help_url is optional
21-
void await_single_qr_activity(
22-
const char* message[], size_t message_size, const uint8_t* data, size_t data_len, const char* help_url);
18+
// Display screen with qr code
19+
// Handles up to v6. codes - ie text up to 134 bytes
20+
void await_single_qr_activity(const char* message[], size_t message_size, const uint8_t* data, size_t data_len);
2321

2422
// Display screen with help url and qr code
2523
void await_qr_help_activity(const char* url);

main/ui/qrmode.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ gui_activity_t* make_qr_options_activity(gui_view_node_t** density_textbox, gui_
228228

229229
// NOTE: 'icons' passed in here must be heap-allocated as the gui element takes ownership
230230
gui_activity_t* make_show_qr_activity(const char* message[], const size_t message_size, Icon* icons,
231-
const size_t num_icons, const size_t frames_per_qr_icon, const bool show_options_button, const bool show_help_btn)
231+
const size_t num_icons, const size_t frames_per_qr_icon, const bool show_options_button)
232232
{
233233
JADE_ASSERT(message);
234234
JADE_ASSERT(message_size < 4);
@@ -249,19 +249,12 @@ gui_activity_t* make_show_qr_activity(const char* message[], const size_t messag
249249
gui_make_vsplit(&vsplit, GUI_SPLIT_RELATIVE, 3, 20, 56, 24);
250250
gui_set_parent(vsplit, hsplit);
251251

252-
// tick button
253-
btn_data_t hdrbtns[]
254-
= { { .txt = "S", .font = VARIOUS_SYMBOLS_FONT, .ev_id = BTN_QR_DISPLAY_EXIT, .borders = GUI_BORDER_ALL },
255-
{ .txt = NULL, .font = GUI_DEFAULT_FONT, .ev_id = GUI_BUTTON_EVENT_NONE },
256-
{ .txt = "?", .font = GUI_TITLE_FONT, .ev_id = BTN_QR_DISPLAY_HELP, .borders = GUI_BORDER_ALL } };
257-
258-
if (!show_help_btn) {
259-
// Remove help button if not needed
260-
hdrbtns[2].txt = NULL;
261-
hdrbtns[2].font = GUI_DEFAULT_FONT;
262-
hdrbtns[2].ev_id = GUI_BUTTON_EVENT_NONE;
263-
hdrbtns[2].borders = 0; // None
264-
}
252+
// back button, space, brightness button
253+
btn_data_t hdrbtns[] = {
254+
{ .txt = "S", .font = VARIOUS_SYMBOLS_FONT, .ev_id = BTN_QR_DISPLAY_EXIT, .borders = GUI_BORDER_ALL },
255+
{ .txt = NULL, .font = GUI_DEFAULT_FONT, .ev_id = GUI_BUTTON_EVENT_NONE },
256+
{ .txt = "P", .font = JADE_SYMBOLS_16x16_FONT, .ev_id = BTN_QR_BRIGHTNESS, .borders = GUI_BORDER_ALL }
257+
};
265258

266259
add_buttons(vsplit, UI_ROW, hdrbtns, 3); // 44 (hsplit) / 3 == 14 - almost 15 so ok
267260

0 commit comments

Comments
 (0)