mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[wpilib] Remove Shuffleboard API (#7730)
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
#include "frc/DSControlWord.h"
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/livewindow/LiveWindow.h"
|
||||
#include "frc/shuffleboard/Shuffleboard.h"
|
||||
#include "frc/smartdashboard/SmartDashboard.h"
|
||||
|
||||
using namespace frc;
|
||||
@@ -153,7 +152,6 @@ void IterativeRobotBase::LoopFunc() {
|
||||
} else if (m_lastMode == Mode::kTest) {
|
||||
if (m_lwEnabledInTest) {
|
||||
LiveWindow::SetEnabled(false);
|
||||
Shuffleboard::DisableActuatorWidgets();
|
||||
}
|
||||
TestExit();
|
||||
}
|
||||
@@ -171,7 +169,6 @@ void IterativeRobotBase::LoopFunc() {
|
||||
} else if (mode == Mode::kTest) {
|
||||
if (m_lwEnabledInTest) {
|
||||
LiveWindow::SetEnabled(true);
|
||||
Shuffleboard::EnableActuatorWidgets();
|
||||
}
|
||||
TestInit();
|
||||
m_watchdog.AddEpoch("TestInit()");
|
||||
@@ -206,8 +203,6 @@ void IterativeRobotBase::LoopFunc() {
|
||||
m_watchdog.AddEpoch("SmartDashboard::UpdateValues()");
|
||||
LiveWindow::UpdateValues();
|
||||
m_watchdog.AddEpoch("LiveWindow::UpdateValues()");
|
||||
Shuffleboard::Update();
|
||||
m_watchdog.AddEpoch("Shuffleboard::Update()");
|
||||
|
||||
if constexpr (IsSimulation()) {
|
||||
HAL_SimPeriodicBefore();
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/shuffleboard/ComplexWidget.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/sendable/Sendable.h>
|
||||
|
||||
#include "frc/smartdashboard/SendableBuilderImpl.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
ComplexWidget::ComplexWidget(ShuffleboardContainer& parent,
|
||||
std::string_view title, wpi::Sendable& sendable)
|
||||
: ShuffleboardValue(title),
|
||||
ShuffleboardWidget(parent, title),
|
||||
m_sendable(sendable) {}
|
||||
|
||||
ComplexWidget::~ComplexWidget() = default;
|
||||
|
||||
void ComplexWidget::EnableIfActuator() {
|
||||
if (m_builder && static_cast<SendableBuilderImpl&>(*m_builder).IsActuator()) {
|
||||
static_cast<SendableBuilderImpl&>(*m_builder).StartLiveWindowMode();
|
||||
}
|
||||
}
|
||||
|
||||
void ComplexWidget::DisableIfActuator() {
|
||||
if (m_builder && static_cast<SendableBuilderImpl&>(*m_builder).IsActuator()) {
|
||||
static_cast<SendableBuilderImpl&>(*m_builder).StopLiveWindowMode();
|
||||
}
|
||||
}
|
||||
|
||||
void ComplexWidget::BuildInto(std::shared_ptr<nt::NetworkTable> parentTable,
|
||||
std::shared_ptr<nt::NetworkTable> metaTable) {
|
||||
BuildMetadata(metaTable);
|
||||
if (!m_builder) {
|
||||
m_builder = std::make_unique<SendableBuilderImpl>();
|
||||
static_cast<SendableBuilderImpl&>(*m_builder)
|
||||
.SetTable(parentTable->GetSubTable(GetTitle()));
|
||||
m_sendable.InitSendable(static_cast<SendableBuilderImpl&>(*m_builder));
|
||||
static_cast<SendableBuilderImpl&>(*m_builder).StartListeners();
|
||||
}
|
||||
m_builder->Update();
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/shuffleboard/LayoutType.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
std::string_view LayoutType::GetLayoutName() const {
|
||||
return m_layoutName;
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/shuffleboard/RecordingController.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
|
||||
using namespace frc;
|
||||
using namespace frc::detail;
|
||||
|
||||
RecordingController::RecordingController(nt::NetworkTableInstance ntInstance) {
|
||||
m_recordingControlEntry =
|
||||
ntInstance.GetBooleanTopic("/Shuffleboard/.recording/RecordData")
|
||||
.Publish();
|
||||
m_recordingFileNameFormatEntry =
|
||||
ntInstance.GetStringTopic("/Shuffleboard/.recording/FileNameFormat")
|
||||
.Publish();
|
||||
m_eventsTable = ntInstance.GetTable("/Shuffleboard/.recording/events");
|
||||
}
|
||||
|
||||
void RecordingController::StartRecording() {
|
||||
m_recordingControlEntry.Set(true);
|
||||
}
|
||||
|
||||
void RecordingController::StopRecording() {
|
||||
m_recordingControlEntry.Set(false);
|
||||
}
|
||||
|
||||
void RecordingController::SetRecordingFileNameFormat(std::string_view format) {
|
||||
m_recordingFileNameFormatEntry.Set(format);
|
||||
}
|
||||
|
||||
void RecordingController::ClearRecordingFileNameFormat() {
|
||||
m_recordingFileNameFormatEntry.Set("");
|
||||
}
|
||||
|
||||
void RecordingController::AddEventMarker(
|
||||
std::string_view name, std::string_view description,
|
||||
ShuffleboardEventImportance importance) {
|
||||
if (name.empty()) {
|
||||
FRC_ReportError(err::Error, "Shuffleboard event name was not specified");
|
||||
return;
|
||||
}
|
||||
m_eventsTable->GetSubTable(name)->GetEntry("Info").SetStringArray(
|
||||
{{std::string{description},
|
||||
std::string{ShuffleboardEventImportanceName(importance)}}});
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/shuffleboard/SendableCameraWrapper.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <wpi/StringMap.h>
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
#include <wpi/sendable/SendableRegistry.h>
|
||||
|
||||
namespace frc {
|
||||
namespace detail {
|
||||
std::shared_ptr<SendableCameraWrapper>& GetSendableCameraWrapper(
|
||||
std::string_view cameraName) {
|
||||
static wpi::StringMap<std::shared_ptr<SendableCameraWrapper>> wrappers;
|
||||
return wrappers[cameraName];
|
||||
}
|
||||
|
||||
void AddToSendableRegistry(wpi::Sendable* sendable, std::string_view name) {
|
||||
wpi::SendableRegistry::Add(sendable, name);
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
void SendableCameraWrapper::InitSendable(wpi::SendableBuilder& builder) {
|
||||
builder.AddStringProperty(
|
||||
".ShuffleboardURI", [this] { return m_uri; }, nullptr);
|
||||
}
|
||||
} // namespace frc
|
||||
@@ -1,92 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/shuffleboard/Shuffleboard.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
|
||||
#include "frc/shuffleboard/ShuffleboardTab.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
void Shuffleboard::Update() {
|
||||
GetInstance().Update();
|
||||
}
|
||||
|
||||
ShuffleboardTab& Shuffleboard::GetTab(std::string_view title) {
|
||||
return GetInstance().GetTab(title);
|
||||
}
|
||||
|
||||
void Shuffleboard::SelectTab(int index) {
|
||||
GetInstance().SelectTab(index);
|
||||
}
|
||||
|
||||
void Shuffleboard::SelectTab(std::string_view title) {
|
||||
GetInstance().SelectTab(title);
|
||||
}
|
||||
|
||||
void Shuffleboard::EnableActuatorWidgets() {
|
||||
GetInstance().EnableActuatorWidgets();
|
||||
}
|
||||
|
||||
void Shuffleboard::DisableActuatorWidgets() {
|
||||
// Need to update to make sure the sendable builders are initialized
|
||||
Update();
|
||||
GetInstance().DisableActuatorWidgets();
|
||||
}
|
||||
|
||||
void Shuffleboard::StartRecording() {
|
||||
GetRecordingController().StartRecording();
|
||||
}
|
||||
|
||||
void Shuffleboard::StopRecording() {
|
||||
GetRecordingController().StopRecording();
|
||||
}
|
||||
|
||||
void Shuffleboard::SetRecordingFileNameFormat(std::string_view format) {
|
||||
GetRecordingController().SetRecordingFileNameFormat(format);
|
||||
}
|
||||
|
||||
void Shuffleboard::ClearRecordingFileNameFormat() {
|
||||
GetRecordingController().ClearRecordingFileNameFormat();
|
||||
}
|
||||
|
||||
void Shuffleboard::AddEventMarker(std::string_view name,
|
||||
std::string_view description,
|
||||
ShuffleboardEventImportance importance) {
|
||||
GetRecordingController().AddEventMarker(name, description, importance);
|
||||
}
|
||||
|
||||
void Shuffleboard::AddEventMarker(std::string_view name,
|
||||
ShuffleboardEventImportance importance) {
|
||||
AddEventMarker(name, "", importance);
|
||||
}
|
||||
|
||||
static std::unique_ptr<detail::ShuffleboardInstance>& GetInstanceHolder() {
|
||||
static std::unique_ptr<detail::ShuffleboardInstance> instance =
|
||||
std::make_unique<detail::ShuffleboardInstance>(
|
||||
nt::NetworkTableInstance::GetDefault());
|
||||
return instance;
|
||||
}
|
||||
|
||||
#ifndef __FRC_ROBORIO__
|
||||
namespace frc::impl {
|
||||
void ResetShuffleboardInstance() {
|
||||
GetInstanceHolder() = std::make_unique<detail::ShuffleboardInstance>(
|
||||
nt::NetworkTableInstance::GetDefault());
|
||||
}
|
||||
} // namespace frc::impl
|
||||
#endif
|
||||
|
||||
detail::ShuffleboardInstance& Shuffleboard::GetInstance() {
|
||||
return *GetInstanceHolder();
|
||||
}
|
||||
|
||||
detail::RecordingController& Shuffleboard::GetRecordingController() {
|
||||
static detail::RecordingController inst(
|
||||
nt::NetworkTableInstance::GetDefault());
|
||||
return inst;
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/shuffleboard/ShuffleboardComponentBase.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
using namespace frc;
|
||||
|
||||
ShuffleboardComponentBase::ShuffleboardComponentBase(
|
||||
ShuffleboardContainer& parent, std::string_view title,
|
||||
std::string_view type)
|
||||
: ShuffleboardValue(title), m_parent(parent), m_type(type) {}
|
||||
|
||||
void ShuffleboardComponentBase::SetType(std::string_view type) {
|
||||
m_type = type;
|
||||
m_metadataDirty = true;
|
||||
}
|
||||
|
||||
void ShuffleboardComponentBase::BuildMetadata(
|
||||
std::shared_ptr<nt::NetworkTable> metaTable) {
|
||||
if (!m_metadataDirty) {
|
||||
return;
|
||||
}
|
||||
// Component type
|
||||
if (!GetType().empty()) {
|
||||
metaTable->GetEntry("PreferredComponent").SetString(GetType());
|
||||
}
|
||||
|
||||
// Tile size
|
||||
if (m_width > 0 && m_height > 0) {
|
||||
metaTable->GetEntry("Size").SetDoubleArray(
|
||||
{{static_cast<double>(m_width), static_cast<double>(m_height)}});
|
||||
}
|
||||
|
||||
// Tile position
|
||||
if (m_column >= 0 && m_row >= 0) {
|
||||
metaTable->GetEntry("Position")
|
||||
.SetDoubleArray(
|
||||
{{static_cast<double>(m_column), static_cast<double>(m_row)}});
|
||||
}
|
||||
|
||||
// Custom properties
|
||||
if (GetProperties().size() > 0) {
|
||||
auto propTable = metaTable->GetSubTable("Properties");
|
||||
for (auto& entry : GetProperties()) {
|
||||
propTable->GetEntry(entry.first).SetValue(entry.second);
|
||||
}
|
||||
}
|
||||
m_metadataDirty = false;
|
||||
}
|
||||
|
||||
ShuffleboardContainer& ShuffleboardComponentBase::GetParent() {
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
const std::string& ShuffleboardComponentBase::GetType() const {
|
||||
return m_type;
|
||||
}
|
||||
|
||||
const wpi::StringMap<nt::Value>& ShuffleboardComponentBase::GetProperties()
|
||||
const {
|
||||
return m_properties;
|
||||
}
|
||||
@@ -1,404 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/shuffleboard/ShuffleboardContainer.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <ntcore_cpp.h>
|
||||
#include <wpi/sendable/SendableRegistry.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/shuffleboard/ComplexWidget.h"
|
||||
#include "frc/shuffleboard/ShuffleboardComponent.h"
|
||||
#include "frc/shuffleboard/ShuffleboardLayout.h"
|
||||
#include "frc/shuffleboard/SimpleWidget.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
static constexpr const char* layoutStrings[] = {"List Layout", "Grid Layout"};
|
||||
|
||||
static constexpr const char* GetStringFromBuiltInLayout(BuiltInLayouts layout) {
|
||||
return layoutStrings[static_cast<int>(layout)];
|
||||
}
|
||||
|
||||
ShuffleboardContainer::ShuffleboardContainer(std::string_view title)
|
||||
: ShuffleboardValue(title) {}
|
||||
|
||||
const std::vector<std::unique_ptr<ShuffleboardComponentBase>>&
|
||||
ShuffleboardContainer::GetComponents() const {
|
||||
return m_components;
|
||||
}
|
||||
|
||||
ShuffleboardLayout& ShuffleboardContainer::GetLayout(std::string_view title,
|
||||
BuiltInLayouts type) {
|
||||
return GetLayout(title, GetStringFromBuiltInLayout(type));
|
||||
}
|
||||
|
||||
ShuffleboardLayout& ShuffleboardContainer::GetLayout(std::string_view title,
|
||||
const LayoutType& type) {
|
||||
return GetLayout(title, type.GetLayoutName());
|
||||
}
|
||||
|
||||
ShuffleboardLayout& ShuffleboardContainer::GetLayout(std::string_view title,
|
||||
std::string_view type) {
|
||||
if (m_layouts.count(title) == 0) {
|
||||
auto layout = std::make_unique<ShuffleboardLayout>(*this, title, type);
|
||||
auto ptr = layout.get();
|
||||
m_components.emplace_back(std::move(layout));
|
||||
m_layouts.insert(std::pair{title, ptr});
|
||||
}
|
||||
return *m_layouts[title];
|
||||
}
|
||||
|
||||
ShuffleboardLayout& ShuffleboardContainer::GetLayout(std::string_view title) {
|
||||
if (m_layouts.count(title) == 0) {
|
||||
throw FRC_MakeError(err::InvalidParameter,
|
||||
"No layout with title {} has been defined", title);
|
||||
}
|
||||
return *m_layouts[title];
|
||||
}
|
||||
|
||||
ComplexWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
wpi::Sendable& sendable) {
|
||||
CheckTitle(title);
|
||||
auto widget = std::make_unique<ComplexWidget>(*this, title, sendable);
|
||||
auto ptr = widget.get();
|
||||
m_components.emplace_back(std::move(widget));
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
ComplexWidget& ShuffleboardContainer::Add(wpi::Sendable& sendable) {
|
||||
auto name = wpi::SendableRegistry::GetName(&sendable);
|
||||
if (name.empty()) {
|
||||
FRC_ReportError(err::Error, "Sendable must have a name");
|
||||
}
|
||||
return Add(name, sendable);
|
||||
}
|
||||
|
||||
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(nt::GetStringFromType(defaultValue.type()))
|
||||
->SetDefault(defaultValue);
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
bool defaultValue) {
|
||||
return Add(title, nt::Value::MakeBoolean(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
double defaultValue) {
|
||||
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::MakeInteger(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
std::string_view defaultValue) {
|
||||
return Add(title, nt::Value::MakeString(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
const char* defaultValue) {
|
||||
return Add(title, nt::Value::MakeString(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
std::span<const bool> defaultValue) {
|
||||
return Add(title, nt::Value::MakeBooleanArray(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
std::span<const double> defaultValue) {
|
||||
return Add(title, nt::Value::MakeDoubleArray(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(std::string_view title,
|
||||
std::span<const float> defaultValue) {
|
||||
return Add(title, nt::Value::MakeFloatArray(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(
|
||||
std::string_view title, std::span<const int64_t> defaultValue) {
|
||||
return Add(title, nt::Value::MakeIntegerArray(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::Add(
|
||||
std::string_view title, std::span<const std::string> defaultValue) {
|
||||
return Add(title, nt::Value::MakeStringArray(defaultValue));
|
||||
}
|
||||
|
||||
SuppliedValueWidget<std::string>& ShuffleboardContainer::AddString(
|
||||
std::string_view title, std::function<std::string()> supplier) {
|
||||
static auto setter = [](nt::GenericPublisher& entry, std::string value) {
|
||||
entry.SetString(value);
|
||||
};
|
||||
|
||||
CheckTitle(title);
|
||||
auto widget = std::make_unique<SuppliedValueWidget<std::string>>(
|
||||
*this, title, "string", supplier, setter);
|
||||
auto ptr = widget.get();
|
||||
m_components.emplace_back(std::move(widget));
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
SuppliedValueWidget<double>& ShuffleboardContainer::AddNumber(
|
||||
std::string_view title, std::function<double()> supplier) {
|
||||
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, "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;
|
||||
}
|
||||
|
||||
SuppliedValueWidget<bool>& ShuffleboardContainer::AddBoolean(
|
||||
std::string_view title, std::function<bool()> supplier) {
|
||||
static auto setter = [](nt::GenericPublisher& entry, bool value) {
|
||||
entry.SetBoolean(value);
|
||||
};
|
||||
|
||||
CheckTitle(title);
|
||||
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;
|
||||
}
|
||||
|
||||
SuppliedValueWidget<std::vector<std::string>>&
|
||||
ShuffleboardContainer::AddStringArray(
|
||||
std::string_view title,
|
||||
std::function<std::vector<std::string>()> supplier) {
|
||||
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, "string[]", supplier, setter);
|
||||
auto ptr = widget.get();
|
||||
m_components.emplace_back(std::move(widget));
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
SuppliedValueWidget<std::vector<double>>& ShuffleboardContainer::AddNumberArray(
|
||||
std::string_view title, std::function<std::vector<double>()> supplier) {
|
||||
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, "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;
|
||||
}
|
||||
|
||||
SuppliedValueWidget<std::vector<int>>& ShuffleboardContainer::AddBooleanArray(
|
||||
std::string_view title, std::function<std::vector<int>()> supplier) {
|
||||
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, "boolean[]", supplier, setter);
|
||||
auto ptr = widget.get();
|
||||
m_components.emplace_back(std::move(widget));
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
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::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, const nt::Value& defaultValue) {
|
||||
auto& widget = Add(title, defaultValue);
|
||||
widget.GetEntry(nt::GetStringFromType(defaultValue.type()))
|
||||
->GetTopic()
|
||||
.SetPersistent(true);
|
||||
return widget;
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::AddPersistent(std::string_view title,
|
||||
bool defaultValue) {
|
||||
return AddPersistent(title, nt::Value::MakeBoolean(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::AddPersistent(std::string_view title,
|
||||
double defaultValue) {
|
||||
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::MakeInteger(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::AddPersistent(
|
||||
std::string_view title, std::string_view defaultValue) {
|
||||
return AddPersistent(title, nt::Value::MakeString(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::AddPersistent(
|
||||
std::string_view title, std::span<const bool> defaultValue) {
|
||||
return AddPersistent(title, nt::Value::MakeBooleanArray(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::AddPersistent(
|
||||
std::string_view title, std::span<const double> defaultValue) {
|
||||
return AddPersistent(title, nt::Value::MakeDoubleArray(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::AddPersistent(
|
||||
std::string_view title, std::span<const float> defaultValue) {
|
||||
return AddPersistent(title, nt::Value::MakeFloatArray(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::AddPersistent(
|
||||
std::string_view title, std::span<const int64_t> defaultValue) {
|
||||
return AddPersistent(title, nt::Value::MakeIntegerArray(defaultValue));
|
||||
}
|
||||
|
||||
SimpleWidget& ShuffleboardContainer::AddPersistent(
|
||||
std::string_view title, std::span<const std::string> defaultValue) {
|
||||
return AddPersistent(title, nt::Value::MakeStringArray(defaultValue));
|
||||
}
|
||||
|
||||
void ShuffleboardContainer::EnableIfActuator() {
|
||||
for (auto& component : GetComponents()) {
|
||||
component->EnableIfActuator();
|
||||
}
|
||||
}
|
||||
|
||||
void ShuffleboardContainer::DisableIfActuator() {
|
||||
for (auto& component : GetComponents()) {
|
||||
component->DisableIfActuator();
|
||||
}
|
||||
}
|
||||
|
||||
void ShuffleboardContainer::CheckTitle(std::string_view title) {
|
||||
std::string titleStr{title};
|
||||
if (m_usedTitles.count(titleStr) > 0) {
|
||||
FRC_ReportError(err::Error, "Title is already in use: {}", title);
|
||||
return;
|
||||
}
|
||||
m_usedTitles.insert(titleStr);
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/shuffleboard/ShuffleboardInstance.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <networktables/NetworkTable.h>
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
#include <wpi/SmallVector.h>
|
||||
#include <wpi/StringMap.h>
|
||||
|
||||
#include "frc/shuffleboard/Shuffleboard.h"
|
||||
|
||||
using namespace frc::detail;
|
||||
|
||||
struct ShuffleboardInstance::Impl {
|
||||
wpi::StringMap<ShuffleboardTab> tabs;
|
||||
|
||||
bool tabsChanged = false;
|
||||
std::shared_ptr<nt::NetworkTable> rootTable;
|
||||
std::shared_ptr<nt::NetworkTable> rootMetaTable;
|
||||
nt::StringPublisher selectedTabPub;
|
||||
};
|
||||
|
||||
ShuffleboardInstance::ShuffleboardInstance(nt::NetworkTableInstance ntInstance)
|
||||
: m_impl(new Impl) {
|
||||
m_impl->rootTable = ntInstance.GetTable(Shuffleboard::kBaseTableName);
|
||||
m_impl->rootMetaTable = m_impl->rootTable->GetSubTable(".metadata");
|
||||
m_impl->selectedTabPub =
|
||||
m_impl->rootMetaTable->GetStringTopic("Selected")
|
||||
.Publish(nt::PubSubOptions{.keepDuplicates = true});
|
||||
}
|
||||
|
||||
ShuffleboardInstance::~ShuffleboardInstance() = default;
|
||||
|
||||
static bool gReported = false;
|
||||
|
||||
frc::ShuffleboardTab& ShuffleboardInstance::GetTab(std::string_view title) {
|
||||
if (!gReported) {
|
||||
HAL_Report(HALUsageReporting::kResourceType_Shuffleboard, 0);
|
||||
gReported = true;
|
||||
}
|
||||
auto [it, added] = m_impl->tabs.try_emplace(title, *this, title);
|
||||
if (added) {
|
||||
m_impl->tabsChanged = true;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void ShuffleboardInstance::Update() {
|
||||
if (m_impl->tabsChanged) {
|
||||
wpi::SmallVector<std::string, 16> tabTitles;
|
||||
for (auto& entry : m_impl->tabs) {
|
||||
tabTitles.emplace_back(entry.second.GetTitle());
|
||||
}
|
||||
m_impl->rootMetaTable->GetEntry("Tabs").SetStringArray(tabTitles);
|
||||
m_impl->tabsChanged = false;
|
||||
}
|
||||
for (auto& entry : m_impl->tabs) {
|
||||
auto& tab = entry.second;
|
||||
tab.BuildInto(m_impl->rootTable,
|
||||
m_impl->rootMetaTable->GetSubTable(tab.GetTitle()));
|
||||
}
|
||||
}
|
||||
|
||||
void ShuffleboardInstance::EnableActuatorWidgets() {
|
||||
for (auto& entry : m_impl->tabs) {
|
||||
auto& tab = entry.second;
|
||||
for (auto& component : tab.GetComponents()) {
|
||||
component->EnableIfActuator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ShuffleboardInstance::DisableActuatorWidgets() {
|
||||
for (auto& entry : m_impl->tabs) {
|
||||
auto& tab = entry.second;
|
||||
for (auto& component : tab.GetComponents()) {
|
||||
component->DisableIfActuator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ShuffleboardInstance::SelectTab(int index) {
|
||||
m_impl->selectedTabPub.Set(std::to_string(index));
|
||||
}
|
||||
|
||||
void ShuffleboardInstance::SelectTab(std::string_view title) {
|
||||
m_impl->selectedTabPub.Set(title);
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/shuffleboard/ShuffleboardLayout.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/json.h>
|
||||
|
||||
using namespace frc;
|
||||
|
||||
static constexpr std::string_view kSmartDashboardType = "ShuffleboardLayout";
|
||||
|
||||
ShuffleboardLayout::ShuffleboardLayout(ShuffleboardContainer& parent,
|
||||
std::string_view title,
|
||||
std::string_view type)
|
||||
: ShuffleboardValue(title),
|
||||
ShuffleboardComponent(parent, title, type),
|
||||
ShuffleboardContainer(title) {
|
||||
m_isLayout = true;
|
||||
}
|
||||
|
||||
void ShuffleboardLayout::BuildInto(
|
||||
std::shared_ptr<nt::NetworkTable> parentTable,
|
||||
std::shared_ptr<nt::NetworkTable> metaTable) {
|
||||
BuildMetadata(metaTable);
|
||||
auto table = parentTable->GetSubTable(GetTitle());
|
||||
table->GetEntry(".type").SetString(kSmartDashboardType);
|
||||
table->GetEntry(".type").GetTopic().SetProperty("SmartDashboard",
|
||||
kSmartDashboardType);
|
||||
for (auto& component : GetComponents()) {
|
||||
component->BuildInto(table, metaTable->GetSubTable(component->GetTitle()));
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/shuffleboard/ShuffleboardTab.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/json.h>
|
||||
|
||||
using namespace frc;
|
||||
|
||||
static constexpr std::string_view kSmartDashboardType = "ShuffleboardLayout";
|
||||
|
||||
ShuffleboardTab::ShuffleboardTab(ShuffleboardRoot& root, std::string_view title)
|
||||
: ShuffleboardValue(title), ShuffleboardContainer(title), m_root(root) {}
|
||||
|
||||
ShuffleboardRoot& ShuffleboardTab::GetRoot() {
|
||||
return m_root;
|
||||
}
|
||||
|
||||
void ShuffleboardTab::BuildInto(std::shared_ptr<nt::NetworkTable> parentTable,
|
||||
std::shared_ptr<nt::NetworkTable> metaTable) {
|
||||
auto tabTable = parentTable->GetSubTable(GetTitle());
|
||||
tabTable->GetEntry(".type").SetString(kSmartDashboardType);
|
||||
tabTable->GetEntry(".type").GetTopic().SetProperty("SmartDashboard",
|
||||
kSmartDashboardType);
|
||||
for (auto& component : GetComponents()) {
|
||||
component->BuildInto(tabTable,
|
||||
metaTable->GetSubTable(component->GetTitle()));
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/shuffleboard/ShuffleboardWidget.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
static constexpr const char* widgetStrings[] = {
|
||||
"Text View",
|
||||
"Number Slider",
|
||||
"Number Bar",
|
||||
"Simple Dial",
|
||||
"Graph",
|
||||
"Boolean Box",
|
||||
"Toggle Button",
|
||||
"Toggle Switch",
|
||||
"Voltage View",
|
||||
"PDP",
|
||||
"ComboBox Chooser",
|
||||
"Split Button Chooser",
|
||||
"Encoder",
|
||||
"Motor Controller",
|
||||
"Command",
|
||||
"PID Command",
|
||||
"PID Controller",
|
||||
"Accelerometer",
|
||||
"3-Axis Accelerometer",
|
||||
"Gyro",
|
||||
"Relay",
|
||||
"Differential Drivebase",
|
||||
"Mecanum Drivebase",
|
||||
"Camera Stream",
|
||||
"Field",
|
||||
};
|
||||
|
||||
const char* detail::GetStringForWidgetType(BuiltInWidgets type) {
|
||||
return widgetStrings[static_cast<int>(type)];
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/shuffleboard/SimpleWidget.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "frc/shuffleboard/Shuffleboard.h"
|
||||
#include "frc/shuffleboard/ShuffleboardLayout.h"
|
||||
#include "frc/shuffleboard/ShuffleboardTab.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
SimpleWidget::SimpleWidget(ShuffleboardContainer& parent,
|
||||
std::string_view title)
|
||||
: ShuffleboardValue(title), ShuffleboardWidget(parent, title), m_entry() {}
|
||||
|
||||
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->GetTopic(GetTitle()).GetGenericEntry(m_typeString);
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleWidget::ForceGenerate() {
|
||||
ShuffleboardContainer* parent = &GetParent();
|
||||
|
||||
while (parent->m_isLayout) {
|
||||
parent = &(static_cast<ShuffleboardLayout*>(parent)->GetParent());
|
||||
}
|
||||
|
||||
auto& tab = *static_cast<ShuffleboardTab*>(parent);
|
||||
tab.GetRoot().Update();
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "frc/shuffleboard/WidgetType.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
std::string_view WidgetType::GetWidgetName() const {
|
||||
return m_widgetName;
|
||||
}
|
||||
Reference in New Issue
Block a user