WPILibC++ 2023.4.3
AddressableLEDSim.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <memory>
8
10
12
13namespace frc {
14
15class AddressableLED;
16
17namespace sim {
18
19/**
20 * Class to control a simulated addressable LED.
21 */
23 public:
24 /**
25 * Constructs for the first addressable LED.
26 */
28
29 /**
30 * Constructs from an AddressableLED object.
31 *
32 * @param addressableLED AddressableLED to simulate
33 */
34 explicit AddressableLEDSim(const AddressableLED& addressableLED);
35
36 /**
37 * Creates an AddressableLEDSim for a PWM channel.
38 *
39 * @param pwmChannel PWM channel
40 * @return Simulated object
41 * @throws std::out_of_range if no AddressableLED is configured for that
42 * channel
43 */
44 static AddressableLEDSim CreateForChannel(int pwmChannel);
45
46 /**
47 * Creates an AddressableLEDSim for a simulated index.
48 * The index is incremented for each simulated AddressableLED.
49 *
50 * @param index simulator index
51 * @return Simulated object
52 */
54
55 /**
56 * Register a callback on the Initialized property.
57 *
58 * @param callback the callback that will be called whenever the Initialized
59 * property is changed
60 * @param initialNotify if true, the callback will be run on the initial value
61 * @return the CallbackStore object storing this callback
62 */
63 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
64 NotifyCallback callback, bool initialNotify);
65
66 /**
67 * Check if initialized.
68 *
69 * @return true if initialized
70 */
71 bool GetInitialized() const;
72
73 /**
74 * Change the Initialized value of the LED strip.
75 *
76 * @param initialized the new value
77 */
78 void SetInitialized(bool initialized);
79
80 /**
81 * Register a callback on the output port.
82 *
83 * @param callback the callback that will be called whenever the output port
84 * is changed
85 * @param initialNotify if true, the callback will be run on the initial value
86 * @return the CallbackStore object associated with this callback
87 */
88 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterOutputPortCallback(
89 NotifyCallback callback, bool initialNotify);
90
91 /**
92 * Get the output port.
93 *
94 * @return the output port
95 */
96 int GetOutputPort() const;
97
98 /**
99 * Change the output port.
100 *
101 * @param outputPort the new output port
102 */
103 void SetOutputPort(int outputPort);
104
105 /**
106 * Register a callback on the length.
107 *
108 * @param callback the callback that will be called whenever the length is
109 * changed
110 * @param initialNotify if true, the callback will be run on the initial value
111 * @return the CallbackStore object associated with this callback
112 */
113 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterLengthCallback(
114 NotifyCallback callback, bool initialNotify);
115
116 /**
117 * Get the length of the LED strip.
118 *
119 * @return the length
120 */
121 int GetLength() const;
122
123 /**
124 * Change the length of the LED strip.
125 *
126 * @param length the new value
127 */
128 void SetLength(int length);
129
130 /**
131 * Register a callback on whether the LEDs are running.
132 *
133 * @param callback the callback that will be called whenever the LED state is
134 * changed
135 * @param initialNotify if true, the callback will be run on the initial value
136 * @return the CallbackStore object associated with this callback
137 */
138 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterRunningCallback(
139 NotifyCallback callback, bool initialNotify);
140
141 /**
142 * Check if the LEDs are running.
143 *
144 * @return true if they are
145 */
146 int GetRunning() const;
147
148 /**
149 * Change whether the LEDs are active.
150 *
151 * @param running the new value
152 */
153 void SetRunning(bool running);
154
155 /**
156 * Register a callback on the LED data.
157 *
158 * @param callback the callback that will be called whenever the LED data is
159 * changed
160 * @param initialNotify if true, the callback will be run on the initial value
161 * @return the CallbackStore object associated with this callback
162 */
163 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterDataCallback(
164 ConstBufferCallback callback, bool initialNotify);
165
166 /**
167 * Get the LED data.
168 *
169 * @param data output parameter to fill with LED data
170 * @return the length of the LED data
171 */
173
174 /**
175 * Change the LED data.
176 *
177 * @param data the new data
178 * @param length the length of the LED data
179 */
180 void SetData(struct HAL_AddressableLEDData* data, int length);
181
182 private:
183 explicit AddressableLEDSim(int index) : m_index{index} {}
184
185 int m_index;
186};
187} // namespace sim
188} // namespace frc
A class for driving addressable LEDs, such as WS2812s and NeoPixels.
Definition: AddressableLED.h:24
Class to control a simulated addressable LED.
Definition: AddressableLEDSim.h:22
void SetInitialized(bool initialized)
Change the Initialized value of the LED strip.
std::unique_ptr< CallbackStore > RegisterRunningCallback(NotifyCallback callback, bool initialNotify)
Register a callback on whether the LEDs are running.
AddressableLEDSim()
Constructs for the first addressable LED.
static AddressableLEDSim CreateForIndex(int index)
Creates an AddressableLEDSim for a simulated index.
int GetData(struct HAL_AddressableLEDData *data) const
Get the LED data.
AddressableLEDSim(const AddressableLED &addressableLED)
Constructs from an AddressableLED object.
void SetRunning(bool running)
Change whether the LEDs are active.
void SetLength(int length)
Change the length of the LED strip.
static AddressableLEDSim CreateForChannel(int pwmChannel)
Creates an AddressableLEDSim for a PWM channel.
bool GetInitialized() const
Check if initialized.
void SetOutputPort(int outputPort)
Change the output port.
int GetOutputPort() const
Get the output port.
int GetLength() const
Get the length of the LED strip.
void SetData(struct HAL_AddressableLEDData *data, int length)
Change the LED data.
std::unique_ptr< CallbackStore > RegisterLengthCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the length.
int GetRunning() const
Check if the LEDs are running.
std::unique_ptr< CallbackStore > RegisterOutputPortCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the output port.
std::unique_ptr< CallbackStore > RegisterDataCallback(ConstBufferCallback callback, bool initialNotify)
Register a callback on the LED data.
std::unique_ptr< CallbackStore > RegisterInitializedCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the Initialized property.
std::function< void(std::string_view, const unsigned char *buffer, unsigned int count)> ConstBufferCallback
Definition: CallbackStore.h:16
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition: CallbackStore.h:14
Definition: AprilTagFieldLayout.h:22
Definition: AddressableLEDTypes.h:11
Definition: format.h:1544