Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/flipperzero-firmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'applications/nfc/nfc.c')
-rw-r--r--applications/nfc/nfc.c84
1 files changed, 21 insertions, 63 deletions
diff --git a/applications/nfc/nfc.c b/applications/nfc/nfc.c
index b19f92f2..32e74e8f 100644
--- a/applications/nfc/nfc.c
+++ b/applications/nfc/nfc.c
@@ -13,78 +13,21 @@ bool nfc_back_event_callback(void* context) {
return scene_manager_handle_back_event(nfc->scene_manager);
}
-void nfc_rpc_exit_callback(Nfc* nfc) {
- if(nfc->rpc_state == NfcRpcStateEmulating) {
- // Stop worker
- nfc_worker_stop(nfc->worker);
- } else if(nfc->rpc_state == NfcRpcStateEmulated) {
- // Stop worker
- nfc_worker_stop(nfc->worker);
- // Save data in shadow file
- nfc_device_save_shadow(nfc->dev, nfc->dev->dev_name);
- }
- if(nfc->rpc_ctx) {
- rpc_system_app_set_callback(nfc->rpc_ctx, NULL, NULL);
- rpc_system_app_send_exited(nfc->rpc_ctx);
- nfc->rpc_ctx = NULL;
- }
-}
-
-static bool nfc_rpc_emulate_callback(NfcWorkerEvent event, void* context) {
- UNUSED(event);
- Nfc* nfc = context;
-
- nfc->rpc_state = NfcRpcStateEmulated;
- return true;
-}
-
-static bool nfc_rpc_command_callback(RpcAppSystemEvent event, const char* arg, void* context) {
+static void nfc_rpc_command_callback(RpcAppSystemEvent event, void* context) {
furi_assert(context);
Nfc* nfc = context;
- if(!nfc->rpc_ctx) {
- return false;
- }
-
- bool result = false;
+ furi_assert(nfc->rpc_ctx);
if(event == RpcAppEventSessionClose) {
- rpc_system_app_set_callback(nfc->rpc_ctx, NULL, NULL);
- nfc->rpc_ctx = NULL;
- view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventViewExit);
- result = true;
+ view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventRpcSessionClose);
} else if(event == RpcAppEventAppExit) {
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventViewExit);
- result = true;
} else if(event == RpcAppEventLoadFile) {
- if((arg) && (nfc->rpc_state == NfcRpcStateIdle)) {
- if(nfc_device_load(nfc->dev, arg, false)) {
- if(nfc->dev->format == NfcDeviceSaveFormatMifareUl) {
- nfc_worker_start(
- nfc->worker,
- NfcWorkerStateMfUltralightEmulate,
- &nfc->dev->dev_data,
- nfc_rpc_emulate_callback,
- nfc);
- } else if(nfc->dev->format == NfcDeviceSaveFormatMifareClassic) {
- nfc_worker_start(
- nfc->worker,
- NfcWorkerStateMfClassicEmulate,
- &nfc->dev->dev_data,
- nfc_rpc_emulate_callback,
- nfc);
- } else {
- nfc_worker_start(
- nfc->worker, NfcWorkerStateUidEmulate, &nfc->dev->dev_data, NULL, nfc);
- }
- nfc->rpc_state = NfcRpcStateEmulating;
- view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventRpcLoad);
- result = true;
- }
- }
+ view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventRpcLoad);
+ } else {
+ rpc_system_app_confirm(nfc->rpc_ctx, event, false);
}
-
- return result;
}
Nfc* nfc_alloc() {
@@ -163,6 +106,21 @@ Nfc* nfc_alloc() {
void nfc_free(Nfc* nfc) {
furi_assert(nfc);
+ if(nfc->rpc_state == NfcRpcStateEmulating) {
+ // Stop worker
+ nfc_worker_stop(nfc->worker);
+ } else if(nfc->rpc_state == NfcRpcStateEmulated) {
+ // Stop worker
+ nfc_worker_stop(nfc->worker);
+ // Save data in shadow file
+ nfc_device_save_shadow(nfc->dev, nfc->dev->dev_name);
+ }
+ if(nfc->rpc_ctx) {
+ rpc_system_app_send_exited(nfc->rpc_ctx);
+ rpc_system_app_set_callback(nfc->rpc_ctx, NULL, NULL);
+ nfc->rpc_ctx = NULL;
+ }
+
// Nfc device
nfc_device_free(nfc->dev);