Skip to content

Commit d80edba

Browse files
nminaylovDrZlo13skotopes
authored
RPC App: state message and GUI update (#1423)
* 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>
1 parent f1cb956 commit d80edba

17 files changed

+235
-60
lines changed

applications/ibutton/ibutton.c

+13-5
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ static bool ibutton_rpc_command_callback(RpcAppSystemEvent event, const char* ar
118118
string_set_str(ibutton->file_path, arg);
119119
if(ibutton_load_key_data(ibutton, ibutton->file_path, false)) {
120120
ibutton_worker_emulate_start(ibutton->key_worker, ibutton->key);
121+
view_dispatcher_send_custom_event(
122+
ibutton->view_dispatcher, iButtonCustomEventRpcLoad);
121123
result = true;
122124
}
123125
}
@@ -162,8 +164,6 @@ iButton* ibutton_alloc() {
162164
ibutton->view_dispatcher, ibutton_tick_event_callback, 100);
163165

164166
ibutton->gui = furi_record_open("gui");
165-
view_dispatcher_attach_to_gui(
166-
ibutton->view_dispatcher, ibutton->gui, ViewDispatcherTypeFullscreen);
167167

168168
ibutton->storage = furi_record_open("storage");
169169
ibutton->dialogs = furi_record_open("dialogs");
@@ -373,6 +373,7 @@ int32_t ibutton_app(void* p) {
373373
ibutton->rpc_ctx = (void*)rpc_ctx;
374374
rpc_mode = true;
375375
rpc_system_app_set_callback(ibutton->rpc_ctx, ibutton_rpc_command_callback, ibutton);
376+
rpc_system_app_send_started(ibutton->rpc_ctx);
376377
} else {
377378
string_set_str(ibutton->file_path, (const char*)p);
378379
if(ibutton_load_key_data(ibutton, ibutton->file_path, true)) {
@@ -383,17 +384,24 @@ int32_t ibutton_app(void* p) {
383384
}
384385

385386
if(rpc_mode) {
387+
view_dispatcher_attach_to_gui(
388+
ibutton->view_dispatcher, ibutton->gui, ViewDispatcherTypeDesktop);
386389
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneRpc);
387-
} else if(key_loaded) {
388-
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneEmulate);
389390
} else {
390-
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneStart);
391+
view_dispatcher_attach_to_gui(
392+
ibutton->view_dispatcher, ibutton->gui, ViewDispatcherTypeFullscreen);
393+
if(key_loaded) {
394+
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneEmulate);
395+
} else {
396+
scene_manager_next_scene(ibutton->scene_manager, iButtonSceneStart);
397+
}
391398
}
392399

393400
view_dispatcher_run(ibutton->view_dispatcher);
394401

395402
if(ibutton->rpc_ctx) {
396403
rpc_system_app_set_callback(ibutton->rpc_ctx, NULL, NULL);
404+
rpc_system_app_send_exited(ibutton->rpc_ctx);
397405
}
398406
ibutton_free(ibutton);
399407
return 0;

applications/ibutton/ibutton_custom_event.h

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ enum iButtonCustomEvent {
1010
iButtonCustomEventWorkerEmulated,
1111
iButtonCustomEventWorkerRead,
1212

13+
iButtonCustomEventRpcLoad,
1314
iButtonCustomEventRpcExit,
1415
};

applications/ibutton/scenes/ibutton_scene_rpc.c

+33-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
void ibutton_scene_rpc_on_enter(void* context) {
55
iButton* ibutton = context;
6-
Widget* widget = ibutton->widget;
6+
Popup* popup = ibutton->popup;
77

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

11-
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget);
11+
popup_set_icon(popup, 2, 14, &I_iButtonKey_49x44);
12+
13+
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewPopup);
1214

1315
notification_message(ibutton->notifications, &sequence_display_backlight_on);
1416
}
@@ -17,12 +19,31 @@ bool ibutton_scene_rpc_on_event(void* context, SceneManagerEvent event) {
1719
UNUSED(context);
1820
UNUSED(event);
1921
iButton* ibutton = context;
22+
Popup* popup = ibutton->popup;
2023

2124
bool consumed = false;
2225

2326
if(event.type == SceneManagerEventTypeCustom) {
2427
consumed = true;
25-
if(event.event == iButtonCustomEventRpcExit) {
28+
if(event.event == iButtonCustomEventRpcLoad) {
29+
string_t key_name;
30+
string_init(key_name);
31+
if(string_end_with_str_p(ibutton->file_path, IBUTTON_APP_EXTENSION)) {
32+
path_extract_filename(ibutton->file_path, key_name, true);
33+
}
34+
35+
if(!string_empty_p(key_name)) {
36+
ibutton_text_store_set(ibutton, "emulating\n%s", string_get_cstr(key_name));
37+
} else {
38+
ibutton_text_store_set(ibutton, "emulating");
39+
}
40+
popup_set_text(popup, ibutton->text_store, 82, 32, AlignCenter, AlignTop);
41+
42+
ibutton_notification_message(ibutton, iButtonNotificationMessageEmulateStart);
43+
44+
string_clear(key_name);
45+
} else if(event.event == iButtonCustomEventRpcExit) {
46+
ibutton_notification_message(ibutton, iButtonNotificationMessageBlinkStop);
2647
view_dispatcher_stop(ibutton->view_dispatcher);
2748
}
2849
}
@@ -32,5 +53,11 @@ bool ibutton_scene_rpc_on_event(void* context, SceneManagerEvent event) {
3253

3354
void ibutton_scene_rpc_on_exit(void* context) {
3455
iButton* ibutton = context;
35-
widget_reset(ibutton->widget);
56+
Popup* popup = ibutton->popup;
57+
58+
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
59+
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
60+
popup_set_icon(popup, 0, 0, NULL);
61+
62+
ibutton_notification_message(ibutton, iButtonNotificationMessageBlinkStop);
3663
}

applications/infrared/infrared.c

+13-4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ static bool
6565
infrared->worker, infrared_worker_tx_get_signal_steady_callback, infrared);
6666
infrared_worker_tx_set_signal_sent_callback(
6767
infrared->worker, infrared_signal_sent_callback, infrared);
68+
view_dispatcher_send_custom_event(
69+
infrared->view_dispatcher, InfraredCustomEventTypeRpcLoaded);
6870
}
6971
} else if(event == RpcAppEventButtonPress) {
7072
if(arg) {
@@ -141,7 +143,6 @@ static Infrared* infrared_alloc() {
141143
infrared->gui = furi_record_open("gui");
142144

143145
ViewDispatcher* view_dispatcher = infrared->view_dispatcher;
144-
view_dispatcher_attach_to_gui(view_dispatcher, infrared->gui, ViewDispatcherTypeFullscreen);
145146
view_dispatcher_enable_queue(view_dispatcher);
146147
view_dispatcher_set_event_callback_context(view_dispatcher, infrared);
147148
view_dispatcher_set_custom_event_callback(view_dispatcher, infrared_custom_event_callback);
@@ -202,6 +203,7 @@ static void infrared_free(Infrared* infrared) {
202203

203204
if(infrared->rpc_ctx) {
204205
rpc_system_app_set_callback(infrared->rpc_ctx, NULL, NULL);
206+
rpc_system_app_send_exited(infrared->rpc_ctx);
205207
infrared->rpc_ctx = NULL;
206208
}
207209

@@ -434,6 +436,7 @@ int32_t infrared_app(void* p) {
434436
infrared->rpc_ctx = (void*)rpc_ctx;
435437
rpc_system_app_set_callback(
436438
infrared->rpc_ctx, infrared_rpc_command_callback, infrared);
439+
rpc_system_app_send_started(infrared->rpc_ctx);
437440
is_rpc_mode = true;
438441
} else {
439442
string_set_str(infrared->file_path, (const char*)p);
@@ -447,11 +450,17 @@ int32_t infrared_app(void* p) {
447450
}
448451

449452
if(is_rpc_mode) {
453+
view_dispatcher_attach_to_gui(
454+
infrared->view_dispatcher, infrared->gui, ViewDispatcherTypeDesktop);
450455
scene_manager_next_scene(infrared->scene_manager, InfraredSceneRpc);
451-
} else if(is_remote_loaded) {
452-
scene_manager_next_scene(infrared->scene_manager, InfraredSceneRemote);
453456
} else {
454-
scene_manager_next_scene(infrared->scene_manager, InfraredSceneStart);
457+
view_dispatcher_attach_to_gui(
458+
infrared->view_dispatcher, infrared->gui, ViewDispatcherTypeFullscreen);
459+
if(is_remote_loaded) {
460+
scene_manager_next_scene(infrared->scene_manager, InfraredSceneRemote);
461+
} else {
462+
scene_manager_next_scene(infrared->scene_manager, InfraredSceneStart);
463+
}
455464
}
456465

457466
view_dispatcher_run(infrared->view_dispatcher);

applications/infrared/infrared_custom_event.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ enum InfraredCustomEventType {
1414
InfraredCustomEventTypePopupClosed,
1515
InfraredCustomEventTypeButtonSelected,
1616
InfraredCustomEventTypeBackPressed,
17+
InfraredCustomEventTypeRpcLoaded,
1718
};
1819

1920
#pragma pack(push, 1)

applications/infrared/scenes/infrared_scene_rpc.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ void infrared_scene_rpc_on_enter(void* context) {
55
Infrared* infrared = context;
66
Popup* popup = infrared->popup;
77

8-
popup_set_text(popup, "Rpc mode", 64, 28, AlignCenter, AlignCenter);
8+
popup_set_header(popup, "Infrared", 82, 28, AlignCenter, AlignBottom);
9+
popup_set_text(popup, "RPC mode", 82, 32, AlignCenter, AlignTop);
10+
11+
popup_set_icon(popup, 2, 14, &I_Warning_30x23); // TODO: icon
912

1013
popup_set_context(popup, context);
1114
popup_set_callback(popup, infrared_popup_closed_callback);
1215

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

1618
notification_message(infrared->notifications, &sequence_display_backlight_on);
@@ -26,6 +28,12 @@ bool infrared_scene_rpc_on_event(void* context, SceneManagerEvent event) {
2628
view_dispatcher_stop(infrared->view_dispatcher);
2729
} else if(event.event == InfraredCustomEventTypePopupClosed) {
2830
view_dispatcher_stop(infrared->view_dispatcher);
31+
} else if(event.event == InfraredCustomEventTypeRpcLoaded) {
32+
const char* remote_name = infrared_remote_get_name(infrared->remote);
33+
34+
infrared_text_store_set(infrared, 0, "loaded\n%s", remote_name);
35+
popup_set_text(
36+
infrared->popup, infrared->text_store[0], 82, 32, AlignCenter, AlignTop);
2937
}
3038
}
3139
return consumed;

applications/lfrfid/lfrfid_app.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ LfRfidApp::~LfRfidApp() {
4444
string_clear(file_path);
4545
if(rpc_ctx) {
4646
rpc_system_app_set_callback(rpc_ctx, NULL, NULL);
47+
rpc_system_app_send_exited(rpc_ctx);
4748
}
4849
}
4950

@@ -91,6 +92,7 @@ void LfRfidApp::run(void* _args) {
9192
if(sscanf(args, "RPC %lX", &rpc_ctx_ptr) == 1) {
9293
rpc_ctx = (RpcAppSystem*)rpc_ctx_ptr;
9394
rpc_system_app_set_callback(rpc_ctx, rpc_command_callback, this);
95+
rpc_system_app_send_started(rpc_ctx);
9496
scene_controller.add_scene(SceneType::Rpc, new LfRfidAppSceneRpc());
9597
scene_controller.process(100, SceneType::Rpc);
9698
} else {

applications/lfrfid/scene/lfrfid_app_scene_rpc.cpp

+22-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,24 @@
22
#include <core/common_defines.h>
33
#include <dolphin/dolphin.h>
44

5+
static const NotificationSequence sequence_blink_start_magenta = {
6+
&message_blink_start_10,
7+
&message_blink_set_color_magenta,
8+
&message_do_not_reset,
9+
NULL,
10+
};
11+
12+
static const NotificationSequence sequence_blink_stop = {
13+
&message_blink_stop,
14+
NULL,
15+
};
16+
517
void LfRfidAppSceneRpc::on_enter(LfRfidApp* app, bool /* need_restore */) {
618
auto popup = app->view_controller.get<PopupVM>();
719

8-
popup->set_header("RPC Mode", 64, 30, AlignCenter, AlignTop);
20+
popup->set_header("LF RFID", 89, 30, AlignCenter, AlignTop);
21+
popup->set_text("RPC mode", 89, 43, AlignCenter, AlignTop);
22+
popup->set_icon(0, 3, &I_RFIDDolphinSend_97x61);
923

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

@@ -23,15 +37,22 @@ bool LfRfidAppSceneRpc::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
2337
view_event.type = LfRfidApp::EventType::Back;
2438
app->view_controller.send_event(&view_event);
2539
} else if(event->type == LfRfidApp::EventType::EmulateStart) {
40+
auto popup = app->view_controller.get<PopupVM>();
2641
consumed = true;
2742
emulating = true;
43+
44+
app->text_store.set("emulating\n%s", app->worker.key.get_name());
45+
popup->set_text(app->text_store.text, 89, 43, AlignCenter, AlignTop);
46+
47+
notification_message(app->notification, &sequence_blink_start_magenta);
2848
}
2949
return consumed;
3050
}
3151

3252
void LfRfidAppSceneRpc::on_exit(LfRfidApp* app) {
3353
if(emulating) {
3454
app->worker.stop_emulate();
55+
notification_message(app->notification, &sequence_blink_stop);
3556
}
3657
app->view_controller.get<PopupVM>()->clean();
3758
}

applications/nfc/helpers/nfc_custom_event.h

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ enum NfcCustomEvent {
99
NfcCustomEventByteInputDone,
1010
NfcCustomEventTextInputDone,
1111
NfcCustomEventDictAttackDone,
12+
NfcCustomEventRpcLoad,
1213
};

applications/nfc/nfc.c

+20-10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ void nfc_rpc_exit_callback(Nfc* nfc) {
3131
}
3232
if(nfc->rpc_ctx) {
3333
rpc_system_app_set_callback(nfc->rpc_ctx, NULL, NULL);
34+
rpc_system_app_send_exited(nfc->rpc_ctx);
3435
nfc->rpc_ctx = NULL;
3536
}
3637
}
@@ -82,6 +83,7 @@ static bool nfc_rpc_command_callback(RpcAppSystemEvent event, const char* arg, v
8283
nfc->worker, NfcWorkerStateEmulate, &nfc->dev->dev_data, NULL, nfc);
8384
}
8485
nfc->rpc_state = NfcRpcStateEmulating;
86+
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventRpcLoad);
8587
result = true;
8688
}
8789
}
@@ -107,7 +109,6 @@ Nfc* nfc_alloc() {
107109

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

112113
// Open Notification record
113114
nfc->notifications = furi_record_open("notification");
@@ -291,21 +292,30 @@ int32_t nfc_app(void* p) {
291292
if(sscanf(p, "RPC %lX", &rpc_ctx) == 1) {
292293
nfc->rpc_ctx = (void*)rpc_ctx;
293294
rpc_system_app_set_callback(nfc->rpc_ctx, nfc_rpc_command_callback, nfc);
295+
rpc_system_app_send_started(nfc->rpc_ctx);
296+
view_dispatcher_attach_to_gui(
297+
nfc->view_dispatcher, nfc->gui, ViewDispatcherTypeDesktop);
294298
scene_manager_next_scene(nfc->scene_manager, NfcSceneRpc);
295-
} else if(nfc_device_load(nfc->dev, p, true)) {
296-
if(nfc->dev->format == NfcDeviceSaveFormatMifareUl) {
297-
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateMifareUl);
298-
} else if(nfc->dev->format == NfcDeviceSaveFormatMifareClassic) {
299-
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateMifareClassic);
299+
} else {
300+
view_dispatcher_attach_to_gui(
301+
nfc->view_dispatcher, nfc->gui, ViewDispatcherTypeFullscreen);
302+
if(nfc_device_load(nfc->dev, p, true)) {
303+
if(nfc->dev->format == NfcDeviceSaveFormatMifareUl) {
304+
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateMifareUl);
305+
} else if(nfc->dev->format == NfcDeviceSaveFormatMifareClassic) {
306+
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateMifareClassic);
307+
} else {
308+
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateUid);
309+
}
300310
} else {
301-
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateUid);
311+
// Exit app
312+
view_dispatcher_stop(nfc->view_dispatcher);
302313
}
303-
} else {
304-
// Exit app
305-
view_dispatcher_stop(nfc->view_dispatcher);
306314
}
307315
nfc_device_set_loading_callback(nfc->dev, NULL, nfc);
308316
} else {
317+
view_dispatcher_attach_to_gui(
318+
nfc->view_dispatcher, nfc->gui, ViewDispatcherTypeFullscreen);
309319
scene_manager_next_scene(nfc->scene_manager, NfcSceneStart);
310320
}
311321

0 commit comments

Comments
 (0)