From b94c71b14f71cdbcce0178afdefcf3811c9cd99d Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 21 Mar 2023 17:46:46 +0000 Subject: [PATCH] RGB backlight toggle as button with confirmation --- .../xtreme_app/scenes/xtreme_app_scene_misc.c | 54 +++++++++++-------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc.c index ff697428a..ff5775f57 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc.c @@ -2,9 +2,10 @@ enum VarItemListIndex { VarItemListIndexChangeDeviceName, - VarItemListIndexRgbBacklight, VarItemListIndexXpLevel, VarItemListIndexButthurtTimer, + VarItemListIndexRgbBacklight, + VarItemListIndexLcdColor, }; void xtreme_app_scene_misc_var_item_list_callback(void* context, uint32_t index) { @@ -21,23 +22,6 @@ static void xtreme_app_scene_misc_xp_level_changed(VariableItem* item) { app->save_level = true; } -static void xtreme_app_scene_misc_rgb_backlight_changed(VariableItem* item) { - XtremeApp* app = variable_item_get_context(item); - bool value = variable_item_get_current_value_index(item); - variable_item_set_current_value_text(item, value ? "ON" : "OFF"); - XTREME_SETTINGS()->rgb_backlight = value; - app->save_settings = true; - notification_message(app->notification, &sequence_display_backlight_on); -} - -static void xtreme_app_scene_misc_lcd_color_changed(VariableItem* item) { - XtremeApp* app = variable_item_get_context(item); - uint8_t index = variable_item_get_current_value_index(item); - variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index)); - rgb_backlight_set_color(index); - notification_message(app->notification, &sequence_display_backlight_on); -} - const char* const butthurt_timer_names[] = {"OFF", "30 M", "1 H", "2 H", "4 H", "6 H", "8 H", "12 H", "24 H", "48 H"}; const int32_t butthurt_timer_values[COUNT_OF(butthurt_timer_names)] = @@ -51,6 +35,14 @@ static void xtreme_app_scene_misc_butthurt_timer_changed(VariableItem* item) { app->require_reboot = true; } +static void xtreme_app_scene_misc_lcd_color_changed(VariableItem* item) { + XtremeApp* app = variable_item_get_context(item); + uint8_t index = variable_item_get_current_value_index(item); + variable_item_set_current_value_text(item, rgb_backlight_get_color_text(index)); + rgb_backlight_set_color(index); + notification_message(app->notification, &sequence_display_backlight_on); +} + void xtreme_app_scene_misc_on_enter(void* context) { XtremeApp* app = context; XtremeSettings* xtreme_settings = XTREME_SETTINGS(); @@ -82,9 +74,7 @@ void xtreme_app_scene_misc_on_enter(void* context) { variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, butthurt_timer_names[value_index]); - item = variable_item_list_add( - var_item_list, "RGB Backlight", 2, xtreme_app_scene_misc_rgb_backlight_changed, app); - variable_item_set_current_value_index(item, xtreme_settings->rgb_backlight); + item = variable_item_list_add(var_item_list, "RGB Backlight", 1, NULL, app); variable_item_set_current_value_text(item, xtreme_settings->rgb_backlight ? "ON" : "OFF"); item = variable_item_list_add( @@ -118,6 +108,28 @@ bool xtreme_app_scene_misc_on_event(void* context, SceneManagerEvent event) { case VarItemListIndexChangeDeviceName: scene_manager_next_scene(app->scene_manager, XtremeAppSceneMiscRename); break; + case VarItemListIndexRgbBacklight: { + bool value = XTREME_SETTINGS()->rgb_backlight; + char* text; + if(value) { + text = "This will disable\nthe RGB backlight!\nAre you sure?"; + } else { + text = "This will enable\nthe RGB backlight!\nAre you sure?"; + } + DialogMessage* msg = dialog_message_alloc(); + dialog_message_set_header(msg, "RGB Backlight", 64, 0, AlignCenter, AlignTop); + dialog_message_set_buttons(msg, "Cancel", NULL, "Continue"); + dialog_message_set_text(msg, text, 64, 32, AlignCenter, AlignCenter); + if(dialog_message_show(app->dialogs, msg) == DialogMessageButtonRight) { + XTREME_SETTINGS()->rgb_backlight = !value; + app->save_settings = true; + notification_message(app->notification, &sequence_display_backlight_on); + scene_manager_previous_scene(app->scene_manager); + scene_manager_next_scene(app->scene_manager, XtremeAppSceneMisc); + } + dialog_message_free(msg); + break; + } default: break; }