From 9bc1faebb06f659c810c846c5b6cce8409ff690e Mon Sep 17 00:00:00 2001 From: miguelgargallo Date: Tue, 27 Jun 2023 23:05:21 +0200 Subject: [PATCH] gh 0.0.1 Source Code --- my_first_app/my_first_app.c | 37 +++++++++++++++++------------------ other/{ => build}/License.md | 0 other/build/my_first_app.fap | Bin 0 -> 2700 bytes other/my_first_app.fap | Bin 2556 -> 0 bytes 4 files changed, 18 insertions(+), 19 deletions(-) rename other/{ => build}/License.md (100%) create mode 100644 other/build/my_first_app.fap delete mode 100644 other/my_first_app.fap diff --git a/my_first_app/my_first_app.c b/my_first_app/my_first_app.c index 180751c..2d68bce 100644 --- a/my_first_app/my_first_app.c +++ b/my_first_app/my_first_app.c @@ -9,11 +9,11 @@ #include // Create a message to display based on user input -static char *message = "Press any button..."; +static char* message = "Press any button..."; +static char* exitMessage = ""; // Function to clear canvas and draw GUI elements -static void drawGui(Canvas *canvas, void *context) -{ +static void drawGui(Canvas* canvas, void* context) { UNUSED(context); canvas_clear(canvas); @@ -24,20 +24,19 @@ static void drawGui(Canvas *canvas, void *context) // Draw the secondary label canvas_set_font(canvas, FontSecondary); canvas_draw_str(canvas, 15, 40, message); + canvas_draw_str(canvas, 15, 55, exitMessage); // Exit message // Draw a line canvas_draw_line(canvas, 2, 23, 126, 23); } // Function to handle user input -static void handleInput(InputEvent *input_event, void *context) -{ - FuriMessageQueue *event_queue = context; +static void handleInput(InputEvent* input_event, void* context) { + FuriMessageQueue* event_queue = context; furi_assert(event_queue != NULL); // Change the message depending on which key was pressed - switch (input_event->key) - { + switch(input_event->key) { case InputKeyUp: message = "You pressed UP!"; break; @@ -53,6 +52,10 @@ static void handleInput(InputEvent *input_event, void *context) case InputKeyOk: message = "You pressed CENTER!"; break; + case InputKeyBack: + message = "You pressed BACK!"; + exitMessage = "Long press to exit."; // Add this line + break; default: message = "Press any button..."; } @@ -61,18 +64,16 @@ static void handleInput(InputEvent *input_event, void *context) } // Main function of the app -int32_t my_first_app_main(void *parameter) -{ +int32_t my_first_app_main(void* parameter) { UNUSED(parameter); // Create an event queue and a viewport for GUI InputEvent input_event; - FuriMessageQueue *event_queue = furi_message_queue_alloc(8, sizeof(InputEvent)); - ViewPort *viewport = view_port_alloc(); + FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(InputEvent)); + ViewPort* viewport = view_port_alloc(); // Error checking - if (!event_queue || !viewport) - { + if(!event_queue || !viewport) { printf("Error: Failed to allocate event_queue or viewport!\n"); return -1; } @@ -82,19 +83,17 @@ int32_t my_first_app_main(void *parameter) view_port_input_callback_set(viewport, handleInput, event_queue); // Create a GUI and associate it with the viewport - Gui *gui = furi_record_open(RECORD_GUI); + Gui* gui = furi_record_open(RECORD_GUI); gui_add_view_port(gui, viewport, GuiLayerFullscreen); // Main event loop - while (true) - { + while(true) { // Check the queue for events FuriStatus status = furi_message_queue_get(event_queue, &input_event, FuriWaitForever); furi_check(status == FuriStatusOk); // Exit the loop if the back button is long-pressed - if (input_event.type == InputTypeLong && input_event.key == InputKeyBack) - { + if(input_event.type == InputTypeLong && input_event.key == InputKeyBack) { break; } } diff --git a/other/License.md b/other/build/License.md similarity index 100% rename from other/License.md rename to other/build/License.md diff --git a/other/build/my_first_app.fap b/other/build/my_first_app.fap new file mode 100644 index 0000000000000000000000000000000000000000..def2422d8c3b77e3ae5e1278e6c0d0c377e2cc31 GIT binary patch literal 2700 zcmb7FO>7%g5FW4X#r}6DjLh(^$h$ZYzQIVBFmcz={ z7aNa5^4Ra;7d|}q@Ech<$ktKijB~hN#sRe7OqntCOfOwz?wSt%MdQ$Aa*qU3SI z(2W;mMJtxLTAr$vN_ti^g)Ejt#Z+IZi@K0?LtZM1<*II&oUBkUVk-T_jQf(lkeUs^ zK*y+quNq{39&7l2e#)zA9<{1kwW{WlqLe4<`ZksRw=h8p?idd8&9`fF&9HbWfSN6z z8;lZ5@b7KA1T6mnkB;$0pYGmm;{1q@ST+TykA)AIOU!Qk2lgO;?R?w!$DVI(qUB?c zUvDqM*0J|C1+98r4V@0x?KOsIaC?x@`w5?pcfci#&$$XCbj_#NeEK^+{Ue|LsZYP_ z(>Hy(^2)pOh0?)D>cbcvK^rXrgLZBm6EtgZ<6>y=;hE`R%_S$Yy zuqLN`u1?MC71Ii0h_b#UJaN3G>QzzMEtpk8JGENGj;T9VzoV1OTCw6LxAv}7tO(DF z>=p7^p~oa{9;$LWEwF4s(wKpCP&l+(&c^c!20*V3=qP7$>?7WNrXuqR)Wb zl%E3!h`t2Ii0%N75#0qIA^IA4i0B@Wc@ub)?=cXM3KQ(;bs!~ct7TJLU^ERI7hTB^ zrKBlVOiCJhPBS$|w%Af$tCj^!g-Tt`iG_NBPvi=s|2N{2tv6?n<9?EH3-vgJ`apPx zo?;$j2F>xqE3;pOWw^r+GHVe>7yl0XJYvRtm)yM1v%#C! zWGB2U@P&_?_cY6h>(UdBciB}K-LWx`jNv&hfRC|FZeI9vh&GkjZ=MaP1;+y!-B#+-eK8vx0 literal 0 HcmV?d00001 diff --git a/other/my_first_app.fap b/other/my_first_app.fap deleted file mode 100644 index 9cf356c3df94724724bb6f8e79c3f65b30e4d946..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2556 zcmb7GOK2oz5UzP-GkGVQ>@%Be&uoN2bl9xBxOj@1^kgR4B!ny?2%XOKKgqZ~(``>r zvVle83q(AKcv!?kz&+&PVO$6(7`%A!;30yC2#ObF6clE~*Fn&)`Z4J=i)ca3S6@|i z{q=YM^)oL_&B~ETgnWrmnwWj#IVKa1(RSH^G<8uYC3bTk#N>p0b~FB9^5EMaqRsaH z(?jQIz8UH6o4K9s%lGF7mgk#)UpgcAf+zO6@;&hU*67H01MfB3^IgE78*TYc;E#=1 zz61DugFf+=Z9zY*G3Zt3EOZ%a?!Huy%e)dLCAoL5p6#9KNlCDKuI*$azVv(LJ(Z%jp1%-<-9EdWjn>V*!*y)b3rchM<$5BSkdvq$cYf)i@%>{mr8E1K8qJNu zpOQy&7iG3ar}?*Cj;F@u5m>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