Loading [MathJax]/jax/input/TeX/config.js
CTRE Phoenix 6 C++ 25.4.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SolidColor.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
17namespace ctre {
18namespace phoenix6 {
19namespace controls {
20
21/**
22 * Sets LEDs to a solid color.
23 *
24 *
25 */
27{
28 ctre::phoenix::StatusCode SendRequest(const char *network, uint32_t deviceHash, std::shared_ptr<ControlRequest> &req) const override
29 {
30 if (req.get() != this)
31 {
32 auto const reqCast = dynamic_cast<SolidColor *>(req.get());
33 if (reqCast != nullptr)
34 {
35 *reqCast = *this;
36 }
37 else
38 {
39 req = std::make_shared<SolidColor>(*this);
40 }
41 }
42
44 }
45
46public:
47 /**
48 * \brief The index of the first LED this animation controls (inclusive).
49 * Indices 0-7 control the onboard LEDs, and 8-399 control an attached LED
50 * strip.
51 */
53 /**
54 * \brief The index of the last LED this animation controls (inclusive). Indices
55 * 0-7 control the onboard LEDs, and 8-399 control an attached LED strip.
56 */
58 /**
59 * \brief The color to apply to the LEDs.
60 */
62
63 /**
64 * \brief The period at which this control will update at.
65 * This is designated in Hertz, with a minimum of 20 Hz
66 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
67 *
68 * If this field is set to 0 Hz, the control request will
69 * be sent immediately as a one-shot frame. This may be useful
70 * for advanced applications that require outputs to be
71 * synchronized with data acquisition. In this case, we
72 * recommend not exceeding 50 ms between control calls.
73 */
74 // This request is always 0 Hz. units::frequency::hertz_t UpdateFreqHz{0_Hz};
75
76 /**
77 * \brief Sets LEDs to a solid color.
78 *
79 * \details
80 *
81 * \param LEDStartIndex The index of the first LED this animation controls
82 * (inclusive). Indices 0-7 control the onboard LEDs,
83 * and 8-399 control an attached LED strip.
84 * \param LEDEndIndex The index of the last LED this animation controls
85 * (inclusive). Indices 0-7 control the onboard LEDs, and
86 * 8-399 control an attached LED strip.
87 */
92
93 /**
94 * \brief Modifies this Control Request's LEDStartIndex parameter and returns itself for
95 * method-chaining and easier to use request API.
96 *
97 * The index of the first LED this animation controls (inclusive). Indices 0-7
98 * control the onboard LEDs, and 8-399 control an attached LED strip.
99 *
100 * \param newLEDStartIndex Parameter to modify
101 * \returns Itself
102 */
103 SolidColor &WithLEDStartIndex(int newLEDStartIndex)
104 {
105 LEDStartIndex = std::move(newLEDStartIndex);
106 return *this;
107 }
108
109 /**
110 * \brief Modifies this Control Request's LEDEndIndex parameter and returns itself for
111 * method-chaining and easier to use request API.
112 *
113 * The index of the last LED this animation controls (inclusive). Indices 0-7
114 * control the onboard LEDs, and 8-399 control an attached LED strip.
115 *
116 * \param newLEDEndIndex Parameter to modify
117 * \returns Itself
118 */
119 SolidColor &WithLEDEndIndex(int newLEDEndIndex)
120 {
121 LEDEndIndex = std::move(newLEDEndIndex);
122 return *this;
123 }
124
125 /**
126 * \brief Modifies this Control Request's Color parameter and returns itself for
127 * method-chaining and easier to use request API.
128 *
129 * The color to apply to the LEDs.
130 *
131 * \param newColor Parameter to modify
132 * \returns Itself
133 */
135 {
136 Color = std::move(newColor);
137 return *this;
138 }
139 /**
140 * \brief Sets the period at which this control will update at.
141 * This is designated in Hertz, with a minimum of 20 Hz
142 * (every 50 ms) and a maximum of 1000 Hz (every 1 ms).
143 *
144 * If this field is set to 0 Hz, the control request will
145 * be sent immediately as a one-shot frame. This may be useful
146 * for advanced applications that require outputs to be
147 * synchronized with data acquisition. In this case, we
148 * recommend not exceeding 50 ms between control calls.
149 *
150 * \param newUpdateFreqHz Parameter to modify
151 * \returns Itself
152 */
153 SolidColor &WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
154 {
155 // This request is always 0 Hz. UpdateFreqHz = newUpdateFreqHz;
156 return *this;
157 }
158 /**
159 * \brief Returns a string representation of the object.
160 *
161 * \returns a string representation of the object.
162 */
163 std::string ToString() const override
164 {
165 std::stringstream ss;
166 ss << "Control: SolidColor" << std::endl;
167 ss << " LEDStartIndex: " << LEDStartIndex << std::endl;
168 ss << " LEDEndIndex: " << LEDEndIndex << std::endl;
169 ss << " Color: " << Color << std::endl;
170 return ss.str();
171 }
172
173 /**
174 * \brief Gets information about this control request.
175 *
176 * \returns Map of control parameter names and corresponding applied values
177 */
178 std::map<std::string, std::string> GetControlInfo() const override
179 {
180 std::map<std::string, std::string> controlInfo;
181 std::stringstream ss;
182 controlInfo["Name"] = GetName();
183 ss << LEDStartIndex; controlInfo["LEDStartIndex"] = ss.str(); ss.str(std::string{});
184 ss << LEDEndIndex; controlInfo["LEDEndIndex"] = ss.str(); ss.str(std::string{});
185 ss << Color; controlInfo["Color"] = ss.str(); ss.str(std::string{});
186 return controlInfo;
187 }
188};
189
190}
191}
192}
193
CTREXPORT int c_ctre_phoenix6_RequestControlSolidColor(const char *canbus, uint32_t ecuEncoding, double updateFrequency, int LEDStartIndex, int LEDEndIndex, int Color_Red, int Color_Green, int Color_Blue, int Color_White)
Abstract Control Request class that other control requests extend for use.
Definition ControlRequest.hpp:30
std::string const & GetName() const
Definition ControlRequest.hpp:53
Sets LEDs to a solid color.
Definition SolidColor.hpp:27
SolidColor & WithLEDStartIndex(int newLEDStartIndex)
Modifies this Control Request's LEDStartIndex parameter and returns itself for method-chaining and ea...
Definition SolidColor.hpp:103
int LEDStartIndex
The index of the first LED this animation controls (inclusive).
Definition SolidColor.hpp:52
int LEDEndIndex
The index of the last LED this animation controls (inclusive).
Definition SolidColor.hpp:57
SolidColor & WithLEDEndIndex(int newLEDEndIndex)
Modifies this Control Request's LEDEndIndex parameter and returns itself for method-chaining and easi...
Definition SolidColor.hpp:119
std::map< std::string, std::string > GetControlInfo() const override
Gets information about this control request.
Definition SolidColor.hpp:178
SolidColor & WithColor(signals::RGBWColor newColor)
Modifies this Control Request's Color parameter and returns itself for method-chaining and easier to ...
Definition SolidColor.hpp:134
std::string ToString() const override
Returns a string representation of the object.
Definition SolidColor.hpp:163
signals::RGBWColor Color
The color to apply to the LEDs.
Definition SolidColor.hpp:61
SolidColor & WithUpdateFreqHz(units::frequency::hertz_t newUpdateFreqHz)
Sets the period at which this control will update at.
Definition SolidColor.hpp:153
SolidColor(int LEDStartIndex, int LEDEndIndex)
The period at which this control will update at.
Definition SolidColor.hpp:88
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