CTRE Phoenix 6 C++ 25.4.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RgbFadeAnimation.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
13#include <units/frequency.h>
14#include <units/time.h>
15#include <units/dimensionless.h>
16
17namespace ctre {
18namespace phoenix6 {
19namespace controls {
20
21/**
22 * Animation that fades all the LEDs of a strip simultaneously between Red,
23 * Green, and Blue.
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<RgbFadeAnimation *>(req.get());
34 if (reqCast != nullptr)
35 {
36 *reqCast = *this;
37 }
38 else
39 {
40 req = std::make_shared<RgbFadeAnimation>(*this);
41 }
42 }
43
44 return c_ctre_phoenix6_RequestControlRgbFadeAnimation(network, deviceHash, UpdateFreqHz.to<double>(), LEDStartIndex, LEDEndIndex, Slot, Brightness.to<double>(), FrameRate.to<double>());
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
51 * strip.
52 */
54 /**
55 * \brief The index of the last LED this animation controls (inclusive). Indices
56 * 0-7 control the onboard LEDs, and 8-399 control an attached LED strip.
57 */
59 /**
60 * \brief The slot of this animation, within [0, 7]. Each slot on the CANdle can
61 * store and run one animation.
62 */
63 int Slot = 0;
64 /**
65 * \brief The brightness of the animation, as a scalar from 0.0 to 1.0.
66 */
67 units::dimensionless::scalar_t Brightness = 1.0;
68 /**
69 * \brief The frame rate of the animation, from [2, 1000] Hz. This determines
70 * the speed of the animation.
71 *
72 * A frame is defined as a transition in the state of the LEDs, adjusting the
73 * brightness of the LEDs by 1%.
74 *
75 * - Units: Hz
76 *
77 */
78 units::frequency::hertz_t FrameRate = 100_Hz;
79
80 /**
81 * \brief The period at which this control will update at.
82 * This is designated in Hertz, with a minimum of 20 Hz
83 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
84 *
85 * If this field is set to 0 Hz, the control request will
86 * be sent immediately as a one-shot frame. This may be useful
87 * for advanced applications that require outputs to be
88 * synchronized with data acquisition. In this case, we
89 * recommend not exceeding 50 ms between control calls.
90 */
91 units::frequency::hertz_t UpdateFreqHz{20_Hz};
92
93 /**
94 * \brief Animation that fades all the LEDs of a strip simultaneously between
95 * Red, Green, and Blue.
96 *
97 * \details
98 *
99 * \param LEDStartIndex The index of the first LED this animation controls
100 * (inclusive). Indices 0-7 control the onboard LEDs,
101 * and 8-399 control an attached LED strip.
102 * \param LEDEndIndex The index of the last LED this animation controls
103 * (inclusive). Indices 0-7 control the onboard LEDs, and
104 * 8-399 control an attached LED strip.
105 */
109 {}
110
111 /**
112 * \brief Modifies this Control Request's LEDStartIndex parameter and returns itself for
113 * method-chaining and easier to use request API.
114 *
115 * The index of the first LED this animation controls (inclusive). Indices 0-7
116 * control the onboard LEDs, and 8-399 control an attached LED strip.
117 *
118 * \param newLEDStartIndex Parameter to modify
119 * \returns Itself
120 */
121 RgbFadeAnimation &WithLEDStartIndex(int newLEDStartIndex)
122 {
123 LEDStartIndex = std::move(newLEDStartIndex);
124 return *this;
125 }
126
127 /**
128 * \brief Modifies this Control Request's LEDEndIndex parameter and returns itself for
129 * method-chaining and easier to use request API.
130 *
131 * The index of the last LED this animation controls (inclusive). Indices 0-7
132 * control the onboard LEDs, and 8-399 control an attached LED strip.
133 *
134 * \param newLEDEndIndex Parameter to modify
135 * \returns Itself
136 */
138 {
139 LEDEndIndex = std::move(newLEDEndIndex);
140 return *this;
141 }
142
143 /**
144 * \brief Modifies this Control Request's Slot parameter and returns itself for
145 * method-chaining and easier to use request API.
146 *
147 * The slot of this animation, within [0, 7]. Each slot on the CANdle can store
148 * and run one animation.
149 *
150 * \param newSlot Parameter to modify
151 * \returns Itself
152 */
154 {
155 Slot = std::move(newSlot);
156 return *this;
157 }
158
159 /**
160 * \brief Modifies this Control Request's Brightness parameter and returns itself for
161 * method-chaining and easier to use request API.
162 *
163 * The brightness of the animation, as a scalar from 0.0 to 1.0.
164 *
165 * \param newBrightness Parameter to modify
166 * \returns Itself
167 */
168 RgbFadeAnimation &WithBrightness(units::dimensionless::scalar_t newBrightness)
169 {
170 Brightness = std::move(newBrightness);
171 return *this;
172 }
173
174 /**
175 * \brief Modifies this Control Request's FrameRate parameter and returns itself for
176 * method-chaining and easier to use request API.
177 *
178 * The frame rate of the animation, from [2, 1000] Hz. This determines the speed
179 * of the animation.
180 *
181 * A frame is defined as a transition in the state of the LEDs, adjusting the
182 * brightness of the LEDs by 1%.
183 *
184 * - Units: Hz
185 *
186 *
187 * \param newFrameRate Parameter to modify
188 * \returns Itself
189 */
190 RgbFadeAnimation &WithFrameRate(units::frequency::hertz_t newFrameRate)
191 {
192 FrameRate = std::move(newFrameRate);
193 return *this;
194 }
195 /**
196 * \brief Sets the period at which this control will update at.
197 * This is designated in Hertz, with a minimum of 20 Hz
198 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
199 *
200 * If this field is set to 0 Hz, the control request will
201 * be sent immediately as a one-shot frame. This may be useful
202 * for advanced applications that require outputs to be
203 * synchronized with data acquisition. In this case, we
204 * recommend not exceeding 50 ms between control calls.
205 *
206 * \param newUpdateFreqHz Parameter to modify
207 * \returns Itself
208 */
209 RgbFadeAnimation &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
210 {
211 UpdateFreqHz = newUpdateFreqHz;
212 return *this;
213 }
214 /**
215 * \brief Returns a string representation of the object.
216 *
217 * \returns a string representation of the object.
218 */
219 std::string ToString() const override
220 {
221 std::stringstream ss;
222 ss << "Control: RgbFadeAnimation" << std::endl;
223 ss << " LEDStartIndex: " << LEDStartIndex << std::endl;
224 ss << " LEDEndIndex: " << LEDEndIndex << std::endl;
225 ss << " Slot: " << Slot << std::endl;
226 ss << " Brightness: " << Brightness.to<double>() << std::endl;
227 ss << " FrameRate: " << FrameRate.to<double>() << " Hz" << std::endl;
228 return ss.str();
229 }
230
231 /**
232 * \brief Gets information about this control request.
233 *
234 * \returns Map of control parameter names and corresponding applied values
235 */
236 std::map<std::string, std::string> GetControlInfo() const override
237 {
238 std::map<std::string, std::string> controlInfo;
239 std::stringstream ss;
240 controlInfo["Name"] = GetName();
241 ss << LEDStartIndex; controlInfo["LEDStartIndex"] = ss.str(); ss.str(std::string{});
242 ss << LEDEndIndex; controlInfo["LEDEndIndex"] = ss.str(); ss.str(std::string{});
243 ss << Slot; controlInfo["Slot"] = ss.str(); ss.str(std::string{});
244 ss << Brightness.to<double>(); controlInfo["Brightness"] = ss.str(); ss.str(std::string{});
245 ss << FrameRate.to<double>(); controlInfo["FrameRate"] = ss.str(); ss.str(std::string{});
246 return controlInfo;
247 }
248};
249
250}
251}
252}
253
CTREXPORT int c_ctre_phoenix6_RequestControlRgbFadeAnimation(const char *canbus, uint32_t ecuEncoding, double updateFrequency, int LEDStartIndex, int LEDEndIndex, int Slot, double Brightness, 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 fades all the LEDs of a strip simultaneously between Red, Green, and Blue.
Definition RgbFadeAnimation.hpp:28
RgbFadeAnimation & WithLEDStartIndex(int newLEDStartIndex)
Modifies this Control Request's LEDStartIndex parameter and returns itself for method-chaining and ea...
Definition RgbFadeAnimation.hpp:121
units::dimensionless::scalar_t Brightness
The brightness of the animation, as a scalar from 0.0 to 1.0.
Definition RgbFadeAnimation.hpp:67
int LEDStartIndex
The index of the first LED this animation controls (inclusive).
Definition RgbFadeAnimation.hpp:53
units::frequency::hertz_t FrameRate
The frame rate of the animation, from [2, 1000] Hz.
Definition RgbFadeAnimation.hpp:78
RgbFadeAnimation & WithSlot(int newSlot)
Modifies this Control Request's Slot parameter and returns itself for method-chaining and easier to u...
Definition RgbFadeAnimation.hpp:153
units::frequency::hertz_t UpdateFreqHz
The period at which this control will update at.
Definition RgbFadeAnimation.hpp:91
RgbFadeAnimation & WithLEDEndIndex(int newLEDEndIndex)
Modifies this Control Request's LEDEndIndex parameter and returns itself for method-chaining and easi...
Definition RgbFadeAnimation.hpp:137
int LEDEndIndex
The index of the last LED this animation controls (inclusive).
Definition RgbFadeAnimation.hpp:58
RgbFadeAnimation & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition RgbFadeAnimation.hpp:209
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition RgbFadeAnimation.hpp:236
RgbFadeAnimation & WithFrameRate(units::frequency::hertz_t newFrameRate)
Modifies this Control Request's FrameRate parameter and returns itself for method-chaining and easier...
Definition RgbFadeAnimation.hpp:190
std::string ToString() const override
Returns a string representation of the object.
Definition RgbFadeAnimation.hpp:219
RgbFadeAnimation(int LEDStartIndex, int LEDEndIndex)
Animation that fades all the LEDs of a strip simultaneously between Red, Green, and Blue.
Definition RgbFadeAnimation.hpp:106
int Slot
The slot of this animation, within [0, 7].
Definition RgbFadeAnimation.hpp:63
RgbFadeAnimation & WithBrightness(units::dimensionless::scalar_t newBrightness)
Modifies this Control Request's Brightness parameter and returns itself for method-chaining and easie...
Definition RgbFadeAnimation.hpp:168
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition Diff_PositionDutyCycle_Position.hpp:15
Definition span.hpp:401