WPILibC++  2020.3.2-60-g3011ebe
SmartDashboard.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2011-2019 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <memory>
11 #include <string>
12 #include <vector>
13 
14 #include <networktables/NetworkTableEntry.h>
15 #include <networktables/NetworkTableValue.h>
16 
17 #include "frc/ErrorBase.h"
18 #include "frc/smartdashboard/ListenerExecutor.h"
19 #include "frc/smartdashboard/Sendable.h"
20 #include "frc/smartdashboard/SendableHelper.h"
21 
22 namespace frc {
23 
24 class SmartDashboard : public ErrorBase,
25  public Sendable,
26  public SendableHelper<SmartDashboard> {
27  public:
28  static void init();
29 
36  static bool ContainsKey(wpi::StringRef key);
37 
42  static std::vector<std::string> GetKeys(int types = 0);
43 
49  static void SetPersistent(wpi::StringRef key);
50 
57  static void ClearPersistent(wpi::StringRef key);
58 
65  static bool IsPersistent(wpi::StringRef key);
66 
74  static void SetFlags(wpi::StringRef key, unsigned int flags);
75 
83  static void ClearFlags(wpi::StringRef key, unsigned int flags);
84 
91  static unsigned int GetFlags(wpi::StringRef key);
92 
98  static void Delete(wpi::StringRef key);
99 
109 
122  static void PutData(wpi::StringRef key, Sendable* data);
123 
136  static void PutData(Sendable* value);
137 
144  static Sendable* GetData(wpi::StringRef keyName);
145 
156  static bool PutBoolean(wpi::StringRef keyName, bool value);
157 
164  static bool SetDefaultBoolean(wpi::StringRef key, bool defaultValue);
165 
174  static bool GetBoolean(wpi::StringRef keyName, bool defaultValue);
175 
186  static bool PutNumber(wpi::StringRef keyName, double value);
187 
195  static bool SetDefaultNumber(wpi::StringRef key, double defaultValue);
196 
205  static double GetNumber(wpi::StringRef keyName, double defaultValue);
206 
217  static bool PutString(wpi::StringRef keyName, wpi::StringRef value);
218 
226  static bool SetDefaultString(wpi::StringRef key, wpi::StringRef defaultValue);
227 
236  static std::string GetString(wpi::StringRef keyName,
237  wpi::StringRef defaultValue);
238 
250  static bool PutBooleanArray(wpi::StringRef key, wpi::ArrayRef<int> value);
251 
259  static bool SetDefaultBooleanArray(wpi::StringRef key,
260  wpi::ArrayRef<int> defaultValue);
261 
280  static std::vector<int> GetBooleanArray(wpi::StringRef key,
281  wpi::ArrayRef<int> defaultValue);
282 
290  static bool PutNumberArray(wpi::StringRef key, wpi::ArrayRef<double> value);
291 
299  static bool SetDefaultNumberArray(wpi::StringRef key,
300  wpi::ArrayRef<double> defaultValue);
301 
316  static std::vector<double> GetNumberArray(wpi::StringRef key,
317  wpi::ArrayRef<double> defaultValue);
318 
326  static bool PutStringArray(wpi::StringRef key,
328 
336  static bool SetDefaultStringArray(wpi::StringRef key,
337  wpi::ArrayRef<std::string> defaultValue);
338 
353  static std::vector<std::string> GetStringArray(
354  wpi::StringRef key, wpi::ArrayRef<std::string> defaultValue);
355 
363  static bool PutRaw(wpi::StringRef key, wpi::StringRef value);
364 
372  static bool SetDefaultRaw(wpi::StringRef key, wpi::StringRef defaultValue);
373 
388  static std::string GetRaw(wpi::StringRef key, wpi::StringRef defaultValue);
389 
401  static bool PutValue(wpi::StringRef keyName,
402  std::shared_ptr<nt::Value> value);
403 
411  static bool SetDefaultValue(wpi::StringRef key,
412  std::shared_ptr<nt::Value> defaultValue);
413 
421  static std::shared_ptr<nt::Value> GetValue(wpi::StringRef keyName);
422 
430  static void PostListenerTask(std::function<void()> task);
431 
435  static void UpdateValues();
436 
437  private:
438  virtual ~SmartDashboard() = default;
439 
440  static detail::ListenerExecutor listenerExecutor;
441 };
442 
443 } // namespace frc
frc::SmartDashboard::SetDefaultBooleanArray
static bool SetDefaultBooleanArray(wpi::StringRef key, wpi::ArrayRef< int > defaultValue)
Gets the current value in the table, setting it if it does not exist.
frc::SmartDashboard::PostListenerTask
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...
frc::SmartDashboard::SetDefaultValue
static bool SetDefaultValue(wpi::StringRef key, std::shared_ptr< nt::Value > defaultValue)
Gets the current value in the table, setting it if it does not exist.
frc::SmartDashboard::SetDefaultNumberArray
static bool SetDefaultNumberArray(wpi::StringRef key, wpi::ArrayRef< double > defaultValue)
Gets the current value in the table, setting it if it does not exist.
frc::SmartDashboard::PutRaw
static bool PutRaw(wpi::StringRef key, wpi::StringRef value)
Put a raw value (byte array) in the table.
frc::SmartDashboard::PutBooleanArray
static bool PutBooleanArray(wpi::StringRef key, wpi::ArrayRef< int > value)
Put a boolean array in the table.
frc::SmartDashboard::PutNumber
static bool PutNumber(wpi::StringRef keyName, double value)
Maps the specified key to the specified value in this table.
frc::SmartDashboard::SetDefaultString
static bool SetDefaultString(wpi::StringRef key, wpi::StringRef defaultValue)
Gets the current value in the table, setting it if it does not exist.
wpi::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:42
frc::SmartDashboard::SetDefaultBoolean
static bool SetDefaultBoolean(wpi::StringRef key, bool defaultValue)
Gets the current value in the table, setting it if it does not exist.
frc::SmartDashboard::GetRaw
static std::string GetRaw(wpi::StringRef key, wpi::StringRef defaultValue)
Returns the raw value (byte array) the key maps to.
frc::SmartDashboard::ClearFlags
static void ClearFlags(wpi::StringRef key, unsigned int flags)
Clears flags on the specified key in this table.
nt::NetworkTableEntry
NetworkTables Entry.
Definition: NetworkTableEntry.h:39
frc::SmartDashboard::GetNumberArray
static std::vector< double > GetNumberArray(wpi::StringRef key, wpi::ArrayRef< double > defaultValue)
Returns the number array the key maps to.
frc::SmartDashboard::GetValue
static std::shared_ptr< nt::Value > GetValue(wpi::StringRef keyName)
Retrieves the complex value (such as an array) in this table into the complex data object.
frc::SmartDashboard::GetNumber
static double GetNumber(wpi::StringRef keyName, double defaultValue)
Returns the value at the specified key.
frc::SmartDashboard::SetDefaultStringArray
static bool SetDefaultStringArray(wpi::StringRef key, wpi::ArrayRef< std::string > defaultValue)
Gets the current value in the table, setting it if it does not exist.
frc::SmartDashboard::SetFlags
static void SetFlags(wpi::StringRef key, unsigned int flags)
Sets flags on the specified key in this table.
frc::detail::ListenerExecutor
An executor for running listener tasks posted by Sendable listeners synchronously from the main appli...
Definition: ListenerExecutor.h:22
frc::SmartDashboard::SetDefaultNumber
static bool SetDefaultNumber(wpi::StringRef key, double defaultValue)
Gets the current value in the table, setting it if it does not exist.
frc::SmartDashboard::GetEntry
static nt::NetworkTableEntry GetEntry(wpi::StringRef key)
Returns an NT Entry mapping to the specified key.
frc::ErrorBase
Base class for most objects.
Definition: ErrorBase.h:104
frc::SmartDashboard::IsPersistent
static bool IsPersistent(wpi::StringRef key)
Returns whether the value is persistent through program restarts.
frc::SmartDashboard::GetKeys
static std::vector< std::string > GetKeys(int types=0)
frc::SmartDashboard::SetPersistent
static void SetPersistent(wpi::StringRef key)
Makes a key's value persistent through program restarts.
frc::SmartDashboard::ClearPersistent
static void ClearPersistent(wpi::StringRef key)
Stop making a key's value persistent through program restarts.
wpi::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
frc::SmartDashboard::PutStringArray
static bool PutStringArray(wpi::StringRef key, wpi::ArrayRef< std::string > value)
Put a string array in the table.
frc::SmartDashboard::PutBoolean
static bool PutBoolean(wpi::StringRef keyName, bool value)
Maps the specified key to the specified value in this table.
frc::SmartDashboard::GetBoolean
static bool GetBoolean(wpi::StringRef keyName, bool defaultValue)
Returns the value at the specified key.
frc::SmartDashboard::Delete
static void Delete(wpi::StringRef key)
Deletes the specified key in this table.
frc::SmartDashboard::GetFlags
static unsigned int GetFlags(wpi::StringRef key)
Returns the flags for the specified key.
frc::Sendable
Interface for Sendable objects.
Definition: Sendable.h:17
frc::SmartDashboard
Definition: SmartDashboard.h:24
frc::SmartDashboard::ContainsKey
static bool ContainsKey(wpi::StringRef key)
Determines whether the given key is in this table.
frc::SmartDashboard::GetString
static std::string GetString(wpi::StringRef keyName, wpi::StringRef defaultValue)
Returns the value at the specified key.
frc::SmartDashboard::PutValue
static bool PutValue(wpi::StringRef keyName, std::shared_ptr< nt::Value > value)
Maps the specified key to the specified complex value (such as an array) in this table.
frc::SmartDashboard::GetStringArray
static std::vector< std::string > GetStringArray(wpi::StringRef key, wpi::ArrayRef< std::string > defaultValue)
Returns the string array the key maps to.
frc
A class that enforces constraints on the differential drive kinematics.
Definition: PDPSim.h:16
frc::SmartDashboard::GetData
static Sendable * GetData(wpi::StringRef keyName)
Returns the value at the specified key.
frc::SmartDashboard::PutData
static void PutData(wpi::StringRef key, Sendable *data)
Maps the specified key to the specified value in this table.
frc::SmartDashboard::UpdateValues
static void UpdateValues()
Puts all sendable data to the dashboard.
frc::SmartDashboard::PutNumberArray
static bool PutNumberArray(wpi::StringRef key, wpi::ArrayRef< double > value)
Put a number array in the table.
frc::SmartDashboard::GetBooleanArray
static std::vector< int > GetBooleanArray(wpi::StringRef key, wpi::ArrayRef< int > defaultValue)
Returns the boolean array the key maps to.
frc::SendableHelper
A helper class for use with objects that add themselves to SendableRegistry.
Definition: SendableHelper.h:28
frc::SmartDashboard::PutString
static bool PutString(wpi::StringRef keyName, wpi::StringRef value)
Maps the specified key to the specified value in this table.
frc::SmartDashboard::SetDefaultRaw
static bool SetDefaultRaw(wpi::StringRef key, wpi::StringRef defaultValue)
Gets the current value in the table, setting it if it does not exist.