@@ -40,116 +40,19 @@ void app_quit(void) {
4040static const char * const INFO_TYPES [SETTING_INFO_NB ] = {"Version" , "Developer" };
4141static const char * const INFO_CONTENTS [SETTING_INFO_NB ] = {APPVERSION , "Ledger" };
4242
43- // settings switches definitions
44- enum { DUMMY_SWITCH_1_TOKEN = FIRST_USER_TOKEN , DUMMY_SWITCH_2_TOKEN };
45- enum { DUMMY_SWITCH_1_ID = 0 , DUMMY_SWITCH_2_ID , SETTINGS_SWITCHES_NB };
46-
47- static nbgl_contentSwitch_t switches [SETTINGS_SWITCHES_NB ] = {0 };
48-
4943static const nbgl_contentInfoList_t infoList = {
5044 .nbInfos = SETTING_INFO_NB ,
5145 .infoTypes = INFO_TYPES ,
5246 .infoContents = INFO_CONTENTS ,
5347};
5448
55- static uint8_t initSettingPage ;
56- static void review_warning_choice (bool confirm );
57- static void controls_callback (int token , uint8_t index , int page );
58-
59- // settings menu definition
60- #define SETTING_CONTENTS_NB 1
61- static const nbgl_content_t contents [SETTING_CONTENTS_NB ] = {
62- {.type = SWITCHES_LIST ,
63- .content .switchesList .nbSwitches = SETTINGS_SWITCHES_NB ,
64- .content .switchesList .switches = switches ,
65- .contentActionCallback = controls_callback }};
66-
67- static const nbgl_genericContents_t settingContents = {.callbackCallNeeded = false,
68- .contentsList = contents ,
69- .nbContents = SETTING_CONTENTS_NB };
70-
71- // callback for setting warning choice
72- static void review_warning_choice (bool confirm ) {
73- uint8_t switch_value ;
74- if (confirm ) {
75- // toggle the switch value
76- switch_value = !N_storage .dummy2_allowed ;
77- switches [DUMMY_SWITCH_2_ID ].initState = (nbgl_state_t ) switch_value ;
78- // store the new setting value in NVM
79- nvm_write ((void * ) & N_storage .dummy2_allowed , & switch_value , 1 );
80- }
81-
82- // Reset setting menu to the right page
83- nbgl_useCaseHomeAndSettings (APPNAME ,
84- & ICON_APP_HOME ,
85- NULL ,
86- initSettingPage ,
87- & settingContents ,
88- & infoList ,
89- NULL ,
90- app_quit );
91- }
92-
93- static void controls_callback (int token , uint8_t index , int page ) {
94- UNUSED (index );
95-
96- initSettingPage = page ;
97-
98- uint8_t switch_value ;
99- if (token == DUMMY_SWITCH_1_TOKEN ) {
100- // Dummy 1 switch touched
101- // toggle the switch value
102- switch_value = !N_storage .dummy1_allowed ;
103- switches [DUMMY_SWITCH_1_ID ].initState = (nbgl_state_t ) switch_value ;
104- // store the new setting value in NVM
105- nvm_write ((void * ) & N_storage .dummy1_allowed , & switch_value , 1 );
106- } else if (token == DUMMY_SWITCH_2_TOKEN ) {
107- // Dummy 2 switch touched
108-
109- // in this example we display a warning when the user wants
110- // to activate the dummy 2 setting
111- if (!N_storage .dummy2_allowed ) {
112- // Display the warning message and ask the user to confirm
113- nbgl_useCaseChoice (& ICON_APP_WARNING ,
114- "Dummy 2" ,
115- "Are you sure to\nallow dummy 2\nin transactions?" ,
116- "I understand, confirm" ,
117- "Cancel" ,
118- review_warning_choice );
119- } else {
120- // toggle the switch value
121- switch_value = !N_storage .dummy2_allowed ;
122- switches [DUMMY_SWITCH_2_ID ].initState = (nbgl_state_t ) switch_value ;
123- // store the new setting value in NVM
124- nvm_write ((void * ) & N_storage .dummy2_allowed , & switch_value , 1 );
125- }
126- }
127- }
128-
12949// home page definition
13050void ui_menu_main (void ) {
131- // Initialize switches data
132- switches [DUMMY_SWITCH_1_ID ].initState = (nbgl_state_t ) N_storage .dummy1_allowed ;
133- switches [DUMMY_SWITCH_1_ID ].text = "Dummy 1" ;
134- switches [DUMMY_SWITCH_1_ID ].subText = "Allow dummy 1\nin transactions" ;
135- switches [DUMMY_SWITCH_1_ID ].token = DUMMY_SWITCH_1_TOKEN ;
136- #ifdef HAVE_PIEZO_SOUND
137- switches [DUMMY_SWITCH_1_ID ].tuneId = TUNE_TAP_CASUAL ;
138- #endif
139-
140- switches [DUMMY_SWITCH_2_ID ].initState = (nbgl_state_t ) N_storage .dummy2_allowed ;
141- switches [DUMMY_SWITCH_2_ID ].text = "Dummy 2" ;
142- switches [DUMMY_SWITCH_2_ID ].subText = "Allow dummy 2\nin transactions" ;
143- switches [DUMMY_SWITCH_2_ID ].token = DUMMY_SWITCH_2_TOKEN ;
144- #ifdef HAVE_PIEZO_SOUND
145- switches [DUMMY_SWITCH_2_ID ].tuneId = TUNE_TAP_CASUAL ;
146- #endif
147-
14851 nbgl_useCaseHomeAndSettings (APPNAME ,
14952 & ICON_APP_HOME ,
15053 NULL ,
15154 INIT_HOME_PAGE ,
152- & settingContents ,
55+ NULL ,
15356 & infoList ,
15457 NULL ,
15558 app_quit );
0 commit comments