[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:
@@ -20,10 +20,13 @@
|
||||
#include "scene/lfrfid_app_scene_saved_info.h"
|
||||
#include "scene/lfrfid_app_scene_delete_confirm.h"
|
||||
#include "scene/lfrfid_app_scene_delete_success.h"
|
||||
#include "scene/lfrfid_app_scene_rpc.h"
|
||||
|
||||
#include <toolbox/path.h>
|
||||
#include <flipper_format/flipper_format.h>
|
||||
|
||||
#include "rpc/rpc_app.h"
|
||||
|
||||
const char* LfRfidApp::app_folder = "/any/lfrfid";
|
||||
const char* LfRfidApp::app_extension = ".rfid";
|
||||
const char* LfRfidApp::app_filetype = "Flipper RFID key";
|
||||
@@ -39,6 +42,43 @@ LfRfidApp::LfRfidApp()
|
||||
|
||||
LfRfidApp::~LfRfidApp() {
|
||||
string_clear(file_path);
|
||||
if(rpc_ctx) {
|
||||
rpc_system_app_set_callback(rpc_ctx, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static bool rpc_command_callback(RpcAppSystemEvent event, const char* arg, void* context) {
|
||||
furi_assert(context);
|
||||
LfRfidApp* app = static_cast<LfRfidApp*>(context);
|
||||
|
||||
bool result = false;
|
||||
|
||||
if(event == RpcAppEventSessionClose) {
|
||||
rpc_system_app_set_callback(app->rpc_ctx, NULL, NULL);
|
||||
app->rpc_ctx = NULL;
|
||||
LfRfidApp::Event event;
|
||||
event.type = LfRfidApp::EventType::Exit;
|
||||
app->view_controller.send_event(&event);
|
||||
result = true;
|
||||
} else if(event == RpcAppEventAppExit) {
|
||||
LfRfidApp::Event event;
|
||||
event.type = LfRfidApp::EventType::Exit;
|
||||
app->view_controller.send_event(&event);
|
||||
result = true;
|
||||
} else if(event == RpcAppEventLoadFile) {
|
||||
if(arg) {
|
||||
string_set_str(app->file_path, arg);
|
||||
if(app->load_key_data(app->file_path, &(app->worker.key), false)) {
|
||||
LfRfidApp::Event event;
|
||||
event.type = LfRfidApp::EventType::EmulateStart;
|
||||
app->view_controller.send_event(&event);
|
||||
app->worker.start_emulate();
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void LfRfidApp::run(void* _args) {
|
||||
@@ -47,10 +87,19 @@ void LfRfidApp::run(void* _args) {
|
||||
make_app_folder();
|
||||
|
||||
if(strlen(args)) {
|
||||
string_set_str(file_path, args);
|
||||
load_key_data(file_path, &worker.key);
|
||||
scene_controller.add_scene(SceneType::Emulate, new LfRfidAppSceneEmulate());
|
||||
scene_controller.process(100, SceneType::Emulate);
|
||||
uint32_t rpc_ctx_ptr = 0;
|
||||
if(sscanf(args, "RPC %lX", &rpc_ctx_ptr) == 1) {
|
||||
rpc_ctx = (RpcAppSystem*)rpc_ctx_ptr;
|
||||
rpc_system_app_set_callback(rpc_ctx, rpc_command_callback, this);
|
||||
scene_controller.add_scene(SceneType::Rpc, new LfRfidAppSceneRpc());
|
||||
scene_controller.process(100, SceneType::Rpc);
|
||||
} else {
|
||||
string_set_str(file_path, args);
|
||||
load_key_data(file_path, &worker.key, true);
|
||||
scene_controller.add_scene(SceneType::Emulate, new LfRfidAppSceneEmulate());
|
||||
scene_controller.process(100, SceneType::Emulate);
|
||||
}
|
||||
|
||||
} else {
|
||||
scene_controller.add_scene(SceneType::Start, new LfRfidAppSceneStart());
|
||||
scene_controller.add_scene(SceneType::Read, new LfRfidAppSceneRead());
|
||||
@@ -99,7 +148,7 @@ bool LfRfidApp::load_key_from_file_select(bool need_restore) {
|
||||
dialogs, file_path, file_path, app_extension, true, &I_125_10px, true);
|
||||
|
||||
if(result) {
|
||||
result = load_key_data(file_path, &worker.key);
|
||||
result = load_key_data(file_path, &worker.key, true);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -110,7 +159,7 @@ bool LfRfidApp::delete_key(RfidKey* key) {
|
||||
return storage_simply_remove(storage, string_get_cstr(file_path));
|
||||
}
|
||||
|
||||
bool LfRfidApp::load_key_data(string_t path, RfidKey* key) {
|
||||
bool LfRfidApp::load_key_data(string_t path, RfidKey* key, bool show_dialog) {
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
bool result = false;
|
||||
string_t str_result;
|
||||
@@ -149,7 +198,7 @@ bool LfRfidApp::load_key_data(string_t path, RfidKey* key) {
|
||||
flipper_format_free(file);
|
||||
string_clear(str_result);
|
||||
|
||||
if(!result) {
|
||||
if((!result) && (show_dialog)) {
|
||||
dialog_message_show_storage_error(dialogs, "Cannot load\nkey file");
|
||||
}
|
||||
|
||||
|
@@ -21,6 +21,7 @@
|
||||
#include <dialogs/dialogs.h>
|
||||
|
||||
#include "helpers/rfid_worker.h"
|
||||
#include "rpc/rpc_app.h"
|
||||
|
||||
class LfRfidApp {
|
||||
public:
|
||||
@@ -30,6 +31,8 @@ public:
|
||||
MenuSelected,
|
||||
Stay,
|
||||
Retry,
|
||||
Exit,
|
||||
EmulateStart,
|
||||
};
|
||||
|
||||
enum class SceneType : uint8_t {
|
||||
@@ -51,6 +54,7 @@ public:
|
||||
SavedInfo,
|
||||
DeleteConfirm,
|
||||
DeleteSuccess,
|
||||
Rpc,
|
||||
};
|
||||
|
||||
class Event {
|
||||
@@ -79,6 +83,8 @@ public:
|
||||
|
||||
string_t file_path;
|
||||
|
||||
RpcAppSystem* rpc_ctx;
|
||||
|
||||
void run(void* args);
|
||||
|
||||
static const char* app_folder;
|
||||
@@ -89,8 +95,9 @@ public:
|
||||
bool load_key_from_file_select(bool need_restore);
|
||||
bool delete_key(RfidKey* key);
|
||||
|
||||
bool load_key_data(string_t path, RfidKey* key);
|
||||
bool load_key_data(string_t path, RfidKey* key, bool show_dialog);
|
||||
bool save_key_data(string_t path, RfidKey* key);
|
||||
|
||||
void make_app_folder();
|
||||
//bool rpc_command_callback(RpcAppSystemEvent event, const char* arg, void* context);
|
||||
};
|
||||
|
37
applications/lfrfid/scene/lfrfid_app_scene_rpc.cpp
Normal file
37
applications/lfrfid/scene/lfrfid_app_scene_rpc.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "lfrfid_app_scene_rpc.h"
|
||||
#include "furi/common_defines.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
void LfRfidAppSceneRpc::on_enter(LfRfidApp* app, bool /* need_restore */) {
|
||||
auto popup = app->view_controller.get<PopupVM>();
|
||||
|
||||
popup->set_header("RPC Mode", 64, 30, AlignCenter, AlignTop);
|
||||
|
||||
app->view_controller.switch_to<PopupVM>();
|
||||
|
||||
notification_message(app->notification, &sequence_display_backlight_on);
|
||||
}
|
||||
|
||||
bool LfRfidAppSceneRpc::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
|
||||
UNUSED(app);
|
||||
UNUSED(event);
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == LfRfidApp::EventType::Exit) {
|
||||
consumed = true;
|
||||
LfRfidApp::Event view_event;
|
||||
view_event.type = LfRfidApp::EventType::Back;
|
||||
app->view_controller.send_event(&view_event);
|
||||
} else if(event->type == LfRfidApp::EventType::EmulateStart) {
|
||||
consumed = true;
|
||||
emulating = true;
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void LfRfidAppSceneRpc::on_exit(LfRfidApp* app) {
|
||||
if(emulating) {
|
||||
app->worker.stop_emulate();
|
||||
}
|
||||
app->view_controller.get<PopupVM>()->clean();
|
||||
}
|
12
applications/lfrfid/scene/lfrfid_app_scene_rpc.h
Normal file
12
applications/lfrfid/scene/lfrfid_app_scene_rpc.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "../lfrfid_app.h"
|
||||
|
||||
class LfRfidAppSceneRpc : public GenericScene<LfRfidApp> {
|
||||
public:
|
||||
void on_enter(LfRfidApp* app, bool need_restore) final;
|
||||
bool on_event(LfRfidApp* app, LfRfidApp::Event* event) final;
|
||||
void on_exit(LfRfidApp* app) final;
|
||||
|
||||
private:
|
||||
bool emulating = false;
|
||||
};
|
Reference in New Issue
Block a user