Skip to content

Commit

Permalink
new scene manager
Browse files Browse the repository at this point in the history
- This is to make adding new scenes easier and also to reduce how many files there are in the source code of the app
  • Loading branch information
acegoal07 committed Apr 11, 2024
1 parent 328cefa commit 8ad052b
Show file tree
Hide file tree
Showing 29 changed files with 177 additions and 290 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.

90 changes: 42 additions & 48 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 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);
}
}
33 changes: 17 additions & 16 deletions nfc_playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@

#include <notification/notification_messages.h>

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

#include <toolbox/stream/stream.h>
#include <toolbox/stream/file_stream.h>

#include "lib/worker/nfc_playlist_worker.h"

#include "scenes/nfc_playlist_scene.h"

typedef enum {
NfcPlaylistView_Menu,
Expand All @@ -34,20 +41,6 @@ typedef enum {
NfcPlaylistView_NameNewFile
} NfcPlayScenesView;

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;

typedef struct {
FuriString* file_path;
bool playlist_selected;
Expand Down Expand Up @@ -81,4 +74,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.

30 changes: 30 additions & 0 deletions scenes/nfc_playlist_scene.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "nfc_playlist_scene.h"

// Generate scene on_enter handlers definition
#define ADD_SCENE(prefix, name, id) prefix##_##name##_scene_on_enter,
void (*const nfc_playlist_on_enter_handlers[])(void*) = {
#include "nfc_playlist_scene_config.h"
};
#undef ADD_SCENE

// Generate scene on_event handlers array
#define ADD_SCENE(prefix, name, id) prefix##_##name##_scene_on_event,
bool (*const nfc_playlist_on_event_handlers[])(void* context, SceneManagerEvent event) = {
#include "nfc_playlist_scene_config.h"
};
#undef ADD_SCENE

// Generate scene on_exit handlers array
#define ADD_SCENE(prefix, name, id) prefix##_##name##_scene_on_exit,
void (*const nfc_playlist_on_exit_handlers[])(void* context) = {
#include "nfc_playlist_scene_config.h"
};
#undef ADD_SCENE

// Initialize scene handlers configuration structure
const SceneManagerHandlers nfc_playlist_scene_handlers = {
.on_enter_handlers = nfc_playlist_on_enter_handlers,
.on_event_handlers = nfc_playlist_on_event_handlers,
.on_exit_handlers = nfc_playlist_on_exit_handlers,
.scene_num = NfcPlaylistScene_Count,
};
Loading

0 comments on commit 8ad052b

Please sign in to comment.