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