Loading [MathJax]/extensions/tex2jax.js
CTRE Phoenix 6 C++ 25.4.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TwinkleOffAnimation.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Cross The Road Electronics.  All rights reserved.
3 * License information can be found in CTRE_LICENSE.txt
4 * For support and suggestions contact support@ctr-electronics.com or file
5 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
6 */
7#pragma once
8
11#include <sstream>
12
14#include <units/frequency.h>
15#include <units/time.h>
16#include <units/dimensionless.h>
17
18namespace ctre {
19namespace phoenix6 {
20namespace controls {
21
22/**
23 * Animation that randomly turns on LEDs until it reaches the maximum count, and
24 * then turns them all off.
25 *
26 *
27 */
29{
30 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override
31 {
32 if (req.get() != this)
33 {
34 auto const reqCast = dynamic_cast<TwinkleOffAnimation *>(req.get());
35 if (reqCast != nullptr)
36 {
37 *reqCast = *this;
38 }
39 else
40 {
41 req = std::make_shared<TwinkleOffAnimation>(*this);
42 }
43 }
44
46 }
47
48public:
49 /**
50 * \brief The index of the first LED this animation controls (inclusive).
51 * Indices 0-7 control the onboard LEDs, and 8-399 control an attached LED
52 * strip.
53 */
55 /**
56 * \brief The index of the last LED this animation controls (inclusive). Indices
57 * 0-7 control the onboard LEDs, and 8-399 control an attached LED strip.
58 */
60 /**
61 * \brief The slot of this animation, within [0, 7]. Each slot on the CANdle can
62 * store and run one animation.
63 */
64 int Slot = 0;
65 /**
66 * \brief The color to use in the animation.
67 */
69 /**
70 * \brief The max proportion of LEDs that can be on, in the range [0.1, 1.0].
71 */
72 units::dimensionless::scalar_t MaxLEDsOnProportion = 1.0;
73 /**
74 * \brief The frame rate of the animation, from [2, 1000] Hz. This determines
75 * the speed of the animation.
76 *
77 * A frame is defined as a transition in the state of the LEDs, turning one LED
78 * on or all LEDs off.
79 *
80 * - Units: Hz
81 *
82 */
83 units::frequency::hertz_t FrameRate = 25_Hz;
84
85 /**
86 * \brief The period at which this control will update at.
87 * This is designated in Hertz, with a minimum of 20 Hz
88 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
89 *
90 * If this field is set to 0 Hz, the control request will
91 * be sent immediately as a one-shot frame. This may be useful
92 * for advanced applications that require outputs to be
93 * synchronized with data acquisition. In this case, we
94 * recommend not exceeding 50 ms between control calls.
95 */
96 units::frequency::hertz_t UpdateFreqHz{20_Hz};
97
98 /**
99 * \brief Animation that randomly turns on LEDs until it reaches the maximum
100 * count, and then turns them all off.
101 *
102 * \details
103 *
104 * \param LEDStartIndex The index of the first LED this animation controls
105 * (inclusive). Indices 0-7 control the onboard LEDs,
106 * and 8-399 control an attached LED strip.
107 * \param LEDEndIndex The index of the last LED this animation controls
108 * (inclusive). Indices 0-7 control the onboard LEDs, and
109 * 8-399 control an attached LED strip.
110 */
114 {}
115
116 /**
117 * \brief Modifies this Control Request's LEDStartIndex parameter and returns itself for
118 * method-chaining and easier to use request API.
119 *
120 * The index of the first LED this animation controls (inclusive). Indices 0-7
121 * control the onboard LEDs, and 8-399 control an attached LED strip.
122 *
123 * \param newLEDStartIndex Parameter to modify
124 * \returns Itself
125 */
127 {
128 LEDStartIndex = std::move(newLEDStartIndex);
129 return *this;
130 }
131
132 /**
133 * \brief Modifies this Control Request's LEDEndIndex parameter and returns itself for
134 * method-chaining and easier to use request API.
135 *
136 * The index of the last LED this animation controls (inclusive). Indices 0-7
137 * control the onboard LEDs, and 8-399 control an attached LED strip.
138 *
139 * \param newLEDEndIndex Parameter to modify
140 * \returns Itself
141 */
143 {
144 LEDEndIndex = std::move(newLEDEndIndex);
145 return *this;
146 }
147
148 /**
149 * \brief Modifies this Control Request's Slot parameter and returns itself for
150 * method-chaining and easier to use request API.
151 *
152 * The slot of this animation, within [0, 7]. Each slot on the CANdle can store
153 * and run one animation.
154 *
155 * \param newSlot Parameter to modify
156 * \returns Itself
157 */
159 {
160 Slot = std::move(newSlot);
161 return *this;
162 }
163
164 /**
165 * \brief Modifies this Control Request's Color parameter and returns itself for
166 * method-chaining and easier to use request API.
167 *
168 * The color to use in the animation.
169 *
170 * \param newColor Parameter to modify
171 * \returns Itself
172 */
174 {
175 Color = std::move(newColor);
176 return *this;
177 }
178
179 /**
180 * \brief Modifies this Control Request's MaxLEDsOnProportion parameter and returns itself for
181 * method-chaining and easier to use request API.
182 *
183 * The max proportion of LEDs that can be on, in the range [0.1, 1.0].
184 *
185 * \param newMaxLEDsOnProportion Parameter to modify
186 * \returns Itself
187 */
188 TwinkleOffAnimation &WithMaxLEDsOnProportion(units::dimensionless::scalar_t newMaxLEDsOnProportion)
189 {
190 MaxLEDsOnProportion = std::move(newMaxLEDsOnProportion);
191 return *this;
192 }
193
194 /**
195 * \brief Modifies this Control Request's FrameRate parameter and returns itself for
196 * method-chaining and easier to use request API.
197 *
198 * The frame rate of the animation, from [2, 1000] Hz. This determines the speed
199 * of the animation.
200 *
201 * A frame is defined as a transition in the state of the LEDs, turning one LED
202 * on or all LEDs off.
203 *
204 * - Units: Hz
205 *
206 *
207 * \param newFrameRate Parameter to modify
208 * \returns Itself
209 */
210 TwinkleOffAnimation &WithFrameRate(units::frequency::hertz_t newFrameRate)
211 {
212 FrameRate = std::move(newFrameRate);
213 return *this;
214 }
215 /**
216 * \brief Sets the period at which this control will update at.
217 * This is designated in Hertz, with a minimum of 20 Hz
218 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
219 *
220 * If this field is set to 0 Hz, the control request will
221 * be sent immediately as a one-shot frame. This may be useful
222 * for advanced applications that require outputs to be
223 * synchronized with data acquisition. In this case, we
224 * recommend not exceeding 50 ms between control calls.
225 *
226 * \param newUpdateFreqHz Parameter to modify
227 * \returns Itself
228 */
229 TwinkleOffAnimation &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
230 {
231 UpdateFreqHz = newUpdateFreqHz;
232 return *this;
233 }
234 /**
235 * \brief Returns a string representation of the object.
236 *
237 * \returns a string representation of the object.
238 */
239 std::string ToString() const override
240 {
241 std::stringstream ss;
242 ss << "Control: TwinkleOffAnimation" << std::endl;
243 ss << " LEDStartIndex: " << LEDStartIndex << std::endl;
244 ss << " LEDEndIndex: " << LEDEndIndex << std::endl;
245 ss << " Slot: " << Slot << std::endl;
246 ss << " Color: " << Color << std::endl;
247 ss << " MaxLEDsOnProportion: " << MaxLEDsOnProportion.to<double>() << std::endl;
248 ss << " FrameRate: " << FrameRate.to<double>() << " Hz" << std::endl;
249 return ss.str();
250 }
251
252 /**
253 * \brief Gets information about this control request.
254 *
255 * \returns Map of control parameter names and corresponding applied values
256 */
257 std::map<std::string, std::string> GetControlInfo() const override
258 {
259 std::map<std::string, std::string> controlInfo;
260 std::stringstream ss;
261 controlInfo["Name"] = GetName();
262 ss << LEDStartIndex; controlInfo["LEDStartIndex"] = ss.str(); ss.str(std::string{});
263 ss << LEDEndIndex; controlInfo["LEDEndIndex"] = ss.str(); ss.str(std::string{});
264 ss << Slot; controlInfo["Slot"] = ss.str(); ss.str(std::string{});
265 ss << Color; controlInfo["Color"] = ss.str(); ss.str(std::string{});
266 ss << MaxLEDsOnProportion.to<double>(); controlInfo["MaxLEDsOnProportion"] = ss.str(); ss.str(std::string{});
267 ss << FrameRate.to<double>(); controlInfo["FrameRate"] = ss.str(); ss.str(std::string{});
268 return controlInfo;
269 }
270};
271
272}
273}
274}
275
CTREXPORT int c_ctre_phoenix6_RequestControlTwinkleOffAnimation(const char *canbus, uint32_t ecuEncoding, double updateFrequency, int LEDStartIndex, int LEDEndIndex, int Slot, int Color_Red, int Color_Green, int Color_Blue, int Color_White, double MaxLEDsOnProportion, double FrameRate)
Abstract Control Request class that other control requests extend for use.
Definition ControlRequest.hpp:30
std::string const & GetName() const
Definition ControlRequest.hpp:53
Animation that randomly turns on LEDs until it reaches the maximum count, and then turns them all off...
Definition TwinkleOffAnimation.hpp:29
TwinkleOffAnimation & WithSlot(int newSlot)
Modifies this Control Request's Slot parameter and returns itself for method-chaining and easier to u...
Definition TwinkleOffAnimation.hpp:158
units::frequency::hertz_t FrameRate
The frame rate of the animation, from [2, 1000] Hz.
Definition TwinkleOffAnimation.hpp:83
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition TwinkleOffAnimation.hpp:257
TwinkleOffAnimation(int LEDStartIndex, int LEDEndIndex)
Animation that randomly turns on LEDs until it reaches the maximum count, and then turns them all off...
Definition TwinkleOffAnimation.hpp:111
TwinkleOffAnimation & WithFrameRate(units::frequency::hertz_t newFrameRate)
Modifies this Control Request's FrameRate parameter and returns itself for method-chaining and easier...
Definition TwinkleOffAnimation.hpp:210
TwinkleOffAnimation & WithLEDEndIndex(int newLEDEndIndex)
Modifies this Control Request's LEDEndIndex parameter and returns itself for method-chaining and easi...
Definition TwinkleOffAnimation.hpp:142
int LEDEndIndex
The index of the last LED this animation controls (inclusive).
Definition TwinkleOffAnimation.hpp:59
TwinkleOffAnimation & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition TwinkleOffAnimation.hpp:229
std::string ToString() const override
Returns a string representation of the object.
Definition TwinkleOffAnimation.hpp:239
TwinkleOffAnimation & WithLEDStartIndex(int newLEDStartIndex)
Modifies this Control Request's LEDStartIndex parameter and returns itself for method-chaining and ea...
Definition TwinkleOffAnimation.hpp:126
TwinkleOffAnimation & WithMaxLEDsOnProportion(units::dimensionless::scalar_t newMaxLEDsOnProportion)
Modifies this Control Request's MaxLEDsOnProportion parameter and returns itself for method-chaining ...
Definition TwinkleOffAnimation.hpp:188
signals::RGBWColor Color
The color to use in the animation.
Definition TwinkleOffAnimation.hpp:68
TwinkleOffAnimation & WithColor(signals::RGBWColor newColor)
Modifies this Control Request's Color parameter and returns itself for method-chaining and easier to ...
Definition TwinkleOffAnimation.hpp:173
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition TwinkleOffAnimation.hpp:96
int LEDStartIndex
The index of the first LED this animation controls (inclusive).
Definition TwinkleOffAnimation.hpp:54
units::dimensionless::scalar_t MaxLEDsOnProportion
The max proportion of LEDs that can be on, in the range [0.1, 1.0].
Definition TwinkleOffAnimation.hpp:72
int Slot
The slot of this animation, within [0, 7].
Definition TwinkleOffAnimation.hpp:64
Represents an RGBW color that can be applied to an LED.
Definition RGBWColor.hpp:27
uint8_t Green
The green component of the color, within [0, 255].
Definition RGBWColor.hpp:36
uint8_t Blue
The blue component of the color, within [0, 255].
Definition RGBWColor.hpp:40
uint8_t White
The white component of the color, within [0, 255].
Definition RGBWColor.hpp:45
uint8_t Red
The red component of the color, within [0, 255].
Definition RGBWColor.hpp:32
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition Diff_PositionDutyCycle_Position.hpp:15
Definition span.hpp:401