From 2de8a27d895c6a7a251942e4a7327af9c383a62d Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 6 Sep 2024 22:59:02 +0500 Subject: [PATCH] Allow to set color more precisely in solid color mode using 'light' --- src/application.cpp | 4 +++- src/fx/color_efect.cpp | 4 +++- src/fx/type.h | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/application.cpp b/src/application.cpp index 6c4760a..ab3db6b 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -157,6 +157,7 @@ void Application::change_color(uint32_t color) { memcpy(preset_names.names[preset_index], preset_name, std::min(preset_names.length, strlen(preset_name))); preset.color_effect = ColorEffectEnum::SOLID; + preset.brightness_effect = BrightnessEffectEnum::FIXED; config.preset_id = preset_index; auto rgb = CRGB(color); @@ -167,6 +168,7 @@ void Application::change_color(uint32_t color) { preset.speed = hsv.h; preset.scale = hsv.s; + preset.light = hsv.l; load(); } @@ -176,7 +178,7 @@ uint32_t Application::current_color() { auto &preset = preset_configs.presets[preset_index]; if (preset.color_effect == ColorEffectEnum::SOLID) { - return HSLToRGB({preset.speed, preset.scale, 127}); + return HSLToRGB({preset.speed, preset.scale, preset.light}); } return 0xffffff; diff --git a/src/fx/color_efect.cpp b/src/fx/color_efect.cpp index 8c97d35..abcf36b 100644 --- a/src/fx/color_efect.cpp +++ b/src/fx/color_efect.cpp @@ -31,6 +31,8 @@ void ColorEffectManager::call(Led &led, const PaletteT *palette, const PresetCon _state.params.scale = config.scale; _state.params.palette = palette; + _state.extra.light = config.brightness_effect == BrightnessEffectEnum::FIXED ? config.light : 127; + #if GAMMA_CORRECTION_RT == ENABLED _state.params.gamma_correction = gamma > 0; _state.params.gamma = gamma_value(gamma); @@ -80,7 +82,7 @@ void ColorEffectManager::solid(Led &led, ColorEffectState &state) { gamma_correction, gamma ] = state.params; - auto color = HSLToRGB({speed, scale, 127}); + auto color = HSLToRGB({speed, scale, state.extra.light}); led.fill_solid(color); if (gamma_correction) led.apply_gamma_correction(gamma); diff --git a/src/fx/type.h b/src/fx/type.h index 5c1123d..734bb42 100644 --- a/src/fx/type.h +++ b/src/fx/type.h @@ -36,6 +36,10 @@ struct ColorEffectState : FxStateBase { bool gamma_correction = false; float gamma = 0; } params; + + struct { + byte light = 0; + } extra; }; typedef void(*ColorEffectFn)(Led &led, ColorEffectState &state);