1
- #include <gui/modules/submenu.h>
2
- #include <gui/modules/popup.h>
1
+ #include <gui/modules/variable_item_list.h>
3
2
4
3
#include "settings_scene.h"
5
4
#include "../app_context.h"
6
5
#include "../tone_gen.h"
7
6
#include "../utils/linked_list.h"
8
7
9
- /** indices for menu items */
10
- typedef enum {
11
- SettingsMenuOptions_WaveType ,
12
- SettingsMenuOptions_Amplitude ,
13
- SettingsMenuOptions_Period ,
14
- } SettingsMenuOptions ;
15
-
16
- /** main menu callback - sends a custom event to the scene manager based on the menu selection */
8
+ // Not actively used in this instance.
17
9
void menu_callback_settings_scene (void * context , uint32_t index ) {
18
10
UNUSED (context );
19
- // struct AppContext_t* app = context;
20
- switch (index ) {
21
- case SettingsMenuOptions_WaveType :
22
- FURI_LOG_I (TAG , "selection one" );
23
- // scene_manager_handle_custom_event(app->scene_manager, ToneGenAppEvent_StartPlayback);
24
- break ;
25
- case SettingsMenuOptions_Amplitude :
26
- FURI_LOG_I (TAG , "selection two" );
27
- // scene_manager_handle_custom_event(app->scene_manager, ToneGenAppEvent_AdjustTone);
28
- break ;
29
- case SettingsMenuOptions_Period :
30
- FURI_LOG_I (TAG , "selection three" );
31
- // scene_manager_handle_custom_event(app->scene_manager, ToneGenAppEvent_AdjustTone);
32
- break ;
33
- }
11
+ UNUSED (index );
12
+ }
13
+
14
+ static uint8_t wave_option_values [] = {SINE , SQUARE };
15
+ static char * wave_option_names [] = {"Sine" , "Square" };
16
+ static void wave_type_option_change (VariableItem * item ) {
17
+ struct AppContext_t * app = variable_item_get_context (item );
18
+ uint8_t index = variable_item_get_current_value_index (item );
19
+ variable_item_set_current_value_text (item , wave_option_names [index ]);
20
+ ((struct ToneData_t * )app -> additionalData )-> waveType = index ;
21
+ }
22
+
23
+ // Since the max number of options for variable item lists is
24
+ // the size of an 8-bit integer, we need to limit the max
25
+ // number of steps. In this case, we limit it to 241 total
26
+ // steps available, incrementing in steps of 10.
27
+ #define MIN_FREQ 100
28
+ #define MAX_FREQ 2500
29
+ #define FREQ_STEPS 10
30
+ #define INDEX_TO_FREQ (index ) (uint16_t)((index * FREQ_STEPS) + MIN_FREQ)
31
+ #define FREQ_TO_INDEX (freq ) (uint8_t)((freq - MIN_FREQ) / FREQ_STEPS)
32
+ char * frequencyStr ;
33
+ static void frequency_option_change (VariableItem * item ) {
34
+ struct AppContext_t * app = variable_item_get_context (item );
35
+ uint8_t index = variable_item_get_current_value_index (item );
36
+ ((struct ToneData_t * )app -> additionalData )-> frequency = INDEX_TO_FREQ (index );
37
+ snprintf (frequencyStr , 8 , "%dhz" , ((struct ToneData_t * )app -> additionalData )-> frequency );
38
+ variable_item_set_current_value_text (item , frequencyStr );
34
39
}
35
40
36
41
/** resets the menu, gives it content, callbacks and selection enums */
@@ -40,62 +45,49 @@ void scene_on_enter_settings_scene(void* context) {
40
45
41
46
// Setup our menu
42
47
FURI_LOG_D (TAG , "Adding view menu" );
43
- struct View_t * menuView = app -> activeViews [ToneGenAppView_Submenu ];
48
+ struct View_t * variableItemListView = app -> activeViews [ToneGenAppView_VariableItemList ];
44
49
45
50
// Set the currently active view
46
- submenu_reset ( menuView -> viewData );
51
+ variable_item_list_reset ( variableItemListView -> viewData );
47
52
48
- submenu_set_header (menuView -> viewData , "Tone Settings" );
49
-
50
- FURI_LOG_D (TAG , "Adding menu options for settings" );
51
- submenu_add_item (
52
- menuView -> viewData ,
53
+ FURI_LOG_D (TAG , "Adding options for settings" );
54
+ VariableItem * item = variable_item_list_add (
55
+ variableItemListView -> viewData ,
53
56
"Wave Type" ,
54
- SettingsMenuOptions_WaveType ,
55
- menu_callback_settings_scene ,
56
- app );
57
- submenu_add_item (
58
- menuView -> viewData ,
59
- "Amplitude" ,
60
- SettingsMenuOptions_Amplitude ,
61
- menu_callback_settings_scene ,
57
+ COUNT_OF (wave_option_values ),
58
+ wave_type_option_change ,
62
59
app );
63
- submenu_add_item (
64
- menuView -> viewData ,
65
- "Period" ,
66
- SettingsMenuOptions_Period ,
67
- menu_callback_settings_scene ,
60
+ variable_item_set_current_value_index (
61
+ item , ((struct ToneData_t * )app -> additionalData )-> waveType );
62
+ variable_item_set_current_value_text (
63
+ item , wave_option_names [((struct ToneData_t * )app -> additionalData )-> waveType ]);
64
+
65
+ item = variable_item_list_add (
66
+ variableItemListView -> viewData ,
67
+ "Frequency" ,
68
+ FREQ_TO_INDEX (MAX_FREQ ) + 1 ,
69
+ frequency_option_change ,
68
70
app );
69
- view_dispatcher_switch_to_view (app -> view_dispatcher , ToneGenAppView_Submenu );
71
+ variable_item_set_current_value_index (
72
+ item , FREQ_TO_INDEX (((struct ToneData_t * )app -> additionalData )-> frequency ));
73
+
74
+ frequencyStr = calloc (8 , sizeof (char ));
75
+ snprintf (frequencyStr , 8 , "%dhz" , ((struct ToneData_t * )app -> additionalData )-> frequency );
76
+ variable_item_set_current_value_text (item , frequencyStr );
77
+
78
+ view_dispatcher_switch_to_view (app -> view_dispatcher , ToneGenAppView_VariableItemList );
70
79
}
71
80
72
- /** main menu event handler - switches scene based on the event */
81
+ // Not actively used in this instance.
73
82
bool scene_on_event_settings_scene (void * context , SceneManagerEvent event ) {
74
83
FURI_LOG_I (TAG , "scene_on_event_settings_scene" );
75
84
UNUSED (context );
76
- // struct AppContext_t* app = context;
77
- bool consumed = false;
78
- switch (event .type ) {
79
- case SceneManagerEventTypeCustom :
80
- // switch(event.event) {
81
- // case ToneGenAppEvent_StartPlayback:
82
- // scene_manager_next_scene(app->scene_manager, ToneGenAppScene_Playback);
83
- // consumed = true;
84
- // break;
85
- // case ToneGenAppEvent_AdjustTone:
86
- // scene_manager_next_scene(app->scene_manager, ToneGenAppScene_AdjustTone);
87
- // consumed = true;
88
- // break;
89
- // }
90
- break ;
91
- default : // eg. SceneManagerEventTypeBack, SceneManagerEventTypeTick
92
- consumed = false;
93
- break ;
94
- }
95
- return consumed ;
85
+ UNUSED (event );
86
+ return false;
96
87
}
97
88
98
89
void scene_on_exit_settings_scene (void * context ) {
99
90
FURI_LOG_I (TAG , "scene_on_exit_settings_scene" );
100
91
UNUSED (context );
92
+ free (frequencyStr );
101
93
}
0 commit comments