2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2011-2018 FIRST. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "SmartDashboard/SmartDashboard.h"
|
|
|
|
|
|
2017-12-04 23:28:33 -08:00
|
|
|
#include <llvm/StringMap.h>
|
2017-12-07 23:34:29 -08:00
|
|
|
#include <networktables/NetworkTable.h>
|
|
|
|
|
#include <networktables/NetworkTableInstance.h>
|
2017-12-04 23:28:33 -08:00
|
|
|
#include <support/mutex.h>
|
2017-09-02 00:17:43 -07:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
#include "HLUsageReporting.h"
|
2017-12-04 23:28:33 -08:00
|
|
|
#include "SmartDashboard/Sendable.h"
|
|
|
|
|
#include "SmartDashboard/SendableBuilderImpl.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
#include "WPIErrors.h"
|
|
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
using namespace frc;
|
|
|
|
|
|
2017-12-04 23:28:33 -08:00
|
|
|
namespace {
|
2017-12-26 17:18:02 -06:00
|
|
|
class SmartDashboardData {
|
|
|
|
|
public:
|
|
|
|
|
SmartDashboardData() = default;
|
|
|
|
|
explicit SmartDashboardData(Sendable* sendable_) : sendable(sendable_) {}
|
|
|
|
|
|
2017-12-04 23:28:33 -08:00
|
|
|
Sendable* sendable = nullptr;
|
|
|
|
|
SendableBuilderImpl builder;
|
|
|
|
|
};
|
|
|
|
|
|
2017-12-04 23:50:27 -08:00
|
|
|
class Singleton {
|
|
|
|
|
public:
|
|
|
|
|
static Singleton& GetInstance();
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<nt::NetworkTable> table;
|
|
|
|
|
llvm::StringMap<SmartDashboardData> tablesToData;
|
|
|
|
|
wpi::mutex tablesToDataMutex;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Singleton() {
|
|
|
|
|
table = nt::NetworkTableInstance::GetDefault().GetTable("SmartDashboard");
|
|
|
|
|
HLUsageReporting::ReportSmartDashboard();
|
|
|
|
|
}
|
|
|
|
|
Singleton(const Singleton&) = delete;
|
|
|
|
|
Singleton& operator=(const Singleton&) = delete;
|
|
|
|
|
};
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2017-12-04 23:50:27 -08:00
|
|
|
} // namespace
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2017-12-04 23:50:27 -08:00
|
|
|
Singleton& Singleton::GetInstance() {
|
|
|
|
|
static Singleton instance;
|
|
|
|
|
return instance;
|
2014-08-04 14:43:31 -04:00
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2017-12-04 23:50:27 -08:00
|
|
|
void SmartDashboard::init() { Singleton::GetInstance(); }
|
|
|
|
|
|
2016-10-03 09:59:18 -07:00
|
|
|
/**
|
2017-11-11 22:09:51 -08:00
|
|
|
* Determines whether the given key is in this table.
|
|
|
|
|
*
|
|
|
|
|
* @param key the key to search for
|
|
|
|
|
* @return true if the table as a value assigned to the given key
|
|
|
|
|
*/
|
2016-10-03 09:59:18 -07:00
|
|
|
bool SmartDashboard::ContainsKey(llvm::StringRef key) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->ContainsKey(key);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param types bitmask of types; 0 is treated as a "don't care".
|
|
|
|
|
* @return keys currently in the table
|
|
|
|
|
*/
|
|
|
|
|
std::vector<std::string> SmartDashboard::GetKeys(int types) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetKeys(types);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Makes a key's value persistent through program restarts.
|
|
|
|
|
*
|
|
|
|
|
* @param key the key to make persistent
|
|
|
|
|
*/
|
|
|
|
|
void SmartDashboard::SetPersistent(llvm::StringRef key) {
|
2017-12-04 23:50:27 -08:00
|
|
|
Singleton::GetInstance().table->GetEntry(key).SetPersistent();
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Stop making a key's value persistent through program restarts.
|
|
|
|
|
* The key cannot be null.
|
|
|
|
|
*
|
|
|
|
|
* @param key the key name
|
|
|
|
|
*/
|
|
|
|
|
void SmartDashboard::ClearPersistent(llvm::StringRef key) {
|
2017-12-04 23:50:27 -08:00
|
|
|
Singleton::GetInstance().table->GetEntry(key).ClearPersistent();
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns whether the value is persistent through program restarts.
|
|
|
|
|
* The key cannot be null.
|
|
|
|
|
*
|
|
|
|
|
* @param key the key name
|
|
|
|
|
*/
|
|
|
|
|
bool SmartDashboard::IsPersistent(llvm::StringRef key) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(key).IsPersistent();
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets flags on the specified key in this table. The key can
|
|
|
|
|
* not be null.
|
|
|
|
|
*
|
|
|
|
|
* @param key the key name
|
|
|
|
|
* @param flags the flags to set (bitmask)
|
|
|
|
|
*/
|
|
|
|
|
void SmartDashboard::SetFlags(llvm::StringRef key, unsigned int flags) {
|
2017-12-04 23:50:27 -08:00
|
|
|
Singleton::GetInstance().table->GetEntry(key).SetFlags(flags);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clears flags on the specified key in this table. The key can
|
|
|
|
|
* not be null.
|
|
|
|
|
*
|
|
|
|
|
* @param key the key name
|
|
|
|
|
* @param flags the flags to clear (bitmask)
|
|
|
|
|
*/
|
|
|
|
|
void SmartDashboard::ClearFlags(llvm::StringRef key, unsigned int flags) {
|
2017-12-04 23:50:27 -08:00
|
|
|
Singleton::GetInstance().table->GetEntry(key).ClearFlags(flags);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the flags for the specified key.
|
|
|
|
|
*
|
|
|
|
|
* @param key the key name
|
|
|
|
|
* @return the flags, or 0 if the key is not defined
|
|
|
|
|
*/
|
|
|
|
|
unsigned int SmartDashboard::GetFlags(llvm::StringRef key) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(key).GetFlags();
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Deletes the specified key in this table.
|
|
|
|
|
*
|
|
|
|
|
* @param key the key name
|
|
|
|
|
*/
|
2017-12-04 23:50:27 -08:00
|
|
|
void SmartDashboard::Delete(llvm::StringRef key) {
|
|
|
|
|
Singleton::GetInstance().table->Delete(key);
|
|
|
|
|
}
|
2016-10-03 09:59:18 -07:00
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
|
|
|
|
* Maps the specified key to the specified value in this table.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* The value can be retrieved by calling the get method with a key that is equal
|
|
|
|
|
* to the original key.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param keyName the key
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param value the value
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
void SmartDashboard::PutData(llvm::StringRef key, Sendable* data) {
|
2015-06-23 04:49:51 -07:00
|
|
|
if (data == nullptr) {
|
2015-06-25 15:07:55 -04:00
|
|
|
wpi_setGlobalWPIErrorWithContext(NullParameter, "value");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-12-04 23:50:27 -08:00
|
|
|
auto& inst = Singleton::GetInstance();
|
|
|
|
|
std::lock_guard<wpi::mutex> lock(inst.tablesToDataMutex);
|
|
|
|
|
auto& sddata = inst.tablesToData[key];
|
2017-12-04 23:28:33 -08:00
|
|
|
if (!sddata.sendable || sddata.sendable != data) {
|
2017-12-26 17:18:02 -06:00
|
|
|
sddata = SmartDashboardData(data);
|
2018-01-02 14:39:16 -08:00
|
|
|
auto dataTable = inst.table->GetSubTable(key);
|
|
|
|
|
sddata.builder.SetTable(dataTable);
|
2017-12-04 23:28:33 -08:00
|
|
|
data->InitSendable(sddata.builder);
|
2017-12-26 17:18:02 -06:00
|
|
|
sddata.builder.UpdateTable();
|
|
|
|
|
sddata.builder.StartListeners();
|
2018-01-02 14:39:16 -08:00
|
|
|
dataTable->GetEntry(".name").SetString(key);
|
2017-12-04 23:28:33 -08:00
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-04 23:28:33 -08:00
|
|
|
* Maps the specified key (where the key is the name of the Sendable)
|
|
|
|
|
* to the specified value in this table.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* The value can be retrieved by calling the get method with a key that is equal
|
|
|
|
|
* to the original key.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param value the value
|
|
|
|
|
*/
|
2017-12-04 23:28:33 -08:00
|
|
|
void SmartDashboard::PutData(Sendable* value) {
|
2015-06-23 04:49:51 -07:00
|
|
|
if (value == nullptr) {
|
2015-06-25 15:07:55 -04:00
|
|
|
wpi_setGlobalWPIErrorWithContext(NullParameter, "value");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
PutData(value->GetName(), value);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the value at the specified key.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param keyName the key
|
|
|
|
|
* @return the value
|
|
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
Sendable* SmartDashboard::GetData(llvm::StringRef key) {
|
2017-12-04 23:50:27 -08:00
|
|
|
auto& inst = Singleton::GetInstance();
|
|
|
|
|
std::lock_guard<wpi::mutex> lock(inst.tablesToDataMutex);
|
|
|
|
|
auto data = inst.tablesToData.find(key);
|
|
|
|
|
if (data == inst.tablesToData.end()) {
|
2015-08-13 23:17:19 -07:00
|
|
|
wpi_setGlobalWPIErrorWithContext(SmartDashboardMissingKey, key);
|
2015-06-23 04:49:51 -07:00
|
|
|
return nullptr;
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
2017-12-04 23:28:33 -08:00
|
|
|
return data->getValue().sendable;
|
2014-08-04 14:43:31 -04:00
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* Maps the specified key to the specified complex value (such as an array) in
|
|
|
|
|
* this table.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* The value can be retrieved by calling the RetrieveValue method with a key
|
|
|
|
|
* that is equal to the original key.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param keyName the key
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param value the value
|
2016-10-03 09:59:18 -07:00
|
|
|
* @return False if the table key already exists with a different type
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2016-10-03 09:59:18 -07:00
|
|
|
bool SmartDashboard::PutValue(llvm::StringRef keyName,
|
2015-08-13 23:17:19 -07:00
|
|
|
std::shared_ptr<nt::Value> value) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(keyName).SetValue(value);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-11-11 22:09:51 -08:00
|
|
|
* Gets the current value in the table, setting it if it does not exist.
|
2017-11-16 00:33:51 -08:00
|
|
|
*
|
2017-11-11 22:09:51 -08:00
|
|
|
* @param key the key
|
2017-11-16 00:33:51 -08:00
|
|
|
* @param defaultValue The default value to set if key doesn't exist.
|
2017-11-11 22:09:51 -08:00
|
|
|
* @returns False if the table key exists with a different type
|
|
|
|
|
*/
|
2016-10-03 09:59:18 -07:00
|
|
|
bool SmartDashboard::SetDefaultValue(llvm::StringRef key,
|
|
|
|
|
std::shared_ptr<nt::Value> defaultValue) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(key).SetDefaultValue(
|
|
|
|
|
defaultValue);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* Retrieves the complex value (such as an array) in this table into the complex
|
2016-05-20 17:30:37 -07:00
|
|
|
* data object.
|
|
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param keyName the key
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param value the object to retrieve the value into
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-08-13 23:17:19 -07:00
|
|
|
std::shared_ptr<nt::Value> SmartDashboard::GetValue(llvm::StringRef keyName) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(keyName).GetValue();
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Maps the specified key to the specified value in this table.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* The value can be retrieved by calling the get method with a key that is equal
|
|
|
|
|
* to the original key.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param keyName the key
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param value the value
|
2016-10-03 09:59:18 -07:00
|
|
|
* @return False if the table key already exists with a different type
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2016-10-03 09:59:18 -07:00
|
|
|
bool SmartDashboard::PutBoolean(llvm::StringRef keyName, bool value) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(keyName).SetBoolean(value);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-11-11 22:09:51 -08:00
|
|
|
* Gets the current value in the table, setting it if it does not exist.
|
|
|
|
|
* @param key the key
|
|
|
|
|
* @param defaultValue the default value to set if key doesn't exist.
|
|
|
|
|
* @returns False if the table key exists with a different type
|
|
|
|
|
*/
|
2016-10-03 09:59:18 -07:00
|
|
|
bool SmartDashboard::SetDefaultBoolean(llvm::StringRef key, bool defaultValue) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(key).SetDefaultBoolean(
|
|
|
|
|
defaultValue);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2014-10-15 17:03:04 -04:00
|
|
|
/**
|
2016-05-20 17:30:37 -07:00
|
|
|
* Returns the value at the specified key.
|
|
|
|
|
*
|
|
|
|
|
* If the key is not found, returns the default value.
|
|
|
|
|
*
|
2014-10-15 17:03:04 -04:00
|
|
|
* @param keyName the key
|
|
|
|
|
* @return the value
|
|
|
|
|
*/
|
2015-08-13 23:17:19 -07:00
|
|
|
bool SmartDashboard::GetBoolean(llvm::StringRef keyName, bool defaultValue) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(keyName).GetBoolean(
|
|
|
|
|
defaultValue);
|
2014-10-15 17:03:04 -04:00
|
|
|
}
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
|
|
|
|
* Maps the specified key to the specified value in this table.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* The value can be retrieved by calling the get method with a key that is equal
|
|
|
|
|
* to the original key.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param keyName the key
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param value the value
|
2016-10-03 09:59:18 -07:00
|
|
|
* @return False if the table key already exists with a different type
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2016-10-03 09:59:18 -07:00
|
|
|
bool SmartDashboard::PutNumber(llvm::StringRef keyName, double value) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(keyName).SetDouble(value);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-11-11 22:09:51 -08:00
|
|
|
* Gets the current value in the table, setting it if it does not exist.
|
2017-11-16 00:33:51 -08:00
|
|
|
*
|
|
|
|
|
* @param key The key.
|
|
|
|
|
* @param defaultValue The default value to set if key doesn't exist.
|
2017-11-11 22:09:51 -08:00
|
|
|
* @returns False if the table key exists with a different type
|
|
|
|
|
*/
|
2016-10-03 09:59:18 -07:00
|
|
|
bool SmartDashboard::SetDefaultNumber(llvm::StringRef key,
|
|
|
|
|
double defaultValue) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(key).SetDefaultDouble(
|
|
|
|
|
defaultValue);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2014-10-15 17:03:04 -04:00
|
|
|
/**
|
2016-05-20 17:30:37 -07:00
|
|
|
* Returns the value at the specified key.
|
|
|
|
|
*
|
|
|
|
|
* If the key is not found, returns the default value.
|
|
|
|
|
*
|
2014-10-15 17:03:04 -04:00
|
|
|
* @param keyName the key
|
|
|
|
|
* @return the value
|
|
|
|
|
*/
|
2015-08-13 23:17:19 -07:00
|
|
|
double SmartDashboard::GetNumber(llvm::StringRef keyName, double defaultValue) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(keyName).GetDouble(
|
|
|
|
|
defaultValue);
|
2014-10-15 17:03:04 -04:00
|
|
|
}
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
|
|
|
|
* Maps the specified key to the specified value in this table.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* The value can be retrieved by calling the get method with a key that is equal
|
|
|
|
|
* to the original key.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @param keyName the key
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param value the value
|
2016-10-03 09:59:18 -07:00
|
|
|
* @return False if the table key already exists with a different type
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2016-10-03 09:59:18 -07:00
|
|
|
bool SmartDashboard::PutString(llvm::StringRef keyName, llvm::StringRef value) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(keyName).SetString(value);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the current value in the table, setting it if it does not exist.
|
|
|
|
|
* @param key the key
|
|
|
|
|
* @param defaultValue the default value to set if key doesn't exist.
|
|
|
|
|
* @returns False if the table key exists with a different type
|
|
|
|
|
*/
|
|
|
|
|
bool SmartDashboard::SetDefaultString(llvm::StringRef key,
|
|
|
|
|
llvm::StringRef defaultValue) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(key).SetDefaultString(
|
|
|
|
|
defaultValue);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2014-10-15 17:03:04 -04:00
|
|
|
/**
|
2016-05-20 17:30:37 -07:00
|
|
|
* Returns the value at the specified key.
|
|
|
|
|
*
|
|
|
|
|
* If the key is not found, returns the default value.
|
|
|
|
|
*
|
2014-10-15 17:03:04 -04:00
|
|
|
* @param keyName the key
|
|
|
|
|
* @return the value
|
|
|
|
|
*/
|
2015-08-13 23:17:19 -07:00
|
|
|
std::string SmartDashboard::GetString(llvm::StringRef keyName,
|
|
|
|
|
llvm::StringRef defaultValue) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(keyName).GetString(
|
|
|
|
|
defaultValue);
|
2014-10-15 17:03:04 -04:00
|
|
|
}
|
2016-10-03 09:59:18 -07:00
|
|
|
|
|
|
|
|
/**
|
2017-11-16 00:33:51 -08:00
|
|
|
* Put a boolean array in the table.
|
|
|
|
|
*
|
2017-11-11 22:09:51 -08:00
|
|
|
* @param key the key to be assigned to
|
|
|
|
|
* @param value the value that will be assigned
|
|
|
|
|
* @return False if the table key already exists with a different type
|
|
|
|
|
*
|
|
|
|
|
* @note The array must be of int's rather than of bool's because
|
2017-11-16 00:33:51 -08:00
|
|
|
* std::vector<bool> is special-cased in C++. 0 is false, any
|
2017-11-11 22:09:51 -08:00
|
|
|
* non-zero value is true.
|
|
|
|
|
*/
|
2016-10-03 09:59:18 -07:00
|
|
|
bool SmartDashboard::PutBooleanArray(llvm::StringRef key,
|
|
|
|
|
llvm::ArrayRef<int> value) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(key).SetBooleanArray(value);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the current value in the table, setting it if it does not exist.
|
2017-11-16 00:33:51 -08:00
|
|
|
*
|
2016-10-03 09:59:18 -07:00
|
|
|
* @param key the key
|
|
|
|
|
* @param defaultValue the default value to set if key doesn't exist.
|
|
|
|
|
* @returns False if the table key exists with a different type
|
|
|
|
|
*/
|
|
|
|
|
bool SmartDashboard::SetDefaultBooleanArray(llvm::StringRef key,
|
|
|
|
|
llvm::ArrayRef<int> defaultValue) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(key).SetDefaultBooleanArray(
|
|
|
|
|
defaultValue);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-11-16 00:33:51 -08:00
|
|
|
* Returns the boolean array the key maps to.
|
|
|
|
|
*
|
|
|
|
|
* If the key does not exist or is of different type, it will return the default
|
|
|
|
|
* value.
|
|
|
|
|
*
|
|
|
|
|
* @param key The key to look up.
|
|
|
|
|
* @param defaultValue The value to be returned if no value is found.
|
2016-10-03 09:59:18 -07:00
|
|
|
* @return the value associated with the given key or the given default value
|
2017-11-16 00:33:51 -08:00
|
|
|
* if there is no value associated with the key
|
2016-10-03 09:59:18 -07:00
|
|
|
*
|
2017-11-16 00:33:51 -08:00
|
|
|
* @note This makes a copy of the array. If the overhead of this is a concern,
|
|
|
|
|
* use GetValue() instead.
|
2016-10-03 09:59:18 -07:00
|
|
|
*
|
|
|
|
|
* @note The returned array is std::vector<int> instead of std::vector<bool>
|
2017-11-16 00:33:51 -08:00
|
|
|
* because std::vector<bool> is special-cased in C++. 0 is false, any
|
2016-10-03 09:59:18 -07:00
|
|
|
* non-zero value is true.
|
|
|
|
|
*/
|
|
|
|
|
std::vector<int> SmartDashboard::GetBooleanArray(
|
|
|
|
|
llvm::StringRef key, llvm::ArrayRef<int> defaultValue) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(key).GetBooleanArray(
|
|
|
|
|
defaultValue);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-11-16 00:33:51 -08:00
|
|
|
* Put a number array in the table.
|
|
|
|
|
*
|
|
|
|
|
* @param key The key to be assigned to.
|
|
|
|
|
* @param value The value that will be assigned.
|
2016-10-03 09:59:18 -07:00
|
|
|
* @return False if the table key already exists with a different type
|
|
|
|
|
*/
|
|
|
|
|
bool SmartDashboard::PutNumberArray(llvm::StringRef key,
|
|
|
|
|
llvm::ArrayRef<double> value) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(key).SetDoubleArray(value);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the current value in the table, setting it if it does not exist.
|
2017-11-16 00:33:51 -08:00
|
|
|
*
|
|
|
|
|
* @param key The key.
|
|
|
|
|
* @param defaultValue The default value to set if key doesn't exist.
|
2016-10-03 09:59:18 -07:00
|
|
|
* @returns False if the table key exists with a different type
|
|
|
|
|
*/
|
|
|
|
|
bool SmartDashboard::SetDefaultNumberArray(
|
|
|
|
|
llvm::StringRef key, llvm::ArrayRef<double> defaultValue) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(key).SetDefaultDoubleArray(
|
|
|
|
|
defaultValue);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-11-16 00:33:51 -08:00
|
|
|
* Returns the number array the key maps to.
|
|
|
|
|
*
|
|
|
|
|
* If the key does not exist or is of different type, it will return the default
|
|
|
|
|
* value.
|
|
|
|
|
*
|
|
|
|
|
* @param key The key to look up.
|
|
|
|
|
* @param defaultValue The value to be returned if no value is found.
|
2016-10-03 09:59:18 -07:00
|
|
|
* @return the value associated with the given key or the given default value
|
|
|
|
|
* if there is no value associated with the key
|
|
|
|
|
*
|
2017-11-16 00:33:51 -08:00
|
|
|
* @note This makes a copy of the array. If the overhead of this is a concern,
|
|
|
|
|
* use GetValue() instead.
|
2016-10-03 09:59:18 -07:00
|
|
|
*/
|
|
|
|
|
std::vector<double> SmartDashboard::GetNumberArray(
|
|
|
|
|
llvm::StringRef key, llvm::ArrayRef<double> defaultValue) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(key).GetDoubleArray(
|
|
|
|
|
defaultValue);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-11-16 00:33:51 -08:00
|
|
|
* Put a string array in the table.
|
|
|
|
|
*
|
|
|
|
|
* @param key The key to be assigned to.
|
|
|
|
|
* @param value The value that will be assigned.
|
2016-10-03 09:59:18 -07:00
|
|
|
* @return False if the table key already exists with a different type
|
|
|
|
|
*/
|
|
|
|
|
bool SmartDashboard::PutStringArray(llvm::StringRef key,
|
|
|
|
|
llvm::ArrayRef<std::string> value) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(key).SetStringArray(value);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the current value in the table, setting it if it does not exist.
|
2017-11-16 00:33:51 -08:00
|
|
|
*
|
|
|
|
|
* @param key The key.
|
|
|
|
|
* @param defaultValue The default value to set if key doesn't exist.
|
2016-10-03 09:59:18 -07:00
|
|
|
* @returns False if the table key exists with a different type
|
|
|
|
|
*/
|
|
|
|
|
bool SmartDashboard::SetDefaultStringArray(
|
|
|
|
|
llvm::StringRef key, llvm::ArrayRef<std::string> defaultValue) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(key).SetDefaultStringArray(
|
|
|
|
|
defaultValue);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-11-16 00:33:51 -08:00
|
|
|
* Returns the string array the key maps to.
|
|
|
|
|
*
|
|
|
|
|
* If the key does not exist or is of different type, it will return the default
|
|
|
|
|
* value.
|
|
|
|
|
*
|
|
|
|
|
* @param key The key to look up.
|
|
|
|
|
* @param defaultValue The value to be returned if no value is found.
|
2016-10-03 09:59:18 -07:00
|
|
|
* @return the value associated with the given key or the given default value
|
|
|
|
|
* if there is no value associated with the key
|
|
|
|
|
*
|
2017-11-16 00:33:51 -08:00
|
|
|
* @note This makes a copy of the array. If the overhead of this is a concern,
|
|
|
|
|
* use GetValue() instead.
|
2016-10-03 09:59:18 -07:00
|
|
|
*/
|
|
|
|
|
std::vector<std::string> SmartDashboard::GetStringArray(
|
|
|
|
|
llvm::StringRef key, llvm::ArrayRef<std::string> defaultValue) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(key).GetStringArray(
|
|
|
|
|
defaultValue);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-11-16 00:33:51 -08:00
|
|
|
* Put a raw value (byte array) in the table.
|
|
|
|
|
*
|
|
|
|
|
* @param key The key to be assigned to.
|
|
|
|
|
* @param value The value that will be assigned.
|
2016-10-03 09:59:18 -07:00
|
|
|
* @return False if the table key already exists with a different type
|
|
|
|
|
*/
|
|
|
|
|
bool SmartDashboard::PutRaw(llvm::StringRef key, llvm::StringRef value) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(key).SetRaw(value);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the current value in the table, setting it if it does not exist.
|
2017-11-16 00:33:51 -08:00
|
|
|
*
|
|
|
|
|
* @param key The key.
|
|
|
|
|
* @param defaultValue The default value to set if key doesn't exist.
|
2016-10-03 09:59:18 -07:00
|
|
|
* @returns False if the table key exists with a different type
|
|
|
|
|
*/
|
|
|
|
|
bool SmartDashboard::SetDefaultRaw(llvm::StringRef key,
|
|
|
|
|
llvm::StringRef defaultValue) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(key).SetDefaultRaw(
|
|
|
|
|
defaultValue);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-11-16 00:33:51 -08:00
|
|
|
* Returns the raw value (byte array) the key maps to.
|
|
|
|
|
*
|
|
|
|
|
* If the key does not exist or is of different type, it will return the default
|
|
|
|
|
* value.
|
|
|
|
|
*
|
|
|
|
|
* @param key The key to look up.
|
|
|
|
|
* @param defaultValue The value to be returned if no value is found.
|
2016-10-03 09:59:18 -07:00
|
|
|
* @return the value associated with the given key or the given default value
|
|
|
|
|
* if there is no value associated with the key
|
|
|
|
|
*
|
2017-11-16 00:33:51 -08:00
|
|
|
* @note This makes a copy of the raw contents. If the overhead of this is a
|
2016-10-03 09:59:18 -07:00
|
|
|
* concern, use GetValue() instead.
|
|
|
|
|
*/
|
|
|
|
|
std::string SmartDashboard::GetRaw(llvm::StringRef key,
|
|
|
|
|
llvm::StringRef defaultValue) {
|
2017-12-04 23:50:27 -08:00
|
|
|
return Singleton::GetInstance().table->GetEntry(key).GetRaw(defaultValue);
|
2016-10-03 09:59:18 -07:00
|
|
|
}
|
2017-12-26 17:18:02 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Puts all sendable data to the dashboard.
|
|
|
|
|
*/
|
|
|
|
|
void SmartDashboard::UpdateValues() {
|
|
|
|
|
auto& inst = Singleton::GetInstance();
|
|
|
|
|
std::lock_guard<wpi::mutex> lock(inst.tablesToDataMutex);
|
|
|
|
|
for (auto& i : inst.tablesToData) {
|
|
|
|
|
i.getValue().builder.UpdateTable();
|
|
|
|
|
}
|
|
|
|
|
}
|