nfc: On-device tag generator (#1319)
* nfc: Add tag generator base * nfc: Fix BCC generation * nfc: Add MFUL EV1 generators * nfc: Fix typos in generator * nfc: Add NTAG21x generators * nfc: More const * nfc: Add NTAG I2C generators * nfc: Add field names to generator initializers * nfc: Move generators to add manually scene * nfc: Revise tag generator UX * nfc: Revert add manually menu item name * nfc: Remove unused scene start submenu index Co-authored-by: あく <alleteam@gmail.com> Co-authored-by: gornekich <n.gorbadey@gmail.com>
This commit is contained in:
		| @@ -37,3 +37,4 @@ ADD_SCENE(nfc, read_mifare_classic, ReadMifareClassic) | ||||
| ADD_SCENE(nfc, emulate_mifare_classic, EmulateMifareClassic) | ||||
| ADD_SCENE(nfc, mifare_classic_menu, MifareClassicMenu) | ||||
| ADD_SCENE(nfc, dict_not_found, DictNotFound) | ||||
| ADD_SCENE(nfc, generate_info, GenerateInfo) | ||||
|   | ||||
							
								
								
									
										55
									
								
								applications/nfc/scenes/nfc_scene_generate_info.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								applications/nfc/scenes/nfc_scene_generate_info.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,55 @@ | ||||
| #include "../nfc_i.h" | ||||
| #include "../helpers/nfc_generators.h" | ||||
|  | ||||
| void nfc_scene_generate_info_dialog_callback(DialogExResult result, void* context) { | ||||
|     Nfc* nfc = context; | ||||
|  | ||||
|     view_dispatcher_send_custom_event(nfc->view_dispatcher, result); | ||||
| } | ||||
|  | ||||
| void nfc_scene_generate_info_on_enter(void* context) { | ||||
|     Nfc* nfc = context; | ||||
|  | ||||
|     // Setup dialog view | ||||
|     FuriHalNfcDevData* data = &nfc->dev->dev_data.nfc_data; | ||||
|     DialogEx* dialog_ex = nfc->dialog_ex; | ||||
|     dialog_ex_set_right_button_text(dialog_ex, "More"); | ||||
|  | ||||
|     // Create info text | ||||
|     string_t info_str; | ||||
|     string_init_printf( | ||||
|         info_str, "%s\n%s\nUID:", nfc->generator->name, nfc_get_dev_type(data->type)); | ||||
|     // Append UID | ||||
|     for(int i = 0; i < data->uid_len; ++i) { | ||||
|         string_cat_printf(info_str, " %02X", data->uid[i]); | ||||
|     } | ||||
|     nfc_text_store_set(nfc, string_get_cstr(info_str)); | ||||
|     string_clear(info_str); | ||||
|  | ||||
|     dialog_ex_set_text(dialog_ex, nfc->text_store, 0, 0, AlignLeft, AlignTop); | ||||
|     dialog_ex_set_context(dialog_ex, nfc); | ||||
|     dialog_ex_set_result_callback(dialog_ex, nfc_scene_generate_info_dialog_callback); | ||||
|  | ||||
|     view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewDialogEx); | ||||
| } | ||||
|  | ||||
| bool nfc_scene_generate_info_on_event(void* context, SceneManagerEvent event) { | ||||
|     Nfc* nfc = context; | ||||
|     bool consumed = false; | ||||
|  | ||||
|     if(event.type == SceneManagerEventTypeCustom) { | ||||
|         if(event.event == DialogExResultRight) { | ||||
|             scene_manager_next_scene(nfc->scene_manager, nfc->generator->next_scene); | ||||
|             consumed = true; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     return consumed; | ||||
| } | ||||
|  | ||||
| void nfc_scene_generate_info_on_exit(void* context) { | ||||
|     Nfc* nfc = context; | ||||
|  | ||||
|     // Clean views | ||||
|     dialog_ex_reset(nfc->dialog_ex); | ||||
| } | ||||
							
								
								
									
										17
									
								
								applications/nfc/scenes/nfc_scene_set_type.c
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										17
									
								
								applications/nfc/scenes/nfc_scene_set_type.c
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							| @@ -1,9 +1,11 @@ | ||||
| #include "../nfc_i.h" | ||||
| #include "m-string.h" | ||||
| #include "../helpers/nfc_generators.h" | ||||
|  | ||||
| enum SubmenuIndex { | ||||
|     SubmenuIndexNFCA4, | ||||
|     SubmenuIndexNFCA7, | ||||
|     SubmenuIndexGeneratorsStart, | ||||
| }; | ||||
|  | ||||
| void nfc_scene_set_type_submenu_callback(void* context, uint32_t index) { | ||||
| @@ -22,6 +24,14 @@ void nfc_scene_set_type_on_enter(void* context) { | ||||
|         submenu, "NFC-A 7-bytes UID", SubmenuIndexNFCA7, nfc_scene_set_type_submenu_callback, nfc); | ||||
|     submenu_add_item( | ||||
|         submenu, "NFC-A 4-bytes UID", SubmenuIndexNFCA4, nfc_scene_set_type_submenu_callback, nfc); | ||||
|  | ||||
|     // Generators | ||||
|     int i = SubmenuIndexGeneratorsStart; | ||||
|     for(const NfcGenerator* const* generator = nfc_generators; *generator != NULL; | ||||
|         ++generator, ++i) { | ||||
|         submenu_add_item(submenu, (*generator)->name, i, nfc_scene_set_type_submenu_callback, nfc); | ||||
|     } | ||||
|  | ||||
|     view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewMenu); | ||||
| } | ||||
|  | ||||
| @@ -40,6 +50,13 @@ bool nfc_scene_set_type_on_event(void* context, SceneManagerEvent event) { | ||||
|             nfc->dev->format = NfcDeviceSaveFormatUid; | ||||
|             scene_manager_next_scene(nfc->scene_manager, NfcSceneSetSak); | ||||
|             consumed = true; | ||||
|         } else { | ||||
|             nfc_device_clear(nfc->dev); | ||||
|             nfc->generator = nfc_generators[event.event - SubmenuIndexGeneratorsStart]; | ||||
|             nfc->generator->generator_func(&nfc->dev->dev_data); | ||||
|  | ||||
|             scene_manager_next_scene(nfc->scene_manager, NfcSceneGenerateInfo); | ||||
|             consumed = true; | ||||
|         } | ||||
|     } | ||||
|     return consumed; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user