@@ -21,6 +21,7 @@ enum amiibo_detail_menu_t {
21
21
AMIIBO_DETAIL_MENU_RAND_UID ,
22
22
AMIIBO_DETAIL_MENU_AUTO_RAND_UID ,
23
23
AMIIBO_DETAIL_MENU_READ_ONLY ,
24
+ AMIIBO_DETAIL_MENU_SET_CUSTOM_UID ,
24
25
AMIIBO_DETAIL_MENU_REMOVE_AMIIBO ,
25
26
AMIIBO_DETAIL_MENU_BACK_AMIIBO_DETAIL ,
26
27
AMIIBO_DETAIL_MENU_BACK_FILE_BROWSER ,
@@ -33,7 +34,6 @@ static ret_code_t amiibo_scene_amiibo_detail_set_readonly(app_amiibo_t *app, boo
33
34
vfs_obj_t obj ;
34
35
uint8_t meta_buf [VFS_MAX_META_LEN ];
35
36
36
-
37
37
cwalk_append_segment (path , string_get_cstr (app -> current_folder ), string_get_cstr (app -> current_file ));
38
38
39
39
vfs_driver_t * p_vfs_driver = vfs_get_driver (VFS_DRIVE_EXT );
@@ -112,6 +112,60 @@ static void amiibo_scene_amiibo_detail_delete_tag_confirmed(mui_msg_box_event_t
112
112
}
113
113
}
114
114
115
+ static void amiibo_scene_amiibo_detail_menu_text_input_set_id_event_cb (mui_text_input_event_t event ,
116
+ mui_text_input_t * p_text_input ) {
117
+ app_amiibo_t * app = p_text_input -> user_data ;
118
+ const char * input_text = mui_text_input_get_input_text (p_text_input );
119
+ if (event == MUI_TEXT_INPUT_EVENT_CONFIRMED && strlen (input_text ) > 0 ) {
120
+
121
+ int8_t uid [7 ];
122
+ ret_code_t err_code ;
123
+ char path [VFS_MAX_PATH_LEN ];
124
+
125
+ ntag_t * ntag = & app -> ntag ;
126
+
127
+ // read uid from input
128
+ if (sscanf (input_text , "%02x.%02x.%02x.%02x.%02x.%02x.%02x" , uid , uid + 1 , uid + 2 , uid + 3 , uid + 4 , uid + 5 ,
129
+ uid + 6 ) != 7 ) {
130
+ mui_toast_view_show (app -> p_toast_view , _T (INAVLID_ID ));
131
+ return ;
132
+ }
133
+
134
+ // same uid as current tag
135
+ uint8_t cur_uid [7 ];
136
+ ntag_store_get_uuid (ntag , cur_uid );
137
+ if (memcmp (cur_uid , uid , 7 ) == 0 ) {
138
+ mui_scene_dispatcher_previous_scene (app -> p_scene_dispatcher );
139
+ return ;
140
+ }
141
+
142
+ // set current ntag uid
143
+ err_code = amiibo_helper_set_amiibo_uuid (ntag , uid );
144
+ if (err_code != NRF_SUCCESS ) {
145
+ mui_toast_view_show (app -> p_toast_view , _T (FAILED ));
146
+ return ;
147
+ }
148
+
149
+ // set ntag emu to emulate new tag
150
+ ntag_emu_set_tag (& app -> ntag );
151
+
152
+ // save to file
153
+ vfs_driver_t * p_driver = vfs_get_driver (app -> current_drive );
154
+
155
+ cwalk_append_segment (path , string_get_cstr (app -> current_folder ), string_get_cstr (app -> current_file ));
156
+ int32_t res = p_driver -> write_file_data (path , ntag -> data , sizeof (ntag -> data ));
157
+
158
+ if (res < 0 ) {
159
+ mui_toast_view_show (app -> p_toast_view , _T (FAILED ));
160
+ return ;
161
+ }
162
+
163
+ mui_scene_dispatcher_previous_scene (app -> p_scene_dispatcher );
164
+ } else {
165
+ mui_scene_dispatcher_previous_scene (app -> p_scene_dispatcher );
166
+ }
167
+ }
168
+
115
169
static void amiibo_scene_amiibo_detail_menu_on_selected (mui_list_view_event_t event , mui_list_view_t * p_list_view ,
116
170
mui_list_item_t * p_item ) {
117
171
app_amiibo_t * app = p_list_view -> user_data ;
@@ -168,6 +222,27 @@ static void amiibo_scene_amiibo_detail_menu_on_selected(mui_list_view_event_t ev
168
222
p_item , (p_settings -> auto_gen_amiibo ? getLangString (_L_ON_F ) : getLangString (_L_OFF_F )));
169
223
} break ;
170
224
225
+ case AMIIBO_DETAIL_MENU_SET_CUSTOM_UID : {
226
+ char id_text [32 ];
227
+ uint8_t id [7 ];
228
+ ntag_t * ntag = & app -> ntag ;
229
+
230
+ if (!amiibo_helper_is_key_loaded ()) {
231
+ amiibo_scene_amiibo_detail_no_key_msg (app );
232
+ return ;
233
+ }
234
+
235
+ ntag_store_get_uuid (ntag , id );
236
+
237
+ sprintf (id_text , "%02x.%02x.%02x.%02x.%02x.%02x.%02x" , id [0 ], id [1 ], id [2 ], id [3 ], id [4 ], id [5 ], id [6 ]);
238
+
239
+ mui_text_input_set_header (app -> p_text_input , getLangString (_L_INPUT_ID ));
240
+ mui_text_input_set_input_text (app -> p_text_input , id_text );
241
+ mui_text_input_set_event_cb (app -> p_text_input , amiibo_scene_amiibo_detail_menu_text_input_set_id_event_cb );
242
+
243
+ mui_view_dispatcher_switch_to_view (app -> p_view_dispatcher , AMIIBO_VIEW_ID_INPUT );
244
+ } break ;
245
+
171
246
case AMIIBO_DETAIL_MENU_READ_ONLY : {
172
247
ret_code_t err_code = amiibo_scene_amiibo_detail_set_readonly (app , !app -> ntag .read_only );
173
248
if (err_code == NRF_SUCCESS ) {
@@ -207,6 +282,9 @@ void amiibo_scene_amiibo_detail_menu_on_enter(void *user_data) {
207
282
(p_settings -> auto_gen_amiibo ? getLangString (_L_ON_F ) : getLangString (_L_OFF_F )),
208
283
(void * )AMIIBO_DETAIL_MENU_AUTO_RAND_UID );
209
284
285
+ mui_list_view_add_item (app -> p_list_view , 0xe1c8 , getLangString (_L_SET_CUSTOM_ID ),
286
+ (void * )AMIIBO_DETAIL_MENU_SET_CUSTOM_UID );
287
+
210
288
mui_list_view_add_item_ext (app -> p_list_view , 0xe007 , getLangString (_L_READ_ONLY ),
211
289
app -> ntag .read_only ? getLangString (_L_ON_F ) : getLangString (_L_OFF_F ),
212
290
(void * )AMIIBO_DETAIL_MENU_READ_ONLY );
0 commit comments