CTRE Phoenix 6 C++ 26.0.0-beta-1
Loading...
Searching...
No Matches
SingleFadeAnimation.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 <units/frequency.h>
12#include <units/time.h>
13
14namespace ctre {
15namespace phoenix6 {
16namespace controls {
17
18/**
19 * Animation that fades into and out of a specified color.
20 *
21 *
22 */
23class SingleFadeAnimation final : public ControlRequest {
24 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override;
25
26public:
27 /**
28 * \brief The index of the first LED this animation controls (inclusive).
29 * Indices 0-7 control the onboard LEDs, and 8-399 control an attached LED
30 * strip.
31 */
33 /**
34 * \brief The index of the last LED this animation controls (inclusive). Indices
35 * 0-7 control the onboard LEDs, and 8-399 control an attached LED strip.
36 */
38 /**
39 * \brief The slot of this animation, within [0, 7]. Each slot on the CANdle can
40 * store and run one animation.
41 */
42 int Slot = 0;
43 /**
44 * \brief The color to use in the animation.
45 */
47 /**
48 * \brief The frame rate of the animation, from [2, 1000] Hz. This determines
49 * the speed of the animation.
50 *
51 * A frame is defined as a transition in the state of the LEDs, adjusting the
52 * brightness of the LEDs by 1%.
53 *
54 * - Units: Hz
55 *
56 */
57 units::frequency::hertz_t FrameRate = 100_Hz;
58
59 /**
60 * \brief The frequency at which this control will update.
61 * This is designated in Hertz, with a minimum of 20 Hz
62 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
63 * Some update frequencies are not supported and will be
64 * promoted up to the next highest supported frequency.
65 *
66 * If this field is set to 0 Hz, the control request will
67 * be sent immediately as a one-shot frame. This may be useful
68 * for advanced applications that require outputs to be
69 * synchronized with data acquisition. In this case, we
70 * recommend not exceeding 50 ms between control calls.
71 */
72 units::frequency::hertz_t UpdateFreqHz{20_Hz};
73
74 /**
75 * \brief Animation that fades into and out of a specified color.
76 *
77 * \details
78 *
79 * \param LEDStartIndex The index of the first LED this animation controls
80 * (inclusive). Indices 0-7 control the onboard LEDs, and
81 * 8-399 control an attached LED strip.
82 * \param LEDEndIndex The index of the last LED this animation controls
83 * (inclusive). Indices 0-7 control the onboard LEDs, and
84 * 8-399 control an attached LED strip.
85 */
90
91 constexpr ~SingleFadeAnimation() override {}
92
93 /**
94 * \brief Gets the name of this control request.
95 *
96 * \returns Name of the control request
97 */
98 constexpr std::string_view GetName() const override
99 {
100 return "SingleFadeAnimation";
101 }
102
103 /**
104 * \brief Modifies this Control Request's LEDStartIndex parameter and returns itself for
105 * method-chaining and easier to use request API.
106 *
107 * The index of the first LED this animation controls (inclusive). Indices 0-7
108 * control the onboard LEDs, and 8-399 control an attached LED strip.
109 *
110 * \param newLEDStartIndex Parameter to modify
111 * \returns Itself
112 */
113 constexpr SingleFadeAnimation &WithLEDStartIndex(int newLEDStartIndex)
114 {
115 LEDStartIndex = std::move(newLEDStartIndex);
116 return *this;
117 }
118
119 /**
120 * \brief Modifies this Control Request's LEDEndIndex parameter and returns itself for
121 * method-chaining and easier to use request API.
122 *
123 * The index of the last LED this animation controls (inclusive). Indices 0-7
124 * control the onboard LEDs, and 8-399 control an attached LED strip.
125 *
126 * \param newLEDEndIndex Parameter to modify
127 * \returns Itself
128 */
129 constexpr SingleFadeAnimation &WithLEDEndIndex(int newLEDEndIndex)
130 {
131 LEDEndIndex = std::move(newLEDEndIndex);
132 return *this;
133 }
134
135 /**
136 * \brief Modifies this Control Request's Slot parameter and returns itself for
137 * method-chaining and easier to use request API.
138 *
139 * The slot of this animation, within [0, 7]. Each slot on the CANdle can store
140 * and run one animation.
141 *
142 * \param newSlot Parameter to modify
143 * \returns Itself
144 */
145 constexpr SingleFadeAnimation &WithSlot(int newSlot)
146 {
147 Slot = std::move(newSlot);
148 return *this;
149 }
150
151 /**
152 * \brief Modifies this Control Request's Color parameter and returns itself for
153 * method-chaining and easier to use request API.
154 *
155 * The color to use in the animation.
156 *
157 * \param newColor Parameter to modify
158 * \returns Itself
159 */
161 {
162 Color = std::move(newColor);
163 return *this;
164 }
165
166 /**
167 * \brief Modifies this Control Request's FrameRate parameter and returns itself for
168 * method-chaining and easier to use request API.
169 *
170 * The frame rate of the animation, from [2, 1000] Hz. This determines the speed
171 * of the animation.
172 *
173 * A frame is defined as a transition in the state of the LEDs, adjusting the
174 * brightness of the LEDs by 1%.
175 *
176 * - Units: Hz
177 *
178 *
179 * \param newFrameRate Parameter to modify
180 * \returns Itself
181 */
182 constexpr SingleFadeAnimation &WithFrameRate(units::frequency::hertz_t newFrameRate)
183 {
184 FrameRate = std::move(newFrameRate);
185 return *this;
186 }
187
188 /**
189 * \brief Sets the frequency at which this control will update.
190 * This is designated in Hertz, with a minimum of 20 Hz
191 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
192 * Some update frequencies are not supported and will be
193 * promoted up to the next highest supported frequency.
194 *
195 * If this field is set to 0 Hz, the control request will
196 * be sent immediately as a one-shot frame. This may be useful
197 * for advanced applications that require outputs to be
198 * synchronized with data acquisition. In this case, we
199 * recommend not exceeding 50 ms between control calls.
200 *
201 * \param newUpdateFreqHz Parameter to modify
202 * \returns Itself
203 */
204 constexpr SingleFadeAnimation &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
205 {
206 UpdateFreqHz = newUpdateFreqHz;
207 return *this;
208 }
209
210 /**
211 * \brief Returns a string representation of the object.
212 *
213 * \returns a string representation of the object.
214 */
215 std::string ToString() const override;
216
217 /**
218 * \brief Gets information about this control request.
219 *
220 * \returns Map of control parameter names and corresponding applied values
221 */
222 std::map<std::string, std::string> GetControlInfo() const override;
223};
224
225}
226}
227}
228
Common interface implemented by all control requests.
Definition ControlRequest.hpp:27
Animation that fades into and out of a specified color.
Definition SingleFadeAnimation.hpp:23
constexpr ~SingleFadeAnimation() override
Definition SingleFadeAnimation.hpp:91
constexpr std::string_view GetName() const override
Gets the name of this control request.
Definition SingleFadeAnimation.hpp:98
std::string ToString() const override
Returns a string representation of the object.
int Slot
The slot of this animation, within [0, 7].
Definition SingleFadeAnimation.hpp:42
constexpr SingleFadeAnimation & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the frequency at which this control will update.
Definition SingleFadeAnimation.hpp:204
constexpr SingleFadeAnimation & WithFrameRate(units::frequency::hertz_t newFrameRate)
Modifies this Control Request's FrameRate parameter and returns itself for method-chaining and easier...
Definition SingleFadeAnimation.hpp:182
units::frequency::hertz_t UpdateFreqHz
The frequency at which this control will update.
Definition SingleFadeAnimation.hpp:72
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
constexpr SingleFadeAnimation & WithSlot(int newSlot)
Modifies this Control Request's Slot parameter and returns itself for method-chaining and easier to u...
Definition SingleFadeAnimation.hpp:145
units::frequency::hertz_t FrameRate
The frame rate of the animation, from [2, 1000] Hz.
Definition SingleFadeAnimation.hpp:57
int LEDEndIndex
The index of the last LED this animation controls (inclusive).
Definition SingleFadeAnimation.hpp:37
constexpr SingleFadeAnimation(int LEDStartIndex, int LEDEndIndex)
Animation that fades into and out of a specified color.
Definition SingleFadeAnimation.hpp:86
constexpr SingleFadeAnimation & WithColor(signals::RGBWColor newColor)
Modifies this Control Request's Color parameter and returns itself for method-chaining and easier to ...
Definition SingleFadeAnimation.hpp:160
signals::RGBWColor Color
The color to use in the animation.
Definition SingleFadeAnimation.hpp:46
constexpr SingleFadeAnimation & WithLEDStartIndex(int newLEDStartIndex)
Modifies this Control Request's LEDStartIndex parameter and returns itself for method-chaining and ea...
Definition SingleFadeAnimation.hpp:113
constexpr SingleFadeAnimation & WithLEDEndIndex(int newLEDEndIndex)
Modifies this Control Request's LEDEndIndex parameter and returns itself for method-chaining and easi...
Definition SingleFadeAnimation.hpp:129
int LEDStartIndex
The index of the first LED this animation controls (inclusive).
Definition SingleFadeAnimation.hpp:32
Represents an RGBW color that can be applied to an LED.
Definition RGBWColor.hpp:27
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
Definition motor_constants.h:14