[FL-3766] Refactor detected protocols list (#3809)

* Refactor detected protocols list
* nfc app: fix detect protocols file name
* nfc app: fix function naming
* nfc app: fix detected protocol menu selection

Co-authored-by: hedger <hedger@users.noreply.github.com>
Co-authored-by: あく <alleteam@gmail.com>
Co-authored-by: gornekich <n.gorbadey@gmail.com>
This commit is contained in:
Astra
2024-08-01 06:37:37 +09:00
committed by GitHub
parent 59eb749b2b
commit f73d60cba8
9 changed files with 137 additions and 46 deletions

View File

@@ -7,7 +7,8 @@ void nfc_scene_detect_scan_callback(NfcScannerEvent event, void* context) {
NfcApp* instance = context;
if(event.type == NfcScannerEventTypeDetected) {
nfc_app_set_detected_protocols(instance, event.data.protocols, event.data.protocol_num);
nfc_detected_protocols_set(
instance->detected_protocols, event.data.protocols, event.data.protocol_num);
view_dispatcher_send_custom_event(instance->view_dispatcher, NfcCustomEventWorkerExit);
}
}
@@ -23,7 +24,7 @@ void nfc_scene_detect_on_enter(void* context) {
popup_set_icon(instance->popup, 0, 8, &I_NFC_manual_60x50);
view_dispatcher_switch_to_view(instance->view_dispatcher, NfcViewPopup);
nfc_app_reset_detected_protocols(instance);
nfc_detected_protocols_reset(instance->detected_protocols);
instance->scanner = nfc_scanner_alloc(instance->nfc);
nfc_scanner_start(instance->scanner, nfc_scene_detect_scan_callback, instance);
@@ -37,7 +38,7 @@ bool nfc_scene_detect_on_event(void* context, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == NfcCustomEventWorkerExit) {
if(instance->protocols_detected_num > 1) {
if(nfc_detected_protocols_get_num(instance->detected_protocols) > 1) {
notification_message(instance->notifications, &sequence_single_vibro);
scene_manager_next_scene(instance->scene_manager, NfcSceneSelectProtocol);
} else {

View File

@@ -57,7 +57,8 @@ bool nfc_scene_mf_ultralight_unlock_warn_on_event(void* context, SceneManagerEve
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == DialogExResultRight) {
const NfcProtocol mfu_protocol[] = {NfcProtocolMfUltralight};
nfc_app_set_detected_protocols(nfc, mfu_protocol, COUNT_OF(mfu_protocol));
nfc_detected_protocols_set(
nfc->detected_protocols, mfu_protocol, COUNT_OF(mfu_protocol));
scene_manager_next_scene(nfc->scene_manager, NfcSceneRead);
dolphin_deed(DolphinDeedNfcRead);
consumed = true;
@@ -77,7 +78,8 @@ bool nfc_scene_mf_ultralight_unlock_warn_on_event(void* context, SceneManagerEve
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == DialogExResultCenter) {
const NfcProtocol mfu_protocol[] = {NfcProtocolMfUltralight};
nfc_app_set_detected_protocols(nfc, mfu_protocol, COUNT_OF(mfu_protocol));
nfc_detected_protocols_set(
nfc->detected_protocols, mfu_protocol, COUNT_OF(mfu_protocol));
scene_manager_next_scene(nfc->scene_manager, NfcSceneRead);
dolphin_deed(DolphinDeedNfcRead);
consumed = true;

View File

@@ -14,21 +14,19 @@ void nfc_scene_select_protocol_on_enter(void* context) {
const char* prefix;
if(scene_manager_has_previous_scene(instance->scene_manager, NfcSceneExtraActions)) {
prefix = "Read";
instance->protocols_detected_num = NfcProtocolNum;
for(uint32_t i = 0; i < NfcProtocolNum; i++) {
instance->protocols_detected[i] = i;
}
nfc_detected_protocols_fill_all_protocols(instance->detected_protocols);
} else {
prefix = "Read as";
submenu_set_header(submenu, "Multi-protocol card");
}
for(uint32_t i = 0; i < instance->protocols_detected_num; i++) {
for(uint32_t i = 0; i < nfc_detected_protocols_get_num(instance->detected_protocols); i++) {
furi_string_printf(
temp_str,
"%s %s",
prefix,
nfc_device_get_protocol_name(instance->protocols_detected[i]));
nfc_device_get_protocol_name(
nfc_detected_protocols_get_protocol(instance->detected_protocols, i)));
furi_string_replace_str(temp_str, "Mifare", "MIFARE");
submenu_add_item(
@@ -40,9 +38,8 @@ void nfc_scene_select_protocol_on_enter(void* context) {
}
furi_string_free(temp_str);
const uint32_t state =
scene_manager_get_scene_state(instance->scene_manager, NfcSceneSelectProtocol);
submenu_set_selected_item(submenu, state);
submenu_set_selected_item(
submenu, nfc_detected_protocols_get_selected_idx(instance->detected_protocols));
view_dispatcher_switch_to_view(instance->view_dispatcher, NfcViewMenu);
}
@@ -52,10 +49,8 @@ bool nfc_scene_select_protocol_on_event(void* context, SceneManagerEvent event)
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
instance->protocols_detected_selected_idx = event.event;
nfc_detected_protocols_select(instance->detected_protocols, event.event);
scene_manager_next_scene(instance->scene_manager, NfcSceneRead);
scene_manager_set_scene_state(
instance->scene_manager, NfcSceneSelectProtocol, event.event);
consumed = true;
} else if(event.type == SceneManagerEventTypeBack) {
if(scene_manager_has_previous_scene(instance->scene_manager, NfcSceneDetect)) {

View File

@@ -25,7 +25,7 @@ void nfc_scene_start_on_enter(void* context) {
nfc_device_clear(nfc->nfc_device);
iso14443_3a_reset(nfc->iso14443_3a_edit_data);
// Reset detected protocols list
nfc_app_reset_detected_protocols(nfc);
nfc_detected_protocols_reset(nfc->detected_protocols);
submenu_add_item(submenu, "Read", SubmenuIndexRead, nfc_scene_start_submenu_callback, nfc);
submenu_add_item(