Skip to content

Commit 3b57691

Browse files
committed
gui: add brightness controls to qrcode displays
1 parent 9859aea commit 3b57691

File tree

3 files changed

+66
-32
lines changed

3 files changed

+66
-32
lines changed

main/button_events.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ typedef enum {
77
BTN_YES,
88
BTN_NO,
99
BTN_QR_HELP_EXIT,
10+
BTN_QR_BRIGHTNESS,
1011

1112
BTN_CAMERA_HELP,
1213
BTN_CAMERA_CLICK,
@@ -241,7 +242,6 @@ typedef enum {
241242
BTN_XPUB_OPTIONS_SCRIPTTYPE,
242243
BTN_XPUB_OPTIONS_WALLETTYPE,
243244
BTN_XPUB_OPTIONS_ACCOUNT,
244-
BTN_XPUB_HELP,
245245
BTN_XPUB_EXIT,
246246

247247
BTN_SCAN_ADDRESS_SKIP_ADDRESSES,

main/qrmode.c

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,9 @@ void display_xpub_qr(void)
408408
// Options were updated - re-create xpub screen
409409
act = create_display_xpub_qr_activity(qr_flags);
410410
}
411-
} else if (ev_id == BTN_XPUB_HELP) {
412-
await_qr_help_activity("blkstrm.com/xpub");
411+
} else if (ev_id == BTN_QR_BRIGHTNESS) {
412+
gui_next_qrcode_color();
413+
gui_repaint(act->root_node);
413414
} else if (ev_id == BTN_XPUB_EXIT) {
414415
// Done
415416
break;
@@ -1511,12 +1512,27 @@ void await_qr_help_activity(const char* url)
15111512
gui_activity_t* const act = make_show_qr_help_activity(url_with_crlf, qr_icon);
15121513
gui_set_current_activity(act);
15131514

1515+
// Show, and await button click
1516+
while (true) {
1517+
int32_t ev_id;
15141518
#ifndef CONFIG_DEBUG_UNATTENDED_CI
1515-
gui_activity_wait_event(act, GUI_BUTTON_EVENT, BTN_QR_HELP_EXIT, NULL, NULL, NULL, 0);
1519+
const bool ret = gui_activity_wait_event(act, GUI_BUTTON_EVENT, ESP_EVENT_ANY_ID, NULL, &ev_id, NULL, 0);
15161520
#else
1517-
gui_activity_wait_event(act, GUI_BUTTON_EVENT, BTN_QR_HELP_EXIT, NULL, NULL, NULL,
1518-
CONFIG_DEBUG_UNATTENDED_CI_TIMEOUT_MS / portTICK_PERIOD_MS);
1521+
gui_activity_wait_event(act, GUI_BUTTON_EVENT, ESP_EVENT_ANY_ID, NULL, NULL, NULL,
1522+
CONFIG_DEBUG_UNATTENDED_CI_TIMEOUT_MS / portTICK_PERIOD_MS);
1523+
const bool ret = true;
1524+
ev_id = BTN_QR_HELP_EXIT;
15191525
#endif
1526+
if (ret) {
1527+
if (ev_id == BTN_QR_BRIGHTNESS) {
1528+
gui_next_qrcode_color();
1529+
gui_repaint(act->root_node);
1530+
} else if (ev_id == BTN_QR_HELP_EXIT) {
1531+
// Done
1532+
break;
1533+
}
1534+
}
1535+
}
15201536
}
15211537

15221538
// Display screen with help url and qr code
@@ -1537,18 +1553,27 @@ bool await_qr_back_continue_activity(
15371553
gui_activity_t* const act = make_qr_back_continue_activity(message, message_size, url, qr_icon, default_selection);
15381554
gui_set_current_activity(act);
15391555

1540-
int32_t ev_id = 0;
1556+
// Show, and await button click
1557+
while (true) {
1558+
int32_t ev_id;
15411559
#ifndef CONFIG_DEBUG_UNATTENDED_CI
1542-
const bool ret = gui_activity_wait_event(act, GUI_BUTTON_EVENT, ESP_EVENT_ANY_ID, NULL, &ev_id, NULL, 0);
1560+
const bool ret = gui_activity_wait_event(act, GUI_BUTTON_EVENT, ESP_EVENT_ANY_ID, NULL, &ev_id, NULL, 0);
15431561
#else
1544-
gui_activity_wait_event(act, GUI_BUTTON_EVENT, ESP_EVENT_ANY_ID, NULL, &ev_id, NULL,
1545-
CONFIG_DEBUG_UNATTENDED_CI_TIMEOUT_MS / portTICK_PERIOD_MS);
1546-
const bool ret = true;
1547-
ev_id = BTN_YES;
1562+
gui_activity_wait_event(act, GUI_BUTTON_EVENT, ESP_EVENT_ANY_ID, NULL, NULL, NULL,
1563+
CONFIG_DEBUG_UNATTENDED_CI_TIMEOUT_MS / portTICK_PERIOD_MS);
1564+
const bool ret = true;
1565+
ev_id = BTN_YES;
15481566
#endif
1549-
1550-
// Return whether 'Continue' was cicked
1551-
return ret && ev_id == BTN_YES;
1567+
if (ret) {
1568+
if (ev_id == BTN_QR_BRIGHTNESS) {
1569+
gui_next_qrcode_color();
1570+
gui_repaint(act->root_node);
1571+
} else if (ev_id == BTN_YES || ev_id == BTN_NO) {
1572+
// Done: return whether 'Continue' was cicked
1573+
return ev_id == BTN_YES;
1574+
}
1575+
}
1576+
}
15521577
}
15531578

15541579
// QR-Mode PinServer interaction

main/ui/qrmode.c

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,26 @@ static void make_qrcode(gui_view_node_t* parent, Icon* icons, const size_t num_i
1717
gui_set_icon_to_qr(icon);
1818
}
1919

20+
static gui_view_node_t* make_back_brightness_row(gui_view_node_t* parent, uint32_t back_ev_id)
21+
{
22+
// Create a row with left back arrow and right brightness button
23+
gui_view_node_t* headersplit;
24+
gui_make_hsplit(&headersplit, GUI_SPLIT_RELATIVE, 3, 27, 46, 27); // 27 x 56% (hsplit) == 15
25+
gui_set_parent(headersplit, parent);
26+
27+
// back button, space, brightness button
28+
btn_data_t hdrbtns[]
29+
= { { .txt = "=", .font = JADE_SYMBOLS_16x16_FONT, .ev_id = back_ev_id, .borders = GUI_BORDER_ALL },
30+
{ .txt = NULL, .font = GUI_DEFAULT_FONT, .ev_id = GUI_BUTTON_EVENT_NONE },
31+
{ .txt = "P", .font = JADE_SYMBOLS_16x16_FONT, .ev_id = BTN_QR_BRIGHTNESS, .borders = GUI_BORDER_ALL } };
32+
// Add individually to avoid creating a new equal 3-way split
33+
for (size_t i = 0; i < sizeof(hdrbtns) / sizeof(hdrbtns[0]); ++i) {
34+
add_button(headersplit, hdrbtns + i);
35+
}
36+
// Return the back button that add_button() created for the caller
37+
return hdrbtns[0].btn;
38+
}
39+
2040
gui_activity_t* make_show_xpub_qr_activity(
2141
const char* label, const char* pathstr, Icon* icons, const size_t num_icons, const size_t frames_per_qr_icon)
2242
{
@@ -37,11 +57,11 @@ gui_activity_t* make_show_xpub_qr_activity(
3757
gui_make_vsplit(&vsplit, GUI_SPLIT_RELATIVE, 4, 20, 30, 25, 25);
3858
gui_set_parent(vsplit, hsplit);
3959

40-
// back button
60+
// back button, space, brightness button
4161
btn_data_t hdrbtns[]
4262
= { { .txt = "=", .font = JADE_SYMBOLS_16x16_FONT, .ev_id = BTN_XPUB_EXIT, .borders = GUI_BORDER_ALL },
4363
{ .txt = NULL, .font = GUI_DEFAULT_FONT, .ev_id = GUI_BUTTON_EVENT_NONE },
44-
{ .txt = "?", .font = GUI_TITLE_FONT, .ev_id = BTN_XPUB_HELP, .borders = GUI_BORDER_ALL } };
64+
{ .txt = "P", .font = JADE_SYMBOLS_16x16_FONT, .ev_id = BTN_QR_BRIGHTNESS, .borders = GUI_BORDER_ALL } };
4565
add_buttons(vsplit, UI_ROW, hdrbtns, 3); // 44 (hsplit) / 3 == 14 - almost 15 so ok
4666

4767
// second row, type label
@@ -303,14 +323,8 @@ gui_activity_t* make_show_qr_help_activity(const char* url, Icon* qr_icon)
303323
gui_make_vsplit(&vsplit, GUI_SPLIT_RELATIVE, 3, 20, 25, 55);
304324
gui_set_parent(vsplit, hsplit);
305325

306-
gui_view_node_t* headersplit;
307-
gui_make_hsplit(&headersplit, GUI_SPLIT_RELATIVE, 2, 27, 73); // 27 x 56% (hsplit) == 15
308-
gui_set_parent(headersplit, vsplit);
309-
310-
// first row, header, back button
311-
btn_data_t hdrbtn
312-
= { .txt = "=", .font = JADE_SYMBOLS_16x16_FONT, .ev_id = BTN_QR_HELP_EXIT, .borders = GUI_BORDER_ALL };
313-
add_buttons(headersplit, UI_ROW, &hdrbtn, 1);
326+
// first row, header: back button, space, brightness button
327+
make_back_brightness_row(vsplit, BTN_QR_HELP_EXIT);
314328

315329
// second row, message
316330
gui_make_text(&node, "Learn more:", TFT_WHITE);
@@ -372,12 +386,7 @@ gui_activity_t* make_qr_back_continue_activity(
372386
gui_make_vsplit(&vsplit, GUI_SPLIT_RELATIVE, 6, 20, 18, 16, 21, 25);
373387
gui_set_parent(vsplit, hsplit);
374388

375-
gui_view_node_t* headersplit;
376-
gui_make_hsplit(&headersplit, GUI_SPLIT_RELATIVE, 2, 27, 73); // 27 x 56% (hsplit) == 15
377-
gui_set_parent(headersplit, vsplit);
378-
379-
btn_data_t hdrbtn = { .txt = "=", .font = JADE_SYMBOLS_16x16_FONT, .ev_id = BTN_NO, .borders = GUI_BORDER_ALL };
380-
add_buttons(headersplit, UI_ROW, &hdrbtn, 1);
389+
gui_view_node_t* back_btn = make_back_brightness_row(vsplit, BTN_NO);
381390

382391
// second/third/fourth row, message
383392
gui_make_text(&node, message[0], TFT_WHITE);
@@ -396,7 +405,7 @@ gui_activity_t* make_qr_back_continue_activity(
396405
add_buttons(vsplit, UI_ROW, &ftrbtn, 1);
397406

398407
// Select default selected button
399-
gui_set_activity_initial_selection(default_selection ? ftrbtn.btn : hdrbtn.btn);
408+
gui_set_activity_initial_selection(default_selection ? ftrbtn.btn : back_btn);
400409
}
401410

402411
// RHS - QR icon

0 commit comments

Comments
 (0)