Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
palette_fade_mode.hpp
Go to the documentation of this file.
1#ifndef PALETTE_FADE_HPP
2#define PALETTE_FADE_HPP
3
5
6#include <cmath>
8
9#include <cstdint>
11
16{
18 static constexpr bool hasCustomRamp = true;
19
20 static void on_enter_mode(auto& ctx)
21 {
22 //
23 ctx.template set_config_bool<ConfigKeys::rampSaturates>(true);
24
25 ctx.state.paletteIndex = 0;
26 }
27
28 static void loop(auto& ctx)
29 {
30 // ramp controls the speed
31 static constexpr uint32_t lowestTiming = 20000;
32 static constexpr uint32_t highestTiming = 3000;
33 // map ramp to period
34 const float wholePaletteLoopTiming =
35 lmpd_map<float>(ctx.get_active_custom_ramp(), 0, 255, lowestTiming, highestTiming);
36
37 const float adding = wholePaletteLoopTiming / static_cast<float>(ctx.lamp.frameDurationMs);
38 ctx.state.paletteIndex += 255.0 / adding;
39 ctx.state.paletteIndex = std::fmod(ctx.state.paletteIndex, 255.0f);
40
41 ctx.lamp.fill(modes::colors::from_palette(static_cast<uint8_t>(ctx.state.paletteIndex), ctx.state.palette));
42 }
43
45 static constexpr bool hasSunsetAnimation = true;
46 static constexpr bool hasSunriseAnimation = true;
47 // Use the two internal gravity modes, so no need to define the callbacks
48 static constexpr bool usesSunsetGravityDissolveMode = true;
49 static constexpr bool usesSunriseGravityAppearMode = true;
50};
51
56{
57 struct StateTy
58 {
63 };
64};
65
66} // namespace lampda::modes::default_modes
67
68#endif
static constexpr uint32_t from_palette(const UIntTy index, const PaletteTy &palette, const uint8_t brightness=255)
Return a color from a palette.
Definition: palettes.hpp:504
std::array< uint32_t, 16 > PaletteTy
Palette types.
Definition: palettes.hpp:18
static constexpr PaletteTy PaletteRainbowColors
HSV Rainbow.
Definition: palettes.hpp:360
Basic "default" modes included with the hardware.
Definition: aurora.hpp:12
Define some useful color palettes, and tools to use them.
Parent object for all custom user modes.
Definition: mode_type.hpp:53
Fade between colors of a palette.
Definition: palette_fade_mode.hpp:16
static constexpr bool hasSunsetAnimation
sunset & sunrise animation on the fixed modes
Definition: palette_fade_mode.hpp:45
static constexpr bool hasCustomRamp
hint manager to save our custom ramp
Definition: palette_fade_mode.hpp:18
static constexpr modes::colors::PaletteTy palette
Color palette to display.
Definition: palette_fade_mode.hpp:60
float paletteIndex
actual palette index
Definition: palette_fade_mode.hpp:62
Fade between the colors of the PartyColor palette.
Definition: palette_fade_mode.hpp:56