@@ -34,91 +34,74 @@ void app_quit(void) {
34
34
os_sched_exit (-1 );
35
35
}
36
36
37
- // home page definition
38
- void ui_menu_main (void ) {
39
- // This parameter shall be set to false if the settings page contains only information
40
- // about the application (version , developer name, ...). It shall be set to
41
- // true if the settings page also contains user configurable parameters related to the
42
- // operation of the application.
43
- #define SETTINGS_BUTTON_ENABLED (true)
44
-
45
- nbgl_useCaseHome (APPNAME ,
46
- & C_app_boilerplate_64px ,
47
- NULL ,
48
- SETTINGS_BUTTON_ENABLED ,
49
- ui_menu_settings ,
50
- app_quit );
51
- }
52
-
53
37
// -----------------------------------------------------------
54
38
// --------------------- SETTINGS MENU -----------------------
55
39
// -----------------------------------------------------------
56
-
57
- static const char * const INFO_TYPES [] = {"Version" , "Developer" };
58
- static const char * const INFO_CONTENTS [] = {APPVERSION , "Ledger" };
40
+ #define SETTING_INFO_NB 2
41
+ static const char * const INFO_TYPES [SETTING_INFO_NB ] = {"Version" , "Developer" };
42
+ static const char * const INFO_CONTENTS [SETTING_INFO_NB ] = {APPVERSION , "Ledger" };
59
43
60
44
// settings switches definitions
61
45
enum { DUMMY_SWITCH_1_TOKEN = FIRST_USER_TOKEN , DUMMY_SWITCH_2_TOKEN };
62
46
enum { DUMMY_SWITCH_1_ID = 0 , DUMMY_SWITCH_2_ID , SETTINGS_SWITCHES_NB };
63
47
64
- static nbgl_layoutSwitch_t switches [SETTINGS_SWITCHES_NB ] = {0 };
48
+ static nbgl_contentSwitch_t switches [SETTINGS_SWITCHES_NB ] = {0 };
65
49
66
- static bool nav_callback (uint8_t page , nbgl_pageContent_t * content ) {
67
- UNUSED (page );
50
+ static const nbgl_contentInfoList_t infoList = {
51
+ .nbInfos = SETTING_INFO_NB ,
52
+ .infoTypes = INFO_TYPES ,
53
+ .infoContents = INFO_CONTENTS ,
54
+ };
68
55
69
- // the first settings page contains only the version and the developer name
70
- // of the app (shall be always on the first setting page)
71
- if (page == 0 ) {
72
- content -> type = INFOS_LIST ;
73
- content -> infosList .nbInfos = 2 ;
74
- content -> infosList .infoTypes = INFO_TYPES ;
75
- content -> infosList .infoContents = INFO_CONTENTS ;
76
- }
77
- // the second settings page contains 2 toggle setting switches
78
- else if (page == 1 ) {
79
- switches [DUMMY_SWITCH_1_ID ].initState = (nbgl_state_t ) N_storage .dummy1_allowed ;
80
- switches [DUMMY_SWITCH_1_ID ].text = "Dummy 1" ;
81
- switches [DUMMY_SWITCH_1_ID ].subText = "Allow dummy 1\nin transactions" ;
82
- switches [DUMMY_SWITCH_1_ID ].token = DUMMY_SWITCH_1_TOKEN ;
83
- switches [DUMMY_SWITCH_1_ID ].tuneId = TUNE_TAP_CASUAL ;
84
-
85
- switches [DUMMY_SWITCH_2_ID ].initState = (nbgl_state_t ) N_storage .dummy2_allowed ;
86
- switches [DUMMY_SWITCH_2_ID ].text = "Dummy 2" ;
87
- switches [DUMMY_SWITCH_2_ID ].subText = "Allow dummy 2\nin transactions" ;
88
- switches [DUMMY_SWITCH_2_ID ].token = DUMMY_SWITCH_2_TOKEN ;
89
- switches [DUMMY_SWITCH_2_ID ].tuneId = TUNE_TAP_CASUAL ;
90
-
91
- content -> type = SWITCHES_LIST ;
92
- content -> switchesList .nbSwitches = SETTINGS_SWITCHES_NB ;
93
- content -> switchesList .switches = (nbgl_layoutSwitch_t * ) switches ;
94
- } else {
95
- return false;
96
- }
97
- // valid page so return true
98
- return true;
99
- }
56
+ static uint8_t initSettingPage ;
57
+ static void review_warning_choice (bool confirm );
58
+ static void controls_callback (int token , uint8_t index , int page );
59
+
60
+ // settings menu definition
61
+ #define SETTING_CONTENTS_NB 1
62
+ static const nbgl_content_t contents [SETTING_CONTENTS_NB ] = {
63
+ {.type = SWITCHES_LIST ,
64
+ .content .switchesList .nbSwitches = SETTINGS_SWITCHES_NB ,
65
+ .content .switchesList .switches = switches ,
66
+ .contentActionCallback = controls_callback }};
67
+
68
+ static const nbgl_genericContents_t settingContents = {.callbackCallNeeded = false,
69
+ .contentsList = contents ,
70
+ .nbContents = SETTING_CONTENTS_NB };
100
71
101
72
// callback for setting warning choice
102
73
static void review_warning_choice (bool confirm ) {
103
74
uint8_t switch_value ;
104
75
if (confirm ) {
105
76
// toggle the switch value
106
77
switch_value = !N_storage .dummy2_allowed ;
78
+ switches [DUMMY_SWITCH_2_ID ].initState = (nbgl_state_t ) switch_value ;
107
79
// store the new setting value in NVM
108
80
nvm_write ((void * ) & N_storage .dummy2_allowed , & switch_value , 1 );
109
81
}
110
82
111
- // return to the settings menu
112
- ui_menu_settings ();
83
+ // Reset setting menu to the right page
84
+ nbgl_useCaseHomeAndSettings (APPNAME ,
85
+ & C_app_boilerplate_64px ,
86
+ NULL ,
87
+ initSettingPage ,
88
+ & settingContents ,
89
+ & infoList ,
90
+ NULL ,
91
+ app_quit );
113
92
}
114
93
115
- static void controls_callback (int token , uint8_t index ) {
94
+ static void controls_callback (int token , uint8_t index , int page ) {
116
95
UNUSED (index );
96
+
97
+ initSettingPage = page ;
98
+
117
99
uint8_t switch_value ;
118
100
if (token == DUMMY_SWITCH_1_TOKEN ) {
119
101
// Dummy 1 switch touched
120
102
// toggle the switch value
121
103
switch_value = !N_storage .dummy1_allowed ;
104
+ switches [DUMMY_SWITCH_1_ID ].initState = (nbgl_state_t ) switch_value ;
122
105
// store the new setting value in NVM
123
106
nvm_write ((void * ) & N_storage .dummy1_allowed , & switch_value , 1 );
124
107
} else if (token == DUMMY_SWITCH_2_TOKEN ) {
@@ -128,7 +111,7 @@ static void controls_callback(int token, uint8_t index) {
128
111
// to activate the dummy 2 setting
129
112
if (!N_storage .dummy2_allowed ) {
130
113
// Display the warning message and ask the user to confirm
131
- nbgl_useCaseChoice (& C_warning64px ,
114
+ nbgl_useCaseChoice (& C_Warning_64px ,
132
115
"Dummy 2" ,
133
116
"Are you sure to\nallow dummy 2\nin transactions?" ,
134
117
"I understand, confirm" ,
@@ -137,24 +120,36 @@ static void controls_callback(int token, uint8_t index) {
137
120
} else {
138
121
// toggle the switch value
139
122
switch_value = !N_storage .dummy2_allowed ;
123
+ switches [DUMMY_SWITCH_2_ID ].initState = (nbgl_state_t ) switch_value ;
140
124
// store the new setting value in NVM
141
125
nvm_write ((void * ) & N_storage .dummy2_allowed , & switch_value , 1 );
142
126
}
143
127
}
144
128
}
145
129
146
- // settings menu definition
147
- void ui_menu_settings () {
148
- #define TOTAL_SETTINGS_PAGE (2)
149
- #define INIT_SETTINGS_PAGE (0)
150
- #define DISABLE_SUB_SETTINGS (false)
151
- nbgl_useCaseSettings (APPNAME ,
152
- INIT_SETTINGS_PAGE ,
153
- TOTAL_SETTINGS_PAGE ,
154
- DISABLE_SUB_SETTINGS ,
155
- ui_menu_main ,
156
- nav_callback ,
157
- controls_callback );
130
+ // home page definition
131
+ void ui_menu_main (void ) {
132
+ // Initialize switches data
133
+ switches [DUMMY_SWITCH_1_ID ].initState = (nbgl_state_t ) N_storage .dummy1_allowed ;
134
+ switches [DUMMY_SWITCH_1_ID ].text = "Dummy 1" ;
135
+ switches [DUMMY_SWITCH_1_ID ].subText = "Allow dummy 1\nin transactions" ;
136
+ switches [DUMMY_SWITCH_1_ID ].token = DUMMY_SWITCH_1_TOKEN ;
137
+ switches [DUMMY_SWITCH_1_ID ].tuneId = TUNE_TAP_CASUAL ;
138
+
139
+ switches [DUMMY_SWITCH_2_ID ].initState = (nbgl_state_t ) N_storage .dummy2_allowed ;
140
+ switches [DUMMY_SWITCH_2_ID ].text = "Dummy 2" ;
141
+ switches [DUMMY_SWITCH_2_ID ].subText = "Allow dummy 2\nin transactions" ;
142
+ switches [DUMMY_SWITCH_2_ID ].token = DUMMY_SWITCH_2_TOKEN ;
143
+ switches [DUMMY_SWITCH_2_ID ].tuneId = TUNE_TAP_CASUAL ;
144
+
145
+ nbgl_useCaseHomeAndSettings (APPNAME ,
146
+ & C_app_boilerplate_64px ,
147
+ NULL ,
148
+ INIT_HOME_PAGE ,
149
+ & settingContents ,
150
+ & infoList ,
151
+ NULL ,
152
+ app_quit );
158
153
}
159
154
160
155
#endif
0 commit comments