Skip to content

Commit

Permalink
Add new field in settings menu "Max Pages"
Browse files Browse the repository at this point in the history
Possible values are 30 60 Unlimited
Update UX for nano for max_pages
  • Loading branch information
ajinkyaraj-23 committed Aug 23, 2024
1 parent 54ef70e commit 8227e30
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 18 deletions.
9 changes: 9 additions & 0 deletions app/src/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,12 @@ toggle_expert_mode(void)
tmp.expert_mode = !N_settings.expert_mode;
nvm_write((void *)&N_settings, (void *)&tmp, sizeof(N_settings));
}

void toggle_max_display_screens(void)
{
settings_t tmp;
memcpy(&tmp, (void *)&N_settings, sizeof(tmp));
tmp.max_screens = (tmp.max_screens + 1) % 3;
nvm_write((void *)&N_settings, (void *)&tmp, sizeof(N_settings));

}
13 changes: 10 additions & 3 deletions app/src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ void init_globals(void);
/// Toggles the persisted expert_mode setting
void toggle_expert_mode(void);

/// toggles the max_screens setting between 30 60, and unlimited.
void toggle_max_display_screens(void);

#define MAX_APDU_SIZE 235
#define MAX_SIGNATURE_SIZE 100
#define ERROR_CODE_SIZE 15
Expand Down Expand Up @@ -113,7 +116,9 @@ typedef struct {
bagl_element_t bagls[4 + TZ_SCREEN_LINES_11PX];
} ux; /// Config for history screens for nano devices.
char expert_mode_state[10]; /// Expert mode state to be displayed in
/// settings.ENAELED/DISABLED.
/// settings.ENAELED/DISABLED
char max_screens_state[14]; /// Max screens state to be displayed in
/// settings. structure [30] 60 Inf
#endif

#ifdef HAVE_NBGL
Expand All @@ -124,8 +129,10 @@ typedef struct {

/* Settings */
typedef struct {
bool expert_mode; /// enable expert mode
} settings_t; /// Special settings available in the app.
bool expert_mode; /// enable expert mode
uint8_t max_screens; /// max screens to display in settings.
///0- 30;1- 60; 2- Unlimited;
} settings_t; /// Special settings available in the app.

extern globals_t global;

Expand Down
7 changes: 1 addition & 6 deletions app/src/ui_home.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
#include "glyphs.h"

#ifdef HAVE_BAGL
/* Prototypes */

static void cb(tz_ui_cb_type_t cb_type);



UX_STEP_NOCB(ux_menu_ready_step, pnn,{&C_tezos_16px , "Application", "is ready"});
UX_STEP_NOCB(ux_menu_version_step, bn, {"Version", APPVERSION});
Expand All @@ -41,7 +36,7 @@ UX_STEP_VALID(ux_menu_exit_step, pb, os_sched_exit(-1), {&C_icon_dashboard_x, "Q
// FLOW for the main menu:
// #1 screen: ready
// #2 screen: version of the app
// #3 screen: about submenu
// #3 screen: Settings submenu
// #4 screen: quit
UX_FLOW(ux_menu_main_flow,
&ux_menu_ready_step,
Expand Down
46 changes: 41 additions & 5 deletions app/src/ui_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,61 @@ expert_mode_toggle()
FUNC_LEAVE();
}

UX_STEP_CB(ux_expert_mode_step, bn, expert_mode_toggle(), {"Expert mode", global.expert_mode_state});
static void
max_screen_change()
{
FUNC_ENTER();
toggle_max_display_screens();
ui_settings_init(SETTINGS_MAX_SCREEN_PAGE);
FUNC_LEAVE();
}

UX_STEP_CB(ux_expert_mode_step, bn, expert_mode_toggle(), {"Expert mode",
global.expert_mode_state});
UX_STEP_CB(ux_max_screen_step, bn, max_screen_change(), {"Max screens",
global.max_screens_state});
UX_STEP_CB(ux_back_step, pb, ui_home_init(), {&C_icon_back, "Back"});

UX_FLOW(ux_expert_mode_flow,
&ux_expert_mode_step,
&ux_max_screen_step,
&ux_back_step,
FLOW_LOOP);

void
ui_settings_init(int16_t page)
{
strncpy(global.expert_mode_state,"DISABLED", sizeof(global.expert_mode_state));
FUNC_ENTER(("%d, Expert Mode: %d, Max_Screen: ", page, N_settings.expert_mode, N_settings.max_screens));
strncpy(global.expert_mode_state, "DISABLED",
sizeof(global.expert_mode_state));

FUNC_ENTER(("void"));

if (N_settings.expert_mode) {
strncpy(global.expert_mode_state, "ENABLED", sizeof(global.expert_mode_state));
strncpy(global.expert_mode_state, "ENABLED",
sizeof(global.expert_mode_state));
}
switch (N_settings.max_screens) {
case 0:
default:
strncpy(global.max_screens_state, " [30] 60 Inf ",
sizeof(global.max_screens_state));
break;
case 1:
strncpy(global.max_screens_state, " 30 [60] Inf ",
sizeof(global.max_screens_state));
break;
case 2:
strncpy(global.max_screens_state, " 30 60 [Inf] ",
sizeof(global.max_screens_state));
break;
}
if(page == SETTINGS_HOME_PAGE) {

ux_flow_init(0, ux_expert_mode_flow, NULL);
ux_flow_init(0, ux_expert_mode_flow, &ux_expert_mode_step);
}
else if(page == SETTINGS_MAX_SCREEN_PAGE) {
ux_flow_init(0, ux_expert_mode_flow, &ux_max_screen_step);
}
FUNC_LEAVE();
}
}
1 change: 1 addition & 0 deletions app/src/ui_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#define SETTINGS_HOME_PAGE 0
#define SETTINGS_MAX_SCREEN_PAGE 1

/**
* @brief Initialize settings screen for nano devices. Displays status of
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 11 additions & 3 deletions tests/integration/nano/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,20 @@ def test_basic(app):
app.backend.both_click()
app.assert_screen(Screen.Settings_expert_mode_enabled)
app.backend.right_click()
app.assert_screen(Screen.Settings_max_screen_30)
app.backend.both_click()
app.assert_screen(Screen.Settings_max_screen_60)
app.backend.both_click()
app.assert_screen(Screen.Settings_max_screen_Inf)
app.backend.both_click()
app.assert_screen(Screen.Settings_max_screen_30)
app.backend.right_click()
app.assert_screen(Screen.Settings_back)
app.backend.left_click()
app.assert_screen(Screen.Settings_max_screen_30)
app.backend.left_click()
app.assert_screen(Screen.Settings_expert_mode_enabled)
app.backend.both_click()
app.assert_screen(Screen.Settings_expert_mode_disabled)
app.backend.right_click()
app.backend.left_click()
app.assert_screen(Screen.Settings_back)
app.backend.both_click()
app.assert_screen(Screen.Home)
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/nano/utils/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ class Screen(str, Enum):
Settings = "settings"
Settings_expert_mode_disabled = "settings_expert_mode_disabled"
Settings_expert_mode_enabled = "settings_expert_mode_enabled"
Settings_max_screen_30 = "settings_max_screen_30"
Settings_max_screen_60 = "settings_max_screen_60"
Settings_max_screen_Inf = "settings_max_screen_inf"
Settings_back = "back"
Quit = "quit"

Expand Down Expand Up @@ -220,7 +223,7 @@ def setup_expert_mode(self) -> None:
self.assert_screen(Screen.Settings_expert_mode_disabled)
self.backend.both_click()
self.assert_screen(Screen.Settings_expert_mode_enabled)
self.backend.right_click()
self.backend.left_click()
self.assert_screen(Screen.Settings_back)
self.backend.both_click()
self.assert_screen(Screen.Home)
Expand Down

0 comments on commit 8227e30

Please sign in to comment.