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"
22 static constexpr bool hasSunriseAnimation =
true;
24 static constexpr bool usesSunsetGravityDissolveMode =
true;
25 static constexpr bool usesSunriseGravityAppearMode =
true;
27 static void loop(
auto& ctx)
30 const uint8_t customRamp = ctx.get_active_custom_ramp();
31 const uint8_t customIndex = ctx.get_active_custom_index();
32 const uint16_t compressedColor = customRamp << 8 | customIndex;
33 const uint32_t color = colors::get_decompressed_32b_color(compressedColor);
41uint32_t get_color_at(
size_t index)
44 assert(
false and
"Invalid color index reached");
48template<
typename Head,
typename... Tail> uint32_t get_color_at(
size_t index, Head head, Tail... tail)
52 return get_color_at(index - 1, tail...);
58 static constexpr float fadeRate = fadeRateUint / (2.0 * UINT8_MAX);
59 static constexpr size_t colorCount =
sizeof...(fadeColors);
60 static_assert((fadeRate == 0 and colorCount != 0) or (fadeRate > 0 and colorCount >= 2),
61 "Cannot fade colors without at least two colors");
67 static constexpr bool hasSunriseAnimation =
true;
69 static constexpr bool usesSunsetGravityDissolveMode =
true;
70 static constexpr bool usesSunriseGravityAppearMode =
true;
74 uint32_t colorStartTime_ms;
78 static uint32_t next_color_index(
auto& ctx)
80 const uint32_t nextIndex = ctx.state.colorIndex + 1;
81 if (nextIndex >= colorCount)
86 static void on_enter_mode(
auto& ctx)
88 ctx.template set_config_bool<ConfigKeys::rampSaturates>(
true);
90 ctx.state.colorStartTime_ms = ctx.lamp.now;
91 ctx.state.colorIndex = 0;
94 static void loop(
auto& ctx)
97 static constexpr uint32_t lowestTiming = fastMode ? 100 : 1000;
98 static constexpr uint32_t highestTiming = fastMode ? 15 : 100;
100 const uint32_t wholePaletteLoopTiming =
101 lmpd_map<float>(ctx.get_active_custom_ramp(), 0, 255, lowestTiming, highestTiming);
103 uint32_t timeSinceStart = ctx.lamp.now - ctx.state.colorStartTime_ms;
104 if (timeSinceStart >= wholePaletteLoopTiming)
106 ctx.state.colorStartTime_ms = ctx.lamp.now;
107 ctx.state.colorIndex = next_color_index(ctx);
109 timeSinceStart = ctx.lamp.now - ctx.state.colorStartTime_ms;
112 uint32_t color = __private::get_color_at(ctx.state.colorIndex, fadeColors...);
114 if constexpr (fadeRateUint != 0)
116 const uint32_t fixedTime_ms = wholePaletteLoopTiming * (1.0 - fadeRate);
117 if (timeSinceStart >= fixedTime_ms)
119 const uint32_t fadeTime_ms = wholePaletteLoopTiming * fadeRate;
120 const float fadeProgress =
121 lmpd_constrain((timeSinceStart - fixedTime_ms) /
static_cast<float>(fadeTime_ms), 0.0f, 0.95f);
122 const uint32_t colorEnd = __private::get_color_at(next_color_index(ctx), fadeColors...);
127 ctx.lamp.fill(color);
Manipulate color representations.
Contains basic interface types to implement custom user modes.
Definition: control_fixed_modes.hpp:14
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
Definition: control_fixed_modes.hpp:19
static constexpr bool hasSunsetAnimation
sunset & sunrise animation on the fixed modes
Definition: control_fixed_modes.hpp:21
Definition: control_fixed_modes.hpp:73
Definition: control_fixed_modes.hpp:57
static constexpr bool hasSunsetAnimation
sunset & sunrise animation on the fixed modes
Definition: control_fixed_modes.hpp:66
static constexpr bool hasCustomRamp
hint manager to save our custom ramp
Definition: control_fixed_modes.hpp:64
Definition: control_fixed_modes.hpp:144
fixed modes
Definition: control_fixed_modes.hpp:133
Definition: control_fixed_modes.hpp:149
jump color
Definition: control_fixed_modes.hpp:138