From cee43d5b790b4235587e84b5c56ec4adb7f8ca6f Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 15 Aug 2023 01:51:04 +0200 Subject: [PATCH] Custom lcd color --- .../scenes/xtreme_app_scene_config.h | 1 + .../scenes/xtreme_app_scene_misc_screen.c | 3 + .../xtreme_app_scene_misc_screen_color.c | 56 +++++++++++++++++++ applications/main/xtreme_app/xtreme_app.c | 6 ++ applications/main/xtreme_app/xtreme_app.h | 4 ++ 5 files changed, 70 insertions(+) create mode 100644 applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen_color.c diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_config.h b/applications/main/xtreme_app/scenes/xtreme_app_scene_config.h index 4d9b161ed..16a9436ad 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_config.h +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_config.h @@ -16,5 +16,6 @@ ADD_SCENE(xtreme_app, protocols_freqs_add, ProtocolsFreqsAdd) ADD_SCENE(xtreme_app, protocols_gpio, ProtocolsGpio) ADD_SCENE(xtreme_app, misc, Misc) ADD_SCENE(xtreme_app, misc_screen, MiscScreen) +ADD_SCENE(xtreme_app, misc_screen_color, MiscScreenColor) ADD_SCENE(xtreme_app, misc_dolphin, MiscDolphin) ADD_SCENE(xtreme_app, misc_rename, MiscRename) diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c index 76ae26baf..795da826c 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen.c @@ -248,6 +248,9 @@ bool xtreme_app_scene_misc_screen_on_event(void* context, SceneManagerEvent even } break; } + case VarItemListIndexLcdColor: + scene_manager_next_scene(app->scene_manager, XtremeAppSceneMiscScreenColor); + break; default: break; } diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen_color.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen_color.c new file mode 100644 index 000000000..f364e4d1a --- /dev/null +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_misc_screen_color.c @@ -0,0 +1,56 @@ +#include "../xtreme_app.h" + +enum ByteInputResult { + ByteInputResultOk, +}; + +void xtreme_app_scene_misc_screen_color_byte_input_callback(void* context) { + XtremeApp* app = context; + + view_dispatcher_send_custom_event(app->view_dispatcher, ByteInputResultOk); +} + +void xtreme_app_scene_misc_screen_color_on_enter(void* context) { + XtremeApp* app = context; + ByteInput* byte_input = app->byte_input; + + byte_input_set_header_text(byte_input, "Set LCD Color (#RRGGBB)"); + + app->lcd_color = rgb_backlight_get_color(); + + byte_input_set_result_callback( + byte_input, + xtreme_app_scene_misc_screen_color_byte_input_callback, + NULL, + app, + (void*)&app->lcd_color, + sizeof(app->lcd_color)); + + view_dispatcher_switch_to_view(app->view_dispatcher, XtremeAppViewByteInput); +} + +bool xtreme_app_scene_misc_screen_color_on_event(void* context, SceneManagerEvent event) { + XtremeApp* app = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + consumed = true; + switch(event.event) { + case ByteInputResultOk: + rgb_backlight_set_color(app->lcd_color); + app->save_backlight = true; + scene_manager_previous_scene(app->scene_manager); + break; + default: + break; + } + } + + return consumed; +} + +void xtreme_app_scene_misc_screen_color_on_exit(void* context) { + XtremeApp* app = context; + byte_input_set_result_callback(app->byte_input, NULL, NULL, NULL, NULL, 0); + byte_input_set_header_text(app->byte_input, ""); +} diff --git a/applications/main/xtreme_app/xtreme_app.c b/applications/main/xtreme_app/xtreme_app.c index f73390e52..ce198a3e4 100644 --- a/applications/main/xtreme_app/xtreme_app.c +++ b/applications/main/xtreme_app/xtreme_app.c @@ -193,6 +193,10 @@ XtremeApp* xtreme_app_alloc() { view_dispatcher_add_view( app->view_dispatcher, XtremeAppViewTextInput, text_input_get_view(app->text_input)); + app->byte_input = byte_input_alloc(); + view_dispatcher_add_view( + app->view_dispatcher, XtremeAppViewByteInput, byte_input_get_view(app->byte_input)); + app->popup = popup_alloc(); view_dispatcher_add_view(app->view_dispatcher, XtremeAppViewPopup, popup_get_view(app->popup)); @@ -315,6 +319,8 @@ void xtreme_app_free(XtremeApp* app) { submenu_free(app->submenu); view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewTextInput); text_input_free(app->text_input); + view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewByteInput); + byte_input_free(app->byte_input); view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewPopup); popup_free(app->popup); view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewDialogEx); diff --git a/applications/main/xtreme_app/xtreme_app.h b/applications/main/xtreme_app/xtreme_app.h index 995b00310..7fbee8bcb 100644 --- a/applications/main/xtreme_app/xtreme_app.h +++ b/applications/main/xtreme_app/xtreme_app.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -42,6 +43,7 @@ typedef struct { VariableItemList* var_item_list; Submenu* submenu; TextInput* text_input; + ByteInput* byte_input; Popup* popup; DialogEx* dialog_ex; @@ -57,6 +59,7 @@ typedef struct { uint8_t subghz_hopper_index; char subghz_freq_buffer[XTREME_SUBGHZ_FREQ_BUFFER_SIZE]; bool subghz_extend; + RgbColor lcd_color; char device_name[FURI_HAL_VERSION_ARRAY_NAME_LENGTH]; int32_t dolphin_level; int32_t dolphin_angry; @@ -79,6 +82,7 @@ typedef enum { XtremeAppViewVarItemList, XtremeAppViewSubmenu, XtremeAppViewTextInput, + XtremeAppViewByteInput, XtremeAppViewPopup, XtremeAppViewDialogEx, } XtremeAppView;