Loading [MathJax]/extensions/tex2jax.js
CTRE Phoenix 6 C++ 25.4.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ColorFlowAnimation.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
15#include <units/frequency.h>
16#include <units/time.h>
17
18namespace ctre {
19namespace phoenix6 {
20namespace controls {
21
22/**
23 * Animation that gradually lights the entire LED strip one LED at a time.
24 *
25 *
26 */
28{
29 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override
30 {
31 if (req.get() != this)
32 {
33 auto const reqCast = dynamic_cast<ColorFlowAnimation *>(req.get());
34 if (reqCast != nullptr)
35 {
36 *reqCast = *this;
37 }
38 else
39 {
40 req = std::make_shared<ColorFlowAnimation>(*this);
41 }
42 }
43
45 }
46
47public:
48 /**
49 * \brief The index of the first LED this animation controls (inclusive).
50 * Indices 0-7 control the onboard LEDs, and 8-399 control an attached LED strip
51 *
52 * If the start index is greater than the end index, the direction will be
53 * reversed. The direction can also be changed using the Direction parameter.
54 */
56 /**
57 * \brief The index of the last LED this animation controls (inclusive). Indices
58 * 0-7 control the onboard LEDs, and 8-399 control an attached LED strip.
59 *
60 * If the end index is less than the start index, the direction will be
61 * reversed. The direction can also be changed using the Direction parameter.
62 */
64 /**
65 * \brief The slot of this animation, within [0, 7]. Each slot on the CANdle can
66 * store and run one animation.
67 */
68 int Slot = 0;
69 /**
70 * \brief The color to use in the animation.
71 */
73 /**
74 * \brief The direction of the animation.
75 */
77 /**
78 * \brief The frame rate of the animation, from [2, 1000] Hz. This determines
79 * the speed of the animation.
80 *
81 * A frame is defined as a transition in the state of the LEDs, turning one on
82 * or off.
83 *
84 * - Units: Hz
85 *
86 */
87 units::frequency::hertz_t FrameRate = 25_Hz;
88
89 /**
90 * \brief The period at which this control will update at.
91 * This is designated in Hertz, with a minimum of 20 Hz
92 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
93 *
94 * If this field is set to 0 Hz, the control request will
95 * be sent immediately as a one-shot frame. This may be useful
96 * for advanced applications that require outputs to be
97 * synchronized with data acquisition. In this case, we
98 * recommend not exceeding 50 ms between control calls.
99 */
100 units::frequency::hertz_t UpdateFreqHz{20_Hz};
101
102 /**
103 * \brief Animation that gradually lights the entire LED strip one LED at a
104 * time.
105 *
106 * \details
107 *
108 * \param LEDStartIndex The index of the first LED this animation controls
109 * (inclusive). Indices 0-7 control the onboard LEDs,
110 * and 8-399 control an attached LED strip
111 *
112 * If the start index is greater than the end index, the
113 * direction will be reversed. The direction can also be
114 * changed using the Direction parameter.
115 * \param LEDEndIndex The index of the last LED this animation controls
116 * (inclusive). Indices 0-7 control the onboard LEDs, and
117 * 8-399 control an attached LED strip.
118 *
119 * If the end index is less than the start index, the
120 * direction will be reversed. The direction can also be
121 * changed using the Direction parameter.
122 */
126 {}
127
128 /**
129 * \brief Modifies this Control Request's LEDStartIndex parameter and returns itself for
130 * method-chaining and easier to use request API.
131 *
132 * The index of the first LED this animation controls (inclusive). Indices 0-7
133 * control the onboard LEDs, and 8-399 control an attached LED strip
134 *
135 * If the start index is greater than the end index, the direction will be
136 * reversed. The direction can also be changed using the Direction parameter.
137 *
138 * \param newLEDStartIndex Parameter to modify
139 * \returns Itself
140 */
142 {
143 LEDStartIndex = std::move(newLEDStartIndex);
144 return *this;
145 }
146
147 /**
148 * \brief Modifies this Control Request's LEDEndIndex parameter and returns itself for
149 * method-chaining and easier to use request API.
150 *
151 * The index of the last LED this animation controls (inclusive). Indices 0-7
152 * control the onboard LEDs, and 8-399 control an attached LED strip.
153 *
154 * If the end index is less than the start index, the direction will be
155 * reversed. The direction can also be changed using the Direction parameter.
156 *
157 * \param newLEDEndIndex Parameter to modify
158 * \returns Itself
159 */
161 {
162 LEDEndIndex = std::move(newLEDEndIndex);
163 return *this;
164 }
165
166 /**
167 * \brief Modifies this Control Request's Slot parameter and returns itself for
168 * method-chaining and easier to use request API.
169 *
170 * The slot of this animation, within [0, 7]. Each slot on the CANdle can store
171 * and run one animation.
172 *
173 * \param newSlot Parameter to modify
174 * \returns Itself
175 */
177 {
178 Slot = std::move(newSlot);
179 return *this;
180 }
181
182 /**
183 * \brief Modifies this Control Request's Color parameter and returns itself for
184 * method-chaining and easier to use request API.
185 *
186 * The color to use in the animation.
187 *
188 * \param newColor Parameter to modify
189 * \returns Itself
190 */
192 {
193 Color = std::move(newColor);
194 return *this;
195 }
196
197 /**
198 * \brief Modifies this Control Request's Direction parameter and returns itself for
199 * method-chaining and easier to use request API.
200 *
201 * The direction of the animation.
202 *
203 * \param newDirection Parameter to modify
204 * \returns Itself
205 */
207 {
208 Direction = std::move(newDirection);
209 return *this;
210 }
211
212 /**
213 * \brief Modifies this Control Request's FrameRate parameter and returns itself for
214 * method-chaining and easier to use request API.
215 *
216 * The frame rate of the animation, from [2, 1000] Hz. This determines the speed
217 * of the animation.
218 *
219 * A frame is defined as a transition in the state of the LEDs, turning one on
220 * or off.
221 *
222 * - Units: Hz
223 *
224 *
225 * \param newFrameRate Parameter to modify
226 * \returns Itself
227 */
228 ColorFlowAnimation &WithFrameRate(units::frequency::hertz_t newFrameRate)
229 {
230 FrameRate = std::move(newFrameRate);
231 return *this;
232 }
233 /**
234 * \brief Sets the period at which this control will update at.
235 * This is designated in Hertz, with a minimum of 20 Hz
236 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
237 *
238 * If this field is set to 0 Hz, the control request will
239 * be sent immediately as a one-shot frame. This may be useful
240 * for advanced applications that require outputs to be
241 * synchronized with data acquisition. In this case, we
242 * recommend not exceeding 50 ms between control calls.
243 *
244 * \param newUpdateFreqHz Parameter to modify
245 * \returns Itself
246 */
247 ColorFlowAnimation &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
248 {
249 UpdateFreqHz = newUpdateFreqHz;
250 return *this;
251 }
252 /**
253 * \brief Returns a string representation of the object.
254 *
255 * \returns a string representation of the object.
256 */
257 std::string ToString() const override
258 {
259 std::stringstream ss;
260 ss << "Control: ColorFlowAnimation" << std::endl;
261 ss << " LEDStartIndex: " << LEDStartIndex << std::endl;
262 ss << " LEDEndIndex: " << LEDEndIndex << std::endl;
263 ss << " Slot: " << Slot << std::endl;
264 ss << " Color: " << Color << std::endl;
265 ss << " Direction: " << Direction << std::endl;
266 ss << " FrameRate: " << FrameRate.to<double>() << " Hz" << std::endl;
267 return ss.str();
268 }
269
270 /**
271 * \brief Gets information about this control request.
272 *
273 * \returns Map of control parameter names and corresponding applied values
274 */
275 std::map<std::string, std::string> GetControlInfo() const override
276 {
277 std::map<std::string, std::string> controlInfo;
278 std::stringstream ss;
279 controlInfo["Name"] = GetName();
280 ss << LEDStartIndex; controlInfo["LEDStartIndex"] = ss.str(); ss.str(std::string{});
281 ss << LEDEndIndex; controlInfo["LEDEndIndex"] = ss.str(); ss.str(std::string{});
282 ss << Slot; controlInfo["Slot"] = ss.str(); ss.str(std::string{});
283 ss << Color; controlInfo["Color"] = ss.str(); ss.str(std::string{});
284 ss << Direction; controlInfo["Direction"] = ss.str(); ss.str(std::string{});
285 ss << FrameRate.to<double>(); controlInfo["FrameRate"] = ss.str(); ss.str(std::string{});
286 return controlInfo;
287 }
288};
289
290}
291}
292}
293
CTREXPORT int c_ctre_phoenix6_RequestControlColorFlowAnimation(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, int Direction, double FrameRate)
Animation that gradually lights the entire LED strip one LED at a time.
Definition ColorFlowAnimation.hpp:28
ColorFlowAnimation & WithFrameRate(units::frequency::hertz_t newFrameRate)
Modifies this Control Request's FrameRate parameter and returns itself for method-chaining and easier...
Definition ColorFlowAnimation.hpp:228
ColorFlowAnimation & WithDirection(signals::AnimationDirectionValue newDirection)
Modifies this Control Request's Direction parameter and returns itself for method-chaining and easier...
Definition ColorFlowAnimation.hpp:206
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition ColorFlowAnimation.hpp:100
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition ColorFlowAnimation.hpp:275
int LEDStartIndex
The index of the first LED this animation controls (inclusive).
Definition ColorFlowAnimation.hpp:55
ColorFlowAnimation & WithLEDEndIndex(int newLEDEndIndex)
Modifies this Control Request's LEDEndIndex parameter and returns itself for method-chaining and easi...
Definition ColorFlowAnimation.hpp:160
units::frequency::hertz_t FrameRate
The frame rate of the animation, from [2, 1000] Hz.
Definition ColorFlowAnimation.hpp:87
signals::RGBWColor Color
The color to use in the animation.
Definition ColorFlowAnimation.hpp:72
ColorFlowAnimation & WithColor(signals::RGBWColor newColor)
Modifies this Control Request's Color parameter and returns itself for method-chaining and easier to ...
Definition ColorFlowAnimation.hpp:191
ColorFlowAnimation & WithLEDStartIndex(int newLEDStartIndex)
Modifies this Control Request's LEDStartIndex parameter and returns itself for method-chaining and ea...
Definition ColorFlowAnimation.hpp:141
int Slot
The slot of this animation, within [0, 7].
Definition ColorFlowAnimation.hpp:68
std::string ToString() const override
Returns a string representation of the object.
Definition ColorFlowAnimation.hpp:257
int LEDEndIndex
The index of the last LED this animation controls (inclusive).
Definition ColorFlowAnimation.hpp:63
ColorFlowAnimation & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition ColorFlowAnimation.hpp:247
ColorFlowAnimation(int LEDStartIndex, int LEDEndIndex)
Animation that gradually lights the entire LED strip one LED at a time.
Definition ColorFlowAnimation.hpp:123
signals::AnimationDirectionValue Direction
The direction of the animation.
Definition ColorFlowAnimation.hpp:76
ColorFlowAnimation & WithSlot(int newSlot)
Modifies this Control Request's Slot parameter and returns itself for method-chaining and easier to u...
Definition ColorFlowAnimation.hpp:176
Abstract Control Request class that other control requests extend for use.
Definition ControlRequest.hpp:30
std::string const & GetName() const
Definition ControlRequest.hpp:53
Direction of the animation.
Definition SpnEnums.hpp:6388
int value
Definition SpnEnums.hpp:6390
static constexpr int Forward
The animation starts at the specified LED start index and moves towards the LED end index.
Definition SpnEnums.hpp:6396
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