flipperzero-firmware/applications/nfc/views/nfc_emulate.c
gornekich a0e1e42f2d
[FL-1479] New NFC app (#544)
* view: add custom event callback
* nfc: rework nfc worker
* gui: introduce view navigator
* nfc_scences: introduce nfc scenes
* nfc: add start scene
* lib: add C application scene template
* nfc: move nfc views to separate directory
* view_dispatcher: add support for view_navigator
* nfc views: rework nfc views
* nfc scenes: add nfc application scenes
* nfc: rework nfc main thread
* view_dispatcher: add separate event for search back scene
* nfc: set worker result address at worker start
* nfc: update read nfc scenes
* view_navigator: rework with M-LIB container
* view_dispatcher: check that all views were freed
* nfc: add debug menu with all functions
* nfc read scene: add notification on success
* api-hal-nfc: add API for UID emulation
* nfc: add nfc emulation UID scene
* assets: add NFC assets
* nfc: update read and emulate scenes UI
* nfc: fix memory leak
* rfal: set custom analog configuration
2021-06-30 20:43:29 +03:00

79 lines
2.1 KiB
C
Executable File

#include "nfc_emulate.h"
#include <furi.h>
#include <api-hal.h>
#include <input/input.h>
#include "../nfc_i.h"
struct NfcEmulate {
NfcCommon* nfc_common;
View* view;
};
void nfc_emulate_draw(Canvas* canvas, void* model) {
canvas_clear(canvas);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str(canvas, 0, 12, "Emulating NFC-A");
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 2, 22, "Type: T2T");
canvas_draw_str(canvas, 2, 32, "UID length: 7");
canvas_draw_str(canvas, 2, 42, "UID: 36 9C E7 B1 0A C1 34");
canvas_draw_str(canvas, 2, 52, "SAK: 00 ATQA: 00/44");
}
bool nfc_emulate_input(InputEvent* event, void* context) {
if(event->key == InputKeyBack) {
return false;
}
return true;
}
void nfc_emulate_enter(void* context) {
furi_assert(context);
NfcEmulate* nfc_emulate = (NfcEmulate*)context;
nfc_worker_start(
nfc_emulate->nfc_common->worker,
NfcWorkerStateEmulate,
&nfc_emulate->nfc_common->worker_result,
NULL,
NULL);
}
void nfc_emulate_exit(void* context) {
furi_assert(context);
NfcEmulate* nfc_emulate = (NfcEmulate*)context;
nfc_worker_stop(nfc_emulate->nfc_common->worker);
}
NfcEmulate* nfc_emulate_alloc(NfcCommon* nfc_common) {
furi_assert(nfc_common);
NfcEmulate* nfc_emulate = furi_alloc(sizeof(NfcEmulate));
nfc_emulate->nfc_common = nfc_common;
// View allocation and configuration
nfc_emulate->view = view_alloc();
view_set_context(nfc_emulate->view, nfc_emulate);
view_set_draw_callback(nfc_emulate->view, (ViewDrawCallback)nfc_emulate_draw);
view_set_input_callback(nfc_emulate->view, nfc_emulate_input);
view_set_enter_callback(nfc_emulate->view, nfc_emulate_enter);
view_set_exit_callback(nfc_emulate->view, nfc_emulate_exit);
return nfc_emulate;
}
void nfc_emulate_free(NfcEmulate* nfc_emulate) {
furi_assert(nfc_emulate);
view_free(nfc_emulate->view);
free(nfc_emulate);
}
View* nfc_emulate_get_view(NfcEmulate* nfc_emulate) {
furi_assert(nfc_emulate);
return nfc_emulate->view;
}