2021-06-30 17:43:29 +00:00
|
|
|
#include "../nfc_i.h"
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 09:20:41 +00:00
|
|
|
#include <dolphin/dolphin.h>
|
2021-06-30 17:43:29 +00:00
|
|
|
|
2022-04-19 15:23:58 +00:00
|
|
|
#define NFC_SCENE_EMULATE_UID_LOG_SIZE_MAX (200)
|
|
|
|
|
2022-02-02 19:59:28 +00:00
|
|
|
enum {
|
|
|
|
NfcSceneEmulateUidStateWidget,
|
|
|
|
NfcSceneEmulateUidStateTextBox,
|
|
|
|
};
|
|
|
|
|
2022-07-26 15:30:49 +00:00
|
|
|
bool nfc_emulate_uid_worker_callback(NfcWorkerEvent event, void* context) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(event);
|
2022-02-02 19:59:28 +00:00
|
|
|
furi_assert(context);
|
|
|
|
Nfc* nfc = context;
|
|
|
|
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventWorkerExit);
|
2022-07-26 15:30:49 +00:00
|
|
|
return true;
|
2022-02-02 19:59:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nfc_scene_emulate_uid_widget_callback(GuiButtonType result, InputType type, void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
Nfc* nfc = context;
|
|
|
|
if(type == InputTypeShort) {
|
|
|
|
view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
|
|
|
|
}
|
|
|
|
}
|
2021-06-30 17:43:29 +00:00
|
|
|
|
2022-02-02 19:59:28 +00:00
|
|
|
void nfc_emulate_uid_textbox_callback(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
Nfc* nfc = context;
|
|
|
|
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventViewExit);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add widget with device name or inform that data received
|
|
|
|
static void nfc_scene_emulate_uid_widget_config(Nfc* nfc, bool data_received) {
|
2022-04-19 15:23:58 +00:00
|
|
|
FuriHalNfcDevData* data = &nfc->dev->dev_data.nfc_data;
|
2022-02-02 19:59:28 +00:00
|
|
|
Widget* widget = nfc->widget;
|
|
|
|
widget_reset(widget);
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* info_str;
|
|
|
|
info_str = furi_string_alloc();
|
2021-07-02 13:44:10 +00:00
|
|
|
|
2022-02-02 19:59:28 +00:00
|
|
|
widget_add_icon_element(widget, 0, 3, &I_RFIDDolphinSend_97x61);
|
2022-04-21 12:33:03 +00:00
|
|
|
widget_add_string_element(widget, 89, 32, AlignCenter, AlignTop, FontPrimary, "Emulating UID");
|
2021-11-08 21:55:06 +00:00
|
|
|
if(strcmp(nfc->dev->dev_name, "")) {
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_printf(info_str, "%s", nfc->dev->dev_name);
|
2022-02-02 19:59:28 +00:00
|
|
|
} else {
|
|
|
|
for(uint8_t i = 0; i < data->uid_len; i++) {
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_cat_printf(info_str, "%02X ", data->uid[i]);
|
2022-02-02 19:59:28 +00:00
|
|
|
}
|
2021-06-30 17:43:29 +00:00
|
|
|
}
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_trim(info_str);
|
2022-02-02 19:59:28 +00:00
|
|
|
widget_add_text_box_element(
|
2022-10-05 15:15:23 +00:00
|
|
|
widget, 56, 43, 70, 21, AlignCenter, AlignTop, furi_string_get_cstr(info_str), true);
|
|
|
|
furi_string_free(info_str);
|
2022-02-02 19:59:28 +00:00
|
|
|
if(data_received) {
|
|
|
|
widget_add_button_element(
|
|
|
|
widget, GuiButtonTypeCenter, "Log", nfc_scene_emulate_uid_widget_callback, nfc);
|
|
|
|
}
|
|
|
|
}
|
2021-06-30 17:43:29 +00:00
|
|
|
|
2022-02-02 19:59:28 +00:00
|
|
|
void nfc_scene_emulate_uid_on_enter(void* context) {
|
|
|
|
Nfc* nfc = context;
|
|
|
|
DOLPHIN_DEED(DolphinDeedNfcEmulate);
|
2021-06-30 17:43:29 +00:00
|
|
|
|
2022-02-02 19:59:28 +00:00
|
|
|
// Setup Widget
|
|
|
|
nfc_scene_emulate_uid_widget_config(nfc, false);
|
|
|
|
// Setup TextBox
|
|
|
|
TextBox* text_box = nfc->text_box;
|
|
|
|
text_box_set_font(text_box, TextBoxFontHex);
|
|
|
|
text_box_set_focus(text_box, TextBoxFocusEnd);
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_reset(nfc->text_box_store);
|
2021-07-02 13:44:10 +00:00
|
|
|
|
2022-02-02 19:59:28 +00:00
|
|
|
// Set Widget state and view
|
|
|
|
scene_manager_set_scene_state(
|
|
|
|
nfc->scene_manager, NfcSceneEmulateUid, NfcSceneEmulateUidStateWidget);
|
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
|
|
|
// Start worker
|
|
|
|
memset(&nfc->dev->dev_data.reader_data, 0, sizeof(NfcReaderRequestData));
|
|
|
|
nfc_worker_start(
|
|
|
|
nfc->worker,
|
2022-07-26 15:30:49 +00:00
|
|
|
NfcWorkerStateUidEmulate,
|
2022-02-02 19:59:28 +00:00
|
|
|
&nfc->dev->dev_data,
|
|
|
|
nfc_emulate_uid_worker_callback,
|
|
|
|
nfc);
|
2022-06-13 01:08:28 +00:00
|
|
|
|
2022-09-15 15:49:10 +00:00
|
|
|
nfc_blink_emulate_start(nfc);
|
2021-06-30 17:43:29 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 09:34:16 +00:00
|
|
|
bool nfc_scene_emulate_uid_on_event(void* context, SceneManagerEvent event) {
|
2022-02-02 19:59:28 +00:00
|
|
|
Nfc* nfc = context;
|
|
|
|
NfcReaderRequestData* reader_data = &nfc->dev->dev_data.reader_data;
|
|
|
|
uint32_t state = scene_manager_get_scene_state(nfc->scene_manager, NfcSceneEmulateUid);
|
|
|
|
bool consumed = false;
|
2021-07-12 18:56:14 +00:00
|
|
|
|
2022-07-26 15:30:49 +00:00
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
2022-02-02 19:59:28 +00:00
|
|
|
if(event.event == NfcCustomEventWorkerExit) {
|
|
|
|
// Add data button to widget if data is received for the first time
|
2022-10-05 15:15:23 +00:00
|
|
|
if(!furi_string_size(nfc->text_box_store)) {
|
2022-02-02 19:59:28 +00:00
|
|
|
nfc_scene_emulate_uid_widget_config(nfc, true);
|
|
|
|
}
|
|
|
|
// Update TextBox data
|
2022-10-05 15:15:23 +00:00
|
|
|
if(furi_string_size(nfc->text_box_store) < NFC_SCENE_EMULATE_UID_LOG_SIZE_MAX) {
|
|
|
|
furi_string_cat_printf(nfc->text_box_store, "R:");
|
2022-04-19 15:23:58 +00:00
|
|
|
for(uint16_t i = 0; i < reader_data->size; i++) {
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_cat_printf(nfc->text_box_store, " %02X", reader_data->data[i]);
|
2022-04-19 15:23:58 +00:00
|
|
|
}
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_push_back(nfc->text_box_store, '\n');
|
|
|
|
text_box_set_text(nfc->text_box, furi_string_get_cstr(nfc->text_box_store));
|
2022-02-02 19:59:28 +00:00
|
|
|
}
|
|
|
|
memset(reader_data, 0, sizeof(NfcReaderRequestData));
|
|
|
|
consumed = true;
|
|
|
|
} else if(event.event == GuiButtonTypeCenter && state == NfcSceneEmulateUidStateWidget) {
|
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextBox);
|
|
|
|
scene_manager_set_scene_state(
|
|
|
|
nfc->scene_manager, NfcSceneEmulateUid, NfcSceneEmulateUidStateTextBox);
|
|
|
|
consumed = true;
|
|
|
|
} else if(event.event == NfcCustomEventViewExit && state == NfcSceneEmulateUidStateTextBox) {
|
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
|
|
|
scene_manager_set_scene_state(
|
|
|
|
nfc->scene_manager, NfcSceneEmulateUid, NfcSceneEmulateUidStateWidget);
|
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
} else if(event.type == SceneManagerEventTypeBack) {
|
|
|
|
if(state == NfcSceneEmulateUidStateTextBox) {
|
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
|
|
|
scene_manager_set_scene_state(
|
|
|
|
nfc->scene_manager, NfcSceneEmulateUid, NfcSceneEmulateUidStateWidget);
|
|
|
|
consumed = true;
|
|
|
|
}
|
2021-07-12 18:56:14 +00:00
|
|
|
}
|
2022-02-02 19:59:28 +00:00
|
|
|
|
|
|
|
return consumed;
|
2021-06-30 17:43:29 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 09:34:16 +00:00
|
|
|
void nfc_scene_emulate_uid_on_exit(void* context) {
|
2022-02-02 19:59:28 +00:00
|
|
|
Nfc* nfc = context;
|
2021-06-30 17:43:29 +00:00
|
|
|
|
|
|
|
// Stop worker
|
2021-07-22 06:05:07 +00:00
|
|
|
nfc_worker_stop(nfc->worker);
|
2021-06-30 17:43:29 +00:00
|
|
|
|
|
|
|
// Clear view
|
2022-02-02 19:59:28 +00:00
|
|
|
widget_reset(nfc->widget);
|
|
|
|
text_box_reset(nfc->text_box);
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_reset(nfc->text_box_store);
|
2022-06-13 01:08:28 +00:00
|
|
|
|
|
|
|
nfc_blink_stop(nfc);
|
2021-06-30 17:43:29 +00:00
|
|
|
}
|