From 4b632c0c98569b346193791d8e21b6e380390c64 Mon Sep 17 00:00:00 2001 From: Alex4386 Date: Mon, 3 Jun 2024 02:35:47 +0900 Subject: [PATCH] chore: implement example MTP page --- icons/Connect_me.png | Bin 0 -> 322 bytes icons/DFU.png | Bin 0 -> 696 bytes icons/Pin_back_arrow.png | Bin 0 -> 148 bytes src/scenes/about/main.c | 8 +-- src/scenes/home/main.c | 10 +++- src/scenes/import.h | 3 +- src/scenes/list.h | 1 + src/scenes/mtp/main.c | 103 +++++++++++++++++++++++++++++++++++++++ src/scenes/mtp/main.h | 18 +++++++ 9 files changed, 137 insertions(+), 6 deletions(-) create mode 100644 icons/Connect_me.png create mode 100644 icons/DFU.png create mode 100644 icons/Pin_back_arrow.png create mode 100644 src/scenes/mtp/main.c create mode 100644 src/scenes/mtp/main.h diff --git a/icons/Connect_me.png b/icons/Connect_me.png new file mode 100644 index 0000000000000000000000000000000000000000..373b8064473549380d9accccb07bc4f677e402fa GIT binary patch literal 322 zcmV-I0lof-P) zn1^mM7we+xSu=;-=k-| zwcQLq(+K*yo|l7g$9(W05wleJN#xk6+XH&J*c6@ef?J0000TbVXQnQ*UN;cVTj606=VYZeeg?X>N2caBgQUV{c?- UWA#HB9smFU07*qoM6N<$f-hl?$N&HU literal 0 HcmV?d00001 diff --git a/icons/DFU.png b/icons/DFU.png new file mode 100644 index 0000000000000000000000000000000000000000..4cf04e912da036349da3fa523ca3168470227543 GIT binary patch literal 696 zcmV;p0!RIcP)kq`K8?0ziF z1;3kE!5w~co~&fd?to_xWW`4Dd8jzF$e_Bs0^Z zJ-!sYpt}oQh(U6qM1IOxosRB=G0p<*&S1y|Y~yJUbp@jQr3Lpso&#t7IEcB}%)b%% z>h88myioVAI|=fszUz5<7a#T|9Lhf0fUj4T;3;Fuob;W(-UR;Ai^!jWDqdg%;+ug- z*B&rzi^{3<6su={yz+4A0dwBxyJKj20S-S3k#j`;T|(KK=*$~#{5JVh1k9f(aDPwm z=$+sMyQAPPJjTYK2F$;~_yZ`e1$GEp^uhoD03CEiSaefwW^{L9a%BKOY;|s7aA9d~ ebT4pjXDwrIWMyOZLm3_b0000kDAIJlDR{a# zhE&W+PDn^dX<&47W8r3+;3D~uWs_LSU5>dtJPa(p3=#`(@q)C-mbgZg1m~xflqVLY pGC1Uv<|P&+X6BXX7v!buCg-Q5CVzF7lmjYc@O1TaS?83{1OU}+DYO6p literal 0 HcmV?d00001 diff --git a/src/scenes/about/main.c b/src/scenes/about/main.c index 8a094b5..e35526b 100644 --- a/src/scenes/about/main.c +++ b/src/scenes/about/main.c @@ -49,7 +49,9 @@ View* About_get_view(void* ptr) { } void About_on_enter(void* context) { - UNUSED(context); + App* app = (App*)context; + + view_dispatcher_switch_to_view(app->view_dispatcher, THIS_SCENE); } bool About_on_event(void* context, SceneManagerEvent event) { @@ -69,6 +71,6 @@ void About_on_exit(void* context) { return; } - if(app->view_dispatcher) view_dispatcher_switch_to_view(app->view_dispatcher, Home); - if(app->scene_manager) scene_manager_previous_scene(app->scene_manager); + //if(app->view_dispatcher) view_dispatcher_switch_to_view(app->view_dispatcher, Home); + //if(app->scene_manager) scene_manager_previous_scene(app->scene_manager); } diff --git a/src/scenes/home/main.c b/src/scenes/home/main.c index 00c2429..e80b49b 100644 --- a/src/scenes/home/main.c +++ b/src/scenes/home/main.c @@ -65,9 +65,12 @@ void Home_on_submenu_item(void* context, uint32_t index) { case 1: FURI_LOG_I("DemoApp", "About"); scene_manager_next_scene(app->scene_manager, About); - view_dispatcher_switch_to_view(app->view_dispatcher, About); break; case 2: + FURI_LOG_I("DemoApp", "MTP"); + scene_manager_next_scene(app->scene_manager, MTP); + break; + case 99: FURI_LOG_I("DemoApp", "Exit"); Home_on_exit(app); view_dispatcher_stop(app->view_dispatcher); @@ -83,7 +86,10 @@ void Home_on_enter(void* context) { submenu_add_item(home->menu, "Hello World", 0, Home_on_submenu_item, app); submenu_add_item(home->menu, "About", 1, Home_on_submenu_item, app); - submenu_add_item(home->menu, "Exit", 2, Home_on_submenu_item, app); + submenu_add_item(home->menu, "MTP", 2, Home_on_submenu_item, app); + submenu_add_item(home->menu, "Exit", 99, Home_on_submenu_item, app); + + view_dispatcher_switch_to_view(app->view_dispatcher, THIS_SCENE); } bool Home_on_event(void* context, SceneManagerEvent event) { diff --git a/src/scenes/import.h b/src/scenes/import.h index 6f5d707..1e08b56 100644 --- a/src/scenes/import.h +++ b/src/scenes/import.h @@ -5,4 +5,5 @@ */ #include "home/main.h" -#include "about/main.h" \ No newline at end of file +#include "about/main.h" +#include "mtp/main.h" diff --git a/src/scenes/list.h b/src/scenes/list.h index 8f7bec4..1a980e3 100644 --- a/src/scenes/list.h +++ b/src/scenes/list.h @@ -14,3 +14,4 @@ SCENE_ACTION(Home) SCENE_ACTION(About) +SCENE_ACTION(MTP) diff --git a/src/scenes/mtp/main.c b/src/scenes/mtp/main.c new file mode 100644 index 0000000..0d6613d --- /dev/null +++ b/src/scenes/mtp/main.c @@ -0,0 +1,103 @@ +#include +#include +#include "../../main.h" +#include "main.h" +#include + +#define THIS_SCENE MTP + +AppMTP* tmp; + +void MTP_on_draw(Canvas* canvas, void* context); +AppMTP* MTP_alloc() { + AppMTP* about = (AppMTP*)malloc(sizeof(AppMTP)); + about->view = view_alloc(); + view_set_context(about->view, about); + view_set_draw_callback(about->view, MTP_on_draw); + + about->usb_connected = true; + tmp = about; + + return about; +} + +void MTP_on_draw(Canvas* canvas, void* context) { + AppMTP* about = (AppMTP*)context; + + canvas_clear(canvas); + canvas_set_bitmap_mode(canvas, true); + + bool usb_connected = false; + if(about == NULL) { + // facepalm + if(tmp != NULL) { + usb_connected = tmp->usb_connected; + } + } else { + usb_connected = about->usb_connected; + } + + if(usb_connected) { + canvas_set_bitmap_mode(canvas, true); + canvas_draw_icon(canvas, 0, 14, &I_DFU); + canvas_draw_icon(canvas, 2, 2, &I_Pin_back_arrow); + canvas_set_font(canvas, FontPrimary); + canvas_draw_str(canvas, 43, 10, "MTP Connection"); + canvas_set_font(canvas, FontSecondary); + canvas_draw_str(canvas, 15, 10, "Back"); + canvas_draw_str(canvas, 3, 22, "Disconnect or"); + canvas_draw_icon(canvas, 28, 23, &I_Pin_back_arrow); + canvas_draw_str(canvas, 3, 31, "Press"); + } else { + canvas_draw_icon(canvas, 1, 31, &I_Connect_me); + canvas_set_font(canvas, FontPrimary); + canvas_draw_str(canvas, 10, 25, "Plug me into computer!"); + canvas_draw_icon(canvas, 2, 2, &I_Pin_back_arrow); + canvas_set_font(canvas, FontSecondary); + canvas_draw_str(canvas, 15, 10, "Back"); + canvas_draw_str(canvas, 61, 41, "Waiting for USB"); + canvas_draw_str(canvas, 72, 50, "Connection..."); + } +} + +void MTP_free(void* ptr) { + AppMTP* home = (AppMTP*)ptr; + FURI_LOG_I("DemoApp", "Triggering Free for view"); + + view_free(home->view); + home->view = NULL; + + free(home); +} + +View* MTP_get_view(void* ptr) { + AppMTP* home = (AppMTP*)ptr; + return home->view; +} + +void MTP_on_enter(void* context) { + App* app = (App*)context; + + view_dispatcher_switch_to_view(app->view_dispatcher, THIS_SCENE); +} + +bool MTP_on_event(void* context, SceneManagerEvent event) { + UNUSED(context); + UNUSED(event); + + if(event.type == SceneManagerEventTypeBack) { + return false; + } + + return true; +} + +void MTP_on_exit(void* context) { + App* app = (App*)context; + if(app == NULL) { + return; + } + + // if(app->view_dispatcher) view_dispatcher_switch_to_view(app->view_dispatcher, Home); + // if(app->scene_manager) scene_manager_previous_scene(app->scene_manager); +} diff --git a/src/scenes/mtp/main.h b/src/scenes/mtp/main.h new file mode 100644 index 0000000..95d27bc --- /dev/null +++ b/src/scenes/mtp/main.h @@ -0,0 +1,18 @@ +#pragma once +#include +#include +#include + +typedef struct AppMTP { + Submenu* menu; + View* view; + + bool usb_connected; +} AppMTP; + +AppMTP* MTP_alloc(); +void MTP_free(void* ptr); +View* MTP_get_view(void* ptr); +void MTP_on_enter(void* context); +bool MTP_on_event(void* context, SceneManagerEvent event); +void MTP_on_exit(void* context);