WPILibC++ 2027.0.0-alpha-2
Loading...
Searching...
No Matches
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 an addressable LED for a specific channel.
26 *
27 * @param channel output channel
28 */
29 explicit AddressableLEDSim(int channel);
30
31 /**
32 * Constructs from an AddressableLED object.
33 *
34 * @param addressableLED AddressableLED to simulate
35 */
36 explicit AddressableLEDSim(const AddressableLED& addressableLED);
37
38 /**
39 * Register a callback on the Initialized property.
40 *
41 * @param callback the callback that will be called whenever the Initialized
42 * property is changed
43 * @param initialNotify if true, the callback will be run on the initial value
44 * @return the CallbackStore object storing this callback
45 */
46 [[nodiscard]]
47 std::unique_ptr<CallbackStore> RegisterInitializedCallback(
48 NotifyCallback callback, bool initialNotify);
49
50 /**
51 * Check if initialized.
52 *
53 * @return true if initialized
54 */
55 bool GetInitialized() const;
56
57 /**
58 * Change the Initialized value of the LED strip.
59 *
60 * @param initialized the new value
61 */
62 void SetInitialized(bool initialized);
63
64 /**
65 * Register a callback on the start.
66 *
67 * @param callback the callback that will be called whenever the start
68 * is changed
69 * @param initialNotify if true, the callback will be run on the initial value
70 * @return the CallbackStore object associated with this callback
71 */
72 [[nodiscard]]
73 std::unique_ptr<CallbackStore> RegisterStartCallback(NotifyCallback callback,
74 bool initialNotify);
75
76 /**
77 * Get the start.
78 *
79 * @return the start
80 */
81 int GetStart() const;
82
83 /**
84 * Change the start.
85 *
86 * @param start the new start
87 */
88 void SetStart(int start);
89
90 /**
91 * Register a callback on the length.
92 *
93 * @param callback the callback that will be called whenever the length is
94 * changed
95 * @param initialNotify if true, the callback will be run on the initial value
96 * @return the CallbackStore object associated with this callback
97 */
98 [[nodiscard]]
99 std::unique_ptr<CallbackStore> RegisterLengthCallback(NotifyCallback callback,
100 bool initialNotify);
101
102 /**
103 * Get the length of the LED strip.
104 *
105 * @return the length
106 */
107 int GetLength() const;
108
109 /**
110 * Change the length of the LED strip.
111 *
112 * @param length the new value
113 */
114 void SetLength(int length);
115
116 /**
117 * Get the LED data.
118 *
119 * @param data output parameter to fill with LED data
120 * @return the length of the LED data
121 */
122 int GetData(struct HAL_AddressableLEDData* data) const;
123
124 /**
125 * Change the LED data.
126 *
127 * @param data the new data
128 */
129 void SetData(struct HAL_AddressableLEDData* data);
130
131 /**
132 * Register a callback on the LED data.
133 *
134 * @param callback the callback that will be called whenever the LED data is
135 * changed
136 * @param initialNotify if true, the callback will be run on the initial value
137 * @return the CallbackStore object associated with this callback
138 */
139 [[nodiscard]]
140 static std::unique_ptr<CallbackStore> RegisterDataCallback(
141 ConstBufferCallback callback, bool initialNotify);
142
143 /**
144 * Get the global LED data.
145 *
146 * @param start the start of the LED data
147 * @param length the length of the LED data
148 * @param data output parameter to fill with LED data
149 * @return the length of the LED data
150 */
151 static int GetGlobalData(int start, int length,
152 struct HAL_AddressableLEDData* data);
153
154 /**
155 * Change the global LED data.
156 *
157 * @param start the start of the LED data
158 * @param length the length of the LED data
159 * @param data the new data
160 */
161 static void SetGlobalData(int start, int length,
162 struct HAL_AddressableLEDData* data);
163
164 private:
165 int m_channel;
166};
167} // namespace sim
168} // namespace frc
A class for driving addressable LEDs, such as WS2812B, WS2815, and NeoPixels.
Definition AddressableLED.h:33
Class to control a simulated addressable LED.
Definition AddressableLEDSim.h:22
void SetData(struct HAL_AddressableLEDData *data)
Change the LED data.
std::unique_ptr< CallbackStore > RegisterStartCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the start.
void SetInitialized(bool initialized)
Change the Initialized value of the LED strip.
int GetStart() const
Get the start.
int GetData(struct HAL_AddressableLEDData *data) const
Get the LED data.
AddressableLEDSim(const AddressableLED &addressableLED)
Constructs from an AddressableLED object.
void SetLength(int length)
Change the length of the LED strip.
static int GetGlobalData(int start, int length, struct HAL_AddressableLEDData *data)
Get the global LED data.
bool GetInitialized() const
Check if initialized.
int GetLength() const
Get the length of the LED strip.
std::unique_ptr< CallbackStore > RegisterLengthCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the length.
void SetStart(int start)
Change the start.
static std::unique_ptr< CallbackStore > RegisterDataCallback(ConstBufferCallback callback, bool initialNotify)
Register a callback on the LED data.
AddressableLEDSim(int channel)
Constructs an addressable LED for a specific channel.
static void SetGlobalData(int start, int length, struct HAL_AddressableLEDData *data)
Change the global 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:15
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition CallbackStore.h:14
Definition SystemServer.h:9
structure for holding one LED's color data.
Definition AddressableLEDTypes.h:14