Skip to content

Commit

Permalink
Allow to set color more precisely in solid color mode using 'light'
Browse files Browse the repository at this point in the history
  • Loading branch information
DrA1ex committed Sep 6, 2024
1 parent a78b652 commit 2de8a27
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ void Application::change_color(uint32_t color) {
memcpy(preset_names.names[preset_index], preset_name, std::min<uint8_t>(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);
Expand All @@ -167,6 +168,7 @@ void Application::change_color(uint32_t color) {

preset.speed = hsv.h;
preset.scale = hsv.s;
preset.light = hsv.l;

load();
}
Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/fx/color_efect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/fx/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2de8a27

Please sign in to comment.