1#ifndef MODES_BLUETOOTH_CONTROLFIXEDMODES_H
2#define MODES_BLUETOOTH_CONTROLFIXEDMODES_H
6#include "src/system/ext/math8.h"
7#include "src/system/ext/noise.h"
24 static constexpr uint8_t dissolveBufferId = 0;
32 static void on_enter_mode(
auto& ctx) { ctx.state.sunsetAnimation.reset(ctx); }
34 static void loop(
auto& ctx)
37 const uint8_t customRamp = ctx.get_active_custom_ramp();
38 const uint8_t customIndex = ctx.get_active_custom_index();
39 const uint16_t compressedColor = customRamp << 8 | customIndex;
40 const uint32_t color = colors::get_decompressed_32b_color(compressedColor);
42 ctx.lamp.fill(color, ctx.lamp.template getTempBuffer<dissolveBufferId>());
45 ctx.state.sunsetAnimation.loop(ctx, color);
49 static void sunset_update(
auto& ctx,
float progress) { ctx.state.sunsetAnimation.update_depop_rate(ctx, progress); }
54uint32_t get_color_at(
size_t index)
57 assert(
false and
"Invalid color index reached");
61template<
typename Head,
typename... Tail> uint32_t get_color_at(
size_t index, Head head, Tail... tail)
65 return get_color_at(index - 1, tail...);
71 static constexpr float fadeRate = fadeRateUint / (2.0 * UINT8_MAX);
72 static constexpr size_t colorCount =
sizeof...(fadeColors);
73 static_assert((fadeRate == 0 and colorCount != 0) or (fadeRate > 0 and colorCount >= 2),
74 "Cannot fade colors without at least two colors");
81 static constexpr uint8_t dissolveBufferId = 0;
85 uint32_t colorStartTime_ms;
92 static uint32_t next_color_index(
auto& ctx)
94 const uint32_t nextIndex = ctx.state.colorIndex + 1;
95 if (nextIndex >= colorCount)
100 static void on_enter_mode(
auto& ctx)
102 ctx.template set_config_bool<ConfigKeys::rampSaturates>(
true);
104 ctx.state.colorStartTime_ms = ctx.lamp.now;
105 ctx.state.colorIndex = 0;
107 ctx.state.sunsetAnimation.reset(ctx);
110 static void loop(
auto& ctx)
113 static constexpr uint32_t lowestTiming = fastMode ? 100 : 1000;
114 static constexpr uint32_t highestTiming = fastMode ? 15 : 100;
116 const uint32_t wholePaletteLoopTiming =
117 lmpd_map<float>(ctx.get_active_custom_ramp(), 0, 255, lowestTiming, highestTiming);
119 uint32_t timeSinceStart = ctx.lamp.now - ctx.state.colorStartTime_ms;
120 if (timeSinceStart >= wholePaletteLoopTiming)
122 ctx.state.colorStartTime_ms = ctx.lamp.now;
123 ctx.state.colorIndex = next_color_index(ctx);
125 timeSinceStart = ctx.lamp.now - ctx.state.colorStartTime_ms;
128 uint32_t color = __private::get_color_at(ctx.state.colorIndex, fadeColors...);
130 if constexpr (fadeRateUint != 0)
132 const uint32_t fixedTime_ms = wholePaletteLoopTiming * (1.0 - fadeRate);
133 if (timeSinceStart >= fixedTime_ms)
135 const uint32_t fadeTime_ms = wholePaletteLoopTiming * fadeRate;
136 const float fadeProgress =
137 lmpd_constrain((timeSinceStart - fixedTime_ms) /
static_cast<float>(fadeTime_ms), 0.0f, 0.95f);
138 const uint32_t colorEnd = __private::get_color_at(next_color_index(ctx), fadeColors...);
143 ctx.lamp.fill(color, ctx.lamp.template getTempBuffer<dissolveBufferId>());
146 ctx.state.sunsetAnimation.loop(ctx, color);
150 static void sunset_update(
auto& ctx,
float progress) { ctx.state.sunsetAnimation.update_depop_rate(ctx, progress); }
Manipulate color representations.
Define some animations to fade out modes.
Contains basic interface types to implement custom user modes.
Definition: control_fixed_modes.hpp:15
uint32_t get_gradient(const uint32_t colorStart, const uint32_t colorEnd, const float level)
Return the color gradient between colorStart to colorEnd.
Definition: utils.cpp:60
static constexpr T lmpd_constrain(const T &a, const T &mini, const T &maxi)
Constrain a number between two numbers.
Definition: utils.h:57
Define some useful color palettes, and tools to use them.
Parent object for all custom user modes.
Definition: mode_type.hpp:53
Make an animation disapear with gravity.
Definition: fadeout.hpp:196
Definition: control_fixed_modes.hpp:27
Definition: control_fixed_modes.hpp:20
static void sunset_update(auto &ctx, float progress)
Sunset timer will drop pixels downward, and never display them again.
Definition: control_fixed_modes.hpp:49
static constexpr bool hasSunsetAnimation
sunset animation on the fixed modes
Definition: control_fixed_modes.hpp:22
Definition: control_fixed_modes.hpp:84
Definition: control_fixed_modes.hpp:70
static constexpr bool hasSunsetAnimation
sunset animation on the fixed modes
Definition: control_fixed_modes.hpp:79
static constexpr bool hasCustomRamp
hint manager to save our custom ramp
Definition: control_fixed_modes.hpp:77
static void sunset_update(auto &ctx, float progress)
Sunset timer will drop pixels downward, and never display them again.
Definition: control_fixed_modes.hpp:150
Definition: control_fixed_modes.hpp:166
fixed modes
Definition: control_fixed_modes.hpp:155
Definition: control_fixed_modes.hpp:171
jump color
Definition: control_fixed_modes.hpp:160