Skip to content

Commit

Permalink
chore: implement example MTP page
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex4386 committed Jun 2, 2024
1 parent 7813960 commit 4b632c0
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 6 deletions.
Binary file added icons/Connect_me.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/DFU.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/Pin_back_arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions src/scenes/about/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
10 changes: 8 additions & 2 deletions src/scenes/home/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/scenes/import.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
*/

#include "home/main.h"
#include "about/main.h"
#include "about/main.h"
#include "mtp/main.h"
1 change: 1 addition & 0 deletions src/scenes/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@

SCENE_ACTION(Home)
SCENE_ACTION(About)
SCENE_ACTION(MTP)
103 changes: 103 additions & 0 deletions src/scenes/mtp/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include <gui/view.h>
#include <gui/modules/submenu.h>
#include "../../main.h"
#include "main.h"
#include <demo_app_icons.h>

#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);
}
18 changes: 18 additions & 0 deletions src/scenes/mtp/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#include <gui/view.h>
#include <gui/modules/submenu.h>
#include <gui/modules/popup.h>

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);

0 comments on commit 4b632c0

Please sign in to comment.