2022-07-04 13:09:46 +00:00
|
|
|
#include "../nfc_i.h"
|
|
|
|
|
|
|
|
void nfc_scene_rpc_on_enter(void* context) {
|
|
|
|
Nfc* nfc = context;
|
2022-07-25 14:16:45 +00:00
|
|
|
Popup* popup = nfc->popup;
|
2022-07-04 13:09:46 +00:00
|
|
|
|
2022-08-11 15:37:23 +00:00
|
|
|
popup_set_header(popup, "NFC", 89, 42, AlignCenter, AlignBottom);
|
|
|
|
popup_set_text(popup, "RPC mode", 89, 44, AlignCenter, AlignTop);
|
2022-07-04 13:09:46 +00:00
|
|
|
|
2022-12-07 16:47:55 +00:00
|
|
|
popup_set_icon(popup, 0, 12, &I_NFC_dolphin_emulation_47x61);
|
2022-07-25 14:16:45 +00:00
|
|
|
|
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup);
|
2022-07-04 13:09:46 +00:00
|
|
|
|
2022-07-25 14:16:45 +00:00
|
|
|
notification_message(nfc->notifications, &sequence_display_backlight_on);
|
2022-07-04 13:09:46 +00:00
|
|
|
}
|
|
|
|
|
2022-08-02 12:54:12 +00:00
|
|
|
static bool nfc_scene_rpc_emulate_callback(NfcWorkerEvent event, void* context) {
|
|
|
|
UNUSED(event);
|
|
|
|
Nfc* nfc = context;
|
|
|
|
|
|
|
|
nfc->rpc_state = NfcRpcStateEmulated;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-07-04 13:09:46 +00:00
|
|
|
bool nfc_scene_rpc_on_event(void* context, SceneManagerEvent event) {
|
|
|
|
Nfc* nfc = context;
|
2022-07-25 14:16:45 +00:00
|
|
|
Popup* popup = nfc->popup;
|
2022-07-04 13:09:46 +00:00
|
|
|
bool consumed = false;
|
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
|
|
|
consumed = true;
|
|
|
|
if(event.event == NfcCustomEventViewExit) {
|
2022-08-02 12:54:12 +00:00
|
|
|
rpc_system_app_confirm(nfc->rpc_ctx, RpcAppEventAppExit, true);
|
2022-08-11 15:37:23 +00:00
|
|
|
scene_manager_stop(nfc->scene_manager);
|
2022-08-02 12:54:12 +00:00
|
|
|
view_dispatcher_stop(nfc->view_dispatcher);
|
|
|
|
} else if(event.event == NfcCustomEventRpcSessionClose) {
|
2022-08-11 15:37:23 +00:00
|
|
|
scene_manager_stop(nfc->scene_manager);
|
2022-07-04 13:09:46 +00:00
|
|
|
view_dispatcher_stop(nfc->view_dispatcher);
|
2022-07-25 14:16:45 +00:00
|
|
|
} else if(event.event == NfcCustomEventRpcLoad) {
|
2022-08-02 12:54:12 +00:00
|
|
|
bool result = false;
|
|
|
|
const char* arg = rpc_system_app_get_data(nfc->rpc_ctx);
|
|
|
|
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_scene_rpc_emulate_callback,
|
|
|
|
nfc);
|
|
|
|
} else if(nfc->dev->format == NfcDeviceSaveFormatMifareClassic) {
|
|
|
|
nfc_worker_start(
|
|
|
|
nfc->worker,
|
|
|
|
NfcWorkerStateMfClassicEmulate,
|
|
|
|
&nfc->dev->dev_data,
|
|
|
|
nfc_scene_rpc_emulate_callback,
|
2023-06-08 05:30:53 +00:00
|
|
|
nfc);
|
|
|
|
} else if(nfc->dev->format == NfcDeviceSaveFormatNfcV) {
|
|
|
|
nfc_worker_start(
|
|
|
|
nfc->worker,
|
|
|
|
NfcWorkerStateNfcVEmulate,
|
|
|
|
&nfc->dev->dev_data,
|
|
|
|
nfc_scene_rpc_emulate_callback,
|
2022-08-02 12:54:12 +00:00
|
|
|
nfc);
|
|
|
|
} else {
|
|
|
|
nfc_worker_start(
|
|
|
|
nfc->worker, NfcWorkerStateUidEmulate, &nfc->dev->dev_data, NULL, nfc);
|
|
|
|
}
|
|
|
|
nfc->rpc_state = NfcRpcStateEmulating;
|
|
|
|
result = true;
|
|
|
|
|
2022-09-15 15:49:10 +00:00
|
|
|
nfc_blink_emulate_start(nfc);
|
2022-08-02 12:54:12 +00:00
|
|
|
nfc_text_store_set(nfc, "emulating\n%s", nfc->dev->dev_name);
|
2022-08-11 15:37:23 +00:00
|
|
|
popup_set_text(popup, nfc->text_store, 89, 44, AlignCenter, AlignTop);
|
2022-08-02 12:54:12 +00:00
|
|
|
}
|
|
|
|
}
|
2022-07-25 14:16:45 +00:00
|
|
|
|
2022-08-02 12:54:12 +00:00
|
|
|
rpc_system_app_confirm(nfc->rpc_ctx, RpcAppEventLoadFile, result);
|
2022-07-04 13:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nfc_scene_rpc_on_exit(void* context) {
|
|
|
|
Nfc* nfc = context;
|
2022-07-25 14:16:45 +00:00
|
|
|
Popup* popup = nfc->popup;
|
2022-07-04 13:09:46 +00:00
|
|
|
|
2022-07-25 14:16:45 +00:00
|
|
|
nfc_blink_stop(nfc);
|
2022-07-04 13:09:46 +00:00
|
|
|
|
2022-07-25 14:16:45 +00:00
|
|
|
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
|
|
|
|
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
|
|
|
|
popup_set_icon(popup, 0, 0, NULL);
|
2022-07-04 13:09:46 +00:00
|
|
|
}
|