Skip to content

Commit

Permalink
Merge pull request #18 from acegoal07/new_scene_manager
Browse files Browse the repository at this point in the history
New scene manager
  • Loading branch information
acegoal07 authored Apr 11, 2024
2 parents 328cefa + cd66660 commit b586b00
Show file tree
Hide file tree
Showing 29 changed files with 207 additions and 333 deletions.
3 changes: 0 additions & 3 deletions application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,5 @@ App(
Lib(
name="worker",
),
Lib(
name="led",
),
],
)
42 changes: 0 additions & 42 deletions lib/led/nfc_playlist_led.c

This file was deleted.

11 changes: 0 additions & 11 deletions lib/led/nfc_playlist_led.h

This file was deleted.

130 changes: 62 additions & 68 deletions nfc_playlist.c
Original file line number Diff line number Diff line change
@@ -1,51 +1,4 @@
#include "nfc_playlist.h"
#include "nfc_playlist_i.h"

static void (*const nfc_playlist_scene_on_enter_handlers[])(void*) = {
nfc_playlist_main_menu_scene_on_enter,
nfc_playlist_settings_scene_on_enter,
nfc_playlist_emulation_scene_on_enter,
nfc_playlist_playlist_select_scene_on_enter,
nfc_playlist_file_edit_scene_on_enter,
nfc_playlist_file_rename_scene_on_enter,
nfc_playlist_confirm_delete_scene_on_enter,
nfc_playlist_view_playlist_content_scene_on_enter,
nfc_playlist_nfc_select_scene_on_enter,
nfc_playlist_name_new_file_scene_on_enter
};

static bool (*const nfc_playlist_scene_on_event_handlers[])(void*, SceneManagerEvent) = {
nfc_playlist_main_menu_scene_on_event,
nfc_playlist_settings_scene_on_event,
nfc_playlist_emulation_scene_on_event,
nfc_playlist_playlist_select_scene_on_event,
nfc_playlist_file_edit_scene_on_event,
nfc_playlist_file_rename_scene_on_event,
nfc_playlist_confirm_delete_scene_on_event,
nfc_playlist_view_playlist_content_scene_on_event,
nfc_playlist_nfc_select_scene_on_event,
nfc_playlist_name_new_file_scene_on_event
};

static void (*const nfc_playlist_scene_on_exit_handlers[])(void*) = {
nfc_playlist_main_menu_scene_on_exit,
nfc_playlist_settings_scene_on_exit,
nfc_playlist_emulation_scene_on_exit,
nfc_playlist_playlist_select_scene_on_exit,
nfc_playlist_file_edit_scene_on_exit,
nfc_playlist_file_rename_scene_on_exit,
nfc_playlist_confirm_delete_scene_on_exit,
nfc_playlist_view_playlist_content_scene_on_exit,
nfc_playlist_nfc_select_scene_on_exit,
nfc_playlist_name_new_file_scene_on_exit
};

static const SceneManagerHandlers nfc_playlist_scene_manager_handlers = {
.on_enter_handlers = nfc_playlist_scene_on_enter_handlers,
.on_event_handlers = nfc_playlist_scene_on_event_handlers,
.on_exit_handlers = nfc_playlist_scene_on_exit_handlers,
.scene_num = NfcPlaylistScene_count
};

static bool nfc_playlist_custom_callback(void* context, uint32_t custom_event) {
furi_assert(context);
Expand All @@ -62,7 +15,7 @@ static bool nfc_playlist_back_event_callback(void* context) {
static NfcPlaylist* nfc_playlist_alloc() {
NfcPlaylist* nfc_playlist = malloc(sizeof(NfcPlaylist));
furi_assert(nfc_playlist);
nfc_playlist->scene_manager = scene_manager_alloc(&nfc_playlist_scene_manager_handlers, nfc_playlist);
nfc_playlist->scene_manager = scene_manager_alloc(&nfc_playlist_scene_handlers, nfc_playlist);
nfc_playlist->view_dispatcher = view_dispatcher_alloc();
view_dispatcher_enable_queue(nfc_playlist->view_dispatcher);
nfc_playlist->variable_item_list = variable_item_list_alloc();
Expand All @@ -86,16 +39,16 @@ static NfcPlaylist* nfc_playlist_alloc() {
view_dispatcher_set_event_callback_context(nfc_playlist->view_dispatcher, nfc_playlist);
view_dispatcher_set_custom_event_callback(nfc_playlist->view_dispatcher, nfc_playlist_custom_callback);
view_dispatcher_set_navigation_event_callback(nfc_playlist->view_dispatcher, nfc_playlist_back_event_callback);
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Menu, submenu_get_view(nfc_playlist->submenu));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings, variable_item_list_get_view(nfc_playlist->variable_item_list));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup, popup_get_view(nfc_playlist->popup));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_PlaylistSelect, file_browser_get_view(nfc_playlist->playlist_file_browser));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit, submenu_get_view(nfc_playlist->submenu));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileRename, text_input_get_view(nfc_playlist->text_input));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ConfirmDelete, widget_get_view(nfc_playlist->widget));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ViewPlaylistContent, widget_get_view(nfc_playlist->widget));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_NfcSelect, file_browser_get_view(nfc_playlist->nfc_file_browser));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistView_NameNewFile, text_input_get_view(nfc_playlist->text_input));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_MainMenu, submenu_get_view(nfc_playlist->submenu));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_Settings, variable_item_list_get_view(nfc_playlist->variable_item_list));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_Emulation, popup_get_view(nfc_playlist->popup));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_PlaylistSelect, file_browser_get_view(nfc_playlist->playlist_file_browser));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_FileEdit, submenu_get_view(nfc_playlist->submenu));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_FileRename, text_input_get_view(nfc_playlist->text_input));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_ConfirmDelete, widget_get_view(nfc_playlist->widget));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_ViewPlaylistContent, widget_get_view(nfc_playlist->widget));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_NfcSelect, file_browser_get_view(nfc_playlist->nfc_file_browser));
view_dispatcher_add_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_NameNewFile, text_input_get_view(nfc_playlist->text_input));

Storage* storage = furi_record_open(RECORD_STORAGE);
if (!storage_common_exists(storage, PLAYLIST_DIR)) {
Expand All @@ -109,16 +62,16 @@ static NfcPlaylist* nfc_playlist_alloc() {
static void nfc_playlist_free(NfcPlaylist* nfc_playlist) {
furi_assert(nfc_playlist);

view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Menu);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Popup);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_PlaylistSelect);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileEdit);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_FileRename);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ConfirmDelete);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_ViewPlaylistContent);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_NfcSelect);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistView_NameNewFile);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_MainMenu);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_Settings);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_Emulation);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_PlaylistSelect);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_FileEdit);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_FileRename);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_ConfirmDelete);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_ViewPlaylistContent);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_NfcSelect);
view_dispatcher_remove_view(nfc_playlist->view_dispatcher, NfcPlaylistScene_NameNewFile);

scene_manager_free(nfc_playlist->scene_manager);
view_dispatcher_free(nfc_playlist->view_dispatcher);
Expand Down Expand Up @@ -161,4 +114,45 @@ int32_t nfc_playlist_main(void* p) {
nfc_playlist_free(nfc_playlist);

return 0;
}

NotificationMessage blink_message_normal = {
.type = NotificationMessageTypeLedBlinkStart,
.data.led_blink.color = LightBlue | LightGreen,
.data.led_blink.on_time = 10,
.data.led_blink.period = 100
};
const NotificationSequence blink_sequence_normal = {
&blink_message_normal,
&message_do_not_reset,
NULL
};

NotificationMessage blink_message_error = {
.type = NotificationMessageTypeLedBlinkStart,
.data.led_blink.color = LightRed,
.data.led_blink.on_time = 10,
.data.led_blink.period = 100
};

const NotificationSequence blink_sequence_error = {
&blink_message_error,
&message_do_not_reset,
NULL
};

void start_blink(NfcPlaylist* nfc_playlist, int state) {
if (nfc_playlist->settings.emulate_led_indicator) {
if (state == NfcPlaylistLedState_Normal) {
notification_message_block(nfc_playlist->notification, &blink_sequence_normal);
} else if (state == NfcPlaylistLedState_Error) {
notification_message_block(nfc_playlist->notification, &blink_sequence_error);
}
}
}

void stop_blink(NfcPlaylist* nfc_playlist) {
if (nfc_playlist->settings.emulate_led_indicator) {
notification_message_block(nfc_playlist->notification, &sequence_blink_stop);
}
}
42 changes: 15 additions & 27 deletions nfc_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,14 @@

#include <notification/notification_messages.h>

#include <nfc_playlist_worker.h>
#include <storage/storage.h>

typedef enum {
NfcPlaylistView_Menu,
NfcPlaylistView_Settings,
NfcPlaylistView_Popup,
NfcPlaylistView_PlaylistSelect,
NfcPlaylistView_FileEdit,
NfcPlaylistView_FileRename,
NfcPlaylistView_ConfirmDelete,
NfcPlaylistView_ViewPlaylistContent,
NfcPlaylistView_NfcSelect,
NfcPlaylistView_NameNewFile
} NfcPlayScenesView;
#include <toolbox/stream/stream.h>
#include <toolbox/stream/file_stream.h>

typedef enum {
NfcPlaylistScene_MainMenu,
NfcPlaylistScene_Settings,
NfcPlaylistScene_EmulatingPopup,
NfcPlaylistScene_PlaylistSelect,
NfcPlaylistScene_FileEdit,
NfcPlaylistScene_FileRename,
NfcPlaylistScene_ConfirmDelete,
NfcPlaylistScene_ViewPlaylistContent,
NfcPlaylistScene_NfcSelect,
NfcPlaylistScene_NameNewFile,
NfcPlaylistScene_count
} NfcPlaylistScene;
#include "lib/worker/nfc_playlist_worker.h"

#include "scenes/nfc_playlist_scene.h"

typedef struct {
FuriString* file_path;
Expand Down Expand Up @@ -81,4 +61,12 @@ static const int default_emulate_delay = 0;
static const bool default_emulate_led_indicator = true;

#define PLAYLIST_LOCATION "/ext/apps_data/nfc_playlist/"
#define PLAYLIST_DIR "/ext/apps_data/nfc_playlist"
#define PLAYLIST_DIR "/ext/apps_data/nfc_playlist"

typedef enum NfcPlaylistLedState {
NfcPlaylistLedState_Normal,
NfcPlaylistLedState_Error
} NfcPlaylistLedState;

void start_blink(NfcPlaylist* nfc_playlist, int state);
void stop_blink(NfcPlaylist* nfc_playlist);
11 changes: 0 additions & 11 deletions nfc_playlist_i.h

This file was deleted.

10 changes: 0 additions & 10 deletions scenes/confirm_delete.h

This file was deleted.

20 changes: 0 additions & 20 deletions scenes/emulation.h

This file was deleted.

17 changes: 0 additions & 17 deletions scenes/file_edit.h

This file was deleted.

10 changes: 0 additions & 10 deletions scenes/file_rename.h

This file was deleted.

23 changes: 0 additions & 23 deletions scenes/main_menu.h

This file was deleted.

10 changes: 0 additions & 10 deletions scenes/name_new_file.h

This file was deleted.

Loading

0 comments on commit b586b00

Please sign in to comment.