Skip to content

Commit

Permalink
consolidate dup code, remove enum, adjust About index
Browse files Browse the repository at this point in the history
  • Loading branch information
rdefeo committed Sep 5, 2024
1 parent 86263f5 commit bb6373b
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions scenes/scene_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@

#include <lib/toolbox/path.h>

typedef enum {
SceneSettingsLayout,
SceneSettingsIcons,
SceneSettingsHeaders,
SceneSettingsRFIDDuration,
SceneSettingsNFCDuration,
SceneSettingsSubGHzRepeat,
SceneSettingsSubGHzExtAnt,
SceneSettingsHidden,
SceneSettingsAbout
} SceneSettingsIndex;
// Unfortunately, the VariableItemList does not provide a method to query the length
// of the list. Since we intend to place "About" last, it would be convenient to
// dynamically know it's list index for our on_event method. However, we'll need to
// hardcode the value..
#define SCENE_SETTINGS_ABOUT 9 // 10 items in our Settings list, so last index is 9

static const char* const layout_text[2] = {"Vert", "Horiz"};
static const uint32_t layout_value[2] = {QUAC_APP_PORTRAIT, QUAC_APP_LANDSCAPE};
Expand Down Expand Up @@ -67,11 +61,8 @@ static const char* const repeat_text[V_REPEAT_COUNT] = {
"50"};
static const uint32_t repeat_value[V_REPEAT_COUNT] = {1, 2, 3, 5, 8, 10, 15, 20, 50};

static const char* const subghz_ext_text[2] = {"Disabled", "Enabled"};
static const uint32_t subghz_ext_value[2] = {false, true};

static const char* const ir_ext_text[2] = {"Disabled", "Enabled"};
static const uint32_t ir_ext_value[2] = {false, true};
static const char* const disabled_enabled_text[2] = {"Disabled", "Enabled"};
static const uint32_t disabled_enabled_value[2] = {false, true};

static void scene_settings_layout_changed(VariableItem* item) {
App* app = variable_item_get_context(item);
Expand Down Expand Up @@ -118,15 +109,15 @@ static void scene_settings_subghz_repeat_changed(VariableItem* item) {
static void scene_settings_subghz_ext_changed(VariableItem* item) {
App* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, subghz_ext_text[index]);
app->settings.subghz_use_ext_antenna = subghz_ext_value[index];
variable_item_set_current_value_text(item, disabled_enabled_text[index]);
app->settings.subghz_use_ext_antenna = disabled_enabled_value[index];
}

static void scene_settings_ir_ext_changed(VariableItem* item) {
App* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, ir_ext_text[index]);
app->settings.ir_use_ext_module = ir_ext_value[index];
variable_item_set_current_value_text(item, disabled_enabled_text[index]);
app->settings.ir_use_ext_module = disabled_enabled_value[index];
}

static void scene_settings_show_hidden_changed(VariableItem* item) {
Expand Down Expand Up @@ -188,14 +179,15 @@ void scene_settings_on_enter(void* context) {

item =
variable_item_list_add(vil, "SubGHz Ext Ant", 2, scene_settings_subghz_ext_changed, app);
value_index = value_index_uint32(app->settings.subghz_use_ext_antenna, subghz_ext_value, 2);
value_index =
value_index_uint32(app->settings.subghz_use_ext_antenna, disabled_enabled_value, 2);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, subghz_ext_text[value_index]);
variable_item_set_current_value_text(item, disabled_enabled_text[value_index]);

item = variable_item_list_add(vil, "IR Ext Module", 2, scene_settings_ir_ext_changed, app);
value_index = value_index_uint32(app->settings.ir_use_ext_module, ir_ext_value, 2);
value_index = value_index_uint32(app->settings.ir_use_ext_module, disabled_enabled_value, 2);
variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, ir_ext_text[value_index]);
variable_item_set_current_value_text(item, disabled_enabled_text[value_index]);

item = variable_item_list_add(vil, "Show Hidden", 2, scene_settings_show_hidden_changed, app);
value_index = value_index_uint32(app->settings.show_hidden, show_offon_value, 2);
Expand All @@ -215,7 +207,7 @@ bool scene_settings_on_event(void* context, SceneManagerEvent event) {

if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case SceneSettingsAbout:
case SCENE_SETTINGS_ABOUT:
consumed = true;
scene_manager_next_scene(app->scene_manager, QScene_About);
break;
Expand Down

0 comments on commit bb6373b

Please sign in to comment.