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 33cc794
Show file tree
Hide file tree
Showing 29 changed files with 64 additions and 71 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
62 changes: 27 additions & 35 deletions app/src/ui_home.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,56 +22,48 @@
#include "app_main.h"
#include "globals.h"
#include "ui_home_nbgl.h"
#include "os.h"
#include "ux.h"

#ifdef HAVE_BAGL
/* Prototypes */
#include "glyphs.h"

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});
UX_STEP_CB(ux_menu_settings_step, pb, ui_settings_init(SETTINGS_HOME_PAGE),
{&C_icon_coggle, "Settings"});
UX_STEP_CB(ux_menu_exit_step, pb, app_exit(), {&C_icon_dashboard_x, "Quit"});

/**
* @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));
// FLOW for the main menu:
// #1 screen: ready
// #2 screen: version of the app
// #3 screen: Settings menu
// #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);

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();
void
ui_home_init(void)
{
FUNC_ENTER(("void"));
// reserve a display stack slot if none yet
if (G_ux.stack_count == 0) {
ux_stack_push();
}

ux_flow_init(0, ux_menu_main_flow, NULL);

FUNC_LEAVE();
}

#endif // HAVE_BAGL

#ifdef HAVE_NBGL
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();
#elif defined(HAVE_NBGL)
tz_ui_home_redisplay();
#endif

FUNC_LEAVE();
}
#endif // HAVE_NBGL
51 changes: 22 additions & 29 deletions app/src/ui_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,39 @@
See the License for the specific language governing permissions and
limitations under the License. */

#ifdef HAVE_BAGL
#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()

Check notice

Code scanning / CodeQL

Unused static function Note

Static function expert_mode_toggle is unreachable
{
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)
ui_settings_init(__attribute__((unused)) int16_t page)
{
const char *exp_mode = "DISABLED";

FUNC_ENTER(("void"));
FUNC_ENTER(("Page number: %d", page));

if (N_settings.expert_mode) {
exp_mode = "ENABLED";
strncpy(global.expert_mode_state, "ENABLED",
sizeof(global.expert_mode_state));
} else {
strncpy(global.expert_mode_state, "DISABLED",
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();
}

#endif
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.
20 changes: 13 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 @@ -60,9 +64,11 @@ def test_basic(app):
app.assert_screen(Screen.Settings_expert_mode_disabled)
app.backend.right_click()
app.assert_screen(Screen.Settings_back)
app.backend.right_click()
app.assert_screen(Screen.Settings_expert_mode_disabled)
app.backend.left_click()
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 33cc794

Please sign in to comment.