[FL-2589] RPC App control commands (#1350)
* RPC App control commands * Button release timeout * SubGhz tx fix Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
78
applications/nfc/nfc.c
Executable file → Normal file
78
applications/nfc/nfc.c
Executable file → Normal file
@@ -19,6 +19,77 @@ void nfc_tick_event_callback(void* context) {
|
||||
scene_manager_handle_tick_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);
|
||||
nfc->rpc_ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void nfc_rpc_emulate_callback(NfcWorkerEvent event, void* context) {
|
||||
UNUSED(event);
|
||||
Nfc* nfc = context;
|
||||
|
||||
nfc->rpc_state = NfcRpcStateEmulated;
|
||||
}
|
||||
|
||||
static bool nfc_rpc_command_callback(RpcAppSystemEvent event, const char* arg, void* context) {
|
||||
furi_assert(context);
|
||||
Nfc* nfc = context;
|
||||
|
||||
if(!nfc->rpc_ctx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
|
||||
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;
|
||||
} 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,
|
||||
NfcWorkerStateEmulateMifareUltralight,
|
||||
&nfc->dev->dev_data,
|
||||
nfc_rpc_emulate_callback,
|
||||
nfc);
|
||||
} else if(nfc->dev->format == NfcDeviceSaveFormatMifareClassic) {
|
||||
nfc_worker_start(
|
||||
nfc->worker,
|
||||
NfcWorkerStateEmulateMifareClassic,
|
||||
&nfc->dev->dev_data,
|
||||
nfc_rpc_emulate_callback,
|
||||
nfc);
|
||||
} else {
|
||||
nfc_worker_start(
|
||||
nfc->worker, NfcWorkerStateEmulate, &nfc->dev->dev_data, NULL, nfc);
|
||||
}
|
||||
nfc->rpc_state = NfcRpcStateEmulating;
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Nfc* nfc_alloc() {
|
||||
Nfc* nfc = malloc(sizeof(Nfc));
|
||||
|
||||
@@ -193,7 +264,12 @@ int32_t nfc_app(void* p) {
|
||||
|
||||
// Check argument and run corresponding scene
|
||||
if((*args != '\0')) {
|
||||
if(nfc_device_load(nfc->dev, p)) {
|
||||
uint32_t rpc_ctx = 0;
|
||||
if(sscanf(p, "RPC %lX", &rpc_ctx) == 1) {
|
||||
nfc->rpc_ctx = (void*)rpc_ctx;
|
||||
rpc_system_app_set_callback(nfc->rpc_ctx, nfc_rpc_command_callback, nfc);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneRpc);
|
||||
} else if(nfc_device_load(nfc->dev, p, true)) {
|
||||
if(nfc->dev->format == NfcDeviceSaveFormatMifareUl) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateMifareUl);
|
||||
} else if(nfc->dev->format == NfcDeviceSaveFormatMifareClassic) {
|
||||
|
Reference in New Issue
Block a user