From d06a11cc7165025e15ba4dc551e9e4b5c27f3251 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Wed, 10 Jan 2024 22:46:32 -0500 Subject: [PATCH 1/2] submenu began --- spotify_remote.c | 332 +++++++++++++++++------------------------------ 1 file changed, 121 insertions(+), 211 deletions(-) diff --git a/spotify_remote.c b/spotify_remote.c index fc5fc4db690..7bb86adceea 100644 --- a/spotify_remote.c +++ b/spotify_remote.c @@ -1,36 +1,38 @@ -#include +#include #include #include #include #include -#include -#include +#include #include -#include +#include +#include +#include /* generated by fbt from .png files in images folder */ #include -// Derek Jamison's uart helper -#include "uart_helper.h" - -#define DEVICE_BAUDRATE 115200 -#define LINE_DELIMITER '\n' -#define INCLUDE_LINE_DELIMITER false - // enum for scenes typedef enum { - SPOTIFY_REMOTE_BUTTON_PANEL_SCENE, - SPOTIFY_REMOTE_TEXT_BOX_SCENE, + SPOTIFY_REMOTE_MAIN_MENU_SCENE, SPOTIFY_REMOTE_LOADING_SCENE, + SPOTIFY_REMOTE_IP_SCENE, + SPOTIFY_REMOTE_BUTTON_PANEL_SCENE, + SPOTIFY_REMOTE_WIFI_SSID_SCENE, + SPOTIFY_REMOTE_WIFI_PASSWORD_SCENE, + SPOTIFY_REMOTE_ABOUT_SCENE, SPOTIFY_REMOTE_SCENE_COUNT, } SpotifyRemoteScene; // enum for referencing module's views typedef enum { - SPOTIFY_REMOTE_BUTTON_PANEL_VIEW, - SPOTIFY_REMOTE_TEXT_BOX_VIEW, + SPOTIFY_REMOTE_MAIN_MENU_VIEW, SPOTIFY_REMOTE_LOADING_VIEW, + SPOTIFY_REMOTE_IP_VIEW, + SPOTIFY_REMOTE_BUTTON_PANEL_VIEW, + SPOTIFY_REMOTE_WIFI_SSID_VIEW, + SPOTIFY_REMOTE_WIFI_PASSWORD_VIEW, + SPOTIFY_REMOTE_ABOUT_VIEW, } SpotifyRemoteView; // enum for button panel incicies @@ -48,171 +50,96 @@ typedef struct SpotifyRemoteApp { Gui* gui; SceneManager* scene_manager; ViewDispatcher* view_dispatcher; - ButtonPanel* button_panel; - TextBox* text_box; + Submenu* main_menu; Loading* loading; - UartHelper* uart_helper; - FuriString* message; + TextBox* ip; + ButtonPanel* button_panel; } SpotifyRemoteApp; +// menu index typedef enum { - SPOTIFY_REMOTE_ON_RECEIVE_EVENT, -} SpotifyRemoteCustomEvent; + SPOTIFY_REMOTE_MAIN_MENU_SCENE_LAUNCH, + SPOTIFY_REMOTE_MAIN_MENU_SCENE_CONFIG, + SPOTIFY_REMOTE_MAIN_MENU_SCENE_ABOUT, +} SpotifyRemoteSubmenuIndex; -// handles data received from UART -static void uart_process_line(FuriString* line, void* context) { - SpotifyRemoteApp* app = context; - furi_string_set(app->message, line); - scene_manager_handle_custom_event(app->scene_manager, SPOTIFY_REMOTE_ON_RECEIVE_EVENT); -} +// id for menu item events +typedef enum { + SPOTIFY_REMOTE_MAIN_MENU_SCENE_LAUNCH_EVENT, + SPOTIFY_REMOTE_MAIN_MENU_SCENE_CONFIG_EVENT, + SPOTIFY_REMOTE_MAIN_MENU_SCENE_ABOUT_EVENT, +} SpotifyRemoteSubmenuEvent; -// called when selection is made in button panel -void button_panel_on_select_callback(void* context, uint32_t index) { +// action taken based on submenu option +void spotify_remote_main_menu_callback(void* context, uint32_t index) { SpotifyRemoteApp* app = context; switch(index) { - case PREV: - uart_helper_send(app->uart_helper, "1\n", 2); + case SPOTIFY_REMOTE_MAIN_MENU_SCENE_LAUNCH: + scene_manager_handle_custom_event( + app->scene_manager, SPOTIFY_REMOTE_MAIN_MENU_SCENE_LAUNCH_EVENT); break; - case NEXT: - uart_helper_send(app->uart_helper, "2\n", 2); + case SPOTIFY_REMOTE_MAIN_MENU_SCENE_CONFIG: + scene_manager_handle_custom_event( + app->scene_manager, SPOTIFY_REMOTE_MAIN_MENU_SCENE_CONFIG_EVENT); break; - case PLAY: - uart_helper_send(app->uart_helper, "3\n", 2); - break; - case PAUSE: - uart_helper_send(app->uart_helper, "4\n", 2); - break; - case SHUFFLE: - uart_helper_send(app->uart_helper, "5\n", 2); - break; - case REPEAT: - uart_helper_send(app->uart_helper, "6\n", 2); + case SPOTIFY_REMOTE_MAIN_MENU_SCENE_ABOUT: + scene_manager_handle_custom_event( + app->scene_manager, SPOTIFY_REMOTE_MAIN_MENU_SCENE_ABOUT_EVENT); break; default: break; } } -// button panel callbacks -void spotify_remote_button_panel_scene_on_enter(void* context) { - SpotifyRemoteApp* app = context; - - button_panel_reserve(app->button_panel, 2, 3); - button_panel_add_item( - app->button_panel, - PREV, - 0, - 0, - 6, - 16, - &I_prev_19x20, - &I_prev_hover_19x20, - button_panel_on_select_callback, - context); - button_panel_add_icon(app->button_panel, 6, 38, &I_prev_text_19x5); - button_panel_add_item( - app->button_panel, - NEXT, - 1, - 0, - 39, - 16, - &I_next_19x20, - &I_next_hover_19x20, - button_panel_on_select_callback, - context); - button_panel_add_icon(app->button_panel, 39, 38, &I_next_text_19x6); - - button_panel_add_item( - app->button_panel, - PLAY, - 0, - 1, - 6, - 50, - &I_play_19x20, - &I_play_hover_19x20, - button_panel_on_select_callback, - context); - button_panel_add_icon(app->button_panel, 6, 72, &I_play_text_19x5); - - button_panel_add_item( - app->button_panel, - PAUSE, - 1, - 1, - 39, - 50, - &I_pause_19x20, - &I_pause_hover_19x20, - button_panel_on_select_callback, - context); - button_panel_add_icon(app->button_panel, 39, 72, &I_pause_text_23x5); - - button_panel_add_item( - app->button_panel, - SHUFFLE, - 0, - 2, - 6, - 84, - &I_shuffle_19x20, - &I_shuffle_hover_19x20, - button_panel_on_select_callback, - context); - button_panel_add_icon(app->button_panel, 5, 106, &I_shuffle_text_21x5); - - button_panel_add_item( - app->button_panel, - REPEAT, - 1, - 2, - 39, - 84, - &I_repeat_19x20, - &I_repeat_hover_19x20, - button_panel_on_select_callback, - context); - button_panel_add_icon(app->button_panel, 40, 106, &I_repeat_text_18x5); - - view_dispatcher_switch_to_view(app->view_dispatcher, SPOTIFY_REMOTE_BUTTON_PANEL_VIEW); -} - -bool spotify_remote_button_panel_scene_on_event(void* context, SceneManagerEvent event) { - UNUSED(context); - UNUSED(event); - return false; -} - -void spotify_remote_button_panel_scene_on_exit(void* context) { +// main menu scene manager callbacks +void spotify_remote_main_menu_scene_on_enter(void* context) { SpotifyRemoteApp* app = context; - button_panel_reset(app->button_panel); + submenu_reset(app->main_menu); + submenu_set_header(app->main_menu, "Spotify Remote"); + + submenu_add_item( + app->main_menu, + "Launch Remote", + SPOTIFY_REMOTE_MAIN_MENU_SCENE_LAUNCH, + spotify_remote_main_menu_callback, + app); + submenu_add_item( + app->main_menu, + "Config", + SPOTIFY_REMOTE_MAIN_MENU_SCENE_CONFIG, + spotify_remote_main_menu_callback, + app); + submenu_add_item( + app->main_menu, + "About", + SPOTIFY_REMOTE_MAIN_MENU_SCENE_ABOUT, + spotify_remote_main_menu_callback, + app); + + view_dispatcher_switch_to_view(app->view_dispatcher, SPOTIFY_REMOTE_MAIN_MENU_VIEW); } -// text box callbacks -void spotify_remote_text_box_scene_on_enter(void* context) { - SpotifyRemoteApp* app = context; - text_box_reset(app->text_box); - text_box_set_text(app->text_box, furi_string_get_cstr(app->message)); - text_box_set_font(app->text_box, TextBoxFontText); - view_dispatcher_switch_to_view(app->view_dispatcher, SPOTIFY_REMOTE_TEXT_BOX_VIEW); -} - -bool spotify_remote_text_box_scene_on_event(void* context, SceneManagerEvent event) { +bool spotify_remote_main_menu_scene_on_event(void* context, SceneManagerEvent event) { SpotifyRemoteApp* app = context; bool consumed = false; switch(event.type) { case SceneManagerEventTypeCustom: switch(event.event) { - case SPOTIFY_REMOTE_ON_RECEIVE_EVENT: - if(furi_string_get_cstr(app->message)[0] == 'O' && - furi_string_get_cstr(app->message)[1] == 'K') { - scene_manager_next_scene(app->scene_manager, SPOTIFY_REMOTE_BUTTON_PANEL_SCENE); - consumed = true; - } + case SPOTIFY_REMOTE_MAIN_MENU_SCENE_LAUNCH_EVENT: + scene_manager_next_scene(app->scene_manager, SPOTIFY_REMOTE_LOADING_SCENE); + consumed = true; + break; + case SPOTIFY_REMOTE_MAIN_MENU_SCENE_CONFIG_EVENT: + scene_manager_next_scene(app->scene_manager, SPOTIFY_REMOTE_WIFI_SSID_SCENE); + consumed = true; + break; + case SPOTIFY_REMOTE_MAIN_MENU_SCENE_ABOUT_EVENT: + scene_manager_next_scene(app->scene_manager, SPOTIFY_REMOTE_ABOUT_SCENE); + consumed = true; break; } + break; default: break; } @@ -220,37 +147,41 @@ bool spotify_remote_text_box_scene_on_event(void* context, SceneManagerEvent eve return consumed; } -void spotify_remote_text_box_scene_on_exit(void* context) { +void spotify_remote_main_menu_scene_on_exit(void* context) { SpotifyRemoteApp* app = context; - text_box_reset(app->text_box); + submenu_reset(app->main_menu); } -// loading callbacks +// loading scene manager callbacks void spotify_remote_loading_scene_on_enter(void* context) { SpotifyRemoteApp* app = context; view_dispatcher_switch_to_view(app->view_dispatcher, SPOTIFY_REMOTE_LOADING_VIEW); } bool spotify_remote_loading_scene_on_event(void* context, SceneManagerEvent event) { - SpotifyRemoteApp* app = context; - bool consumed = false; - - switch(event.type) { - case SceneManagerEventTypeCustom: - switch(event.event) { - case SPOTIFY_REMOTE_ON_RECEIVE_EVENT: - if(furi_string_get_cstr(app->message)[0] == 'I' && - furi_string_get_cstr(app->message)[1] == 'P') { - scene_manager_next_scene(app->scene_manager, SPOTIFY_REMOTE_TEXT_BOX_SCENE); - consumed = true; - } - break; - } - default: - break; - } + // SpotifyRemoteApp* app = context; + // bool consumed = false; + + // switch(event.type) { + // case SceneManagerEventTypeCustom: + // switch(event.event) { + // case SPOTIFY_REMOTE_ON_RECEIVE_EVENT: + // if(furi_string_get_cstr(app->message)[0] == 'I' && + // furi_string_get_cstr(app->message)[1] == 'P') { + // scene_manager_next_scene(app->scene_manager, SPOTIFY_REMOTE_IP_SCENE); + // consumed = true; + // } + // break; + // } + // default: + // break; + // } + + // return consumed; + UNUSED(context); + UNUSED(event); - return consumed; + return false; } void spotify_remote_loading_scene_on_exit(void* context) { @@ -259,22 +190,19 @@ void spotify_remote_loading_scene_on_exit(void* context) { // array of on_enter handlers void (*const spotify_remote_scene_on_enter_handlers[])(void*) = { - spotify_remote_button_panel_scene_on_enter, - spotify_remote_text_box_scene_on_enter, + spotify_remote_main_menu_scene_on_enter, spotify_remote_loading_scene_on_enter, }; // array of on_event handlers bool (*const spotify_remote_scene_on_event_handlers[])(void*, SceneManagerEvent) = { - spotify_remote_button_panel_scene_on_event, - spotify_remote_text_box_scene_on_event, + spotify_remote_main_menu_scene_on_event, spotify_remote_loading_scene_on_event, }; // array of on_exit handlers void (*const spotify_remote_scene_on_exit_handlers[])(void*) = { - spotify_remote_button_panel_scene_on_exit, - spotify_remote_text_box_scene_on_exit, + spotify_remote_main_menu_scene_on_exit, spotify_remote_loading_scene_on_exit, }; @@ -307,10 +235,8 @@ static SpotifyRemoteApp* spotify_remote_app_alloc() { // initialize app, scene manager, and view dispatcher SpotifyRemoteApp* app = malloc(sizeof(SpotifyRemoteApp)); - app->gui = furi_record_open(RECORD_GUI); app->scene_manager = scene_manager_alloc(&spotify_remote_scene_manager_handlers, app); app->view_dispatcher = view_dispatcher_alloc(); - view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); // enable view dispatcher queue to handle events view_dispatcher_enable_queue(app->view_dispatcher); @@ -323,45 +249,25 @@ static SpotifyRemoteApp* spotify_remote_app_alloc() { app->view_dispatcher, spotify_remote_back_event_callback); // create and add views for modules - app->button_panel = button_panel_alloc(); - view_dispatcher_add_view( - app->view_dispatcher, - SPOTIFY_REMOTE_BUTTON_PANEL_VIEW, - button_panel_get_view(app->button_panel)); - app->text_box = text_box_alloc(); + app->main_menu = submenu_alloc(); view_dispatcher_add_view( - app->view_dispatcher, SPOTIFY_REMOTE_TEXT_BOX_VIEW, text_box_get_view(app->text_box)); + app->view_dispatcher, SPOTIFY_REMOTE_MAIN_MENU_SCENE, submenu_get_view(app->main_menu)); app->loading = loading_alloc(); view_dispatcher_add_view( - app->view_dispatcher, SPOTIFY_REMOTE_LOADING_VIEW, loading_get_view(app->loading)); - - // Initialize the UART helper. - app->uart_helper = uart_helper_alloc(); - uart_helper_set_baud_rate(app->uart_helper, DEVICE_BAUDRATE); - uart_helper_set_delimiter(app->uart_helper, LINE_DELIMITER, INCLUDE_LINE_DELIMITER); - uart_helper_set_callback(app->uart_helper, uart_process_line, app); - - app->message = furi_string_alloc(); + app->view_dispatcher, SPOTIFY_REMOTE_LOADING_SCENE, loading_get_view(app->loading)); return app; } // free all data -static void spotify_remote_app_free(SpotifyRemoteApp* app) { - uart_helper_free(app->uart_helper); - +static void app_free(SpotifyRemoteApp* app) { furi_assert(app); - view_dispatcher_remove_view(app->view_dispatcher, SPOTIFY_REMOTE_BUTTON_PANEL_VIEW); - view_dispatcher_remove_view(app->view_dispatcher, SPOTIFY_REMOTE_TEXT_BOX_VIEW); + view_dispatcher_remove_view(app->view_dispatcher, SPOTIFY_REMOTE_MAIN_MENU_VIEW); view_dispatcher_remove_view(app->view_dispatcher, SPOTIFY_REMOTE_LOADING_VIEW); - scene_manager_free(app->scene_manager); view_dispatcher_free(app->view_dispatcher); - button_panel_free(app->button_panel); - text_box_free(app->text_box); + submenu_free(app->main_menu); loading_free(app->loading); - furi_record_close(RECORD_GUI); - free(app); } @@ -369,9 +275,13 @@ int32_t spotify_remote_app(void* p) { UNUSED(p); SpotifyRemoteApp* app = spotify_remote_app_alloc(); - scene_manager_next_scene(app->scene_manager, SPOTIFY_REMOTE_LOADING_SCENE); + + Gui* gui = furi_record_open(RECORD_GUI); + view_dispatcher_attach_to_gui(app->view_dispatcher, gui, ViewDispatcherTypeFullscreen); + scene_manager_next_scene(app->scene_manager, SPOTIFY_REMOTE_MAIN_MENU_SCENE); view_dispatcher_run(app->view_dispatcher); - spotify_remote_app_free(app); + app_free(app); + return 0; -} +} \ No newline at end of file From 0ee787744ea4c58ac97397021179c4b7ee8c59b0 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Thu, 11 Jan 2024 21:55:16 -0500 Subject: [PATCH 2/2] back button works --- spotify_remote.c | 284 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 261 insertions(+), 23 deletions(-) diff --git a/spotify_remote.c b/spotify_remote.c index 7bb86adceea..335134e1a31 100644 --- a/spotify_remote.c +++ b/spotify_remote.c @@ -12,6 +12,15 @@ /* generated by fbt from .png files in images folder */ #include +// Derek Jamison's uart helper +#include "uart_helper.h" + +#define DEVICE_BAUDRATE 115200 +#define LINE_DELIMITER '\n' +#define INCLUDE_LINE_DELIMITER false + +SceneManager* global_scene_manager; + // enum for scenes typedef enum { SPOTIFY_REMOTE_MAIN_MENU_SCENE, @@ -54,8 +63,14 @@ typedef struct SpotifyRemoteApp { Loading* loading; TextBox* ip; ButtonPanel* button_panel; + UartHelper* uart_helper; + FuriString* message; } SpotifyRemoteApp; +typedef enum { + SPOTIFY_REMOTE_ON_RECEIVE_EVENT = 100, +} SpotifyRemoteCustomEvent; + // menu index typedef enum { SPOTIFY_REMOTE_MAIN_MENU_SCENE_LAUNCH, @@ -70,6 +85,28 @@ typedef enum { SPOTIFY_REMOTE_MAIN_MENU_SCENE_ABOUT_EVENT, } SpotifyRemoteSubmenuEvent; +static bool input_callback(InputEvent* input_event, void* context) { + UNUSED(context); + bool handled = false; + + if(input_event->type == InputTypeShort) { + if(input_event->key == InputKeyBack) { + scene_manager_search_and_switch_to_another_scene( + global_scene_manager, SPOTIFY_REMOTE_MAIN_MENU_SCENE); + handled = true; + } + } + + return handled; +} + +// handles data received from UART +static void uart_process_line(FuriString* line, void* context) { + SpotifyRemoteApp* app = context; + furi_string_set(app->message, line); + scene_manager_handle_custom_event(app->scene_manager, SPOTIFY_REMOTE_ON_RECEIVE_EVENT); +} + // action taken based on submenu option void spotify_remote_main_menu_callback(void* context, uint32_t index) { SpotifyRemoteApp* app = context; @@ -159,20 +196,189 @@ void spotify_remote_loading_scene_on_enter(void* context) { } bool spotify_remote_loading_scene_on_event(void* context, SceneManagerEvent event) { + SpotifyRemoteApp* app = context; + bool consumed = false; + + switch(event.type) { + case SceneManagerEventTypeCustom: + switch(event.event) { + case SPOTIFY_REMOTE_ON_RECEIVE_EVENT: + if(furi_string_get_cstr(app->message)[0] == 'I' && + furi_string_get_cstr(app->message)[1] == 'P') { + scene_manager_next_scene(app->scene_manager, SPOTIFY_REMOTE_IP_SCENE); + consumed = true; + } + break; + } + default: + break; + } + + return consumed; +} + +void spotify_remote_loading_scene_on_exit(void* context) { + UNUSED(context); +} + +// ip scene callbacks +void spotify_remote_ip_scene_on_enter(void* context) { + SpotifyRemoteApp* app = context; + text_box_reset(app->ip); + text_box_set_text(app->ip, furi_string_get_cstr(app->message)); + text_box_set_font(app->ip, TextBoxFontText); + view_dispatcher_switch_to_view(app->view_dispatcher, SPOTIFY_REMOTE_IP_VIEW); +} + +bool spotify_remote_ip_scene_on_event(void* context, SceneManagerEvent event) { + SpotifyRemoteApp* app = context; + bool consumed = false; + + switch(event.type) { + case SceneManagerEventTypeCustom: + switch(event.event) { + case SPOTIFY_REMOTE_ON_RECEIVE_EVENT: + if(furi_string_get_cstr(app->message)[0] == 'O' && + furi_string_get_cstr(app->message)[1] == 'K') { + scene_manager_next_scene(app->scene_manager, SPOTIFY_REMOTE_BUTTON_PANEL_SCENE); + consumed = true; + } + break; + } + default: + break; + } + + return consumed; +} + +void spotify_remote_ip_scene_on_exit(void* context) { + SpotifyRemoteApp* app = context; + text_box_reset(app->ip); +} + +// called when selection is made in button panel +void button_panel_on_select_callback(void* context, uint32_t index) { + SpotifyRemoteApp* app = context; + switch(index) { + case PREV: + uart_helper_send(app->uart_helper, "1\n", 2); + break; + case NEXT: + uart_helper_send(app->uart_helper, "2\n", 2); + break; + case PLAY: + uart_helper_send(app->uart_helper, "3\n", 2); + break; + case PAUSE: + uart_helper_send(app->uart_helper, "4\n", 2); + break; + case SHUFFLE: + uart_helper_send(app->uart_helper, "5\n", 2); + break; + case REPEAT: + uart_helper_send(app->uart_helper, "6\n", 2); + break; + default: + break; + } +} + +// button panel callbacks +void spotify_remote_button_panel_scene_on_enter(void* context) { + SpotifyRemoteApp* app = context; + + button_panel_reserve(app->button_panel, 2, 3); + button_panel_add_item( + app->button_panel, + PREV, + 0, + 0, + 6, + 16, + &I_prev_19x20, + &I_prev_hover_19x20, + button_panel_on_select_callback, + context); + button_panel_add_icon(app->button_panel, 6, 38, &I_prev_text_19x5); + button_panel_add_item( + app->button_panel, + NEXT, + 1, + 0, + 39, + 16, + &I_next_19x20, + &I_next_hover_19x20, + button_panel_on_select_callback, + context); + button_panel_add_icon(app->button_panel, 39, 38, &I_next_text_19x6); + + button_panel_add_item( + app->button_panel, + PLAY, + 0, + 1, + 6, + 50, + &I_play_19x20, + &I_play_hover_19x20, + button_panel_on_select_callback, + context); + button_panel_add_icon(app->button_panel, 6, 72, &I_play_text_19x5); + + button_panel_add_item( + app->button_panel, + PAUSE, + 1, + 1, + 39, + 50, + &I_pause_19x20, + &I_pause_hover_19x20, + button_panel_on_select_callback, + context); + button_panel_add_icon(app->button_panel, 39, 72, &I_pause_text_23x5); + + button_panel_add_item( + app->button_panel, + SHUFFLE, + 0, + 2, + 6, + 84, + &I_shuffle_19x20, + &I_shuffle_hover_19x20, + button_panel_on_select_callback, + context); + button_panel_add_icon(app->button_panel, 5, 106, &I_shuffle_text_21x5); + + button_panel_add_item( + app->button_panel, + REPEAT, + 1, + 2, + 39, + 84, + &I_repeat_19x20, + &I_repeat_hover_19x20, + button_panel_on_select_callback, + context); + button_panel_add_icon(app->button_panel, 40, 106, &I_repeat_text_18x5); + + view_dispatcher_switch_to_view(app->view_dispatcher, SPOTIFY_REMOTE_BUTTON_PANEL_VIEW); +} + +bool spotify_remote_button_panel_scene_on_event(void* context, SceneManagerEvent event) { // SpotifyRemoteApp* app = context; // bool consumed = false; // switch(event.type) { - // case SceneManagerEventTypeCustom: - // switch(event.event) { - // case SPOTIFY_REMOTE_ON_RECEIVE_EVENT: - // if(furi_string_get_cstr(app->message)[0] == 'I' && - // furi_string_get_cstr(app->message)[1] == 'P') { - // scene_manager_next_scene(app->scene_manager, SPOTIFY_REMOTE_IP_SCENE); - // consumed = true; - // } - // break; - // } + // case SceneManagerEventTypeBack: + // scene_manager_search_and_switch_to_another_scene( + // app->scene_manager, SPOTIFY_REMOTE_MAIN_MENU_SCENE); + // consumed = true; + // break; // default: // break; // } @@ -184,26 +390,33 @@ bool spotify_remote_loading_scene_on_event(void* context, SceneManagerEvent even return false; } -void spotify_remote_loading_scene_on_exit(void* context) { - UNUSED(context); +void spotify_remote_button_panel_scene_on_exit(void* context) { + SpotifyRemoteApp* app = context; + button_panel_reset(app->button_panel); } // array of on_enter handlers void (*const spotify_remote_scene_on_enter_handlers[])(void*) = { spotify_remote_main_menu_scene_on_enter, spotify_remote_loading_scene_on_enter, + spotify_remote_ip_scene_on_enter, + spotify_remote_button_panel_scene_on_enter, }; // array of on_event handlers bool (*const spotify_remote_scene_on_event_handlers[])(void*, SceneManagerEvent) = { spotify_remote_main_menu_scene_on_event, spotify_remote_loading_scene_on_event, + spotify_remote_ip_scene_on_event, + spotify_remote_button_panel_scene_on_event, }; // array of on_exit handlers void (*const spotify_remote_scene_on_exit_handlers[])(void*) = { spotify_remote_main_menu_scene_on_exit, spotify_remote_loading_scene_on_exit, + spotify_remote_ip_scene_on_exit, + spotify_remote_button_panel_scene_on_exit, }; // create custom event callback @@ -214,13 +427,13 @@ static bool spotify_remote_custom_callback(void* context, uint32_t custom_event) return scene_manager_handle_custom_event(app->scene_manager, custom_event); } -// create back event callback -bool spotify_remote_back_event_callback(void* context) { - furi_assert(context); - SpotifyRemoteApp* app = context; - // delegate back event to scene manager - return scene_manager_handle_back_event(app->scene_manager); -} +// // create back event callback +// bool spotify_remote_back_event_callback(void* context) { +// furi_assert(context); +// SpotifyRemoteApp* app = context; +// // delegate back event to scene manager +// return (app->scene_manager); +// } // attach all handlers to the scene manager static const SceneManagerHandlers spotify_remote_scene_manager_handlers = { @@ -236,6 +449,7 @@ static SpotifyRemoteApp* spotify_remote_app_alloc() { SpotifyRemoteApp* app = malloc(sizeof(SpotifyRemoteApp)); app->scene_manager = scene_manager_alloc(&spotify_remote_scene_manager_handlers, app); + global_scene_manager = app->scene_manager; app->view_dispatcher = view_dispatcher_alloc(); // enable view dispatcher queue to handle events @@ -245,16 +459,33 @@ static SpotifyRemoteApp* spotify_remote_app_alloc() { view_dispatcher_set_event_callback_context(app->view_dispatcher, app); view_dispatcher_set_custom_event_callback( app->view_dispatcher, spotify_remote_custom_callback); - view_dispatcher_set_navigation_event_callback( - app->view_dispatcher, spotify_remote_back_event_callback); + // view_dispatcher_set_navigation_event_callback( + // app->view_dispatcher, spotify_remote_custom_callback); // create and add views for modules app->main_menu = submenu_alloc(); view_dispatcher_add_view( - app->view_dispatcher, SPOTIFY_REMOTE_MAIN_MENU_SCENE, submenu_get_view(app->main_menu)); + app->view_dispatcher, SPOTIFY_REMOTE_MAIN_MENU_VIEW, submenu_get_view(app->main_menu)); app->loading = loading_alloc(); view_dispatcher_add_view( - app->view_dispatcher, SPOTIFY_REMOTE_LOADING_SCENE, loading_get_view(app->loading)); + app->view_dispatcher, SPOTIFY_REMOTE_LOADING_VIEW, loading_get_view(app->loading)); + app->ip = text_box_alloc(); + view_dispatcher_add_view( + app->view_dispatcher, SPOTIFY_REMOTE_IP_VIEW, text_box_get_view(app->ip)); + app->button_panel = button_panel_alloc(); + view_dispatcher_add_view( + app->view_dispatcher, + SPOTIFY_REMOTE_BUTTON_PANEL_VIEW, + button_panel_get_view(app->button_panel)); + view_set_input_callback(button_panel_get_view(app->button_panel), input_callback); + + // Initialize the UART helper. + app->uart_helper = uart_helper_alloc(); + uart_helper_set_baud_rate(app->uart_helper, DEVICE_BAUDRATE); + uart_helper_set_delimiter(app->uart_helper, LINE_DELIMITER, INCLUDE_LINE_DELIMITER); + uart_helper_set_callback(app->uart_helper, uart_process_line, app); + + app->message = furi_string_alloc(); return app; } @@ -262,12 +493,19 @@ static SpotifyRemoteApp* spotify_remote_app_alloc() { // free all data static void app_free(SpotifyRemoteApp* app) { furi_assert(app); + uart_helper_free(app->uart_helper); + view_dispatcher_remove_view(app->view_dispatcher, SPOTIFY_REMOTE_MAIN_MENU_VIEW); view_dispatcher_remove_view(app->view_dispatcher, SPOTIFY_REMOTE_LOADING_VIEW); + + furi_string_free(app->message); scene_manager_free(app->scene_manager); + scene_manager_free(global_scene_manager); view_dispatcher_free(app->view_dispatcher); submenu_free(app->main_menu); loading_free(app->loading); + button_panel_free(app->button_panel); + free(app); }