mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[ntcore] NetworkTables 4 (#3217)
This commit is contained in:
@@ -9,29 +9,30 @@
|
||||
using namespace frc;
|
||||
using namespace frc::detail;
|
||||
|
||||
RecordingController::RecordingController(nt::NetworkTableInstance ntInstance)
|
||||
: m_recordingControlEntry(), m_recordingFileNameFormatEntry() {
|
||||
RecordingController::RecordingController(nt::NetworkTableInstance ntInstance) {
|
||||
m_recordingControlEntry =
|
||||
ntInstance.GetEntry("/Shuffleboard/.recording/RecordData");
|
||||
ntInstance.GetBooleanTopic("/Shuffleboard/.recording/RecordData")
|
||||
.Publish();
|
||||
m_recordingFileNameFormatEntry =
|
||||
ntInstance.GetEntry("/Shuffleboard/.recording/FileNameFormat");
|
||||
ntInstance.GetStringTopic("/Shuffleboard/.recording/FileNameFormat")
|
||||
.Publish();
|
||||
m_eventsTable = ntInstance.GetTable("/Shuffleboard/.recording/events");
|
||||
}
|
||||
|
||||
void RecordingController::StartRecording() {
|
||||
m_recordingControlEntry.SetBoolean(true);
|
||||
m_recordingControlEntry.Set(true);
|
||||
}
|
||||
|
||||
void RecordingController::StopRecording() {
|
||||
m_recordingControlEntry.SetBoolean(false);
|
||||
m_recordingControlEntry.Set(false);
|
||||
}
|
||||
|
||||
void RecordingController::SetRecordingFileNameFormat(std::string_view format) {
|
||||
m_recordingFileNameFormatEntry.SetString(format);
|
||||
m_recordingFileNameFormatEntry.Set(format);
|
||||
}
|
||||
|
||||
void RecordingController::ClearRecordingFileNameFormat() {
|
||||
m_recordingFileNameFormatEntry.Delete();
|
||||
m_recordingFileNameFormatEntry.Set("");
|
||||
}
|
||||
|
||||
void RecordingController::AddEventMarker(
|
||||
@@ -43,6 +44,6 @@ void RecordingController::AddEventMarker(
|
||||
return;
|
||||
}
|
||||
m_eventsTable->GetSubTable(name)->GetEntry("Info").SetStringArray(
|
||||
{std::string{description},
|
||||
std::string{ShuffleboardEventImportanceName(importance)}});
|
||||
{{std::string{description},
|
||||
std::string{ShuffleboardEventImportanceName(importance)}}});
|
||||
}
|
||||
|
||||
@@ -22,27 +22,21 @@ void ShuffleboardComponentBase::BuildMetadata(
|
||||
return;
|
||||
}
|
||||
// Component type
|
||||
if (GetType() == "") {
|
||||
metaTable->GetEntry("PreferredComponent").Delete();
|
||||
} else {
|
||||
metaTable->GetEntry("PreferredComponent").ForceSetString(GetType());
|
||||
if (!GetType().empty()) {
|
||||
metaTable->GetEntry("PreferredComponent").SetString(GetType());
|
||||
}
|
||||
|
||||
// Tile size
|
||||
if (m_width <= 0 || m_height <= 0) {
|
||||
metaTable->GetEntry("Size").Delete();
|
||||
} else {
|
||||
if (m_width > 0 && m_height > 0) {
|
||||
metaTable->GetEntry("Size").SetDoubleArray(
|
||||
{static_cast<double>(m_width), static_cast<double>(m_height)});
|
||||
{{static_cast<double>(m_width), static_cast<double>(m_height)}});
|
||||
}
|
||||
|
||||
// Tile position
|
||||
if (m_column < 0 || m_row < 0) {
|
||||
metaTable->GetEntry("Position").Delete();
|
||||
} else {
|
||||
if (m_column >= 0 && m_row >= 0) {
|
||||
metaTable->GetEntry("Position")
|
||||
.SetDoubleArray(
|
||||
{static_cast<double>(m_column), static_cast<double>(m_row)});
|
||||
{{static_cast<double>(m_column), static_cast<double>(m_row)}});
|
||||
}
|
||||
|
||||
// Custom properties
|
||||
@@ -63,7 +57,7 @@ const std::string& ShuffleboardComponentBase::GetType() const {
|
||||
return m_type;
|
||||
}
|
||||
|
||||
const wpi::StringMap<std::shared_ptr<nt::Value>>&
|
||||
ShuffleboardComponentBase::GetProperties() const {
|
||||
const wpi::StringMap<nt::Value>& ShuffleboardComponentBase::GetProperties()
|
||||
const {
|
||||
return m_properties;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "frc/shuffleboard/ShuffleboardContainer.h"
|
||||
|
||||
#include <ntcore_cpp.h>
|
||||
#include <wpi/sendable/SendableRegistry.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
@@ -74,14 +75,15 @@ ComplexWidget& ShuffleboardContainer::Add(wpi::Sendable& sendable) {
|
||||
return Add(name, sendable);
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(
|
||||
std::string_view title, std::shared_ptr<nt::Value> defaultValue) {
|
||||
SimpleWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
const nt::Value& defaultValue) {
|
||||
CheckTitle(title);
|
||||
|
||||
auto widget = std::make_unique<SimpleWidget>(*this, title);
|
||||
auto ptr = widget.get();
|
||||
m_components.emplace_back(std::move(widget));
|
||||
ptr->GetEntry().SetDefaultValue(defaultValue);
|
||||
ptr->GetEntry(nt::GetStringFromType(defaultValue.type()))
|
||||
.SetDefault(defaultValue);
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
@@ -95,9 +97,14 @@ SimpleWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
return Add(title, nt::Value::MakeDouble(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
float defaultValue) {
|
||||
return Add(title, nt::Value::MakeFloat(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
int defaultValue) {
|
||||
return Add(title, nt::Value::MakeDouble(defaultValue));
|
||||
return Add(title, nt::Value::MakeInteger(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
@@ -120,6 +127,16 @@ SimpleWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
return Add(title, nt::Value::MakeDoubleArray(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
wpi::span<const float> defaultValue) {
|
||||
return Add(title, nt::Value::MakeFloatArray(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(
|
||||
std::string_view title, wpi::span<const int64_t> defaultValue) {
|
||||
return Add(title, nt::Value::MakeIntegerArray(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(
|
||||
std::string_view title, wpi::span<const std::string> defaultValue) {
|
||||
return Add(title, nt::Value::MakeStringArray(defaultValue));
|
||||
@@ -127,13 +144,13 @@ SimpleWidget& ShuffleboardContainer::Add(
|
||||
|
||||
SuppliedValueWidget<std::string>& ShuffleboardContainer::AddString(
|
||||
std::string_view title, std::function<std::string()> supplier) {
|
||||
static auto setter = [](nt::NetworkTableEntry entry, std::string value) {
|
||||
static auto setter = [](nt::GenericPublisher& entry, std::string value) {
|
||||
entry.SetString(value);
|
||||
};
|
||||
|
||||
CheckTitle(title);
|
||||
auto widget = std::make_unique<SuppliedValueWidget<std::string>>(
|
||||
*this, title, supplier, setter);
|
||||
*this, title, "string", supplier, setter);
|
||||
auto ptr = widget.get();
|
||||
m_components.emplace_back(std::move(widget));
|
||||
return *ptr;
|
||||
@@ -141,13 +158,46 @@ SuppliedValueWidget<std::string>& ShuffleboardContainer::AddString(
|
||||
|
||||
SuppliedValueWidget<double>& ShuffleboardContainer::AddNumber(
|
||||
std::string_view title, std::function<double()> supplier) {
|
||||
static auto setter = [](nt::NetworkTableEntry entry, double value) {
|
||||
return AddDouble(title, std::move(supplier));
|
||||
}
|
||||
|
||||
SuppliedValueWidget<double>& ShuffleboardContainer::AddDouble(
|
||||
std::string_view title, std::function<double()> supplier) {
|
||||
static auto setter = [](nt::GenericPublisher& entry, double value) {
|
||||
entry.SetDouble(value);
|
||||
};
|
||||
|
||||
CheckTitle(title);
|
||||
auto widget = std::make_unique<SuppliedValueWidget<double>>(*this, title,
|
||||
supplier, setter);
|
||||
auto widget = std::make_unique<SuppliedValueWidget<double>>(
|
||||
*this, title, "double", supplier, setter);
|
||||
auto ptr = widget.get();
|
||||
m_components.emplace_back(std::move(widget));
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
SuppliedValueWidget<float>& ShuffleboardContainer::AddFloat(
|
||||
std::string_view title, std::function<float()> supplier) {
|
||||
static auto setter = [](nt::GenericPublisher& entry, float value) {
|
||||
entry.SetFloat(value);
|
||||
};
|
||||
|
||||
CheckTitle(title);
|
||||
auto widget = std::make_unique<SuppliedValueWidget<float>>(
|
||||
*this, title, "float", supplier, setter);
|
||||
auto ptr = widget.get();
|
||||
m_components.emplace_back(std::move(widget));
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
SuppliedValueWidget<int64_t>& ShuffleboardContainer::AddInteger(
|
||||
std::string_view title, std::function<int64_t()> supplier) {
|
||||
static auto setter = [](nt::GenericPublisher& entry, int64_t value) {
|
||||
entry.SetInteger(value);
|
||||
};
|
||||
|
||||
CheckTitle(title);
|
||||
auto widget = std::make_unique<SuppliedValueWidget<int64_t>>(
|
||||
*this, title, "int", supplier, setter);
|
||||
auto ptr = widget.get();
|
||||
m_components.emplace_back(std::move(widget));
|
||||
return *ptr;
|
||||
@@ -155,13 +205,13 @@ SuppliedValueWidget<double>& ShuffleboardContainer::AddNumber(
|
||||
|
||||
SuppliedValueWidget<bool>& ShuffleboardContainer::AddBoolean(
|
||||
std::string_view title, std::function<bool()> supplier) {
|
||||
static auto setter = [](nt::NetworkTableEntry entry, bool value) {
|
||||
static auto setter = [](nt::GenericPublisher& entry, bool value) {
|
||||
entry.SetBoolean(value);
|
||||
};
|
||||
|
||||
CheckTitle(title);
|
||||
auto widget = std::make_unique<SuppliedValueWidget<bool>>(*this, title,
|
||||
supplier, setter);
|
||||
auto widget = std::make_unique<SuppliedValueWidget<bool>>(
|
||||
*this, title, "boolean", supplier, setter);
|
||||
auto ptr = widget.get();
|
||||
m_components.emplace_back(std::move(widget));
|
||||
return *ptr;
|
||||
@@ -171,14 +221,14 @@ SuppliedValueWidget<std::vector<std::string>>&
|
||||
ShuffleboardContainer::AddStringArray(
|
||||
std::string_view title,
|
||||
std::function<std::vector<std::string>()> supplier) {
|
||||
static auto setter = [](nt::NetworkTableEntry entry,
|
||||
static auto setter = [](nt::GenericPublisher& entry,
|
||||
std::vector<std::string> value) {
|
||||
entry.SetStringArray(value);
|
||||
};
|
||||
|
||||
CheckTitle(title);
|
||||
auto widget = std::make_unique<SuppliedValueWidget<std::vector<std::string>>>(
|
||||
*this, title, supplier, setter);
|
||||
*this, title, "string[]", supplier, setter);
|
||||
auto ptr = widget.get();
|
||||
m_components.emplace_back(std::move(widget));
|
||||
return *ptr;
|
||||
@@ -186,14 +236,50 @@ ShuffleboardContainer::AddStringArray(
|
||||
|
||||
SuppliedValueWidget<std::vector<double>>& ShuffleboardContainer::AddNumberArray(
|
||||
std::string_view title, std::function<std::vector<double>()> supplier) {
|
||||
static auto setter = [](nt::NetworkTableEntry entry,
|
||||
return AddDoubleArray(title, std::move(supplier));
|
||||
}
|
||||
|
||||
SuppliedValueWidget<std::vector<double>>& ShuffleboardContainer::AddDoubleArray(
|
||||
std::string_view title, std::function<std::vector<double>()> supplier) {
|
||||
static auto setter = [](nt::GenericPublisher& entry,
|
||||
std::vector<double> value) {
|
||||
entry.SetDoubleArray(value);
|
||||
};
|
||||
|
||||
CheckTitle(title);
|
||||
auto widget = std::make_unique<SuppliedValueWidget<std::vector<double>>>(
|
||||
*this, title, supplier, setter);
|
||||
*this, title, "double[]", supplier, setter);
|
||||
auto ptr = widget.get();
|
||||
m_components.emplace_back(std::move(widget));
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
SuppliedValueWidget<std::vector<float>>& ShuffleboardContainer::AddFloatArray(
|
||||
std::string_view title, std::function<std::vector<float>()> supplier) {
|
||||
static auto setter = [](nt::GenericPublisher& entry,
|
||||
std::vector<float> value) {
|
||||
entry.SetFloatArray(value);
|
||||
};
|
||||
|
||||
CheckTitle(title);
|
||||
auto widget = std::make_unique<SuppliedValueWidget<std::vector<float>>>(
|
||||
*this, title, "float[]", supplier, setter);
|
||||
auto ptr = widget.get();
|
||||
m_components.emplace_back(std::move(widget));
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
SuppliedValueWidget<std::vector<int64_t>>&
|
||||
ShuffleboardContainer::AddIntegerArray(
|
||||
std::string_view title, std::function<std::vector<int64_t>()> supplier) {
|
||||
static auto setter = [](nt::GenericPublisher& entry,
|
||||
std::vector<int64_t> value) {
|
||||
entry.SetIntegerArray(value);
|
||||
};
|
||||
|
||||
CheckTitle(title);
|
||||
auto widget = std::make_unique<SuppliedValueWidget<std::vector<int64_t>>>(
|
||||
*this, title, "int[]", supplier, setter);
|
||||
auto ptr = widget.get();
|
||||
m_components.emplace_back(std::move(widget));
|
||||
return *ptr;
|
||||
@@ -201,36 +287,43 @@ SuppliedValueWidget<std::vector<double>>& ShuffleboardContainer::AddNumberArray(
|
||||
|
||||
SuppliedValueWidget<std::vector<int>>& ShuffleboardContainer::AddBooleanArray(
|
||||
std::string_view title, std::function<std::vector<int>()> supplier) {
|
||||
static auto setter = [](nt::NetworkTableEntry entry, std::vector<int> value) {
|
||||
static auto setter = [](nt::GenericPublisher& entry, std::vector<int> value) {
|
||||
entry.SetBooleanArray(value);
|
||||
};
|
||||
|
||||
CheckTitle(title);
|
||||
auto widget = std::make_unique<SuppliedValueWidget<std::vector<int>>>(
|
||||
*this, title, supplier, setter);
|
||||
*this, title, "boolean[]", supplier, setter);
|
||||
auto ptr = widget.get();
|
||||
m_components.emplace_back(std::move(widget));
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
SuppliedValueWidget<std::string_view>& ShuffleboardContainer::AddRaw(
|
||||
std::string_view title, std::function<std::string_view()> supplier) {
|
||||
static auto setter = [](nt::NetworkTableEntry entry, std::string_view value) {
|
||||
entry.SetRaw(value);
|
||||
};
|
||||
SuppliedValueWidget<std::vector<uint8_t>>& ShuffleboardContainer::AddRaw(
|
||||
std::string_view title, std::function<std::vector<uint8_t>()> supplier) {
|
||||
return AddRaw(title, "raw", std::move(supplier));
|
||||
}
|
||||
|
||||
SuppliedValueWidget<std::vector<uint8_t>>& ShuffleboardContainer::AddRaw(
|
||||
std::string_view title, std::string_view typeString,
|
||||
std::function<std::vector<uint8_t>()> supplier) {
|
||||
static auto setter = [](nt::GenericPublisher& entry,
|
||||
std::vector<uint8_t> value) { entry.SetRaw(value); };
|
||||
|
||||
CheckTitle(title);
|
||||
auto widget = std::make_unique<SuppliedValueWidget<std::string_view>>(
|
||||
*this, title, supplier, setter);
|
||||
auto widget = std::make_unique<SuppliedValueWidget<std::vector<uint8_t>>>(
|
||||
*this, title, typeString, supplier, setter);
|
||||
auto ptr = widget.get();
|
||||
m_components.emplace_back(std::move(widget));
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::AddPersistent(
|
||||
std::string_view title, std::shared_ptr<nt::Value> defaultValue) {
|
||||
std::string_view title, const nt::Value& defaultValue) {
|
||||
auto& widget = Add(title, defaultValue);
|
||||
widget.GetEntry().SetPersistent();
|
||||
widget.GetEntry(nt::GetStringFromType(defaultValue.type()))
|
||||
.GetTopic()
|
||||
.SetPersistent(true);
|
||||
return widget;
|
||||
}
|
||||
|
||||
@@ -244,9 +337,14 @@ SimpleWidget& ShuffleboardContainer::AddPersistent(std::string_view title,
|
||||
return AddPersistent(title, nt::Value::MakeDouble(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::AddPersistent(std::string_view title,
|
||||
float defaultValue) {
|
||||
return AddPersistent(title, nt::Value::MakeFloat(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::AddPersistent(std::string_view title,
|
||||
int defaultValue) {
|
||||
return AddPersistent(title, nt::Value::MakeDouble(defaultValue));
|
||||
return AddPersistent(title, nt::Value::MakeInteger(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::AddPersistent(
|
||||
@@ -264,6 +362,16 @@ SimpleWidget& ShuffleboardContainer::AddPersistent(
|
||||
return AddPersistent(title, nt::Value::MakeDoubleArray(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::AddPersistent(
|
||||
std::string_view title, wpi::span<const float> defaultValue) {
|
||||
return AddPersistent(title, nt::Value::MakeFloatArray(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::AddPersistent(
|
||||
std::string_view title, wpi::span<const int64_t> defaultValue) {
|
||||
return AddPersistent(title, nt::Value::MakeIntegerArray(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::AddPersistent(
|
||||
std::string_view title, wpi::span<const std::string> defaultValue) {
|
||||
return AddPersistent(title, nt::Value::MakeStringArray(defaultValue));
|
||||
|
||||
@@ -46,7 +46,7 @@ void ShuffleboardInstance::Update() {
|
||||
for (auto& entry : m_impl->tabs) {
|
||||
tabTitles.emplace_back(entry.second->GetTitle());
|
||||
}
|
||||
m_impl->rootMetaTable->GetEntry("Tabs").ForceSetStringArray(tabTitles);
|
||||
m_impl->rootMetaTable->GetEntry("Tabs").SetStringArray(tabTitles);
|
||||
m_impl->tabsChanged = false;
|
||||
}
|
||||
for (auto& entry : m_impl->tabs) {
|
||||
@@ -75,9 +75,9 @@ void ShuffleboardInstance::DisableActuatorWidgets() {
|
||||
}
|
||||
|
||||
void ShuffleboardInstance::SelectTab(int index) {
|
||||
m_impl->rootMetaTable->GetEntry("Selected").ForceSetDouble(index);
|
||||
m_impl->rootMetaTable->GetEntry("Selected").SetDouble(index);
|
||||
}
|
||||
|
||||
void ShuffleboardInstance::SelectTab(std::string_view title) {
|
||||
m_impl->rootMetaTable->GetEntry("Selected").ForceSetString(title);
|
||||
m_impl->rootMetaTable->GetEntry("Selected").SetString(title);
|
||||
}
|
||||
|
||||
@@ -14,18 +14,26 @@ SimpleWidget::SimpleWidget(ShuffleboardContainer& parent,
|
||||
std::string_view title)
|
||||
: ShuffleboardValue(title), ShuffleboardWidget(parent, title), m_entry() {}
|
||||
|
||||
nt::NetworkTableEntry SimpleWidget::GetEntry() {
|
||||
nt::GenericEntry& SimpleWidget::GetEntry() {
|
||||
if (!m_entry) {
|
||||
ForceGenerate();
|
||||
}
|
||||
return m_entry;
|
||||
}
|
||||
|
||||
nt::GenericEntry& SimpleWidget::GetEntry(std::string_view typeString) {
|
||||
if (!m_entry) {
|
||||
m_typeString = typeString;
|
||||
ForceGenerate();
|
||||
}
|
||||
return m_entry;
|
||||
}
|
||||
|
||||
void SimpleWidget::BuildInto(std::shared_ptr<nt::NetworkTable> parentTable,
|
||||
std::shared_ptr<nt::NetworkTable> metaTable) {
|
||||
BuildMetadata(metaTable);
|
||||
if (!m_entry) {
|
||||
m_entry = parentTable->GetEntry(GetTitle());
|
||||
m_entry = parentTable->GetTopic(GetTitle()).GetGenericEntry(m_typeString);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user