Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
rainbow_swirl_mode.hpp
Go to the documentation of this file.
1#ifndef RAINBOW_SWIRL_MODE_HPP
2#define RAINBOW_SWIRL_MODE_HPP
3
5
7
8#include <cstdint>
10
15{
16 struct StateTy
17 {
19 uint32_t increment;
21 uint16_t firstPixelHue;
22 };
23
24 static void on_enter_mode(auto& ctx)
25 {
26 //
27 static constexpr uint32_t animationPeriod_ms = 5000;
28 ctx.state.increment = (UINT16_MAX / (animationPeriod_ms / ctx.lamp.frameDurationMs));
29 ctx.state.firstPixelHue = 0;
30 }
31
32 static void loop(auto& ctx)
33 {
34 const uint16_t firstPixelColor = ctx.state.firstPixelHue;
35 const float multiplier = UINT16_MAX / static_cast<float>(ctx.lamp.ledCount);
36 for (size_t i = 0; i < ctx.lamp.ledCount; i++)
37 {
38 const uint16_t pixelHue = firstPixelColor + i * multiplier;
39 uint32_t color = colors::fromAngleHue(lmpd_map<uint16_t>(pixelHue, 0, UINT16_MAX, 0, 360));
40 ctx.lamp.setPixelColor(i, color);
41 }
42
43 // update first led color
44 ctx.state.firstPixelHue += ctx.state.increment;
45 }
46
48 static constexpr bool hasSunsetAnimation = true;
49 static constexpr bool hasSunriseAnimation = true;
50 // Use the two internal gravity modes, so no need to define the callbacks
51 static constexpr bool usesSunsetGravityDissolveMode = true;
52 static constexpr bool usesSunriseGravityAppearMode = true;
53};
54
55} // namespace lampda::modes::default_modes
56
57#endif
static constexpr LMBD_INLINE uint32_t fromAngleHue(uint16_t angleDegrees)
Given a 360 degrees angle, return a corresponding color as an integer.
Definition: utils.hpp:71
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
Definition: rainbow_swirl_mode.hpp:17
uint16_t firstPixelHue
hue of the first pixel of the strip
Definition: rainbow_swirl_mode.hpp:21
uint32_t increment
per loop increment
Definition: rainbow_swirl_mode.hpp:19
Display a rainbow that moves.
Definition: rainbow_swirl_mode.hpp:15
static constexpr bool hasSunsetAnimation
sunset & sunrise animation on the fixed modes
Definition: rainbow_swirl_mode.hpp:48