[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:
Nikolay Minaylov
2022-07-04 16:09:46 +03:00
committed by GitHub
parent 0e78f38404
commit 4a1695ba1c
32 changed files with 768 additions and 45 deletions

View File

@@ -36,6 +36,52 @@ static void infrared_tick_event_callback(void* context) {
scene_manager_handle_tick_event(infrared->scene_manager);
}
static bool
infrared_rpc_command_callback(RpcAppSystemEvent event, const char* arg, void* context) {
furi_assert(context);
Infrared* infrared = context;
if(!infrared->rpc_ctx) {
return false;
}
bool result = false;
if(event == RpcAppEventSessionClose) {
rpc_system_app_set_callback(infrared->rpc_ctx, NULL, NULL);
infrared->rpc_ctx = NULL;
view_dispatcher_send_custom_event(
infrared->view_dispatcher, InfraredCustomEventTypeBackPressed);
result = true;
} else if(event == RpcAppEventAppExit) {
view_dispatcher_send_custom_event(
infrared->view_dispatcher, InfraredCustomEventTypeBackPressed);
result = true;
} else if(event == RpcAppEventLoadFile) {
if(arg) {
string_set_str(infrared->file_path, arg);
result = infrared_remote_load(infrared->remote, infrared->file_path);
infrared_worker_tx_set_get_signal_callback(
infrared->worker, infrared_worker_tx_get_signal_steady_callback, infrared);
infrared_worker_tx_set_signal_sent_callback(
infrared->worker, infrared_signal_sent_callback, infrared);
}
} else if(event == RpcAppEventButtonPress) {
if(arg) {
size_t button_index = 0;
if(infrared_remote_find_button_by_name(infrared->remote, arg, &button_index)) {
infrared_tx_start_button_index(infrared, button_index);
result = true;
}
}
} else if(event == RpcAppEventButtonRelease) {
infrared_tx_stop(infrared);
result = true;
}
return result;
}
static void infrared_find_vacant_remote_name(string_t name, const char* path) {
Storage* storage = furi_record_open("storage");
@@ -154,6 +200,11 @@ static void infrared_free(Infrared* infrared) {
ViewDispatcher* view_dispatcher = infrared->view_dispatcher;
InfraredAppState* app_state = &infrared->app_state;
if(infrared->rpc_ctx) {
rpc_system_app_set_callback(infrared->rpc_ctx, NULL, NULL);
infrared->rpc_ctx = NULL;
}
view_dispatcher_remove_view(view_dispatcher, InfraredViewSubmenu);
submenu_free(infrared->submenu);
@@ -375,18 +426,29 @@ int32_t infrared_app(void* p) {
infrared_make_app_folder(infrared);
bool is_remote_loaded = false;
bool is_rpc_mode = false;
if(p) {
string_set_str(infrared->file_path, (const char*)p);
is_remote_loaded = infrared_remote_load(infrared->remote, infrared->file_path);
if(!is_remote_loaded) {
dialog_message_show_storage_error(
infrared->dialogs, "Failed to load\nselected remote");
return -1;
uint32_t rpc_ctx = 0;
if(sscanf(p, "RPC %lX", &rpc_ctx) == 1) {
infrared->rpc_ctx = (void*)rpc_ctx;
rpc_system_app_set_callback(
infrared->rpc_ctx, infrared_rpc_command_callback, infrared);
is_rpc_mode = true;
} else {
string_set_str(infrared->file_path, (const char*)p);
is_remote_loaded = infrared_remote_load(infrared->remote, infrared->file_path);
if(!is_remote_loaded) {
dialog_message_show_storage_error(
infrared->dialogs, "Failed to load\nselected remote");
return -1;
}
}
}
if(is_remote_loaded) {
if(is_rpc_mode) {
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 File

@@ -30,6 +30,8 @@
#include "views/infrared_progress_view.h"
#include "views/infrared_debug_view.h"
#include "rpc/rpc_app.h"
#define INFRARED_FILE_NAME_SIZE 100
#define INFRARED_TEXT_STORE_NUM 2
#define INFRARED_TEXT_STORE_SIZE 128
@@ -95,6 +97,8 @@ struct Infrared {
string_t file_path;
char text_store[INFRARED_TEXT_STORE_NUM][INFRARED_TEXT_STORE_SIZE + 1];
InfraredAppState app_state;
void* rpc_ctx;
};
typedef enum {

View File

@@ -1,5 +1,7 @@
#include "infrared_remote.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <m-string.h>
#include <m-array.h>
@@ -73,6 +75,17 @@ InfraredRemoteButton* infrared_remote_get_button(InfraredRemote* remote, size_t
return *InfraredButtonArray_get(remote->buttons, index);
}
bool infrared_remote_find_button_by_name(InfraredRemote* remote, const char* name, size_t* index) {
for(size_t i = 0; i < InfraredButtonArray_size(remote->buttons); i++) {
InfraredRemoteButton* button = *InfraredButtonArray_get(remote->buttons, i);
if(!strcmp(infrared_remote_button_get_name(button), name)) {
*index = i;
return true;
}
}
return false;
}
bool infrared_remote_add_button(InfraredRemote* remote, const char* name, InfraredSignal* signal) {
InfraredRemoteButton* button = infrared_remote_button_alloc();
infrared_remote_button_set_name(button, name);

View File

@@ -18,6 +18,7 @@ const char* infrared_remote_get_path(InfraredRemote* remote);
size_t infrared_remote_get_button_count(InfraredRemote* remote);
InfraredRemoteButton* infrared_remote_get_button(InfraredRemote* remote, size_t index);
bool infrared_remote_find_button_by_name(InfraredRemote* remote, const char* name, size_t* index);
bool infrared_remote_add_button(InfraredRemote* remote, const char* name, InfraredSignal* signal);
bool infrared_remote_rename_button(InfraredRemote* remote, const char* new_name, size_t index);

View File

@@ -16,3 +16,4 @@ ADD_SCENE(infrared, universal, Universal)
ADD_SCENE(infrared, universal_tv, UniversalTV)
ADD_SCENE(infrared, debug, Debug)
ADD_SCENE(infrared, error_databases, ErrorDatabases)
ADD_SCENE(infrared, rpc, Rpc)

View File

@@ -0,0 +1,37 @@
#include "../infrared_i.h"
#include "gui/canvas.h"
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_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);
}
bool infrared_scene_rpc_on_event(void* context, SceneManagerEvent event) {
Infrared* infrared = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
if(event.event == InfraredCustomEventTypeBackPressed) {
view_dispatcher_stop(infrared->view_dispatcher);
} else if(event.event == InfraredCustomEventTypePopupClosed) {
view_dispatcher_stop(infrared->view_dispatcher);
}
}
return consumed;
}
void infrared_scene_rpc_on_exit(void* context) {
Infrared* infrared = context;
popup_reset(infrared->popup);
}