[FL-2505] Active RPC session icon (#2583)
* Active RPC session icon * Add RpcOwner, don't show the RPC icon when the session was started from BLE * Fix rpc_test and f18 api * Bump API version Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
parent
f68c3b2a65
commit
2c7eb53cac
@ -84,7 +84,7 @@ static void test_rpc_setup(void) {
|
|||||||
|
|
||||||
rpc = furi_record_open(RECORD_RPC);
|
rpc = furi_record_open(RECORD_RPC);
|
||||||
for(int i = 0; !(rpc_session[0].session) && (i < 10000); ++i) {
|
for(int i = 0; !(rpc_session[0].session) && (i < 10000); ++i) {
|
||||||
rpc_session[0].session = rpc_session_open(rpc);
|
rpc_session[0].session = rpc_session_open(rpc, RpcOwnerUnknown);
|
||||||
furi_delay_tick(1);
|
furi_delay_tick(1);
|
||||||
}
|
}
|
||||||
furi_check(rpc_session[0].session);
|
furi_check(rpc_session[0].session);
|
||||||
@ -104,7 +104,7 @@ static void test_rpc_setup_second_session(void) {
|
|||||||
furi_check(!(rpc_session[1].session));
|
furi_check(!(rpc_session[1].session));
|
||||||
|
|
||||||
for(int i = 0; !(rpc_session[1].session) && (i < 10000); ++i) {
|
for(int i = 0; !(rpc_session[1].session) && (i < 10000); ++i) {
|
||||||
rpc_session[1].session = rpc_session_open(rpc);
|
rpc_session[1].session = rpc_session_open(rpc, RpcOwnerUnknown);
|
||||||
furi_delay_tick(1);
|
furi_delay_tick(1);
|
||||||
}
|
}
|
||||||
furi_check(rpc_session[1].session);
|
furi_check(rpc_session[1].session);
|
||||||
|
@ -225,7 +225,7 @@ static bool bt_on_gap_event_callback(GapEvent event, void* context) {
|
|||||||
furi_event_flag_clear(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
|
furi_event_flag_clear(bt->rpc_event, BT_RPC_EVENT_DISCONNECTED);
|
||||||
if(bt->profile == BtProfileSerial) {
|
if(bt->profile == BtProfileSerial) {
|
||||||
// Open RPC session
|
// Open RPC session
|
||||||
bt->rpc_session = rpc_session_open(bt->rpc);
|
bt->rpc_session = rpc_session_open(bt->rpc, RpcOwnerBle);
|
||||||
if(bt->rpc_session) {
|
if(bt->rpc_session) {
|
||||||
FURI_LOG_I(TAG, "Open RPC connection");
|
FURI_LOG_I(TAG, "Open RPC connection");
|
||||||
rpc_session_set_send_bytes_callback(bt->rpc_session, bt_rpc_send_bytes_callback);
|
rpc_session_set_send_bytes_callback(bt->rpc_session, bt_rpc_send_bytes_callback);
|
||||||
|
@ -76,6 +76,7 @@ struct RpcSession {
|
|||||||
RpcBufferIsEmptyCallback buffer_is_empty_callback;
|
RpcBufferIsEmptyCallback buffer_is_empty_callback;
|
||||||
RpcSessionClosedCallback closed_callback;
|
RpcSessionClosedCallback closed_callback;
|
||||||
RpcSessionTerminatedCallback terminated_callback;
|
RpcSessionTerminatedCallback terminated_callback;
|
||||||
|
RpcOwner owner;
|
||||||
void* context;
|
void* context;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -83,6 +84,11 @@ struct Rpc {
|
|||||||
FuriMutex* busy_mutex;
|
FuriMutex* busy_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
RpcOwner rpc_session_get_owner(RpcSession* session) {
|
||||||
|
furi_assert(session);
|
||||||
|
return session->owner;
|
||||||
|
}
|
||||||
|
|
||||||
static void rpc_close_session_process(const PB_Main* request, void* context) {
|
static void rpc_close_session_process(const PB_Main* request, void* context) {
|
||||||
furi_assert(request);
|
furi_assert(request);
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
@ -348,7 +354,7 @@ static void rpc_session_free_callback(FuriThreadState thread_state, void* contex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RpcSession* rpc_session_open(Rpc* rpc) {
|
RpcSession* rpc_session_open(Rpc* rpc, RpcOwner owner) {
|
||||||
furi_assert(rpc);
|
furi_assert(rpc);
|
||||||
|
|
||||||
RpcSession* session = malloc(sizeof(RpcSession));
|
RpcSession* session = malloc(sizeof(RpcSession));
|
||||||
@ -357,6 +363,7 @@ RpcSession* rpc_session_open(Rpc* rpc) {
|
|||||||
session->rpc = rpc;
|
session->rpc = rpc;
|
||||||
session->terminate = false;
|
session->terminate = false;
|
||||||
session->decode_error = false;
|
session->decode_error = false;
|
||||||
|
session->owner = owner;
|
||||||
RpcHandlerDict_init(session->handlers);
|
RpcHandlerDict_init(session->handlers);
|
||||||
|
|
||||||
session->decoded_message = malloc(sizeof(PB_Main));
|
session->decoded_message = malloc(sizeof(PB_Main));
|
||||||
|
@ -30,6 +30,21 @@ typedef void (*RpcSessionClosedCallback)(void* context);
|
|||||||
* and all operations were finished */
|
* and all operations were finished */
|
||||||
typedef void (*RpcSessionTerminatedCallback)(void* context);
|
typedef void (*RpcSessionTerminatedCallback)(void* context);
|
||||||
|
|
||||||
|
/** RPC owner */
|
||||||
|
typedef enum {
|
||||||
|
RpcOwnerUnknown = 0,
|
||||||
|
RpcOwnerBle,
|
||||||
|
RpcOwnerUsb,
|
||||||
|
RpcOwnerCount,
|
||||||
|
} RpcOwner;
|
||||||
|
|
||||||
|
/** Get RPC session owner
|
||||||
|
*
|
||||||
|
* @param session pointer to RpcSession descriptor
|
||||||
|
* @return session owner
|
||||||
|
*/
|
||||||
|
RpcOwner rpc_session_get_owner(RpcSession* session);
|
||||||
|
|
||||||
/** Open RPC session
|
/** Open RPC session
|
||||||
*
|
*
|
||||||
* USAGE:
|
* USAGE:
|
||||||
@ -44,10 +59,11 @@ typedef void (*RpcSessionTerminatedCallback)(void* context);
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param rpc instance
|
* @param rpc instance
|
||||||
|
* @param owner owner of session
|
||||||
* @return pointer to RpcSession descriptor, or
|
* @return pointer to RpcSession descriptor, or
|
||||||
* NULL if RPC is busy and can't open session now
|
* NULL if RPC is busy and can't open session now
|
||||||
*/
|
*/
|
||||||
RpcSession* rpc_session_open(Rpc* rpc);
|
RpcSession* rpc_session_open(Rpc* rpc, RpcOwner owner);
|
||||||
|
|
||||||
/** Close RPC session
|
/** Close RPC session
|
||||||
* It is guaranteed that no callbacks will be called
|
* It is guaranteed that no callbacks will be called
|
||||||
|
@ -47,7 +47,7 @@ void rpc_cli_command_start_session(Cli* cli, FuriString* args, void* context) {
|
|||||||
FURI_LOG_D(TAG, "Free memory %lu", mem_before);
|
FURI_LOG_D(TAG, "Free memory %lu", mem_before);
|
||||||
|
|
||||||
furi_hal_usb_lock();
|
furi_hal_usb_lock();
|
||||||
RpcSession* rpc_session = rpc_session_open(rpc);
|
RpcSession* rpc_session = rpc_session_open(rpc, RpcOwnerUsb);
|
||||||
if(rpc_session == NULL) {
|
if(rpc_session == NULL) {
|
||||||
printf("Session start error\r\n");
|
printf("Session start error\r\n");
|
||||||
furi_hal_usb_unlock();
|
furi_hal_usb_unlock();
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "rpc_i.h"
|
#include "rpc_i.h"
|
||||||
#include "gui.pb.h"
|
#include "gui.pb.h"
|
||||||
#include <gui/gui_i.h>
|
#include <gui/gui_i.h>
|
||||||
|
#include <assets_icons.h>
|
||||||
|
|
||||||
#define TAG "RpcGui"
|
#define TAG "RpcGui"
|
||||||
|
|
||||||
@ -31,6 +32,8 @@ typedef struct {
|
|||||||
|
|
||||||
uint32_t input_key_counter[InputKeyMAX];
|
uint32_t input_key_counter[InputKeyMAX];
|
||||||
uint32_t input_counter;
|
uint32_t input_counter;
|
||||||
|
|
||||||
|
ViewPort* rpc_session_active_viewport;
|
||||||
} RpcGuiSystem;
|
} RpcGuiSystem;
|
||||||
|
|
||||||
static const PB_Gui_ScreenOrientation rpc_system_gui_screen_orientation_map[] = {
|
static const PB_Gui_ScreenOrientation rpc_system_gui_screen_orientation_map[] = {
|
||||||
@ -352,6 +355,12 @@ static void rpc_system_gui_virtual_display_frame_process(const PB_Main* request,
|
|||||||
(void)session;
|
(void)session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void rpc_active_session_icon_draw_callback(Canvas* canvas, void* context) {
|
||||||
|
UNUSED(context);
|
||||||
|
furi_assert(canvas);
|
||||||
|
canvas_draw_icon(canvas, 0, 0, &I_Rpc_active_7x8);
|
||||||
|
}
|
||||||
|
|
||||||
void* rpc_system_gui_alloc(RpcSession* session) {
|
void* rpc_system_gui_alloc(RpcSession* session) {
|
||||||
furi_assert(session);
|
furi_assert(session);
|
||||||
|
|
||||||
@ -359,6 +368,18 @@ void* rpc_system_gui_alloc(RpcSession* session) {
|
|||||||
rpc_gui->gui = furi_record_open(RECORD_GUI);
|
rpc_gui->gui = furi_record_open(RECORD_GUI);
|
||||||
rpc_gui->session = session;
|
rpc_gui->session = session;
|
||||||
|
|
||||||
|
// Active session icon
|
||||||
|
rpc_gui->rpc_session_active_viewport = view_port_alloc();
|
||||||
|
view_port_set_width(rpc_gui->rpc_session_active_viewport, icon_get_width(&I_Rpc_active_7x8));
|
||||||
|
view_port_draw_callback_set(
|
||||||
|
rpc_gui->rpc_session_active_viewport, rpc_active_session_icon_draw_callback, session);
|
||||||
|
if(rpc_session_get_owner(rpc_gui->session) != RpcOwnerBle) {
|
||||||
|
view_port_enabled_set(rpc_gui->rpc_session_active_viewport, true);
|
||||||
|
} else {
|
||||||
|
view_port_enabled_set(rpc_gui->rpc_session_active_viewport, false);
|
||||||
|
}
|
||||||
|
gui_add_view_port(rpc_gui->gui, rpc_gui->rpc_session_active_viewport, GuiLayerStatusBarLeft);
|
||||||
|
|
||||||
RpcHandler rpc_handler = {
|
RpcHandler rpc_handler = {
|
||||||
.message_handler = NULL,
|
.message_handler = NULL,
|
||||||
.decode_submessage = NULL,
|
.decode_submessage = NULL,
|
||||||
@ -399,6 +420,9 @@ void rpc_system_gui_free(void* context) {
|
|||||||
rpc_gui->virtual_display_not_empty = false;
|
rpc_gui->virtual_display_not_empty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gui_remove_view_port(rpc_gui->gui, rpc_gui->rpc_session_active_viewport);
|
||||||
|
view_port_free(rpc_gui->rpc_session_active_viewport);
|
||||||
|
|
||||||
if(rpc_gui->is_streaming) {
|
if(rpc_gui->is_streaming) {
|
||||||
rpc_gui->is_streaming = false;
|
rpc_gui->is_streaming = false;
|
||||||
// Remove GUI framebuffer callback
|
// Remove GUI framebuffer callback
|
||||||
|
BIN
assets/icons/StatusBar/Rpc_active_7x8.png
Normal file
BIN
assets/icons/StatusBar/Rpc_active_7x8.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
@ -1,5 +1,5 @@
|
|||||||
entry,status,name,type,params
|
entry,status,name,type,params
|
||||||
Version,+,22.0,,
|
Version,+,23.0,,
|
||||||
Header,+,applications/services/bt/bt_service/bt.h,,
|
Header,+,applications/services/bt/bt_service/bt.h,,
|
||||||
Header,+,applications/services/cli/cli.h,,
|
Header,+,applications/services/cli/cli.h,,
|
||||||
Header,+,applications/services/cli/cli_vcp.h,,
|
Header,+,applications/services/cli/cli_vcp.h,,
|
||||||
@ -1596,7 +1596,8 @@ Function,-,rindex,char*,"const char*, int"
|
|||||||
Function,+,rpc_session_close,void,RpcSession*
|
Function,+,rpc_session_close,void,RpcSession*
|
||||||
Function,+,rpc_session_feed,size_t,"RpcSession*, uint8_t*, size_t, TickType_t"
|
Function,+,rpc_session_feed,size_t,"RpcSession*, uint8_t*, size_t, TickType_t"
|
||||||
Function,+,rpc_session_get_available_size,size_t,RpcSession*
|
Function,+,rpc_session_get_available_size,size_t,RpcSession*
|
||||||
Function,+,rpc_session_open,RpcSession*,Rpc*
|
Function,+,rpc_session_get_owner,RpcOwner,RpcSession*
|
||||||
|
Function,+,rpc_session_open,RpcSession*,"Rpc*, RpcOwner"
|
||||||
Function,+,rpc_session_set_buffer_is_empty_callback,void,"RpcSession*, RpcBufferIsEmptyCallback"
|
Function,+,rpc_session_set_buffer_is_empty_callback,void,"RpcSession*, RpcBufferIsEmptyCallback"
|
||||||
Function,+,rpc_session_set_close_callback,void,"RpcSession*, RpcSessionClosedCallback"
|
Function,+,rpc_session_set_close_callback,void,"RpcSession*, RpcSessionClosedCallback"
|
||||||
Function,+,rpc_session_set_context,void,"RpcSession*, void*"
|
Function,+,rpc_session_set_context,void,"RpcSession*, void*"
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
entry,status,name,type,params
|
entry,status,name,type,params
|
||||||
Version,+,22.0,,
|
Version,+,23.0,,
|
||||||
Header,+,applications/services/bt/bt_service/bt.h,,
|
Header,+,applications/services/bt/bt_service/bt.h,,
|
||||||
Header,+,applications/services/cli/cli.h,,
|
Header,+,applications/services/cli/cli.h,,
|
||||||
Header,+,applications/services/cli/cli_vcp.h,,
|
Header,+,applications/services/cli/cli_vcp.h,,
|
||||||
@ -2373,7 +2373,8 @@ Function,-,roundl,long double,long double
|
|||||||
Function,+,rpc_session_close,void,RpcSession*
|
Function,+,rpc_session_close,void,RpcSession*
|
||||||
Function,+,rpc_session_feed,size_t,"RpcSession*, uint8_t*, size_t, TickType_t"
|
Function,+,rpc_session_feed,size_t,"RpcSession*, uint8_t*, size_t, TickType_t"
|
||||||
Function,+,rpc_session_get_available_size,size_t,RpcSession*
|
Function,+,rpc_session_get_available_size,size_t,RpcSession*
|
||||||
Function,+,rpc_session_open,RpcSession*,Rpc*
|
Function,+,rpc_session_get_owner,RpcOwner,RpcSession*
|
||||||
|
Function,+,rpc_session_open,RpcSession*,"Rpc*, RpcOwner"
|
||||||
Function,+,rpc_session_set_buffer_is_empty_callback,void,"RpcSession*, RpcBufferIsEmptyCallback"
|
Function,+,rpc_session_set_buffer_is_empty_callback,void,"RpcSession*, RpcBufferIsEmptyCallback"
|
||||||
Function,+,rpc_session_set_close_callback,void,"RpcSession*, RpcSessionClosedCallback"
|
Function,+,rpc_session_set_close_callback,void,"RpcSession*, RpcSessionClosedCallback"
|
||||||
Function,+,rpc_session_set_context,void,"RpcSession*, void*"
|
Function,+,rpc_session_set_context,void,"RpcSession*, void*"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user