@@ -34,91 +34,74 @@ void app_quit(void) {
3434 os_sched_exit (-1 );
3535}
3636
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-
5337// -----------------------------------------------------------
5438// --------------------- SETTINGS MENU -----------------------
5539// -----------------------------------------------------------
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" };
5943
6044// settings switches definitions
6145enum { DUMMY_SWITCH_1_TOKEN = FIRST_USER_TOKEN , DUMMY_SWITCH_2_TOKEN };
6246enum { DUMMY_SWITCH_1_ID = 0 , DUMMY_SWITCH_2_ID , SETTINGS_SWITCHES_NB };
6347
64- static nbgl_layoutSwitch_t switches [SETTINGS_SWITCHES_NB ] = {0 };
48+ static nbgl_contentSwitch_t switches [SETTINGS_SWITCHES_NB ] = {0 };
6549
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+ };
6855
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 };
10071
10172// callback for setting warning choice
10273static void review_warning_choice (bool confirm ) {
10374 uint8_t switch_value ;
10475 if (confirm ) {
10576 // toggle the switch value
10677 switch_value = !N_storage .dummy2_allowed ;
78+ switches [DUMMY_SWITCH_2_ID ].initState = (nbgl_state_t ) switch_value ;
10779 // store the new setting value in NVM
10880 nvm_write ((void * ) & N_storage .dummy2_allowed , & switch_value , 1 );
10981 }
11082
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 );
11392}
11493
115- static void controls_callback (int token , uint8_t index ) {
94+ static void controls_callback (int token , uint8_t index , int page ) {
11695 UNUSED (index );
96+
97+ initSettingPage = page ;
98+
11799 uint8_t switch_value ;
118100 if (token == DUMMY_SWITCH_1_TOKEN ) {
119101 // Dummy 1 switch touched
120102 // toggle the switch value
121103 switch_value = !N_storage .dummy1_allowed ;
104+ switches [DUMMY_SWITCH_1_ID ].initState = (nbgl_state_t ) switch_value ;
122105 // store the new setting value in NVM
123106 nvm_write ((void * ) & N_storage .dummy1_allowed , & switch_value , 1 );
124107 } else if (token == DUMMY_SWITCH_2_TOKEN ) {
@@ -128,7 +111,7 @@ static void controls_callback(int token, uint8_t index) {
128111 // to activate the dummy 2 setting
129112 if (!N_storage .dummy2_allowed ) {
130113 // Display the warning message and ask the user to confirm
131- nbgl_useCaseChoice (& C_warning64px ,
114+ nbgl_useCaseChoice (& C_Warning_64px ,
132115 "Dummy 2" ,
133116 "Are you sure to\nallow dummy 2\nin transactions?" ,
134117 "I understand, confirm" ,
@@ -137,24 +120,36 @@ static void controls_callback(int token, uint8_t index) {
137120 } else {
138121 // toggle the switch value
139122 switch_value = !N_storage .dummy2_allowed ;
123+ switches [DUMMY_SWITCH_2_ID ].initState = (nbgl_state_t ) switch_value ;
140124 // store the new setting value in NVM
141125 nvm_write ((void * ) & N_storage .dummy2_allowed , & switch_value , 1 );
142126 }
143127 }
144128}
145129
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 );
158153}
159154
160155#endif
0 commit comments