From a5b3d71e5963876cc88bd4692b15cb2e56437cb1 Mon Sep 17 00:00:00 2001 From: Anna Antonenko Date: Mon, 16 Sep 2024 15:37:40 +0300 Subject: [PATCH] feat: cli icon on the desktop --- applications/services/cli/cli_vcp.c | 35 ++++++++++++++++++ assets/icons/StatusBar/Console_active_8x8.png | Bin 0 -> 4347 bytes 2 files changed, 35 insertions(+) create mode 100644 assets/icons/StatusBar/Console_active_8x8.png diff --git a/applications/services/cli/cli_vcp.c b/applications/services/cli/cli_vcp.c index cdabaaa05..9eabd4d7d 100644 --- a/applications/services/cli/cli_vcp.c +++ b/applications/services/cli/cli_vcp.c @@ -2,6 +2,9 @@ #include #include #include +#include +#include +#include #define TAG "CliVcp" @@ -43,6 +46,10 @@ typedef struct { FuriHalUsbInterface* usb_if_prev; uint8_t data_buffer[USB_CDC_PKT_LEN]; + + // CLI icon + Gui* gui; + ViewPort* view_port; } CliVcp; static int32_t vcp_worker(void* context); @@ -64,6 +71,13 @@ static CliVcp* vcp = NULL; static const uint8_t ascii_soh = 0x01; static const uint8_t ascii_eot = 0x04; +static void cli_vcp_icon_draw_callback(Canvas* canvas, void* context) { + furi_assert(canvas); + furi_assert(context); + const Icon* icon = context; + canvas_draw_icon(canvas, 0, 0, icon); +} + static void cli_vcp_init(void) { if(vcp == NULL) { vcp = malloc(sizeof(CliVcp)); @@ -115,6 +129,18 @@ static int32_t vcp_worker(void* context) { if(vcp->connected == false) { vcp->connected = true; furi_stream_buffer_send(vcp->rx_stream, &ascii_soh, 1, FuriWaitForever); + + // GUI icon + furi_assert(!vcp->gui); + furi_assert(!vcp->view_port); + const Icon* icon = &I_Console_active_8x8; + vcp->gui = furi_record_open(RECORD_GUI); + vcp->view_port = view_port_alloc(); + view_port_set_width(vcp->view_port, icon_get_width(icon)); + // casting const away. we know that we cast it right back in the callback + view_port_draw_callback_set( + vcp->view_port, cli_vcp_icon_draw_callback, (void*)icon); + gui_add_view_port(vcp->gui, vcp->view_port, GuiLayerStatusBarLeft); } } @@ -126,6 +152,15 @@ static int32_t vcp_worker(void* context) { vcp->connected = false; furi_stream_buffer_receive(vcp->tx_stream, vcp->data_buffer, USB_CDC_PKT_LEN, 0); furi_stream_buffer_send(vcp->rx_stream, &ascii_eot, 1, FuriWaitForever); + + // remove GUI icon + furi_assert(vcp->gui); + furi_assert(vcp->view_port); + gui_remove_view_port(vcp->gui, vcp->view_port); + view_port_free(vcp->view_port); + furi_record_close(RECORD_GUI); + vcp->gui = NULL; + vcp->view_port = NULL; } } diff --git a/assets/icons/StatusBar/Console_active_8x8.png b/assets/icons/StatusBar/Console_active_8x8.png new file mode 100644 index 0000000000000000000000000000000000000000..0423c12563b7602ed5ca6b513b2ceb9eab3751f8 GIT binary patch literal 4347 zcmeHKeQZ-z6o2jb7-Qg^AYVgYIzU8T-$!4&_HBhhJ6Hpq1FEYZfUob}*FISLO8d5U z2pS0B_)x;YL39D4l1xQ|Mo>U;D09Tfha!-OAOS-Zi9{rTM49KkcHIahW{Lc_*WBLo z&OP^c?)lwwPkUEZR!kj`Gdu^wumPTO_e|)swU*rnz7O2DZ#9M)1|h#k@_5GSBmF_q z3p1qc3|(ZSAq&d_eFL+PPkM%{+H{O7^+F7VMYFE?1?;<-(&eMUtx# zh9#R8uXC1vSz6FK_nB?u1`jT-=fviU+8Ot^J-yuI%icNp-GO5^zA$P1iczhtGopn3 z#s~hI=zYhr2B$fiNF-#XAfdijI&Lj~8*pZ=`vbaBgE(sKM#z2O~c*xT-B z4~kXG&px*2+qHR9D4d?P<$=~wC2c32ixz#h`pWpr@fTm2Gdjq$Jd)S8DdImc;(+D# z#=~`6?BA?vn7pW>gg@GQ<-@zpd;k7w_t_m=f-7ED=WVu6A3x{^e?)ka^_`Q?)xR-s z!{sBNY>%Efx4rS*?RAge`l7PpnWrvrhh~i0Q9rsq4}Wu2{?|M5wmnhU>Rxs2{6n|+ zHnL&bn5uqj3i>yfF8}$){`RwpkEIvpedo<-U2=HHsar#{mhLTmQ#$oi+pg1ggYihq zt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