Skip to content

Commit

Permalink
RPC App: state message and GUI update (#1423)
Browse files Browse the repository at this point in the history
* RPC App: state message and GUI update
* Protobuf submodule update

Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: あく <alleteam@gmail.com>
  • Loading branch information
3 people authored Jul 25, 2022
1 parent f1cb956 commit d80edba
Show file tree
Hide file tree
Showing 17 changed files with 235 additions and 60 deletions.
18 changes: 13 additions & 5 deletions applications/ibutton/ibutton.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ static bool ibutton_rpc_command_callback(RpcAppSystemEvent event, const char* ar
string_set_str(ibutton->file_path, arg);
if(ibutton_load_key_data(ibutton, ibutton->file_path, false)) {
ibutton_worker_emulate_start(ibutton->key_worker, ibutton->key);
view_dispatcher_send_custom_event(
ibutton->view_dispatcher, iButtonCustomEventRpcLoad);
result = true;
}
}
Expand Down Expand Up @@ -162,8 +164,6 @@ iButton* ibutton_alloc() {
ibutton->view_dispatcher, ibutton_tick_event_callback, 100);

ibutton->gui = furi_record_open("gui");
view_dispatcher_attach_to_gui(
ibutton->view_dispatcher, ibutton->gui, ViewDispatcherTypeFullscreen);

ibutton->storage = furi_record_open("storage");
ibutton->dialogs = furi_record_open("dialogs");
Expand Down Expand Up @@ -373,6 +373,7 @@ int32_t ibutton_app(void* p) {
ibutton->rpc_ctx = (void*)rpc_ctx;
rpc_mode = true;
rpc_system_app_set_callback(ibutton->rpc_ctx, ibutton_rpc_command_callback, ibutton);
rpc_system_app_send_started(ibutton->rpc_ctx);
} else {
string_set_str(ibutton->file_path, (const char*)p);
if(ibutton_load_key_data(ibutton, ibutton->file_path, true)) {
Expand All @@ -383,17 +384,24 @@ int32_t ibutton_app(void* p) {
}

if(rpc_mode) {
view_dispatcher_attach_to_gui(
ibutton->view_dispatcher, ibutton->gui, ViewDispatcherTypeDesktop);
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneRpc);
} else if(key_loaded) {
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneEmulate);
} else {
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneStart);
view_dispatcher_attach_to_gui(
ibutton->view_dispatcher, ibutton->gui, ViewDispatcherTypeFullscreen);
if(key_loaded) {
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneEmulate);
} else {
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneStart);
}
}

view_dispatcher_run(ibutton->view_dispatcher);

if(ibutton->rpc_ctx) {
rpc_system_app_set_callback(ibutton->rpc_ctx, NULL, NULL);
rpc_system_app_send_exited(ibutton->rpc_ctx);
}
ibutton_free(ibutton);
return 0;
Expand Down
1 change: 1 addition & 0 deletions applications/ibutton/ibutton_custom_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ enum iButtonCustomEvent {
iButtonCustomEventWorkerEmulated,
iButtonCustomEventWorkerRead,

iButtonCustomEventRpcLoad,
iButtonCustomEventRpcExit,
};
39 changes: 33 additions & 6 deletions applications/ibutton/scenes/ibutton_scene_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

void ibutton_scene_rpc_on_enter(void* context) {
iButton* ibutton = context;
Widget* widget = ibutton->widget;
Popup* popup = ibutton->popup;

widget_add_text_box_element(
widget, 0, 0, 128, 28, AlignCenter, AlignCenter, "RPC mode", false);
popup_set_header(popup, "iButton", 82, 28, AlignCenter, AlignBottom);
popup_set_text(popup, "RPC mode", 82, 32, AlignCenter, AlignTop);

view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget);
popup_set_icon(popup, 2, 14, &I_iButtonKey_49x44);

view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewPopup);

notification_message(ibutton->notifications, &sequence_display_backlight_on);
}
Expand All @@ -17,12 +19,31 @@ bool ibutton_scene_rpc_on_event(void* context, SceneManagerEvent event) {
UNUSED(context);
UNUSED(event);
iButton* ibutton = context;
Popup* popup = ibutton->popup;

bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
if(event.event == iButtonCustomEventRpcExit) {
if(event.event == iButtonCustomEventRpcLoad) {
string_t key_name;
string_init(key_name);
if(string_end_with_str_p(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
path_extract_filename(ibutton->file_path, key_name, true);
}

if(!string_empty_p(key_name)) {
ibutton_text_store_set(ibutton, "emulating\n%s", string_get_cstr(key_name));
} else {
ibutton_text_store_set(ibutton, "emulating");
}
popup_set_text(popup, ibutton->text_store, 82, 32, AlignCenter, AlignTop);

ibutton_notification_message(ibutton, iButtonNotificationMessageEmulateStart);

string_clear(key_name);
} else if(event.event == iButtonCustomEventRpcExit) {
ibutton_notification_message(ibutton, iButtonNotificationMessageBlinkStop);
view_dispatcher_stop(ibutton->view_dispatcher);
}
}
Expand All @@ -32,5 +53,11 @@ bool ibutton_scene_rpc_on_event(void* context, SceneManagerEvent event) {

void ibutton_scene_rpc_on_exit(void* context) {
iButton* ibutton = context;
widget_reset(ibutton->widget);
Popup* popup = ibutton->popup;

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);

ibutton_notification_message(ibutton, iButtonNotificationMessageBlinkStop);
}
17 changes: 13 additions & 4 deletions applications/infrared/infrared.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ static bool
infrared->worker, infrared_worker_tx_get_signal_steady_callback, infrared);
infrared_worker_tx_set_signal_sent_callback(
infrared->worker, infrared_signal_sent_callback, infrared);
view_dispatcher_send_custom_event(
infrared->view_dispatcher, InfraredCustomEventTypeRpcLoaded);
}
} else if(event == RpcAppEventButtonPress) {
if(arg) {
Expand Down Expand Up @@ -141,7 +143,6 @@ static Infrared* infrared_alloc() {
infrared->gui = furi_record_open("gui");

ViewDispatcher* view_dispatcher = infrared->view_dispatcher;
view_dispatcher_attach_to_gui(view_dispatcher, infrared->gui, ViewDispatcherTypeFullscreen);
view_dispatcher_enable_queue(view_dispatcher);
view_dispatcher_set_event_callback_context(view_dispatcher, infrared);
view_dispatcher_set_custom_event_callback(view_dispatcher, infrared_custom_event_callback);
Expand Down Expand Up @@ -202,6 +203,7 @@ static void infrared_free(Infrared* infrared) {

if(infrared->rpc_ctx) {
rpc_system_app_set_callback(infrared->rpc_ctx, NULL, NULL);
rpc_system_app_send_exited(infrared->rpc_ctx);
infrared->rpc_ctx = NULL;
}

Expand Down Expand Up @@ -434,6 +436,7 @@ int32_t infrared_app(void* p) {
infrared->rpc_ctx = (void*)rpc_ctx;
rpc_system_app_set_callback(
infrared->rpc_ctx, infrared_rpc_command_callback, infrared);
rpc_system_app_send_started(infrared->rpc_ctx);
is_rpc_mode = true;
} else {
string_set_str(infrared->file_path, (const char*)p);
Expand All @@ -447,11 +450,17 @@ int32_t infrared_app(void* p) {
}

if(is_rpc_mode) {
view_dispatcher_attach_to_gui(
infrared->view_dispatcher, infrared->gui, ViewDispatcherTypeDesktop);
scene_manager_next_scene(infrared->scene_manager, InfraredSceneRpc);
} else if(is_remote_loaded) {
scene_manager_next_scene(infrared->scene_manager, InfraredSceneRemote);
} else {
scene_manager_next_scene(infrared->scene_manager, InfraredSceneStart);
view_dispatcher_attach_to_gui(
infrared->view_dispatcher, infrared->gui, ViewDispatcherTypeFullscreen);
if(is_remote_loaded) {
scene_manager_next_scene(infrared->scene_manager, InfraredSceneRemote);
} else {
scene_manager_next_scene(infrared->scene_manager, InfraredSceneStart);
}
}

view_dispatcher_run(infrared->view_dispatcher);
Expand Down
1 change: 1 addition & 0 deletions applications/infrared/infrared_custom_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum InfraredCustomEventType {
InfraredCustomEventTypePopupClosed,
InfraredCustomEventTypeButtonSelected,
InfraredCustomEventTypeBackPressed,
InfraredCustomEventTypeRpcLoaded,
};

#pragma pack(push, 1)
Expand Down
12 changes: 10 additions & 2 deletions applications/infrared/scenes/infrared_scene_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ void infrared_scene_rpc_on_enter(void* context) {
Infrared* infrared = context;
Popup* popup = infrared->popup;

popup_set_text(popup, "Rpc mode", 64, 28, AlignCenter, AlignCenter);
popup_set_header(popup, "Infrared", 82, 28, AlignCenter, AlignBottom);
popup_set_text(popup, "RPC mode", 82, 32, AlignCenter, AlignTop);

popup_set_icon(popup, 2, 14, &I_Warning_30x23); // TODO: icon

popup_set_context(popup, context);
popup_set_callback(popup, infrared_popup_closed_callback);

infrared_play_notification_message(infrared, InfraredNotificationMessageYellowOn);
view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewPopup);

notification_message(infrared->notifications, &sequence_display_backlight_on);
Expand All @@ -26,6 +28,12 @@ bool infrared_scene_rpc_on_event(void* context, SceneManagerEvent event) {
view_dispatcher_stop(infrared->view_dispatcher);
} else if(event.event == InfraredCustomEventTypePopupClosed) {
view_dispatcher_stop(infrared->view_dispatcher);
} else if(event.event == InfraredCustomEventTypeRpcLoaded) {
const char* remote_name = infrared_remote_get_name(infrared->remote);

infrared_text_store_set(infrared, 0, "loaded\n%s", remote_name);
popup_set_text(
infrared->popup, infrared->text_store[0], 82, 32, AlignCenter, AlignTop);
}
}
return consumed;
Expand Down
2 changes: 2 additions & 0 deletions applications/lfrfid/lfrfid_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ LfRfidApp::~LfRfidApp() {
string_clear(file_path);
if(rpc_ctx) {
rpc_system_app_set_callback(rpc_ctx, NULL, NULL);
rpc_system_app_send_exited(rpc_ctx);
}
}

Expand Down Expand Up @@ -91,6 +92,7 @@ void LfRfidApp::run(void* _args) {
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);
rpc_system_app_send_started(rpc_ctx);
scene_controller.add_scene(SceneType::Rpc, new LfRfidAppSceneRpc());
scene_controller.process(100, SceneType::Rpc);
} else {
Expand Down
23 changes: 22 additions & 1 deletion applications/lfrfid/scene/lfrfid_app_scene_rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@
#include <core/common_defines.h>
#include <dolphin/dolphin.h>

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,
};

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);
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);

app->view_controller.switch_to<PopupVM>();

Expand All @@ -23,15 +37,22 @@ bool LfRfidAppSceneRpc::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
view_event.type = LfRfidApp::EventType::Back;
app->view_controller.send_event(&view_event);
} else if(event->type == LfRfidApp::EventType::EmulateStart) {
auto popup = app->view_controller.get<PopupVM>();
consumed = true;
emulating = true;

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);
}
return consumed;
}

void LfRfidAppSceneRpc::on_exit(LfRfidApp* app) {
if(emulating) {
app->worker.stop_emulate();
notification_message(app->notification, &sequence_blink_stop);
}
app->view_controller.get<PopupVM>()->clean();
}
1 change: 1 addition & 0 deletions applications/nfc/helpers/nfc_custom_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ enum NfcCustomEvent {
NfcCustomEventByteInputDone,
NfcCustomEventTextInputDone,
NfcCustomEventDictAttackDone,
NfcCustomEventRpcLoad,
};
30 changes: 20 additions & 10 deletions applications/nfc/nfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void nfc_rpc_exit_callback(Nfc* nfc) {
}
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;
}
}
Expand Down Expand Up @@ -82,6 +83,7 @@ static bool nfc_rpc_command_callback(RpcAppSystemEvent event, const char* arg, v
nfc->worker, NfcWorkerStateEmulate, &nfc->dev->dev_data, NULL, nfc);
}
nfc->rpc_state = NfcRpcStateEmulating;
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventRpcLoad);
result = true;
}
}
Expand All @@ -107,7 +109,6 @@ Nfc* nfc_alloc() {

// Open GUI record
nfc->gui = furi_record_open("gui");
view_dispatcher_attach_to_gui(nfc->view_dispatcher, nfc->gui, ViewDispatcherTypeFullscreen);

// Open Notification record
nfc->notifications = furi_record_open("notification");
Expand Down Expand Up @@ -291,21 +292,30 @@ int32_t nfc_app(void* p) {
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);
rpc_system_app_send_started(nfc->rpc_ctx);
view_dispatcher_attach_to_gui(
nfc->view_dispatcher, nfc->gui, ViewDispatcherTypeDesktop);
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) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateMifareClassic);
} else {
view_dispatcher_attach_to_gui(
nfc->view_dispatcher, nfc->gui, ViewDispatcherTypeFullscreen);
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) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateMifareClassic);
} else {
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateUid);
}
} else {
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateUid);
// Exit app
view_dispatcher_stop(nfc->view_dispatcher);
}
} else {
// Exit app
view_dispatcher_stop(nfc->view_dispatcher);
}
nfc_device_set_loading_callback(nfc->dev, NULL, nfc);
} else {
view_dispatcher_attach_to_gui(
nfc->view_dispatcher, nfc->gui, ViewDispatcherTypeFullscreen);
scene_manager_next_scene(nfc->scene_manager, NfcSceneStart);
}

Expand Down
Loading

0 comments on commit d80edba

Please sign in to comment.