Skip to content

Commit

Permalink
Change menu and settings code according to app_boilerplate from Ledge…
Browse files Browse the repository at this point in the history
…r for bagl.

It simplifies maintainance.
  • Loading branch information
ajinkyaraj-23 committed Aug 23, 2024
1 parent 953b699 commit 54ef70e
Show file tree
Hide file tree
Showing 29 changed files with 53 additions and 66 deletions.
Binary file added app/glyphs/tezos_16px.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions app/src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ typedef struct {
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.
#endif

#ifdef HAVE_NBGL
Expand Down
59 changes: 26 additions & 33 deletions app/src/ui_home.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,53 +22,46 @@
#include "app_main.h"
#include "globals.h"
#include "ui_home_nbgl.h"
#include "os.h"
#include "ux.h"
#include "glyphs.h"

#ifdef HAVE_BAGL
/* Prototypes */

static void cb(tz_ui_cb_type_t cb_type);

/**
* @brief Callback for home screen stream.
*
* @param cb_type one of the 4 home screens (HOME, VERSION, SETTINGS, QUIT) */
static void
cb(tz_ui_cb_type_t cb_type)
{
FUNC_ENTER(("cb_type=%u", cb_type));

switch (cb_type) {
case SCREEN_HOME:
case SCREEN_VERSION:
break;
case SCREEN_SETTINGS:
ui_settings_init(SETTINGS_HOME_PAGE);
break;
case SCREEN_QUIT:
app_exit();
}

FUNC_LEAVE();
}

#endif // HAVE_BAGL
UX_STEP_NOCB(ux_menu_ready_step, pnn,{&C_tezos_16px , "Application", "is ready"});
UX_STEP_NOCB(ux_menu_version_step, bn, {"Version", APPVERSION});
UX_STEP_CB(ux_menu_settings_step, pb, ui_settings_init(SETTINGS_HOME_PAGE), {&C_icon_coggle, "Settings"});
UX_STEP_VALID(ux_menu_exit_step, pb, os_sched_exit(-1), {&C_icon_dashboard_x, "Quit"});

// FLOW for the main menu:
// #1 screen: ready
// #2 screen: version of the app
// #3 screen: about submenu
// #4 screen: quit
UX_FLOW(ux_menu_main_flow,
&ux_menu_ready_step,
&ux_menu_version_step,
&ux_menu_settings_step,
&ux_menu_exit_step,
FLOW_LOOP);

#endif // HAVE_BAGL
void
ui_home_init(void)
{
FUNC_ENTER(("void"));
#ifdef HAVE_BAGL
tz_ui_stream_init(cb);
tz_ui_stream_push(SCREEN_HOME, "Application", "is ready",
TZ_UI_LAYOUT_HOME_N, TZ_UI_ICON_NONE);
tz_ui_stream_push(SCREEN_VERSION, "Version", APPVERSION,
TZ_UI_LAYOUT_HOME_BN, TZ_UI_ICON_NONE);
tz_ui_stream_push(SCREEN_SETTINGS, "Settings", "", TZ_UI_LAYOUT_HOME_PB,
TZ_UI_ICON_SETTINGS);
tz_ui_stream_push(SCREEN_QUIT, "Quit?", "", TZ_UI_LAYOUT_HOME_PB,
TZ_UI_ICON_DASHBOARD);
tz_ui_stream_close();
tz_ui_stream_start();
if (G_ux.stack_count == 0) {
ux_stack_push();
}

ux_flow_init(0, ux_menu_main_flow, NULL);

#elif defined(HAVE_NBGL)
tz_ui_home_redisplay();
#endif
Expand Down
42 changes: 16 additions & 26 deletions app/src/ui_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,34 @@

#include "globals.h"

static void cb(tz_ui_cb_type_t cb_type);

#define EXPERT_MODE 0x01
#define BACK 0x02

static void
cb(tz_ui_cb_type_t cb_type)
expert_mode_toggle()
{
FUNC_ENTER(("cb_type=%u", cb_type));
switch (cb_type) {
case EXPERT_MODE:
toggle_expert_mode();
ui_settings_init(SETTINGS_HOME_PAGE);
break;
case BACK:
ui_home_init();
break;
}
FUNC_ENTER();
toggle_expert_mode();
ui_settings_init(SETTINGS_HOME_PAGE);
FUNC_LEAVE();
}

UX_STEP_CB(ux_expert_mode_step, bn, expert_mode_toggle(), {"Expert mode", global.expert_mode_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_back_step,
FLOW_LOOP);

void
ui_settings_init(int16_t page)
{
const char *exp_mode = "DISABLED";
strncpy(global.expert_mode_state,"DISABLED", sizeof(global.expert_mode_state));

FUNC_ENTER(("void"));

if (N_settings.expert_mode) {
exp_mode = "ENABLED";
strncpy(global.expert_mode_state, "ENABLED", sizeof(global.expert_mode_state));
}

tz_ui_stream_init(cb);
tz_ui_stream_push(EXPERT_MODE, "Expert mode", exp_mode,
TZ_UI_LAYOUT_HOME_BN, TZ_UI_ICON_NONE);
tz_ui_stream_push(BACK, "Back", "", TZ_UI_LAYOUT_HOME_PB,
TZ_UI_ICON_BACK);
tz_ui_stream_close();
global.stream.current = page;
tz_ui_stream_start();
ux_flow_init(0, ux_expert_mode_flow, NULL);
FUNC_LEAVE();
}
Binary file modified tests/integration/nano/snapshots/nanos/back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/integration/nano/snapshots/nanos/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/integration/nano/snapshots/nanos/quit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/integration/nano/snapshots/nanos/settings.png
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.
Binary file modified tests/integration/nano/snapshots/nanos/version.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/integration/nano/snapshots/nanosp/back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/integration/nano/snapshots/nanosp/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/integration/nano/snapshots/nanosp/quit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/integration/nano/snapshots/nanosp/settings.png
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.
Binary file modified tests/integration/nano/snapshots/nanosp/version.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/integration/nano/snapshots/nanox/back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/integration/nano/snapshots/nanox/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/integration/nano/snapshots/nanox/quit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/integration/nano/snapshots/nanox/settings.png
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.
Binary file modified tests/integration/nano/snapshots/nanox/version.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 9 additions & 7 deletions tests/integration/nano/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,25 @@ def test_basic(app):
app.assert_screen(Screen.Version)
app.backend.left_click()
app.assert_screen(Screen.Home)
app.backend.left_click()
app.assert_screen(Screen.Home)
app.backend.both_click()
app.assert_screen(Screen.Home)
app.backend.left_click()
app.assert_screen(Screen.Quit)
app.backend.right_click()
app.assert_screen(Screen.Home)
app.backend.right_click()
app.assert_screen(Screen.Version)
app.backend.right_click()
app.assert_screen(Screen.Settings)
app.backend.right_click()
app.assert_screen(Screen.Quit)
app.backend.right_click()
app.assert_screen(Screen.Quit)
app.assert_screen(Screen.Home)
app.backend.right_click()
app.assert_screen(Screen.Version)

# Check Settings menu operation
app.backend.left_click()
app.backend.right_click()
app.assert_screen(Screen.Settings)
app.backend.both_click()
app.assert_screen(Screen.Settings_expert_mode_disabled)
Expand All @@ -62,7 +66,5 @@ def test_basic(app):
app.assert_screen(Screen.Settings_back)
app.backend.both_click()
app.assert_screen(Screen.Home)
app.backend.right_click()
app.backend.right_click()
app.backend.right_click()
app.backend.left_click()
app._quit()

0 comments on commit 54ef70e

Please sign in to comment.