2022-07-04 13:09:46 +00:00
|
|
|
#include "lfrfid_app_scene_rpc.h"
|
2022-07-20 10:56:33 +00:00
|
|
|
#include <core/common_defines.h>
|
2022-07-04 13:09:46 +00:00
|
|
|
#include <dolphin/dolphin.h>
|
2022-08-02 12:54:12 +00:00
|
|
|
#include <rpc/rpc_app.h>
|
2022-07-04 13:09:46 +00:00
|
|
|
|
2022-07-25 14:16:45 +00:00
|
|
|
static const NotificationSequence sequence_blink_start_magenta = {
|
|
|
|
&message_blink_start_10,
|
|
|
|
&message_blink_set_color_magenta,
|
|
|
|
&message_do_not_reset,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const NotificationSequence sequence_blink_stop = {
|
|
|
|
&message_blink_stop,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2022-07-04 13:09:46 +00:00
|
|
|
void LfRfidAppSceneRpc::on_enter(LfRfidApp* app, bool /* need_restore */) {
|
|
|
|
auto popup = app->view_controller.get<PopupVM>();
|
|
|
|
|
2022-07-25 14:16:45 +00:00
|
|
|
popup->set_header("LF RFID", 89, 30, AlignCenter, AlignTop);
|
|
|
|
popup->set_text("RPC mode", 89, 43, AlignCenter, AlignTop);
|
|
|
|
popup->set_icon(0, 3, &I_RFIDDolphinSend_97x61);
|
2022-07-04 13:09:46 +00:00
|
|
|
|
|
|
|
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);
|
2022-08-02 12:54:12 +00:00
|
|
|
rpc_system_app_confirm(app->rpc_ctx, RpcAppEventAppExit, true);
|
|
|
|
} else if(event->type == LfRfidApp::EventType::RpcSessionClose) {
|
|
|
|
// Detach RPC
|
|
|
|
rpc_system_app_set_callback(app->rpc_ctx, NULL, NULL);
|
|
|
|
app->rpc_ctx = NULL;
|
|
|
|
|
|
|
|
consumed = true;
|
|
|
|
LfRfidApp::Event view_event;
|
|
|
|
view_event.type = LfRfidApp::EventType::Back;
|
|
|
|
app->view_controller.send_event(&view_event);
|
2022-07-04 13:09:46 +00:00
|
|
|
} else if(event->type == LfRfidApp::EventType::EmulateStart) {
|
2022-07-25 14:16:45 +00:00
|
|
|
auto popup = app->view_controller.get<PopupVM>();
|
2022-07-04 13:09:46 +00:00
|
|
|
consumed = true;
|
|
|
|
emulating = true;
|
2022-07-25 14:16:45 +00:00
|
|
|
|
|
|
|
app->text_store.set("emulating\n%s", app->worker.key.get_name());
|
|
|
|
popup->set_text(app->text_store.text, 89, 43, AlignCenter, AlignTop);
|
|
|
|
|
|
|
|
notification_message(app->notification, &sequence_blink_start_magenta);
|
2022-08-02 12:54:12 +00:00
|
|
|
} else if(event->type == LfRfidApp::EventType::RpcLoadFile) {
|
|
|
|
const char* arg = rpc_system_app_get_data(app->rpc_ctx);
|
|
|
|
bool result = false;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rpc_system_app_confirm(app->rpc_ctx, RpcAppEventLoadFile, result);
|
2022-07-04 13:09:46 +00:00
|
|
|
}
|
2022-08-02 12:54:12 +00:00
|
|
|
|
2022-07-04 13:09:46 +00:00
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LfRfidAppSceneRpc::on_exit(LfRfidApp* app) {
|
|
|
|
if(emulating) {
|
|
|
|
app->worker.stop_emulate();
|
2022-07-25 14:16:45 +00:00
|
|
|
notification_message(app->notification, &sequence_blink_stop);
|
2022-07-04 13:09:46 +00:00
|
|
|
}
|
|
|
|
app->view_controller.get<PopupVM>()->clean();
|
|
|
|
}
|