-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/gornek/nfc_refactoring_v1' into …
…gsurkov/3594_nfc_refactoring_docs
- Loading branch information
Showing
21 changed files
with
1,017 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
applications/main/nfc/helpers/protocol_support/st25tb/st25tb.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#include <nfc/protocols/nfc_protocol.h> | ||
#include <nfc/protocols/st25tb/st25tb_poller.h> | ||
|
||
#include "nfc/nfc_app_i.h" | ||
#include "st25tb_render.h" | ||
#include "../nfc_protocol_support_base.h" | ||
#include "../nfc_protocol_support_gui_common.h" | ||
|
||
static void nfc_scene_info_on_enter_st25tb(NfcApp* instance) { | ||
const NfcDevice* device = instance->nfc_device; | ||
const St25tbData* data = nfc_device_get_data(device, NfcProtocolSt25tb); | ||
|
||
FuriString* temp_str = furi_string_alloc(); | ||
furi_string_cat_printf( | ||
temp_str, "\e#%s\n", nfc_device_get_name(device, NfcDeviceNameTypeFull)); | ||
nfc_render_st25tb_info(data, NfcProtocolFormatTypeFull, temp_str); | ||
|
||
widget_add_text_scroll_element( | ||
instance->widget, 0, 0, 128, 64, furi_string_get_cstr(temp_str)); | ||
|
||
furi_string_free(temp_str); | ||
} | ||
|
||
static NfcCommand nfc_scene_read_poller_callback_st25tb(NfcGenericEvent event, void* context) { | ||
furi_assert(event.protocol == NfcProtocolSt25tb); | ||
|
||
NfcApp* instance = context; | ||
const St25tbPollerEvent* st25tb_event = event.event_data; | ||
|
||
if(st25tb_event->type == St25tbPollerEventTypeReady) { | ||
nfc_device_set_data( | ||
instance->nfc_device, NfcProtocolSt25tb, nfc_poller_get_data(instance->poller)); | ||
view_dispatcher_send_custom_event(instance->view_dispatcher, NfcCustomEventPollerSuccess); | ||
return NfcCommandStop; | ||
} | ||
|
||
return NfcCommandContinue; | ||
} | ||
|
||
static void nfc_scene_read_on_enter_st25tb(NfcApp* instance) { | ||
nfc_poller_start(instance->poller, nfc_scene_read_poller_callback_st25tb, instance); | ||
} | ||
|
||
static void nfc_scene_read_success_on_enter_st25tb(NfcApp* instance) { | ||
const NfcDevice* device = instance->nfc_device; | ||
const St25tbData* data = nfc_device_get_data(device, NfcProtocolSt25tb); | ||
|
||
FuriString* temp_str = furi_string_alloc(); | ||
furi_string_cat_printf( | ||
temp_str, "\e#%s\n", nfc_device_get_name(device, NfcDeviceNameTypeFull)); | ||
nfc_render_st25tb_info(data, NfcProtocolFormatTypeShort, temp_str); | ||
|
||
widget_add_text_scroll_element( | ||
instance->widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str)); | ||
|
||
furi_string_free(temp_str); | ||
} | ||
|
||
static bool nfc_scene_info_on_event_st25tb(NfcApp* instance, uint32_t event) { | ||
if(event == GuiButtonTypeRight) { | ||
scene_manager_next_scene(instance->scene_manager, NfcSceneNotImplemented); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
static bool nfc_scene_saved_menu_on_event_st25tb(NfcApp* instance, uint32_t event) { | ||
if(event == SubmenuIndexCommonEdit) { | ||
scene_manager_next_scene(instance->scene_manager, NfcSceneSetUid); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
const NfcProtocolSupportBase nfc_protocol_support_st25tb = { | ||
.features = NfcProtocolFeatureNone, // TODO: Implement better UID editing, | ||
|
||
.scene_info = | ||
{ | ||
.on_enter = nfc_scene_info_on_enter_st25tb, | ||
.on_event = nfc_scene_info_on_event_st25tb, | ||
}, | ||
.scene_read = | ||
{ | ||
.on_enter = nfc_scene_read_on_enter_st25tb, | ||
.on_event = NULL, | ||
}, | ||
.scene_read_menu = | ||
{ | ||
.on_enter = nfc_protocol_support_common_on_enter_empty, | ||
.on_event = nfc_protocol_support_common_on_event_empty, | ||
}, | ||
.scene_read_success = | ||
{ | ||
.on_enter = nfc_scene_read_success_on_enter_st25tb, | ||
.on_event = NULL, | ||
}, | ||
.scene_saved_menu = | ||
{ | ||
.on_enter = nfc_protocol_support_common_on_enter_empty, | ||
.on_event = nfc_scene_saved_menu_on_event_st25tb, | ||
}, | ||
.scene_emulate = | ||
{ | ||
.on_enter = NULL, | ||
.on_event = NULL, | ||
}, | ||
}; |
5 changes: 5 additions & 0 deletions
5
applications/main/nfc/helpers/protocol_support/st25tb/st25tb.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#pragma once | ||
|
||
#include "../nfc_protocol_support_base.h" | ||
|
||
extern const NfcProtocolSupportBase nfc_protocol_support_st25tb; |
22 changes: 22 additions & 0 deletions
22
applications/main/nfc/helpers/protocol_support/st25tb/st25tb_render.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "st25tb_render.h" | ||
#include <nfc/protocols/st25tb/st25tb.h> | ||
|
||
void nfc_render_st25tb_info( | ||
const St25tbData* data, | ||
NfcProtocolFormatType format_type, | ||
FuriString* str) { | ||
furi_string_cat_printf(str, "UID"); | ||
|
||
for(size_t i = 0; i < ST25TB_UID_SIZE; i++) { | ||
furi_string_cat_printf(str, " %02X", data->uid[i]); | ||
} | ||
|
||
if(format_type == NfcProtocolFormatTypeFull) { | ||
furi_string_cat_printf(str, "\nSys. OTP: %08lX", data->system_otp_block); | ||
furi_string_cat_printf(str, "\nBlocks:"); | ||
for(size_t i = 0; i < st25tb_get_block_count(data->type); i += 2) { | ||
furi_string_cat_printf( | ||
str, "\n %02X %08lX %08lX", i, data->blocks[i], data->blocks[i + 1]); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
applications/main/nfc/helpers/protocol_support/st25tb/st25tb_render.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
#include <nfc/protocols/st25tb/st25tb.h> | ||
|
||
#include "../nfc_protocol_support_render_common.h" | ||
|
||
void nfc_render_st25tb_info( | ||
const St25tbData* data, | ||
NfcProtocolFormatType format_type, | ||
FuriString* str); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.