Skip to content

Commit 2dc8f38

Browse files
authored
Merge pull request #2 from acegoal07/New-UI
New UI Update
2 parents 5f807c4 + 9330ae6 commit 2dc8f38

File tree

2 files changed

+70
-21
lines changed

2 files changed

+70
-21
lines changed

nfc_playlist.c

Lines changed: 70 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
#include <furi.h>
22
#include <string.h>
3-
43
#include <storage/storage.h>
54
#include <toolbox/stream/stream.h>
65
#include <toolbox/stream/file_stream.h>
7-
86
#include <nfc_playlist_worker.h>
9-
107
#include <gui/gui.h>
118
#include <gui/view_dispatcher.h>
129
#include <gui/scene_manager.h>
13-
#include <gui/modules/submenu.h>
1410
#include <gui/modules/popup.h>
11+
#include <gui/modules/variable_item_list.h>
1512

1613
// Define log tag
1714
#define TAG "NfcPlaylist"
@@ -30,16 +27,20 @@ typedef enum { NfcPlaylistView_Menu, NfcPlaylistView_Popup } NfcPlaylistView;
3027
typedef struct {
3128
SceneManager* scene_manager;
3229
ViewDispatcher* view_dispatcher;
33-
Submenu* submenu;
30+
VariableItemList* variable_item_list;
3431
Popup* popup;
3532
NfcPlaylistWorker* nfc_worker;
36-
int emulate_timeout;
37-
int emulate_delay;
33+
int emulate_timeout; uint8_t emulate_timeout_index;
34+
int emulate_delay; uint8_t emulate_delay_index;
3835
} NfcPlaylist;
3936

4037
// All custom events
4138
typedef enum { NfcPlaylistEvent_ShowEmulatingPopup } NfcPlaylistEvent;
4239

40+
// All options for the emulate timeout and delay
41+
const int options_emulate_timeout[] = { 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000 };
42+
const int options_emulate_delay[] = { 0000, 1000, 2000, 3000, 4000, 5000 };
43+
4344
/* main menu scene */
4445

4546
// Indices for menu items
@@ -50,24 +51,71 @@ void nfc_playlist_menu_callback_main_menu(void* context, uint32_t index) {
5051
FURI_LOG_T(TAG, "nfc_playlist_menu_callback_main_menu");
5152
NfcPlaylist* app = context;
5253
switch(index) {
53-
case NfcPlaylistMenuSelection_Start:
54+
case 0:
5455
scene_manager_handle_custom_event(app->scene_manager, NfcPlaylistEvent_ShowEmulatingPopup);
5556
break;
57+
default:
58+
break;
59+
}
60+
}
61+
62+
static void nfc_playlist_settings_change_callback(VariableItem* item) {
63+
NfcPlaylist* app = variable_item_get_context(item);
64+
65+
uint8_t current_option = variable_item_list_get_selected_item_index(app->variable_item_list);
66+
uint8_t option_value_index = variable_item_get_current_value_index(item);
67+
68+
switch(current_option) {
69+
case 1: ;
70+
app->emulate_timeout = options_emulate_timeout[option_value_index];
71+
app->emulate_timeout_index = option_value_index;
72+
char emulate_timeout_text[9];
73+
snprintf(emulate_timeout_text, 9, "%d", (app->emulate_timeout/1000));
74+
variable_item_set_current_value_text(item, (char*)emulate_timeout_text);
75+
76+
break;
77+
case 2: ;
78+
app->emulate_delay = options_emulate_delay[option_value_index];
79+
app->emulate_delay_index = option_value_index;
80+
char emulate_delay_text[9];
81+
snprintf(emulate_delay_text, 9, "%d", (app->emulate_delay/1000));
82+
variable_item_set_current_value_text(item, (char*)emulate_delay_text);
83+
break;
5684
}
5785
}
5886

5987
// Resets the menu, gives it content, callbacks and selection enums
6088
void nfc_playlist_scene_on_enter_main_menu(void* context) {
6189
FURI_LOG_T(TAG, "nfc_playlist_scene_on_enter_main_menu");
6290
NfcPlaylist* app = context;
63-
submenu_reset(app->submenu);
64-
submenu_set_header(app->submenu, "NFC Playlist");
65-
submenu_add_item(
66-
app->submenu,
67-
"Start",
68-
NfcPlaylistMenuSelection_Start,
69-
nfc_playlist_menu_callback_main_menu,
91+
92+
// make a variable item list that goes up in 2
93+
94+
variable_item_list_set_header(app->variable_item_list, "NFC Playlist");
95+
variable_item_list_add(app->variable_item_list, "Start", 0, NULL, NULL);
96+
VariableItem* emulation_timeout_settings = variable_item_list_add(
97+
app->variable_item_list,
98+
"Emulation timeout",
99+
10,
100+
nfc_playlist_settings_change_callback,
101+
app);
102+
variable_item_set_current_value_index(emulation_timeout_settings, app->emulate_timeout_index);
103+
char emulation_timeout_settings_text[9];
104+
snprintf(emulation_timeout_settings_text, 9, "%d", (app->emulate_timeout/1000));
105+
variable_item_set_current_value_text(emulation_timeout_settings, (char*)emulation_timeout_settings_text);
106+
107+
VariableItem* emulation_delay_settings = variable_item_list_add(
108+
app->variable_item_list,
109+
"Emulation delay",
110+
6,
111+
nfc_playlist_settings_change_callback,
70112
app);
113+
variable_item_set_current_value_index(emulation_delay_settings, app->emulate_delay_index);
114+
char emulation_delay_settings_text[9];
115+
snprintf(emulation_delay_settings_text, 9, "%d", (app->emulate_delay/1000));
116+
variable_item_set_current_value_text(emulation_delay_settings, (char*)emulation_delay_settings_text);
117+
118+
variable_item_list_set_enter_callback(app->variable_item_list, nfc_playlist_menu_callback_main_menu, app);
71119
view_dispatcher_switch_to_view(app->view_dispatcher, NfcPlaylistView_Menu);
72120
}
73121

@@ -95,7 +143,7 @@ bool nfc_playlist_scene_on_event_main_menu(void* context, SceneManagerEvent even
95143
void nfc_playlist_scene_on_exit_main_menu(void* context) {
96144
FURI_LOG_T(TAG, "nfc_playlist_scene_on_exit_main_menu");
97145
NfcPlaylist* app = context;
98-
submenu_reset(app->submenu);
146+
variable_item_list_reset(app->variable_item_list);
99147
}
100148

101149
// Emulating scene
@@ -251,10 +299,12 @@ void nfc_playlist_view_dispatcher_init(NfcPlaylist* app) {
251299

252300
// allocate each view
253301
FURI_LOG_D(TAG, "nfc_playlist_view_dispatcher_init allocating views");
254-
app->submenu = submenu_alloc();
302+
app->variable_item_list = variable_item_list_alloc();
255303
app->popup = popup_alloc();
256304
app->emulate_timeout = 5000;
257-
app->emulate_delay = 2000;
305+
app->emulate_timeout_index = 4;
306+
app->emulate_delay = 0000;
307+
app->emulate_delay_index = 0;
258308

259309
// assign callback that pass events from views to the scene manager
260310
FURI_LOG_D(TAG, "nfc_playlist_view_dispatcher_init setting callbacks");
@@ -264,7 +314,7 @@ void nfc_playlist_view_dispatcher_init(NfcPlaylist* app) {
264314

265315
// add views to the dispatcher, indexed by their enum value
266316
FURI_LOG_D(TAG, "nfc_playlist_view_dispatcher_init adding view menu");
267-
view_dispatcher_add_view(app->view_dispatcher, NfcPlaylistView_Menu, submenu_get_view(app->submenu));
317+
view_dispatcher_add_view(app->view_dispatcher, NfcPlaylistView_Menu, variable_item_list_get_view(app->variable_item_list));
268318

269319
FURI_LOG_D(TAG, "nfc_playlist_view_dispatcher_init adding view popup");
270320
view_dispatcher_add_view(app->view_dispatcher, NfcPlaylistView_Popup, popup_get_view(app->popup));
@@ -286,7 +336,7 @@ void nfc_playlist_free(NfcPlaylist* app) {
286336
view_dispatcher_remove_view(app->view_dispatcher, NfcPlaylistView_Menu);
287337
view_dispatcher_remove_view(app->view_dispatcher, NfcPlaylistView_Popup);
288338
view_dispatcher_free(app->view_dispatcher);
289-
submenu_free(app->submenu);
339+
variable_item_list_free(app->variable_item_list);
290340
popup_free(app->popup);
291341
free(app);
292342
}

nfc_playlist_worker.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22
#include <furi.h>
33
#include <furi_hal.h>
4-
54
#include <nfc/nfc.h>
65
#include <nfc/nfc_device.h>
76
#include <nfc/nfc_listener.h>

0 commit comments

Comments
 (0)