WPILibC++ 2023.4.3-108-ge5452e3
SmartDashboard.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#include <span>
9#include <string>
10#include <string_view>
11#include <vector>
12
15
16namespace wpi {
17class Sendable;
18} // namespace wpi
19
20namespace frc {
21
23 public:
24 SmartDashboard() = delete;
25
26 static void init();
27
28 /**
29 * Determines whether the given key is in this table.
30 *
31 * @param key the key to search for
32 * @return true if the table as a value assigned to the given key
33 */
34 static bool ContainsKey(std::string_view key);
35
36 /**
37 * @param types bitmask of types; 0 is treated as a "don't care".
38 * @return keys currently in the table
39 */
40 static std::vector<std::string> GetKeys(int types = 0);
41
42 /**
43 * Makes a key's value persistent through program restarts.
44 *
45 * @param key the key to make persistent
46 */
48
49 /**
50 * Stop making a key's value persistent through program restarts.
51 * The key cannot be null.
52 *
53 * @param key the key name
54 */
56
57 /**
58 * Returns whether the value is persistent through program restarts.
59 * The key cannot be null.
60 *
61 * @param key the key name
62 */
64
65 /**
66 * Returns an NT Entry mapping to the specified key
67 *
68 * This is useful if an entry is used often, or is read and then modified.
69 *
70 * @param key the key
71 * @return the entry for the key
72 */
74
75 /**
76 * Maps the specified key to the specified value in this table.
77 *
78 * The value can be retrieved by calling the get method with a key that is
79 * equal to the original key.
80 *
81 * In order for the value to appear in the dashboard, it must be registered
82 * with SendableRegistry. WPILib components do this automatically.
83 *
84 * @param key the key
85 * @param data the value
86 */
88
89 /**
90 * Maps the specified key (where the key is the name of the Sendable)
91 * to the specified value in this table.
92 *
93 * The value can be retrieved by calling the get method with a key that is
94 * equal to the original key.
95 *
96 * In order for the value to appear in the dashboard, it must be registered
97 * with SendableRegistry. WPILib components do this automatically.
98 *
99 * @param value the value
100 */
102
103 /**
104 * Returns the value at the specified key.
105 *
106 * @param keyName the key
107 * @return the value
108 */
110
111 /**
112 * Maps the specified key to the specified value in this table.
113 *
114 * The value can be retrieved by calling the get method with a key that is
115 * equal to the original key.
116 *
117 * @param keyName the key
118 * @param value the value
119 * @return False if the table key already exists with a different type
120 */
121 static bool PutBoolean(std::string_view keyName, bool value);
122
123 /**
124 * Gets the current value in the table, setting it if it does not exist.
125 * @param key the key
126 * @param defaultValue the default value to set if key doesn't exist.
127 * @returns False if the table key exists with a different type
128 */
129 static bool SetDefaultBoolean(std::string_view key, bool defaultValue);
130
131 /**
132 * Returns the value at the specified key.
133 *
134 * If the key is not found, returns the default value.
135 *
136 * @param keyName the key
137 * @param defaultValue the default value to set if key doesn't exist
138 * @return the value
139 */
140 static bool GetBoolean(std::string_view keyName, bool defaultValue);
141
142 /**
143 * Maps the specified key to the specified value in this table.
144 *
145 * The value can be retrieved by calling the get method with a key that is
146 * equal to the original key.
147 *
148 * @param keyName the key
149 * @param value the value
150 * @return False if the table key already exists with a different type
151 */
152 static bool PutNumber(std::string_view keyName, double value);
153
154 /**
155 * Gets the current value in the table, setting it if it does not exist.
156 *
157 * @param key The key.
158 * @param defaultValue The default value to set if key doesn't exist.
159 * @returns False if the table key exists with a different type
160 */
161 static bool SetDefaultNumber(std::string_view key, double defaultValue);
162
163 /**
164 * Returns the value at the specified key.
165 *
166 * If the key is not found, returns the default value.
167 *
168 * @param keyName the key
169 * @param defaultValue the default value to set if the key doesn't exist
170 * @return the value
171 */
172 static double GetNumber(std::string_view keyName, double defaultValue);
173
174 /**
175 * Maps the specified key to the specified value in this table.
176 *
177 * The value can be retrieved by calling the get method with a key that is
178 * equal to the original key.
179 *
180 * @param keyName the key
181 * @param value the value
182 * @return False if the table key already exists with a different type
183 */
185
186 /**
187 * Gets the current value in the table, setting it if it does not exist.
188 *
189 * @param key the key
190 * @param defaultValue the default value to set if key doesn't exist.
191 * @returns False if the table key exists with a different type
192 */
194 std::string_view defaultValue);
195
196 /**
197 * Returns the value at the specified key.
198 *
199 * If the key is not found, returns the default value.
200 *
201 * @param keyName the key
202 * @param defaultValue the default value to set if the key doesn't exist
203 * @return the value
204 */
205 static std::string GetString(std::string_view keyName,
206 std::string_view defaultValue);
207
208 /**
209 * Put a boolean array in the table.
210 *
211 * @param key the key to be assigned to
212 * @param value the value that will be assigned
213 * @return False if the table key already exists with a different type
214 *
215 * @note The array must be of int's rather than of bool's because
216 * std::vector<bool> is special-cased in C++. 0 is false, any
217 * non-zero value is true.
218 */
219 static bool PutBooleanArray(std::string_view key, std::span<const int> value);
220
221 /**
222 * Gets the current value in the table, setting it if it does not exist.
223 *
224 * @param key the key
225 * @param defaultValue the default value to set if key doesn't exist.
226 * @returns False if the table key exists with a different type
227 */
229 std::span<const int> defaultValue);
230
231 /**
232 * Returns the boolean array the key maps to.
233 *
234 * If the key does not exist or is of different type, it will return the
235 * default value.
236 *
237 * @param key The key to look up.
238 * @param defaultValue The value to be returned if no value is found.
239 * @return the value associated with the given key or the given default value
240 * if there is no value associated with the key
241 *
242 * @note This makes a copy of the array. If the overhead of this is a concern,
243 * use GetValue() instead.
244 *
245 * @note The returned array is std::vector<int> instead of std::vector<bool>
246 * because std::vector<bool> is special-cased in C++. 0 is false, any
247 * non-zero value is true.
248 */
249 static std::vector<int> GetBooleanArray(std::string_view key,
250 std::span<const int> defaultValue);
251
252 /**
253 * Put a number array in the table.
254 *
255 * @param key The key to be assigned to.
256 * @param value The value that will be assigned.
257 * @return False if the table key already exists with a different type
258 */
260 std::span<const double> value);
261
262 /**
263 * Gets the current value in the table, setting it if it does not exist.
264 *
265 * @param key The key.
266 * @param defaultValue The default value to set if key doesn't exist.
267 * @returns False if the table key exists with a different type
268 */
270 std::span<const double> defaultValue);
271
272 /**
273 * Returns the number array the key maps to.
274 *
275 * If the key does not exist or is of different type, it will return the
276 * default value.
277 *
278 * @param key The key to look up.
279 * @param defaultValue The value to be returned if no value is found.
280 * @return the value associated with the given key or the given default value
281 * if there is no value associated with the key
282 *
283 * @note This makes a copy of the array. If the overhead of this is a concern,
284 * use GetValue() instead.
285 */
286 static std::vector<double> GetNumberArray(
287 std::string_view key, std::span<const double> defaultValue);
288
289 /**
290 * Put a string array in the table.
291 *
292 * @param key The key to be assigned to.
293 * @param value The value that will be assigned.
294 * @return False if the table key already exists with a different type
295 */
297 std::span<const std::string> value);
298
299 /**
300 * Gets the current value in the table, setting it if it does not exist.
301 *
302 * @param key The key.
303 * @param defaultValue The default value to set if key doesn't exist.
304 * @returns False if the table key exists with a different type
305 */
307 std::span<const std::string> defaultValue);
308
309 /**
310 * Returns the string array the key maps to.
311 *
312 * If the key does not exist or is of different type, it will return the
313 * default value.
314 *
315 * @param key The key to look up.
316 * @param defaultValue The value to be returned if no value is found.
317 * @return the value associated with the given key or the given default value
318 * if there is no value associated with the key
319 *
320 * @note This makes a copy of the array. If the overhead of this is a concern,
321 * use GetValue() instead.
322 */
323 static std::vector<std::string> GetStringArray(
324 std::string_view key, std::span<const std::string> defaultValue);
325
326 /**
327 * Put a raw value (byte array) in the table.
328 *
329 * @param key The key to be assigned to.
330 * @param value The value that will be assigned.
331 * @return False if the table key already exists with a different type
332 */
333 static bool PutRaw(std::string_view key, std::span<const uint8_t> value);
334
335 /**
336 * Gets the current value in the table, setting it if it does not exist.
337 *
338 * @param key The key.
339 * @param defaultValue The default value to set if key doesn't exist.
340 * @returns False if the table key exists with a different type
341 */
343 std::span<const uint8_t> defaultValue);
344
345 /**
346 * Returns the raw value (byte array) the key maps to.
347 *
348 * If the key does not exist or is of different type, it will return the
349 * default value.
350 *
351 * @param key The key to look up.
352 * @param defaultValue The value to be returned if no value is found.
353 * @return the value associated with the given key or the given default value
354 * if there is no value associated with the key
355 *
356 * @note This makes a copy of the raw contents. If the overhead of this is a
357 * concern, use GetValue() instead.
358 */
359 static std::vector<uint8_t> GetRaw(std::string_view key,
360 std::span<const uint8_t> defaultValue);
361
362 /**
363 * Maps the specified key to the specified complex value (such as an array) in
364 * this table.
365 *
366 * The value can be retrieved by calling the RetrieveValue method with a key
367 * that is equal to the original key.
368 *
369 * @param keyName the key
370 * @param value the value
371 * @return False if the table key already exists with a different type
372 */
373 static bool PutValue(std::string_view keyName, const nt::Value& value);
374
375 /**
376 * Gets the current value in the table, setting it if it does not exist.
377 *
378 * @param key the key
379 * @param defaultValue The default value to set if key doesn't exist.
380 * @returns False if the table key exists with a different type
381 */
383 const nt::Value& defaultValue);
384
385 /**
386 * Retrieves the complex value (such as an array) in this table into the
387 * complex data object.
388 *
389 * @param keyName the key
390 */
392
393 /**
394 * Posts a task from a listener to the ListenerExecutor, so that it can be run
395 * synchronously from the main loop on the next call to updateValues().
396 *
397 * @param task The task to run synchronously from the main thread.
398 */
399 static void PostListenerTask(std::function<void()> task);
400
401 /**
402 * Puts all sendable data to the dashboard.
403 */
404 static void UpdateValues();
405};
406
407} // namespace frc
Definition: SmartDashboard.h:22
static wpi::Sendable * GetData(std::string_view keyName)
Returns the value at the specified key.
static void init()
static bool IsPersistent(std::string_view key)
Returns whether the value is persistent through program restarts.
static void UpdateValues()
Puts all sendable data to the dashboard.
static void PutData(wpi::Sendable *value)
Maps the specified key (where the key is the name of the Sendable) to the specified value in this tab...
static bool SetDefaultNumber(std::string_view key, double defaultValue)
Gets the current value in the table, setting it if it does not exist.
static bool PutBoolean(std::string_view keyName, bool value)
Maps the specified key to the specified value in this table.
static bool SetDefaultNumberArray(std::string_view key, std::span< const double > defaultValue)
Gets the current value in the table, setting it if it does not exist.
static bool GetBoolean(std::string_view keyName, bool defaultValue)
Returns the value at the specified key.
static void SetPersistent(std::string_view key)
Makes a key's value persistent through program restarts.
static bool PutBooleanArray(std::string_view key, std::span< const int > value)
Put a boolean array in the table.
static bool SetDefaultStringArray(std::string_view key, std::span< const std::string > defaultValue)
Gets the current value in the table, setting it if it does not exist.
static bool SetDefaultBoolean(std::string_view key, bool defaultValue)
Gets the current value in the table, setting it if it does not exist.
static nt::Value GetValue(std::string_view keyName)
Retrieves the complex value (such as an array) in this table into the complex data object.
static std::string GetString(std::string_view keyName, std::string_view defaultValue)
Returns the value at the specified key.
static nt::NetworkTableEntry GetEntry(std::string_view key)
Returns an NT Entry mapping to the specified key.
static bool SetDefaultBooleanArray(std::string_view key, std::span< const int > defaultValue)
Gets the current value in the table, setting it if it does not exist.
static bool PutNumber(std::string_view keyName, double value)
Maps the specified key to the specified value in this table.
static std::vector< double > GetNumberArray(std::string_view key, std::span< const double > defaultValue)
Returns the number array the key maps to.
static std::vector< std::string > GetStringArray(std::string_view key, std::span< const std::string > defaultValue)
Returns the string array the key maps to.
static std::vector< uint8_t > GetRaw(std::string_view key, std::span< const uint8_t > defaultValue)
Returns the raw value (byte array) the key maps to.
static bool SetDefaultString(std::string_view key, std::string_view defaultValue)
Gets the current value in the table, setting it if it does not exist.
static bool PutValue(std::string_view keyName, const nt::Value &value)
Maps the specified key to the specified complex value (such as an array) in this table.
static bool SetDefaultRaw(std::string_view key, std::span< const uint8_t > defaultValue)
Gets the current value in the table, setting it if it does not exist.
static void ClearPersistent(std::string_view key)
Stop making a key's value persistent through program restarts.
static bool SetDefaultValue(std::string_view key, const nt::Value &defaultValue)
Gets the current value in the table, setting it if it does not exist.
static bool ContainsKey(std::string_view key)
Determines whether the given key is in this table.
static double GetNumber(std::string_view keyName, double defaultValue)
Returns the value at the specified key.
static bool PutStringArray(std::string_view key, std::span< const std::string > value)
Put a string array in the table.
static void PutData(std::string_view key, wpi::Sendable *data)
Maps the specified key to the specified value in this table.
static void PostListenerTask(std::function< void()> task)
Posts a task from a listener to the ListenerExecutor, so that it can be run synchronously from the ma...
static std::vector< int > GetBooleanArray(std::string_view key, std::span< const int > defaultValue)
Returns the boolean array the key maps to.
static bool PutString(std::string_view keyName, std::string_view value)
Maps the specified key to the specified value in this table.
static bool PutRaw(std::string_view key, std::span< const uint8_t > value)
Put a raw value (byte array) in the table.
static bool PutNumberArray(std::string_view key, std::span< const double > value)
Put a number array in the table.
static std::vector< std::string > GetKeys(int types=0)
NetworkTables Entry.
Definition: NetworkTableEntry.h:34
A network table entry value.
Definition: NetworkTableValue.h:27
Definition: core.h:1240
Interface for Sendable objects.
Definition: Sendable.h:16
basic_string_view< char > string_view
Definition: core.h:520
Definition: AprilTagPoseEstimator.h:15
Definition: AprilTagFieldLayout.h:18
Definition: format.h:1552