From b8a6ba70286d00500178b7560a049e7df0d14c2d Mon Sep 17 00:00:00 2001 From: HaxSam Date: Sat, 6 Apr 2024 17:19:42 +0200 Subject: [PATCH] use all the 32bit modified: applications/main/momentum_app/scenes/momentum_app_scene_misc_vgm.c modified: applications/services/rpc/rpc_gui.c modified: lib/momentum/momentum.h modified: lib/momentum/rpc_rgb.c modified: lib/momentum/rpc_rgb.h modified: applications/main/momentum_app/scenes/momentum_app_scene_misc_vgm.c modified: applications/services/rpc/rpc_gui.c modified: lib/momentum/momentum.h modified: lib/momentum/rpc_rgb.c modified: lib/momentum/rpc_rgb.h --- .../scenes/momentum_app_scene_misc_vgm.c | 43 +++++++++++++++++-- applications/services/rpc/rpc_gui.c | 6 ++- lib/momentum/momentum.h | 12 +++++- lib/momentum/rpc_rgb.c | 41 ------------------ lib/momentum/rpc_rgb.h | 15 ------- 5 files changed, 53 insertions(+), 64 deletions(-) diff --git a/applications/main/momentum_app/scenes/momentum_app_scene_misc_vgm.c b/applications/main/momentum_app/scenes/momentum_app_scene_misc_vgm.c index f52f4470eb..47e798864b 100644 --- a/applications/main/momentum_app/scenes/momentum_app_scene_misc_vgm.c +++ b/applications/main/momentum_app/scenes/momentum_app_scene_misc_vgm.c @@ -17,11 +17,18 @@ const char* const colors_names[VgmColorModeCount] = { "Rainbow", "RGB Backlight", }; + static void momentum_app_scene_misc_vgm_colors_changed(VariableItem* item) { MomentumApp* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, colors_names[index]); momentum_settings.vgm_color_mode = index; + + if(index == VgmColorModeDefault) { + momentum_settings.vgm_color_fg.mode = VgmColorModeDefault; + momentum_settings.vgm_color_bg.mode = VgmColorModeDefault; + } + app->save_settings = true; variable_item_set_locked( variable_item_list_get(app->var_item_list, VarItemListIndexForeground), @@ -39,6 +46,8 @@ static const struct { } vgm_colors[] = { // clang-format off {"Off", {{0, 0, 0}}}, + {"Rainbow", {{0, 0, 0}}}, + {"RgbMod", {{0, 0, 0}}}, {"Orange", {{255, 69, 0}}}, {"Red", {{255, 0, 0}}}, {"Maroon", {{128, 0, 0}}}, @@ -59,19 +68,40 @@ static const struct { {"White", {{255, 192, 203}}}, // clang-format on }; + static const size_t vgm_colors_count = COUNT_OF(vgm_colors); + static void momentum_app_scene_misc_vgm_foreground_changed(VariableItem* item) { MomentumApp* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, vgm_colors[index].name); - momentum_settings.vgm_color_fg = vgm_colors[index].color; + momentum_settings.vgm_color_fg.rgb = vgm_colors[index].color; + + if(strcmp("Rainbow", vgm_colors[index].name) == 0) { + momentum_settings.vgm_color_fg.mode = VgmColorModeRainbow; + } + if(strcmp("RgbMod", vgm_colors[index].name) == 0) { + momentum_settings.vgm_color_fg.mode = VgmColorModeRgbBacklight; + rgb_backlight_get_color(0, &momentum_settings.vgm_color_fg.rgb); + } + app->save_settings = true; } + static void momentum_app_scene_misc_vgm_background_changed(VariableItem* item) { MomentumApp* app = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, vgm_colors[index].name); - momentum_settings.vgm_color_bg = vgm_colors[index].color; + momentum_settings.vgm_color_bg.rgb = vgm_colors[index].color; + + if(strcmp("Rainbow", vgm_colors[index].name) == 0) { + momentum_settings.vgm_color_bg.mode = VgmColorModeRainbow; + } + if(strcmp("RgbMod", vgm_colors[index].name) == 0) { + momentum_settings.vgm_color_bg.mode = VgmColorModeRgbBacklight; + rgb_backlight_get_color(0, &momentum_settings.vgm_color_bg.rgb); + } + app->save_settings = true; } @@ -97,14 +127,16 @@ void momentum_app_scene_misc_vgm_on_enter(void* context) { vgm_colors_count, momentum_app_scene_misc_vgm_foreground_changed, app); - RgbColor color = momentum_settings.vgm_color_fg; + RgbColor color = momentum_settings.vgm_color_fg.rgb; bool found = false; + for(size_t i = 0; i < vgm_colors_count; i++) { if(rgbcmp(&color, &vgm_colors[i].color) != 0) continue; value_index = i; found = true; break; } + variable_item_set_current_value_index(item, found ? value_index : vgm_colors_count); if(found) { variable_item_set_current_value_text(item, vgm_colors[value_index].name); @@ -122,14 +154,16 @@ void momentum_app_scene_misc_vgm_on_enter(void* context) { vgm_colors_count, momentum_app_scene_misc_vgm_background_changed, app); - color = momentum_settings.vgm_color_bg; + color = momentum_settings.vgm_color_bg.rgb; found = false; + for(size_t i = 0; i < vgm_colors_count; i++) { if(rgbcmp(&color, &vgm_colors[i].color) != 0) continue; value_index = i; found = true; break; } + variable_item_set_current_value_index(item, found ? value_index : vgm_colors_count); if(found) { variable_item_set_current_value_text(item, vgm_colors[value_index].name); @@ -157,6 +191,7 @@ bool momentum_app_scene_misc_vgm_on_event(void* context, SceneManagerEvent event if(event.type == SceneManagerEventTypeCustom) { scene_manager_set_scene_state(app->scene_manager, MomentumAppSceneMiscVgm, event.event); consumed = true; + switch(event.event) { case VarItemListIndexForeground: case VarItemListIndexBackground: diff --git a/applications/services/rpc/rpc_gui.c b/applications/services/rpc/rpc_gui.c index 3ef2a0edaa..513e6141dd 100644 --- a/applications/services/rpc/rpc_gui.c +++ b/applications/services/rpc/rpc_gui.c @@ -98,8 +98,10 @@ static void rpc_system_gui_screen_stream_frame_callback( rpc_gui->transmit_frame->content.gui_screen_frame.orientation = rpc_system_gui_screen_orientation_map[orientation]; - rpc_gui->transmit_frame->content.gui_screen_frame.fg_color = get_screen_color_fg(); - rpc_gui->transmit_frame->content.gui_screen_frame.bg_color = get_screen_color_bg(); + rpc_gui->transmit_frame->content.gui_screen_frame.fg_color = + momentum_settings.vgm_color_fg.value; + rpc_gui->transmit_frame->content.gui_screen_frame.bg_color = + momentum_settings.vgm_color_bg.value; furi_thread_flags_set(furi_thread_get_id(rpc_gui->transmit_thread), RpcGuiWorkerFlagTransmit); } diff --git a/lib/momentum/momentum.h b/lib/momentum/momentum.h index f595f2154f..f8d943f8e3 100644 --- a/lib/momentum/momentum.h +++ b/lib/momentum/momentum.h @@ -53,6 +53,14 @@ typedef enum { VgmColorModeCount, } VgmColorMode; +typedef union __attribute__((packed)) { + struct { + VgmColorMode mode; + RgbColor rgb; + }; + uint32_t value; +} RgbColorTransmit; + typedef struct { char asset_pack[ASSET_PACKS_NAME_LEN]; uint32_t anim_speed; @@ -89,8 +97,8 @@ typedef struct { bool file_naming_prefix_after; VgmColorMode vgm_color_mode; FuriHalVersionColor spoof_color; - RgbColor vgm_color_fg; - RgbColor vgm_color_bg; + RgbColorTransmit vgm_color_fg; + RgbColorTransmit vgm_color_bg; } MomentumSettings; typedef struct { diff --git a/lib/momentum/rpc_rgb.c b/lib/momentum/rpc_rgb.c index 24f6c8e1d3..80089c2bac 100644 --- a/lib/momentum/rpc_rgb.c +++ b/lib/momentum/rpc_rgb.c @@ -1,42 +1 @@ #include "rpc_rgb.h" - -#include "drivers/rgb_backlight.h" - -uint32_t get_screen_color_fg() { - RgbColorTransmit color = { - .mode = momentum_settings.vgm_color_mode, - .rgb = {{0, 0, 0}}, - }; - - switch(momentum_settings.vgm_color_mode) { - case VgmColorModeCustom: - color.rgb = momentum_settings.vgm_color_fg; - break; - case VgmColorModeRgbBacklight: - break; - default: - break; - } - - return color.value; -} - -uint32_t get_screen_color_bg() { - RgbColorTransmit color = { - .mode = momentum_settings.vgm_color_mode, - .rgb = {{255, 130, 0}}, - }; - - switch(momentum_settings.vgm_color_mode) { - case VgmColorModeCustom: - color.rgb = momentum_settings.vgm_color_bg; - break; - case VgmColorModeRgbBacklight: - rgb_backlight_get_color(0, &color.rgb); - break; - default: - break; - } - - return color.value; -} diff --git a/lib/momentum/rpc_rgb.h b/lib/momentum/rpc_rgb.h index 36a5897389..eda1bfe259 100644 --- a/lib/momentum/rpc_rgb.h +++ b/lib/momentum/rpc_rgb.h @@ -6,21 +6,6 @@ extern "C" { #endif -typedef union __attribute__((packed)) { - struct { - VgmColorMode mode : 8; - RgbColor rgb; - }; - uint32_t value; -} RgbColorTransmit; - -void rpc_rgb_init(); - -uint32_t get_screen_color_fg(); -uint32_t get_screen_color_bg(); - -void rpc_rgb_deinit(); - #ifdef __cplusplus } #endif