@@ -56,6 +56,12 @@ unsafe extern "C" fn quit_callback() {
56
56
exit_app ( 0 ) ;
57
57
}
58
58
59
+ impl SyncNBGL for NbglHomeAndSettings { }
60
+
61
+ unsafe extern "C" fn quit_cb ( ) {
62
+ exit_app ( 0 ) ;
63
+ }
64
+
59
65
impl < ' a > NbglHomeAndSettings {
60
66
pub fn new ( ) -> NbglHomeAndSettings {
61
67
NbglHomeAndSettings {
@@ -118,7 +124,87 @@ impl<'a> NbglHomeAndSettings {
118
124
}
119
125
}
120
126
121
- pub fn show ( & mut self ) {
127
+ pub fn show < T : TryFrom < ApduHeader > > ( & mut self ) -> Event < T >
128
+ where
129
+ Reply : From < <T as TryFrom < ApduHeader > >:: Error > ,
130
+ {
131
+ unsafe {
132
+ loop {
133
+ self . info_contents_ptr = self
134
+ . info_contents
135
+ . iter ( )
136
+ . map ( |s| s. as_ptr ( ) )
137
+ . collect :: < Vec < _ > > ( ) ;
138
+
139
+ self . info_list = nbgl_contentInfoList_t {
140
+ infoTypes : INFO_FIELDS . as_ptr ( ) as * const * const c_char ,
141
+ infoContents : self . info_contents_ptr [ ..] . as_ptr ( ) as * const * const c_char ,
142
+ nbInfos : INFO_FIELDS . len ( ) as u8 ,
143
+ } ;
144
+
145
+ for ( i, setting) in self . setting_contents . iter ( ) . enumerate ( ) {
146
+ SWITCH_ARRAY [ i] . text = setting[ 0 ] . as_ptr ( ) ;
147
+ SWITCH_ARRAY [ i] . subText = setting[ 1 ] . as_ptr ( ) ;
148
+ let state = if let Some ( data) = NVM_REF . as_mut ( ) {
149
+ data. get_ref ( ) [ i]
150
+ } else {
151
+ OFF_STATE
152
+ } ;
153
+ SWITCH_ARRAY [ i] . initState = state;
154
+ SWITCH_ARRAY [ i] . token = ( FIRST_USER_TOKEN + i as u32 ) as u8 ;
155
+ SWITCH_ARRAY [ i] . tuneId = TuneIndex :: TapCasual as u8 ;
156
+ }
157
+
158
+ self . content = nbgl_content_t {
159
+ content : nbgl_content_u {
160
+ switchesList : nbgl_pageSwitchesList_s {
161
+ switches : & SWITCH_ARRAY as * const nbgl_contentSwitch_t ,
162
+ nbSwitches : self . nb_settings ,
163
+ } ,
164
+ } ,
165
+ contentActionCallback : Some ( settings_callback) ,
166
+ type_ : SWITCHES_LIST ,
167
+ } ;
168
+
169
+ self . generic_contents = nbgl_genericContents_t {
170
+ callbackCallNeeded : false ,
171
+ __bindgen_anon_1 : nbgl_genericContents_t__bindgen_ty_1 {
172
+ contentsList : & self . content as * const nbgl_content_t ,
173
+ } ,
174
+ nbContents : if self . nb_settings > 0 { 1 } else { 0 } ,
175
+ } ;
176
+
177
+ self . ux_sync_init ( ) ;
178
+ nbgl_useCaseHomeAndSettings (
179
+ self . app_name . as_ptr ( ) as * const c_char ,
180
+ & self . icon as * const nbgl_icon_details_t ,
181
+ core:: ptr:: null ( ) ,
182
+ INIT_HOME_PAGE as u8 ,
183
+ & self . generic_contents as * const nbgl_genericContents_t ,
184
+ & self . info_list as * const nbgl_contentInfoList_t ,
185
+ core:: ptr:: null ( ) ,
186
+ Some ( quit_callback) ,
187
+ ) ;
188
+ match self . ux_sync_wait ( true ) {
189
+ SyncNbgl :: UxSyncRetApduReceived => {
190
+ if let Some ( comm) = COMM_REF . as_mut ( ) {
191
+ if let Some ( value) = comm. check_event ( ) {
192
+ return value;
193
+ }
194
+ }
195
+ }
196
+ SyncNbgl :: UxSyncRetQuitted => {
197
+ exit_app ( 0 ) ;
198
+ }
199
+ _ => {
200
+ panic ! ( "Unexpected return value from ux_sync_homeAndSettings" ) ;
201
+ }
202
+ }
203
+ }
204
+ }
205
+ }
206
+
207
+ pub fn display ( & mut self ) {
122
208
unsafe {
123
209
self . info_contents_ptr = self
124
210
. info_contents
@@ -172,7 +258,7 @@ impl<'a> NbglHomeAndSettings {
172
258
& self . generic_contents as * const nbgl_genericContents_t ,
173
259
& self . info_list as * const nbgl_contentInfoList_t ,
174
260
core:: ptr:: null ( ) ,
175
- Some ( quit_callback ) ,
261
+ Some ( quit_cb ) ,
176
262
) ;
177
263
}
178
264
}
0 commit comments