diff --git a/wpilibc/src/main/native/cpp/IterativeRobotBase.cpp b/wpilibc/src/main/native/cpp/IterativeRobotBase.cpp index 78a3067b388..2a97988b19a 100644 --- a/wpilibc/src/main/native/cpp/IterativeRobotBase.cpp +++ b/wpilibc/src/main/native/cpp/IterativeRobotBase.cpp @@ -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(); diff --git a/wpilibc/src/main/native/cpp/shuffleboard/ComplexWidget.cpp b/wpilibc/src/main/native/cpp/shuffleboard/ComplexWidget.cpp deleted file mode 100644 index adc015c914f..00000000000 --- a/wpilibc/src/main/native/cpp/shuffleboard/ComplexWidget.cpp +++ /dev/null @@ -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 - -#include - -#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(*m_builder).IsActuator()) { - static_cast(*m_builder).StartLiveWindowMode(); - } -} - -void ComplexWidget::DisableIfActuator() { - if (m_builder && static_cast(*m_builder).IsActuator()) { - static_cast(*m_builder).StopLiveWindowMode(); - } -} - -void ComplexWidget::BuildInto(std::shared_ptr parentTable, - std::shared_ptr metaTable) { - BuildMetadata(metaTable); - if (!m_builder) { - m_builder = std::make_unique(); - static_cast(*m_builder) - .SetTable(parentTable->GetSubTable(GetTitle())); - m_sendable.InitSendable(static_cast(*m_builder)); - static_cast(*m_builder).StartListeners(); - } - m_builder->Update(); -} diff --git a/wpilibc/src/main/native/cpp/shuffleboard/LayoutType.cpp b/wpilibc/src/main/native/cpp/shuffleboard/LayoutType.cpp deleted file mode 100644 index 9c47efb8e9b..00000000000 --- a/wpilibc/src/main/native/cpp/shuffleboard/LayoutType.cpp +++ /dev/null @@ -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; -} diff --git a/wpilibc/src/main/native/cpp/shuffleboard/RecordingController.cpp b/wpilibc/src/main/native/cpp/shuffleboard/RecordingController.cpp deleted file mode 100644 index 90adca62085..00000000000 --- a/wpilibc/src/main/native/cpp/shuffleboard/RecordingController.cpp +++ /dev/null @@ -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 - -#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)}}}); -} diff --git a/wpilibc/src/main/native/cpp/shuffleboard/SendableCameraWrapper.cpp b/wpilibc/src/main/native/cpp/shuffleboard/SendableCameraWrapper.cpp deleted file mode 100644 index d5e076acb90..00000000000 --- a/wpilibc/src/main/native/cpp/shuffleboard/SendableCameraWrapper.cpp +++ /dev/null @@ -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 -#include -#include - -#include -#include -#include - -namespace frc { -namespace detail { -std::shared_ptr& GetSendableCameraWrapper( - std::string_view cameraName) { - static wpi::StringMap> 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 diff --git a/wpilibc/src/main/native/cpp/shuffleboard/Shuffleboard.cpp b/wpilibc/src/main/native/cpp/shuffleboard/Shuffleboard.cpp deleted file mode 100644 index 0fff070d50a..00000000000 --- a/wpilibc/src/main/native/cpp/shuffleboard/Shuffleboard.cpp +++ /dev/null @@ -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 - -#include - -#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& GetInstanceHolder() { - static std::unique_ptr instance = - std::make_unique( - nt::NetworkTableInstance::GetDefault()); - return instance; -} - -#ifndef __FRC_ROBORIO__ -namespace frc::impl { -void ResetShuffleboardInstance() { - GetInstanceHolder() = std::make_unique( - 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; -} diff --git a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardComponentBase.cpp b/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardComponentBase.cpp deleted file mode 100644 index 8dc962e819d..00000000000 --- a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardComponentBase.cpp +++ /dev/null @@ -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 -#include - -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 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(m_width), static_cast(m_height)}}); - } - - // Tile position - if (m_column >= 0 && m_row >= 0) { - metaTable->GetEntry("Position") - .SetDoubleArray( - {{static_cast(m_column), static_cast(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& ShuffleboardComponentBase::GetProperties() - const { - return m_properties; -} diff --git a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardContainer.cpp b/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardContainer.cpp deleted file mode 100644 index 2b25ef81038..00000000000 --- a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardContainer.cpp +++ /dev/null @@ -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 -#include -#include -#include - -#include -#include - -#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(layout)]; -} - -ShuffleboardContainer::ShuffleboardContainer(std::string_view title) - : ShuffleboardValue(title) {} - -const std::vector>& -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(*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(*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(*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 defaultValue) { - return Add(title, nt::Value::MakeBooleanArray(defaultValue)); -} - -SimpleWidget& ShuffleboardContainer::Add(std::string_view title, - std::span defaultValue) { - return Add(title, nt::Value::MakeDoubleArray(defaultValue)); -} - -SimpleWidget& ShuffleboardContainer::Add(std::string_view title, - std::span defaultValue) { - return Add(title, nt::Value::MakeFloatArray(defaultValue)); -} - -SimpleWidget& ShuffleboardContainer::Add( - std::string_view title, std::span defaultValue) { - return Add(title, nt::Value::MakeIntegerArray(defaultValue)); -} - -SimpleWidget& ShuffleboardContainer::Add( - std::string_view title, std::span defaultValue) { - return Add(title, nt::Value::MakeStringArray(defaultValue)); -} - -SuppliedValueWidget& ShuffleboardContainer::AddString( - std::string_view title, std::function supplier) { - static auto setter = [](nt::GenericPublisher& entry, std::string value) { - entry.SetString(value); - }; - - CheckTitle(title); - auto widget = std::make_unique>( - *this, title, "string", supplier, setter); - auto ptr = widget.get(); - m_components.emplace_back(std::move(widget)); - return *ptr; -} - -SuppliedValueWidget& ShuffleboardContainer::AddNumber( - std::string_view title, std::function supplier) { - return AddDouble(title, std::move(supplier)); -} - -SuppliedValueWidget& ShuffleboardContainer::AddDouble( - std::string_view title, std::function supplier) { - static auto setter = [](nt::GenericPublisher& entry, double value) { - entry.SetDouble(value); - }; - - CheckTitle(title); - auto widget = std::make_unique>( - *this, title, "double", supplier, setter); - auto ptr = widget.get(); - m_components.emplace_back(std::move(widget)); - return *ptr; -} - -SuppliedValueWidget& ShuffleboardContainer::AddFloat( - std::string_view title, std::function supplier) { - static auto setter = [](nt::GenericPublisher& entry, float value) { - entry.SetFloat(value); - }; - - CheckTitle(title); - auto widget = std::make_unique>( - *this, title, "float", supplier, setter); - auto ptr = widget.get(); - m_components.emplace_back(std::move(widget)); - return *ptr; -} - -SuppliedValueWidget& ShuffleboardContainer::AddInteger( - std::string_view title, std::function supplier) { - static auto setter = [](nt::GenericPublisher& entry, int64_t value) { - entry.SetInteger(value); - }; - - CheckTitle(title); - auto widget = std::make_unique>( - *this, title, "int", supplier, setter); - auto ptr = widget.get(); - m_components.emplace_back(std::move(widget)); - return *ptr; -} - -SuppliedValueWidget& ShuffleboardContainer::AddBoolean( - std::string_view title, std::function supplier) { - static auto setter = [](nt::GenericPublisher& entry, bool value) { - entry.SetBoolean(value); - }; - - CheckTitle(title); - auto widget = std::make_unique>( - *this, title, "boolean", supplier, setter); - auto ptr = widget.get(); - m_components.emplace_back(std::move(widget)); - return *ptr; -} - -SuppliedValueWidget>& -ShuffleboardContainer::AddStringArray( - std::string_view title, - std::function()> supplier) { - static auto setter = [](nt::GenericPublisher& entry, - std::vector value) { - entry.SetStringArray(value); - }; - - CheckTitle(title); - auto widget = std::make_unique>>( - *this, title, "string[]", supplier, setter); - auto ptr = widget.get(); - m_components.emplace_back(std::move(widget)); - return *ptr; -} - -SuppliedValueWidget>& ShuffleboardContainer::AddNumberArray( - std::string_view title, std::function()> supplier) { - return AddDoubleArray(title, std::move(supplier)); -} - -SuppliedValueWidget>& ShuffleboardContainer::AddDoubleArray( - std::string_view title, std::function()> supplier) { - static auto setter = [](nt::GenericPublisher& entry, - std::vector value) { - entry.SetDoubleArray(value); - }; - - CheckTitle(title); - auto widget = std::make_unique>>( - *this, title, "double[]", supplier, setter); - auto ptr = widget.get(); - m_components.emplace_back(std::move(widget)); - return *ptr; -} - -SuppliedValueWidget>& ShuffleboardContainer::AddFloatArray( - std::string_view title, std::function()> supplier) { - static auto setter = [](nt::GenericPublisher& entry, - std::vector value) { - entry.SetFloatArray(value); - }; - - CheckTitle(title); - auto widget = std::make_unique>>( - *this, title, "float[]", supplier, setter); - auto ptr = widget.get(); - m_components.emplace_back(std::move(widget)); - return *ptr; -} - -SuppliedValueWidget>& -ShuffleboardContainer::AddIntegerArray( - std::string_view title, std::function()> supplier) { - static auto setter = [](nt::GenericPublisher& entry, - std::vector value) { - entry.SetIntegerArray(value); - }; - - CheckTitle(title); - auto widget = std::make_unique>>( - *this, title, "int[]", supplier, setter); - auto ptr = widget.get(); - m_components.emplace_back(std::move(widget)); - return *ptr; -} - -SuppliedValueWidget>& ShuffleboardContainer::AddBooleanArray( - std::string_view title, std::function()> supplier) { - static auto setter = [](nt::GenericPublisher& entry, std::vector value) { - entry.SetBooleanArray(value); - }; - - CheckTitle(title); - auto widget = std::make_unique>>( - *this, title, "boolean[]", supplier, setter); - auto ptr = widget.get(); - m_components.emplace_back(std::move(widget)); - return *ptr; -} - -SuppliedValueWidget>& ShuffleboardContainer::AddRaw( - std::string_view title, std::function()> supplier) { - return AddRaw(title, "raw", std::move(supplier)); -} - -SuppliedValueWidget>& ShuffleboardContainer::AddRaw( - std::string_view title, std::string_view typeString, - std::function()> supplier) { - static auto setter = [](nt::GenericPublisher& entry, - std::vector value) { entry.SetRaw(value); }; - - CheckTitle(title); - auto widget = std::make_unique>>( - *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 defaultValue) { - return AddPersistent(title, nt::Value::MakeBooleanArray(defaultValue)); -} - -SimpleWidget& ShuffleboardContainer::AddPersistent( - std::string_view title, std::span defaultValue) { - return AddPersistent(title, nt::Value::MakeDoubleArray(defaultValue)); -} - -SimpleWidget& ShuffleboardContainer::AddPersistent( - std::string_view title, std::span defaultValue) { - return AddPersistent(title, nt::Value::MakeFloatArray(defaultValue)); -} - -SimpleWidget& ShuffleboardContainer::AddPersistent( - std::string_view title, std::span defaultValue) { - return AddPersistent(title, nt::Value::MakeIntegerArray(defaultValue)); -} - -SimpleWidget& ShuffleboardContainer::AddPersistent( - std::string_view title, std::span 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); -} diff --git a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardInstance.cpp b/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardInstance.cpp deleted file mode 100644 index 0e216c34d34..00000000000 --- a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardInstance.cpp +++ /dev/null @@ -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 -#include - -#include -#include -#include -#include -#include - -#include "frc/shuffleboard/Shuffleboard.h" - -using namespace frc::detail; - -struct ShuffleboardInstance::Impl { - wpi::StringMap tabs; - - bool tabsChanged = false; - std::shared_ptr rootTable; - std::shared_ptr 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 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); -} diff --git a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardLayout.cpp b/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardLayout.cpp deleted file mode 100644 index da2f71460cc..00000000000 --- a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardLayout.cpp +++ /dev/null @@ -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 - -#include - -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 parentTable, - std::shared_ptr 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())); - } -} diff --git a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardTab.cpp b/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardTab.cpp deleted file mode 100644 index 359a63c753b..00000000000 --- a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardTab.cpp +++ /dev/null @@ -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 - -#include - -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 parentTable, - std::shared_ptr 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())); - } -} diff --git a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardWidget.cpp b/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardWidget.cpp deleted file mode 100644 index bb475fdce52..00000000000 --- a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardWidget.cpp +++ /dev/null @@ -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(type)]; -} diff --git a/wpilibc/src/main/native/cpp/shuffleboard/SimpleWidget.cpp b/wpilibc/src/main/native/cpp/shuffleboard/SimpleWidget.cpp deleted file mode 100644 index 5550136d6d3..00000000000 --- a/wpilibc/src/main/native/cpp/shuffleboard/SimpleWidget.cpp +++ /dev/null @@ -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 - -#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 parentTable, - std::shared_ptr 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(parent)->GetParent()); - } - - auto& tab = *static_cast(parent); - tab.GetRoot().Update(); -} diff --git a/wpilibc/src/main/native/cpp/shuffleboard/WidgetType.cpp b/wpilibc/src/main/native/cpp/shuffleboard/WidgetType.cpp deleted file mode 100644 index 3062cba9ad8..00000000000 --- a/wpilibc/src/main/native/cpp/shuffleboard/WidgetType.cpp +++ /dev/null @@ -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; -} diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/BuiltInLayouts.h b/wpilibc/src/main/native/include/frc/shuffleboard/BuiltInLayouts.h deleted file mode 100644 index ca5e29f37bc..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/BuiltInLayouts.h +++ /dev/null @@ -1,49 +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. - -#pragma once - -#include "frc/shuffleboard/LayoutType.h" - -namespace frc { - -/** - * The types of layouts bundled with Shuffleboard. - * - *
{@code
- * ShuffleboardLayout myList = Shuffleboard::GetTab("My Tab")
- *   .GetLayout(BuiltinLayouts::kList, "My List");
- * }
- */ -enum class BuiltInLayouts { - /** - * Groups components in a vertical list. New widgets added to the layout will - * be placed at the bottom of the list.
Custom properties: - * - * - * - *
NameTypeDefault ValueNotes
Label positionString"BOTTOM"The position of component labels inside the grid. One of - * {@code ["TOP", "LEFT", "BOTTOM", "RIGHT", "HIDDEN"}
- */ - kList, - - /** - * Groups components in an n x m grid. Grid layouts default to - * 3x3.
Custom properties: - * - * - * - * - * - * - * - *
NameTypeDefault ValueNotes
Number of columnsNumber3Must be in the - * range [1,15]
Number of rowsNumber3Must be in the - * range [1,15]
Label position String"BOTTOM"The position of component labels inside the grid. - * One of {@code ["TOP", "LEFT", "BOTTOM", "RIGHT", "HIDDEN"}
- */ - kGrid -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/BuiltInWidgets.h b/wpilibc/src/main/native/include/frc/shuffleboard/BuiltInWidgets.h deleted file mode 100644 index d7ed1d57511..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/BuiltInWidgets.h +++ /dev/null @@ -1,385 +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. - -#pragma once - -#include "frc/shuffleboard/WidgetType.h" - -namespace frc { - -/** - * The types of the widgets bundled with Shuffleboard. - * - *

For example, setting a number to be displayed with a slider: - *

{@code
- * NetworkTableEntry example = Shuffleboard.getTab("My Tab")
- *   .add("My Number", 0)
- *   .withWidget(BuiltInWidgets.kNumberSlider)
- *   .getEntry();
- * }
- * - *

Each value in this enum goes into detail on what data types that widget - * can support, as well as the custom properties that widget uses. - */ -enum class BuiltInWidgets { - /** - * Displays a value with a simple text field. - *
Supported types: - *

    - *
  • String
  • - *
  • Number
  • - *
  • Boolean
  • - *
- *
This widget has no custom properties. - */ - kTextView, - /** - * Displays a number with a controllable slider. - *
Supported types: - *
    - *
  • Number
  • - *
- *
Custom properties: - * - * - * - *
NameTypeDefault ValueNotes
MinNumber-1.0The minimum value of the - * slider
MaxNumber1.0The maximum - * value of the slider
Block - * incrementNumber0.0625 How much to move the - * slider by with the arrow keys
- */ - kNumberSlider, - /** - * Displays a number with a view-only bar. - *
Supported types: - *
    - *
  • Number
  • - *
- *
Custom properties: - * - * - * - * - *
NameTypeDefault ValueNotes
MinNumber-1.0The minimum value of the - * bar
MaxNumber1.0The maximum - * value of the bar
CenterNumber0The center ("zero") value - * of the bar
- */ - kNumberBar, - /** - * Displays a number with a view-only dial. Displayed values are rounded to - * the nearest integer.
Supported types:
  • Number
  • - *
- *
Custom properties: - * - * - * - *
NameTypeDefault ValueNotes
MinNumber0The minimum value of the - * dial
MaxNumber100The maximum - * value of the dial
Show - * valueBooleantrue Whether or not to show the - * value as text
- */ - kDial, - /** - * Displays a number with a graph. NOTE: graphs can be taxing - * on the computer running the dashboard. Keep the number of visible data - * points to a minimum. Making the widget smaller also helps with performance, - * but may cause the graph to become difficult to read.
Supported types: - *
    - *
  • Number
  • - *
  • Number array
  • - *
- *
Custom properties: - * - * - * - * - *
NameTypeDefault ValueNotes
Visible timeNumber30How long, in seconds, should past data be visible for
- */ - kGraph, - /** - * Displays a boolean value as a large colored box. - *
Supported types: - *
    - *
  • Boolean
  • - *
- *
Custom properties: - * - * - * - * - * - * - *
NameTypeDefault ValueNotes
Color when trueColor"green"Can be specified as a string ({@code "#00FF00"}) or a rgba integer - * ({@code 0x00FF0000}) - *
Color when falseColor"red"Can be specified as a string or a number
- */ - kBooleanBox, - /** - * Displays a boolean with a large interactive toggle button. - *
Supported types: - *
    - *
  • Boolean
  • - *
- *
This widget has no custom properties. - */ - kToggleButton, - /** - * Displays a boolean with a fixed-size toggle switch. - *
Supported types: - *
    - *
  • Boolean
  • - *
- *
This widget has no custom properties. - */ - kToggleSwitch, - /** - * Displays an analog input or a raw number with a number bar. - *
Supported types: - *
    - *
  • Number
  • - *
  • AnalogInput
  • - *
- *
Custom properties: - * - * - * - * - * - * - *
NameTypeDefault ValueNotes
MinNumber0The minimum value of the - * bar
MaxNumber5The maximum - * value of the bar
CenterNumber0The center ("zero") value - * of the bar
OrientationString"HORIZONTAL"The orientation of the bar. One of {@code ["HORIZONTAL", - * "VERTICAL"]}
Number of tick - * marksNumber5 The number of discrete ticks on the - * bar
- */ - kVoltageView, - /** - * Displays a PowerDistribution.
Supported types:
  • - * PowerDistribution
  • - *
- *
Custom properties: - * - * - * - * - *
NameTypeDefault ValueNotes
Show voltage and current valuesBooleantrueWhether or not to display the voltage and current draw
- */ - kPowerDistribution, - /** - * Displays a SendableChooser with a dropdown combo box with a list of - * options. - *
Supported types: - *
    - *
  • SendableChooser
  • - *
- *
This widget has no custom properties. - */ - kComboBoxChooser, - /** - * Displays a SendableChooserwith a toggle button for each available option. - *
Supported types: - *
    - *
  • SendableChooser
  • - *
- *
This widget has no custom properties. - */ - kSplitButtonChooser, - /** - * Displays an Encoder displaying its speed, - * total traveled distance, and its distance per tick.
Supported types: - *
    - *
  • Encoder
  • - *
- *
This widget has no custom properties. - */ - kEncoder, - /** - * Displays a MotorController. - * The motor controller will be controllable from the dashboard when test mode - * is enabled, but will otherwise be view-only.
Supported types:
    - *
  • PWMMotorController
  • - *
  • DMC60
  • - *
  • Jaguar
  • - *
  • PWMTalonSRX
  • - *
  • PWMVictorSPX
  • - *
  • SD540
  • - *
  • Spark
  • - *
  • Talon
  • - *
  • Victor
  • - *
  • VictorSP
  • - *
  • MotorControllerGroup
  • - *
  • Any custom subclass of {@code SpeedContorller}
  • - *
- *
Custom properties: - * - * - * - * - *
NameTypeDefault ValueNotes
OrientationString"HORIZONTAL"One of {@code ["HORIZONTAL", "VERTICAL"]}
- */ - kMotorController, - /** - * Displays a command with a toggle button. Pressing the button will start the - * command, and the button will automatically release when the command - * completes.
Supported types:
  • Command
  • CommandGroup
  • - *
  • Any custom subclass of {@code Command} or {@code CommandGroup}
  • - *
- *
This widget has no custom properties. - */ - kCommand, - /** - * Displays a PID command with a checkbox and an editor for the PIDF - * constants. Selecting the checkbox will start the command, and the checkbox - * will automatically deselect when the command completes.
Supported - * types:
  • PIDCommand
  • - *
  • Any custom subclass of {@code PIDCommand}
  • - *
- *
This widget has no custom properties. - */ - kPIDCommand, - /** - * Displays a PID controller with an editor for the PIDF constants and a - * toggle switch for enabling and disabling the controller.
Supported - * types:
  • PIDController
  • - *
- *
This widget has no custom properties. - */ - kPIDController, - /** - * Displays an accelerometer with a number bar displaying the magnitude of the - * acceleration and text displaying the exact value.
Supported types:
    - *
  • AnalogAccelerometer
  • - *
- *
Custom properties: - * - * - * - * - * - * - * - * - * - * - * - * - *
NameTypeDefault ValueNotes
MinNumber-1The minimum acceleration value to display
MaxNumber1The maximum acceleration value to display
Show textBooleantrueShow or hide the acceleration values
PrecisionNumber2How many numbers to display after the decimal point
Show tick marksBooleanfalseShow or hide the tick marks on the number bars
- */ - kAccelerometer, - /** - * Displays a 3-axis accelerometer with a number bar for each axis' - * acceleration.
Supported types:
  • ADXL345_I2C
  • - * ADXL345_SPI
  • ADXL362
  • - *
- *
Custom properties: - * - * - * - * - * - * - * - * - *
NameTypeDefault ValueNotes
RangeRangek16GThe accelerometer - * range
Show valueBooleantrueShow or hide the acceleration values
PrecisionNumber2How many numbers to display after the decimal point
Show tick marksBooleanfalseShow or hide the tick marks on the number bars
- */ - k3AxisAccelerometer, - /** - * Displays a gyro with a dial from 0 to 360 degrees. - *
Supported types: - *
    - *
  • ADXRS450_Gyro
  • - *
  • AnalogGyro
  • - *
  • Any custom subclass of {@code GyroBase} (such as a MXP gyro)
  • - *
- *
Custom properties: - * - * - * - * - * - * - *
NameTypeDefault ValueNotes
Major tick - * spacingNumber45Degrees
Starting angleNumber180How far to rotate the entire dial, in degrees
Show tick mark ringBooleantrue
- */ - kGyro, - /** - * Displays a relay with toggle buttons for each supported mode (off, on, - * forward, reverse).
Supported types:
  • Relay
  • - *
- *
This widget has no custom properties. - */ - kRelay, - /** - * Displays a differential drive with a widget that displays the speed of each - * side of the drivebase and a vector for the direction and rotation of the - * drivebase. The widget will be controllable if the robot is in test mode. - *
Supported types: - *
    - *
  • DifferentialDrive
  • - *
- *
Custom properties: - * - * - * - * - * - *
NameTypeDefault ValueNotes
Number of wheelsNumber4Must be a - * positive even integer - *
Wheel diameterNumber80Pixels
Show velocity vectorsBooleantrue
- */ - kDifferentialDrive, - /** - * Displays a mecanum drive with a widget that displays the speed of each - * wheel, and vectors for the direction and rotation of the drivebase. The - * widget will be controllable if the robot is in test mode.
Supported - * types:
  • MecanumDrive
  • - *
- *
Custom properties: - * - * - * - *
NameTypeDefault ValueNotes
Show velocity vectorsBooleantrue
- */ - kMecanumDrive, - /** - * Displays a camera stream. - *
Supported types: - *
    - *
  • VideoSource (as long as it is streaming on an MJPEG server)
  • - *
- *
Custom properties: - * - * - * - * - * - * - * - * - * - *
NameTypeDefault ValueNotes
Show crosshairBooleantrueShow or hide a crosshair on the image
Crosshair colorColor"white"Can be a string or a rgba integer
Show controlsBooleantrueShow or hide the - * stream controls - *
RotationString"NONE"Rotates the displayed image. One of {@code ["NONE", "QUARTER_CW", - * "QUARTER_CCW", "HALF"]} - *
- */ - kCameraStream, - /** - * Displays a field2d object.
- * Supported types: - * - *
    - *
  • Field2d - *
- */ - kField, -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/ComplexWidget.h b/wpilibc/src/main/native/include/frc/shuffleboard/ComplexWidget.h deleted file mode 100644 index a96f879dbaf..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/ComplexWidget.h +++ /dev/null @@ -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. - -#pragma once - -#include -#include - -#include - -#include "frc/shuffleboard/ShuffleboardWidget.h" - -namespace wpi { -class Sendable; -class SendableBuilder; -} // namespace wpi - -namespace frc { - -class ShuffleboardContainer; - -/** - * A Shuffleboard widget that handles a Sendable object such as a motor - * controller or sensor. - */ -class ComplexWidget final : public ShuffleboardWidget { - public: - ComplexWidget(ShuffleboardContainer& parent, std::string_view title, - wpi::Sendable& sendable); - - ~ComplexWidget() override; - - void EnableIfActuator() override; - - void DisableIfActuator() override; - - void BuildInto(std::shared_ptr parentTable, - std::shared_ptr metaTable) override; - - private: - wpi::Sendable& m_sendable; - std::unique_ptr m_builder; -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/LayoutType.h b/wpilibc/src/main/native/include/frc/shuffleboard/LayoutType.h deleted file mode 100644 index 5fa5ca4ad0c..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/LayoutType.h +++ /dev/null @@ -1,34 +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. - -#pragma once - -#include - -namespace frc { - -/** - * Represents the type of a layout in Shuffleboard. Using this is preferred over - * specifying raw strings, to avoid typos and having to know or look up the - * exact string name for a desired layout. - * - * @see BuiltInLayouts the built-in layout types - */ -class LayoutType { - public: - explicit constexpr LayoutType(const char* layoutName) - : m_layoutName(layoutName) {} - ~LayoutType() = default; - - /** - * Gets the string type of the layout as defined by that layout in - * Shuffleboard. - */ - std::string_view GetLayoutName() const; - - private: - const char* m_layoutName; -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/RecordingController.h b/wpilibc/src/main/native/include/frc/shuffleboard/RecordingController.h deleted file mode 100644 index 3ef51208767..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/RecordingController.h +++ /dev/null @@ -1,40 +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. - -#pragma once - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "frc/shuffleboard/ShuffleboardEventImportance.h" - -namespace frc::detail { - -class RecordingController final { - public: - explicit RecordingController(nt::NetworkTableInstance ntInstance); - virtual ~RecordingController() = default; - - void StartRecording(); - void StopRecording(); - void SetRecordingFileNameFormat(std::string_view format); - void ClearRecordingFileNameFormat(); - - void AddEventMarker(std::string_view name, std::string_view description, - ShuffleboardEventImportance importance); - - private: - nt::BooleanPublisher m_recordingControlEntry; - nt::StringPublisher m_recordingFileNameFormatEntry; - std::shared_ptr m_eventsTable; -}; - -} // namespace frc::detail diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/SendableCameraWrapper.h b/wpilibc/src/main/native/include/frc/shuffleboard/SendableCameraWrapper.h deleted file mode 100644 index 7951cf91e04..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/SendableCameraWrapper.h +++ /dev/null @@ -1,136 +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. - -#pragma once - -#include -#include -#include -#include -#include - -#ifndef DYNAMIC_CAMERA_SERVER -#include -#include -#include -#include -#else -namespace cs { -class VideoSource; -} // namespace cs -using CS_Handle = int; // NOLINT -using CS_Source = CS_Handle; // NOLINT -#endif - -#include -#include -#include - -namespace frc { - -class SendableCameraWrapper; - -namespace detail { -constexpr const char* kProtocol = "camera_server://"; -std::shared_ptr& GetSendableCameraWrapper( - std::string_view cameraName); -void AddToSendableRegistry(wpi::Sendable* sendable, std::string_view name); -} // namespace detail - -/** - * A wrapper to make video sources sendable and usable from Shuffleboard. - */ -class SendableCameraWrapper - : public wpi::Sendable, - public wpi::SendableHelper { - private: - struct private_init {}; - - public: - /** - * Creates a new sendable wrapper. Private constructor to avoid direct - * instantiation with multiple wrappers floating around for the same camera. - * - * @param cameraName the name of the camera to wrap - */ - SendableCameraWrapper(std::string_view cameraName, const private_init&); - - /** - * Creates a new sendable wrapper. Private constructor to avoid direct - * instantiation with multiple wrappers floating around for the same camera. - * - * @param cameraName the name of the camera to wrap - * @param cameraUrls camera URLs - */ - SendableCameraWrapper(std::string_view cameraName, - std::span cameraUrls, - const private_init&); - - /** - * Gets a sendable wrapper object for the given video source, creating the - * wrapper if one does not already exist for the source. - * - * @param source the video source to wrap - * @return a sendable wrapper object for the video source, usable in - * Shuffleboard via ShuffleboardTab::Add() and ShuffleboardLayout::Add() - */ - static SendableCameraWrapper& Wrap(const cs::VideoSource& source); - static SendableCameraWrapper& Wrap(CS_Source source); - - static SendableCameraWrapper& Wrap(std::string_view cameraName, - std::span cameraUrls); - - void InitSendable(wpi::SendableBuilder& builder) override; - - private: - std::string m_uri; - nt::StringArrayPublisher m_streams; -}; - -#ifndef DYNAMIC_CAMERA_SERVER -inline SendableCameraWrapper::SendableCameraWrapper(std::string_view name, - const private_init&) - : m_uri(detail::kProtocol) { - detail::AddToSendableRegistry(this, name); - m_uri += name; -} - -inline SendableCameraWrapper::SendableCameraWrapper( - std::string_view cameraName, std::span cameraUrls, - const private_init&) - : SendableCameraWrapper(cameraName, private_init{}) { - m_streams = nt::NetworkTableInstance::GetDefault() - .GetStringArrayTopic( - fmt::format("/CameraPublisher/{}/streams", cameraName)) - .Publish(); - m_streams.Set(cameraUrls); -} - -inline SendableCameraWrapper& SendableCameraWrapper::Wrap( - const cs::VideoSource& source) { - return Wrap(source.GetHandle()); -} - -inline SendableCameraWrapper& SendableCameraWrapper::Wrap(CS_Source source) { - CS_Status status = 0; - auto name = cs::GetSourceName(source, &status); - auto& wrapper = detail::GetSendableCameraWrapper(name); - if (!wrapper) { - wrapper = std::make_shared(name, private_init{}); - } - return *wrapper; -} - -inline SendableCameraWrapper& SendableCameraWrapper::Wrap( - std::string_view cameraName, std::span cameraUrls) { - auto& wrapper = detail::GetSendableCameraWrapper(cameraName); - if (!wrapper) { - wrapper = std::make_shared(cameraName, cameraUrls, - private_init{}); - } - return *wrapper; -} -#endif - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/Shuffleboard.h b/wpilibc/src/main/native/include/frc/shuffleboard/Shuffleboard.h deleted file mode 100644 index 252d74ab2ca..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/Shuffleboard.h +++ /dev/null @@ -1,196 +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. - -#pragma once - -#include - -#include "frc/shuffleboard/RecordingController.h" -#include "frc/shuffleboard/ShuffleboardEventImportance.h" -#include "frc/shuffleboard/ShuffleboardInstance.h" - -namespace frc { - -class ShuffleboardTab; - -/** - * The Shuffleboard class provides a mechanism with which data can be added and - * laid out in the Shuffleboard dashboard application from a robot program. Tabs - * and layouts can be specified, as well as choosing which widgets to display - * with and setting properties of these widgets; for example, programmers can - * specify a specific {@code boolean} value to be displayed with a toggle button - * instead of the default colored box, or set custom colors for that box. - * - * For example, displaying a boolean entry with a toggle button: - *
{@code
- * NetworkTableEntry myBoolean = Shuffleboard.getTab("Example Tab")
- *   .add("My Boolean", false)
- *   .withWidget("Toggle Button")
- *   .getEntry();
- * }
- * - * Changing the colors of the boolean box: - *
{@code
- * NetworkTableEntry myBoolean = Shuffleboard.getTab("Example Tab")
- *   .add("My Boolean", false)
- *   .withWidget("Boolean Box")
- *   .withProperties(Map.of("colorWhenTrue", "green", "colorWhenFalse",
- * "maroon")) .getEntry();
- * }
- * - * Specifying a parent layout. Note that the layout type must always be - * specified, even if the layout has already been generated by a previously - * defined entry. - *
{@code
- * NetworkTableEntry myBoolean = Shuffleboard.getTab("Example Tab")
- *   .getLayout("List", "Example List")
- *   .add("My Boolean", false)
- *   .withWidget("Toggle Button")
- *   .getEntry();
- * }
- *

- * - * Teams are encouraged to set up shuffleboard layouts at the start of the robot - * program. - */ -class Shuffleboard final { - public: - /** - * The name of the base NetworkTable into which all Shuffleboard data will be - * added. - */ - static constexpr const char* kBaseTableName = "/Shuffleboard"; - - /** - * Updates all the values in Shuffleboard. Iterative and timed robots are - * pre-configured to call this method in the main robot loop; teams using - * custom robot base classes, or subclass SampleRobot, should make sure to - * call this repeatedly to keep data on the dashboard up to date. - */ - static void Update(); - - /** - * Gets the Shuffleboard tab with the given title, creating it if it does not - * already exist. - * - * @param title the title of the tab - * @return the tab with the given title - */ - static ShuffleboardTab& GetTab(std::string_view title); - - /** - * Selects the tab in the dashboard with the given index in the range - * [0..n-1], where n is the number of tabs in the dashboard at the time - * this method is called. - * - * @param index the index of the tab to select - */ - static void SelectTab(int index); - - /** - * Selects the tab in the dashboard with the given title. - * - * @param title the title of the tab to select - */ - static void SelectTab(std::string_view title); - - /** - * Enables user control of widgets containing actuators: motor controllers, - * relays, etc. This should only be used when the robot is in test mode. - * IterativeRobotBase and SampleRobot are both configured to call this method - * when entering test mode; most users should not need to use this method - * directly. - */ - static void EnableActuatorWidgets(); - - /** - * Disables user control of widgets containing actuators. For safety reasons, - * actuators should only be controlled while in test mode. IterativeRobotBase - * and SampleRobot are both configured to call this method when exiting in - * test mode; most users should not need to use this method directly. - */ - static void DisableActuatorWidgets(); - - /** - * Starts data recording on the dashboard. Has no effect if recording is - * already in progress. - */ - static void StartRecording(); - - /** - * Stops data recording on the dashboard. Has no effect if no recording is in - * progress. - */ - static void StopRecording(); - - /** - * Sets the file name format for new recording files to use. If recording is - * in progress when this method is called, it will continue to use the same - * file. New recordings will use the format. - * - *

To avoid recording files overwriting each other, make sure to use unique - * recording file names. File name formats accept templates for inserting the - * date and time when the recording started with the {@code ${date}} and - * {@code ${time}} templates, respectively. For example, the default format is - * {@code "recording-${time}"} and recording files created with it will have - * names like {@code "recording-2018.01.15.sbr"}. Users are - * strongly recommended to use the {@code ${time}} template - * to ensure unique file names. - *

- * - * @param format the format for the - */ - static void SetRecordingFileNameFormat(std::string_view format); - - /** - * Clears the custom name format for recording files. New recordings will use - * the default format. - * - * @see SetRecordingFileNameFormat(std::string_view) - */ - static void ClearRecordingFileNameFormat(); - - /** - * Notifies Shuffleboard of an event. Events can range from as trivial as a - * change in a command state to as critical as a total power loss or component - * failure. If Shuffleboard is recording, the event will also be recorded. - * - *

If {@code name} is {@code null} or empty, no event will be sent and an - * error will be printed to the driver station. - * - * @param name the name of the event - * @param description a description of the event - * @param importance the importance of the event - */ - static void AddEventMarker(std::string_view name, - std::string_view description, - ShuffleboardEventImportance importance); - - /** - * Notifies Shuffleboard of an event. Events can range from as trivial as a - * change in a command state to as critical as a total power loss or component - * failure. If Shuffleboard is recording, the event will also be recorded. - * - *

If {@code name} is {@code null} or empty, no event will be sent and an - * error will be printed to the driver station. - * - * @param name the name of the event - * @param importance the importance of the event - */ - static void AddEventMarker(std::string_view name, - ShuffleboardEventImportance importance); - - private: - static detail::ShuffleboardInstance& GetInstance(); - static detail::RecordingController& GetRecordingController(); - - // TODO usage reporting - - Shuffleboard() = default; -}; - -} // namespace frc - -// Make use of references returned by member functions usable -#include "frc/shuffleboard/ShuffleboardTab.h" diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardComponent.h b/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardComponent.h deleted file mode 100644 index 3441c5784df..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardComponent.h +++ /dev/null @@ -1,89 +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. - -#pragma once - -#include - -#include -#include -#include - -#include "frc/shuffleboard/ShuffleboardComponentBase.h" - -namespace frc { - -class ShuffleboardContainer; - -/** - * A generic component in Shuffleboard. - * - * @tparam Derived the self type - */ -template -class ShuffleboardComponent : public ShuffleboardComponentBase { - public: - /** - * Constructs a ShuffleboardComponent. - * - * @param parent The parent container. - * @param title The component title. - * @param type The component type. - */ - ShuffleboardComponent(ShuffleboardContainer& parent, std::string_view title, - std::string_view type = "") - : ShuffleboardValue(title), - ShuffleboardComponentBase(parent, title, type) {} - - /** - * Sets custom properties for this component. Property names are - * case-sensitive and whitespace-insensitive (capitalization and spaces do not - * matter). - * - * @param properties the properties for this component - * @return this component - */ - Derived& WithProperties(const wpi::StringMap& properties) { - m_properties = properties; - m_metadataDirty = true; - return *static_cast(this); - } - - /** - * Sets the position of this component in the tab. This has no effect if this - * component is inside a layout. - * - * If the position of a single component is set, it is recommended to set the - * positions of all components inside a tab to prevent Shuffleboard - * from automatically placing another component there before the one with the - * specific position is sent. - * - * @param columnIndex the column in the tab to place this component - * @param rowIndex the row in the tab to place this component - * @return this component - */ - Derived& WithPosition(int columnIndex, int rowIndex) { - m_column = columnIndex; - m_row = rowIndex; - m_metadataDirty = true; - return *static_cast(this); - } - - /** - * Sets the size of this component in the tab. This has no effect if this - * component is inside a layout. - * - * @param width how many columns wide the component should be - * @param height how many rows high the component should be - * @return this component - */ - Derived& WithSize(int width, int height) { - m_width = width; - m_height = height; - m_metadataDirty = true; - return *static_cast(this); - } -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardComponentBase.h b/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardComponentBase.h deleted file mode 100644 index de27b3528a0..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardComponentBase.h +++ /dev/null @@ -1,55 +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. - -#pragma once - -#include -#include -#include - -#include -#include -#include - -#include "frc/shuffleboard/ShuffleboardValue.h" - -namespace frc { - -class ShuffleboardContainer; - -/** - * A shim class to allow storing ShuffleboardComponents in arrays. - */ -class ShuffleboardComponentBase : public virtual ShuffleboardValue { - public: - ShuffleboardComponentBase(ShuffleboardContainer& parent, - std::string_view title, std::string_view type = ""); - - void SetType(std::string_view type); - - void BuildMetadata(std::shared_ptr metaTable); - - ShuffleboardContainer& GetParent(); - - const std::string& GetType() const; - - protected: - wpi::StringMap m_properties; - bool m_metadataDirty = true; - int m_column = -1; - int m_row = -1; - int m_width = -1; - int m_height = -1; - - private: - ShuffleboardContainer& m_parent; - std::string m_type; - - /** - * Gets the custom properties for this component. May be null. - */ - const wpi::StringMap& GetProperties() const; -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardContainer.h b/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardContainer.h deleted file mode 100644 index 5d207838208..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardContainer.h +++ /dev/null @@ -1,727 +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. - -#pragma once - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "frc/shuffleboard/BuiltInLayouts.h" -#include "frc/shuffleboard/LayoutType.h" -#include "frc/shuffleboard/ShuffleboardComponentBase.h" -#include "frc/shuffleboard/ShuffleboardValue.h" -#include "frc/shuffleboard/SuppliedValueWidget.h" - -namespace cs { -class VideoSource; -} // namespace cs - -namespace wpi { -class Sendable; -} // namespace wpi - -namespace frc { - -class ComplexWidget; -class ShuffleboardLayout; -class SimpleWidget; - -/** - * Common interface for objects that can contain shuffleboard components. - */ -class ShuffleboardContainer : public virtual ShuffleboardValue { - public: - explicit ShuffleboardContainer(std::string_view title); - - ShuffleboardContainer(ShuffleboardContainer&& rhs) = default; - - ~ShuffleboardContainer() override = default; - - /** - * Gets the components that are direct children of this container. - */ - const std::vector>& GetComponents() - const; - - /** - * Gets the layout with the given type and title, creating it if it does not - * already exist at the time this method is called. - * - * @param title the title of the layout - * @param type the type of the layout, eg "List" or "Grid" - * @return the layout - */ - ShuffleboardLayout& GetLayout(std::string_view title, BuiltInLayouts type); - - /** - * Gets the layout with the given type and title, creating it if it does not - * already exist at the time this method is called. - * - * @param title the title of the layout - * @param type the type of the layout, eg "List" or "Grid" - * @return the layout - */ - ShuffleboardLayout& GetLayout(std::string_view title, const LayoutType& type); - - /** - * Gets the layout with the given type and title, creating it if it does not - * already exist at the time this method is called. Note: this method should - * only be used to use a layout type that is not already built into - * Shuffleboard. To use a layout built into Shuffleboard, use - * GetLayout(std::string_view, const LayoutType&) and the layouts in - * BuiltInLayouts. - * - * @param title the title of the layout - * @param type the type of the layout, eg "List Layout" or "Grid Layout" - * @return the layout - * @see GetLayout(std::string_view, const LayoutType&) - */ - ShuffleboardLayout& GetLayout(std::string_view title, std::string_view type); - - /** - * Gets the already-defined layout in this container with the given title. - * - *

{@code
-   * Shuffleboard::GetTab("Example Tab")->getLayout("My Layout",
-   * &BuiltInLayouts.kList);
-   *
-   * // Later...
-   * Shuffleboard::GetTab("Example Tab")->GetLayout("My Layout");
-   * }
- * - * @param title the title of the layout to get - * @return the layout with the given title - * @throws if no layout has yet been defined with the given title - */ - ShuffleboardLayout& GetLayout(std::string_view title); - - /** - * Adds a widget to this container to display the given sendable. - * - * @param title the title of the widget - * @param sendable the sendable to display - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this - * container with the given title - */ - ComplexWidget& Add(std::string_view title, wpi::Sendable& sendable); - - /** - * Adds a widget to this container to display the given video stream. - * - * @param title the title of the widget - * @param video the video stream to display - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this - * container with the given title - */ - ComplexWidget& Add(std::string_view title, const cs::VideoSource& video); - - /** - * Adds a widget to this container to display a video stream. - * - * @param title the title of the widget - * @param cameraName the name of the streamed camera - * @param cameraUrls the URLs with which the dashboard can access the camera - * stream - * @return a widget to display the camera stream - */ - ComplexWidget& AddCamera(std::string_view title, std::string_view cameraName, - std::span cameraUrls); - - /** - * Adds a widget to this container to display the given sendable. - * - * @param sendable the sendable to display - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this - * container with the given title, or if the sendable's name has not been - * specified - */ - ComplexWidget& Add(wpi::Sendable& sendable); - - /** - * Adds a widget to this container to display the given video stream. - * - * @param video the video to display - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this - * container with the same title as the video source - */ - ComplexWidget& Add(const cs::VideoSource& video); - - /** - * Adds a widget to this container to display the given data. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this - * container with the given title - * @see AddPersistent(std::string_view, std::shared_ptr) - * Add(std::string_view title, std::shared_ptr defaultValue) - */ - SimpleWidget& Add(std::string_view title, const nt::Value& defaultValue); - - /** - * Adds a widget to this container to display the given data. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this - * container with the given title - * @see AddPersistent(std::string_view, bool) - * Add(std::string_view title, bool defaultValue) - */ - SimpleWidget& Add(std::string_view title, bool defaultValue); - - /** - * Adds a widget to this container to display the given data. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this - * container with the given title - * @see AddPersistent(std::string_view, double) - * Add(std::string_view title, double defaultValue) - */ - SimpleWidget& Add(std::string_view title, double defaultValue); - - /** - * Adds a widget to this container to display the given data. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this - * container with the given title - * @see AddPersistent(std::string_view, double) - * Add(std::string_view title, double defaultValue) - */ - SimpleWidget& Add(std::string_view title, float defaultValue); - - /** - * Adds a widget to this container to display the given data. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this - * container with the given title - * @see AddPersistent(std::string_view, int) - * Add(std::string_view title, int defaultValue) - */ - SimpleWidget& Add(std::string_view title, int defaultValue); - - /** - * Adds a widget to this container to display the given data. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this - * container with the given title - * @see AddPersistent(std::string_view, std::string_view) - * Add(std::string_view title, std::string_view defaultValue) - */ - SimpleWidget& Add(std::string_view title, std::string_view defaultValue); - - /** - * Adds a widget to this container to display the given data. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this - * container with the given title - * @see AddPersistent(std::string_view, const char*) - * Add(std::string_view title, const char* defaultValue) - */ - SimpleWidget& Add(std::string_view title, const char* defaultValue); - - /** - * Adds a widget to this container to display the given data. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this - * container with the given title - * @see AddPersistent(std::string_view, std::span) - * Add(std::string_view title, std::span defaultValue) - */ - SimpleWidget& Add(std::string_view title, std::span defaultValue); - - /** - * Adds a widget to this container to display the given data. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this - * container with the given title - * @see AddPersistent(std::string_view, std::span) - * Add(std::string_view title, std::span defaultValue) - */ - SimpleWidget& Add(std::string_view title, - std::span defaultValue); - - /** - * Adds a widget to this container to display the given data. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this - * container with the given title - * @see AddPersistent(std::string_view, std::span) - * Add(std::string_view title, std::span defaultValue) - */ - SimpleWidget& Add(std::string_view title, - std::span defaultValue); - - /** - * Adds a widget to this container to display the given data. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this - * container with the given title - * @see AddPersistent(std::string_view, std::span) - * Add(std::string_view title, std::span defaultValue) - */ - SimpleWidget& Add(std::string_view title, - std::span defaultValue); - - /** - * Adds a widget to this container to display the given data. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this - * container with the given title - * @see AddPersistent(std::string_view, std::span) - * Add(std::string_view title, std::span defaultValue) - */ - SimpleWidget& Add(std::string_view title, - std::span defaultValue); - - /** - * Adds a widget to this container. The widget will display the data provided - * by the value supplier. Changes made on the dashboard will not propagate to - * the widget object, and will be overridden by values from the value - * supplier. - * - * @param title the title of the widget - * @param supplier the supplier for values - * @return a widget to display data - */ - SuppliedValueWidget& AddString( - std::string_view title, std::function supplier); - - /** - * Adds a widget to this container. The widget will display the data provided - * by the value supplier. Changes made on the dashboard will not propagate to - * the widget object, and will be overridden by values from the value - * supplier. - * - * @param title the title of the widget - * @param supplier the supplier for values - * @return a widget to display data - */ - SuppliedValueWidget& AddNumber(std::string_view title, - std::function supplier); - - /** - * Adds a widget to this container. The widget will display the data provided - * by the value supplier. Changes made on the dashboard will not propagate to - * the widget object, and will be overridden by values from the value - * supplier. - * - * @param title the title of the widget - * @param supplier the supplier for values - * @return a widget to display data - */ - SuppliedValueWidget& AddDouble(std::string_view title, - std::function supplier); - - /** - * Adds a widget to this container. The widget will display the data provided - * by the value supplier. Changes made on the dashboard will not propagate to - * the widget object, and will be overridden by values from the value - * supplier. - * - * @param title the title of the widget - * @param supplier the supplier for values - * @return a widget to display data - */ - SuppliedValueWidget& AddFloat(std::string_view title, - std::function supplier); - - /** - * Adds a widget to this container. The widget will display the data provided - * by the value supplier. Changes made on the dashboard will not propagate to - * the widget object, and will be overridden by values from the value - * supplier. - * - * @param title the title of the widget - * @param supplier the supplier for values - * @return a widget to display data - */ - SuppliedValueWidget& AddInteger(std::string_view title, - std::function supplier); - - /** - * Adds a widget to this container. The widget will display the data provided - * by the value supplier. Changes made on the dashboard will not propagate to - * the widget object, and will be overridden by values from the value - * supplier. - * - * @param title the title of the widget - * @param supplier the supplier for values - * @return a widget to display data - */ - SuppliedValueWidget& AddBoolean(std::string_view title, - std::function supplier); - - /** - * Adds a widget to this container. The widget will display the data provided - * by the value supplier. Changes made on the dashboard will not propagate to - * the widget object, and will be overridden by values from the value - * supplier. - * - * @param title the title of the widget - * @param supplier the supplier for values - * @return a widget to display data - */ - SuppliedValueWidget>& AddStringArray( - std::string_view title, - std::function()> supplier); - - /** - * Adds a widget to this container. The widget will display the data provided - * by the value supplier. Changes made on the dashboard will not propagate to - * the widget object, and will be overridden by values from the value - * supplier. - * - * @param title the title of the widget - * @param supplier the supplier for values - * @return a widget to display data - */ - SuppliedValueWidget>& AddNumberArray( - std::string_view title, std::function()> supplier); - - /** - * Adds a widget to this container. The widget will display the data provided - * by the value supplier. Changes made on the dashboard will not propagate to - * the widget object, and will be overridden by values from the value - * supplier. - * - * @param title the title of the widget - * @param supplier the supplier for values - * @return a widget to display data - */ - SuppliedValueWidget>& AddDoubleArray( - std::string_view title, std::function()> supplier); - - /** - * Adds a widget to this container. The widget will display the data provided - * by the value supplier. Changes made on the dashboard will not propagate to - * the widget object, and will be overridden by values from the value - * supplier. - * - * @param title the title of the widget - * @param supplier the supplier for values - * @return a widget to display data - */ - SuppliedValueWidget>& AddFloatArray( - std::string_view title, std::function()> supplier); - - /** - * Adds a widget to this container. The widget will display the data provided - * by the value supplier. Changes made on the dashboard will not propagate to - * the widget object, and will be overridden by values from the value - * supplier. - * - * @param title the title of the widget - * @param supplier the supplier for values - * @return a widget to display data - */ - SuppliedValueWidget>& AddIntegerArray( - std::string_view title, std::function()> supplier); - - /** - * Adds a widget to this container. The widget will display the data provided - * by the value supplier. Changes made on the dashboard will not propagate to - * the widget object, and will be overridden by values from the value - * supplier. - * - * @param title the title of the widget - * @param supplier the supplier for values - * @return a widget to display data - */ - SuppliedValueWidget>& AddBooleanArray( - std::string_view title, std::function()> supplier); - - /** - * Adds a widget to this container. The widget will display the data provided - * by the value supplier. Changes made on the dashboard will not propagate to - * the widget object, and will be overridden by values from the value - * supplier. - * - * @param title the title of the widget - * @param supplier the supplier for values - * @return a widget to display data - */ - SuppliedValueWidget>& AddRaw( - std::string_view title, std::function()> supplier); - - /** - * Adds a widget to this container. The widget will display the data provided - * by the value supplier. Changes made on the dashboard will not propagate to - * the widget object, and will be overridden by values from the value - * supplier. - * - * @param title the title of the widget - * @param typeString the NT type string - * @param supplier the supplier for values - * @return a widget to display data - */ - SuppliedValueWidget>& AddRaw( - std::string_view title, std::string_view typeString, - std::function()> supplier); - - /** - * Adds a widget to this container to display a simple piece of data. - * - * Unlike Add(std::string_view, std::shared_ptr), the value in the - * widget will be saved on the robot and will be used when the robot program - * next starts rather than {@code defaultValue}. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @see Add(stdd::string_view, std::shared_ptr) - * Add(std::string_view title, std::shared_ptr defaultValue) - */ - SimpleWidget& AddPersistent(std::string_view title, - const nt::Value& defaultValue); - - /** - * Adds a widget to this container to display a simple piece of data. - * - * Unlike Add(std::string_view, bool), the value in the widget will be saved - * on the robot and will be used when the robot program next starts rather - * than {@code defaultValue}. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @see Add(std::string_view, bool) - * Add(std::string_view title, bool defaultValue) - */ - SimpleWidget& AddPersistent(std::string_view title, bool defaultValue); - - /** - * Adds a widget to this container to display a simple piece of data. - * - * Unlike Add(std::string_view, double), the value in the widget will be saved - * on the robot and will be used when the robot program next starts rather - * than {@code defaultValue}. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @see Add(std::string_view, double) - * Add(std::string_view title, double defaultValue) - */ - SimpleWidget& AddPersistent(std::string_view title, double defaultValue); - - /** - * Adds a widget to this container to display a simple piece of data. - * - * Unlike Add(std::string_view, float), the value in the widget will be saved - * on the robot and will be used when the robot program next starts rather - * than {@code defaultValue}. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @see Add(std::string_view, float) - * Add(std::string_view title, float defaultValue) - */ - SimpleWidget& AddPersistent(std::string_view title, float defaultValue); - - /** - * Adds a widget to this container to display a simple piece of data. - * - * Unlike Add(std::string_view, int64_t), the value in the widget will be - * saved on the robot and will be used when the robot program next starts - * rather than {@code defaultValue}. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @see Add(std:string_view, int64_t) - * Add(std::string_view title, int64_t defaultValue) - */ - SimpleWidget& AddPersistent(std::string_view title, int defaultValue); - - /** - * Adds a widget to this container to display a simple piece of data. - * - * Unlike Add(std::string_view, std::string_view), the value in the widget - * will be saved on the robot and will be used when the robot program next - * starts rather than {@code defaultValue}. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @see Add(std::string_view, std::string_view) - * Add(std::string_view title, std::string_view defaultValue) - */ - SimpleWidget& AddPersistent(std::string_view title, - std::string_view defaultValue); - - /** - * Adds a widget to this container to display a simple piece of data. - * - * Unlike Add(std::string_view, std::span), the value in the - * widget will be saved on the robot and will be used when the robot program - * next starts rather than {@code defaultValue}. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @see Add(std::string_view, std::span) - * Add(std::string_view title, std::span defaultValue) - */ - SimpleWidget& AddPersistent(std::string_view title, - std::span defaultValue); - - /** - * Adds a widget to this container to display a simple piece of data. - * - * Unlike Add(std::string_view, std::span), the value in the - * widget will be saved on the robot and will be used when the robot program - * next starts rather than {@code defaultValue}. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @see Add(std::string_view, std::span) - * Add(std::string_view title, std::span defaultValue) - */ - SimpleWidget& AddPersistent(std::string_view title, - std::span defaultValue); - - /** - * Adds a widget to this container to display a simple piece of data. - * - * Unlike Add(std::string_view, std::span), the value in the - * widget will be saved on the robot and will be used when the robot program - * next starts rather than {@code defaultValue}. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @see Add(std::string_view, std::span) - * Add(std::string_view title, std::span defaultValue) - */ - SimpleWidget& AddPersistent(std::string_view title, - std::span defaultValue); - - /** - * Adds a widget to this container to display a simple piece of data. - * - * Unlike Add(std::string_view, std::span), the value in the - * widget will be saved on the robot and will be used when the robot program - * next starts rather than {@code defaultValue}. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @see Add(std::string_view, std::span) - * Add(std::string_view title, std::span defaultValue) - */ - SimpleWidget& AddPersistent(std::string_view title, - std::span defaultValue); - - /** - * Adds a widget to this container to display a simple piece of data. - * - * Unlike Add(std::string_view, std::span), the value in - * the widget will be saved on the robot and will be used when the robot - * program next starts rather than {@code defaultValue}. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @see Add(std::string_view, std::span) - * Add(std::string_view title, std::span defaultValue) - */ - SimpleWidget& AddPersistent(std::string_view title, - std::span defaultValue); - - void EnableIfActuator() override; - - void DisableIfActuator() override; - - protected: - bool m_isLayout = false; - - private: - wpi::SmallSet m_usedTitles; - std::vector> m_components; - wpi::StringMap m_layouts; - - /** - * Adds title to internal set if it hasn't already. - * - * @return True if title isn't in use; false otherwise. - */ - void CheckTitle(std::string_view title); - - friend class SimpleWidget; -}; - -} // namespace frc - -// Make use of references returned by member functions usable -#include "frc/shuffleboard/ComplexWidget.h" -#include "frc/shuffleboard/ShuffleboardLayout.h" -#include "frc/shuffleboard/SimpleWidget.h" - -#ifndef DYNAMIC_CAMERA_SERVER -#include "frc/shuffleboard/SendableCameraWrapper.h" - -inline frc::ComplexWidget& frc::ShuffleboardContainer::Add( - const cs::VideoSource& video) { - return Add(frc::SendableCameraWrapper::Wrap(video)); -} - -inline frc::ComplexWidget& frc::ShuffleboardContainer::Add( - std::string_view title, const cs::VideoSource& video) { - return Add(title, frc::SendableCameraWrapper::Wrap(video)); -} - -inline frc::ComplexWidget& frc::ShuffleboardContainer::AddCamera( - std::string_view title, std::string_view cameraName, - std::span cameraUrls) { - return Add(title, frc::SendableCameraWrapper::Wrap(cameraName, cameraUrls)); -} -#endif diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardEventImportance.h b/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardEventImportance.h deleted file mode 100644 index ea251ec9158..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardEventImportance.h +++ /dev/null @@ -1,40 +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. - -#pragma once - -#include - -namespace frc { - -// Maintainer note: this enum is mirrored in WPILibJ and in Shuffleboard -// Modifying the enum or enum strings requires a corresponding change to the -// Java enum and the enum in Shuffleboard - -enum ShuffleboardEventImportance { kTrivial, kLow, kNormal, kHigh, kCritical }; - -/** - * Returns name of the given enum. - * - * @return Name of the given enum. - */ -inline std::string_view ShuffleboardEventImportanceName( - ShuffleboardEventImportance importance) { - switch (importance) { - case kTrivial: - return "TRIVIAL"; - case kLow: - return "LOW"; - case kNormal: - return "NORMAL"; - case kHigh: - return "HIGH"; - case kCritical: - return "CRITICAL"; - default: - return "NORMAL"; - } -} - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardInstance.h b/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardInstance.h deleted file mode 100644 index 2885af7b8a5..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardInstance.h +++ /dev/null @@ -1,40 +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. - -#pragma once - -#include -#include - -#include "frc/shuffleboard/ShuffleboardRoot.h" -#include "frc/shuffleboard/ShuffleboardTab.h" - -namespace frc::detail { - -class ShuffleboardInstance final : public ShuffleboardRoot { - public: - explicit ShuffleboardInstance(nt::NetworkTableInstance ntInstance); - virtual ~ShuffleboardInstance(); - - ShuffleboardInstance(ShuffleboardInstance&&) = default; - ShuffleboardInstance& operator=(ShuffleboardInstance&&) = default; - - frc::ShuffleboardTab& GetTab(std::string_view title) override; - - void Update() override; - - void EnableActuatorWidgets() override; - - void DisableActuatorWidgets() override; - - void SelectTab(int index) override; - - void SelectTab(std::string_view) override; - - private: - struct Impl; - std::unique_ptr m_impl; -}; - -} // namespace frc::detail diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardLayout.h b/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardLayout.h deleted file mode 100644 index fe9e102be83..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardLayout.h +++ /dev/null @@ -1,40 +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. - -#pragma once - -#include -#include - -#include - -#include "frc/shuffleboard/ShuffleboardComponent.h" -#include "frc/shuffleboard/ShuffleboardContainer.h" - -#ifdef _WIN32 -#pragma warning(push) -#pragma warning(disable : 4250) -#endif - -namespace frc { - -/** - * A layout in a Shuffleboard tab. Layouts can contain widgets and other - * layouts. - */ -class ShuffleboardLayout : public ShuffleboardComponent, - public ShuffleboardContainer { - public: - ShuffleboardLayout(ShuffleboardContainer& parent, std::string_view name, - std::string_view type); - - void BuildInto(std::shared_ptr parentTable, - std::shared_ptr metaTable) override; -}; - -} // namespace frc - -#ifdef _WIN32 -#pragma warning(pop) -#endif diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardRoot.h b/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardRoot.h deleted file mode 100644 index 1e766a84e46..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardRoot.h +++ /dev/null @@ -1,63 +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. - -#pragma once - -#include - -namespace frc { - -class ShuffleboardTab; - -/** - * The root of the data placed in Shuffleboard. It contains the tabs, but no - * data is placed directly in the root. - * - * This class is package-private to minimize API surface area. - */ -class ShuffleboardRoot { - public: - /** - * Gets the tab with the given title, creating it if it does not already - * exist. - * - * @param title the title of the tab - * @return the tab with the given title - */ - virtual ShuffleboardTab& GetTab(std::string_view title) = 0; - - /** - * Updates all tabs. - */ - virtual void Update() = 0; - - /** - * Enables all widgets in Shuffleboard that offer user control over actuators. - */ - virtual void EnableActuatorWidgets() = 0; - - /** - * Disables all widgets in Shuffleboard that offer user control over - * actuators. - */ - virtual void DisableActuatorWidgets() = 0; - - /** - * Selects the tab in the dashboard with the given index in the range - * [0..n-1], where n is the number of tabs in the dashboard at the time - * this method is called. - * - * @param index the index of the tab to select - */ - virtual void SelectTab(int index) = 0; - - /** - * Selects the tab in the dashboard with the given title. - * - * @param title the title of the tab to select - */ - virtual void SelectTab(std::string_view title) = 0; -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardTab.h b/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardTab.h deleted file mode 100644 index 8864cdb97dd..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardTab.h +++ /dev/null @@ -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. - -#pragma once - -#include -#include - -#include - -#include "frc/shuffleboard/ShuffleboardContainer.h" - -namespace frc { - -class ShuffleboardRoot; - -/** - * Represents a tab in the Shuffleboard dashboard. Widgets can be added to the - * tab with Add(Sendable), Add(std::string_view, Object), and - * Add(String, Sendable). Widgets can also be added to layouts with - * GetLayout(std::string_view, std::string_view); layouts can be nested - * arbitrarily deep (note that too many levels may make deeper components - * unusable). - */ -class ShuffleboardTab final : public ShuffleboardContainer { - public: - ShuffleboardTab(ShuffleboardRoot& root, std::string_view title); - - ShuffleboardRoot& GetRoot(); - - void BuildInto(std::shared_ptr parentTable, - std::shared_ptr metaTable) override; - - private: - ShuffleboardRoot& m_root; -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardValue.h b/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardValue.h deleted file mode 100644 index 4b7ccd46e76..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardValue.h +++ /dev/null @@ -1,67 +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. - -#pragma once - -#include -#include -#include - -#include - -namespace frc { - -class ShuffleboardValue { - public: - explicit ShuffleboardValue(std::string_view title) : m_title(title) {} - - virtual ~ShuffleboardValue() = default; - - ShuffleboardValue(const ShuffleboardValue&) = delete; - ShuffleboardValue& operator=(const ShuffleboardValue&) = delete; - - /** - * Gets the title of this Shuffleboard value. - */ - const std::string& GetTitle() const { return m_title; } - - /** - * Builds the entries for this value. - * - * @param parentTable The table containing all the data for the parent. Values - * that require a complex entry or table structure should - * call {@code parentTable.getSubtable(getTitle())} to get - * the table to put data into. Values that only use a - * single entry should call - * {@code parentTable.getEntry(getTitle())} to get that - * entry. - * @param metaTable The table containing all the metadata for this value and - * its sub-values - */ - virtual void BuildInto(std::shared_ptr parentTable, - std::shared_ptr metaTable) = 0; - - /** - * Enables user control of this widget in the Shuffleboard application. - * - * This method is package-private to prevent users from enabling control - * themselves. Has no effect if the sendable is not marked as an actuator with - * SendableBuilder::SetActuator(). - */ - virtual void EnableIfActuator() {} - - /** - * Disables user control of this widget in the Shuffleboard application. - * - * This method is package-private to prevent users from enabling control - * themselves. Has no effect if the sendable is not marked as an actuator with - * SendableBuilder::SetActuator(). - */ - virtual void DisableIfActuator() {} - - private: - std::string m_title; -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardWidget.h b/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardWidget.h deleted file mode 100644 index ce01367074a..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/ShuffleboardWidget.h +++ /dev/null @@ -1,74 +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. - -#pragma once - -#include - -#include "frc/shuffleboard/BuiltInWidgets.h" -#include "frc/shuffleboard/ShuffleboardComponent.h" -#include "frc/shuffleboard/WidgetType.h" - -namespace frc { - -class ShuffleboardContainer; - -namespace detail { -const char* GetStringForWidgetType(BuiltInWidgets type); -} // namespace detail - -/** - * Abstract superclass for widgets. - * - *

This class is package-private to minimize API surface area. - * - * @tparam Derived the self type - */ -template -class ShuffleboardWidget : public ShuffleboardComponent { - public: - ShuffleboardWidget(ShuffleboardContainer& parent, std::string_view title) - : ShuffleboardValue(title), - ShuffleboardComponent(parent, title) {} - - /** - * Sets the type of widget used to display the data. If not set, the default - * widget type will be used. - * - * @param widgetType the type of the widget used to display the data - * @return this widget object - * @see BuiltInWidgets - */ - Derived& WithWidget(BuiltInWidgets widgetType) { - return WithWidget(detail::GetStringForWidgetType(widgetType)); - } - - /** - * Sets the type of widget used to display the data. If not set, the default - * widget type will be used. - * - * @param widgetType the type of the widget used to display the data - * @return this widget object - */ - Derived& WithWidget(const WidgetType& widgetType) { - return WithWidget(widgetType.GetWidgetName()); - } - - /** - * Sets the type of widget used to display the data. If not set, the default - * widget type will be used. This method should only be used to use a widget - * that does not come built into Shuffleboard (i.e. one that comes with a - * custom or third-party plugin). To use a widget that is built into - * Shuffleboard, use WithWidget(WidgetType) and BuiltInWidgets. - * - * @param widgetType the type of the widget used to display the data - * @return this widget object - */ - Derived& WithWidget(std::string_view widgetType) { - this->SetType(widgetType); - return *static_cast(this); - } -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/SimpleWidget.h b/wpilibc/src/main/native/include/frc/shuffleboard/SimpleWidget.h deleted file mode 100644 index 97502be5ad9..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/SimpleWidget.h +++ /dev/null @@ -1,54 +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. - -#pragma once - -#include -#include -#include - -#include -#include - -#include "frc/shuffleboard/ShuffleboardWidget.h" - -namespace frc { - -class ShuffleboardContainer; - -/** - * A Shuffleboard widget that handles a single data point such as a number or - * string. - */ -class SimpleWidget final : public ShuffleboardWidget { - public: - SimpleWidget(ShuffleboardContainer& parent, std::string_view title); - - /** - * Gets the NetworkTable entry that contains the data for this widget. - * The widget owns the entry; the returned pointer's lifetime is the same as - * that of the widget. - */ - nt::GenericEntry* GetEntry(); - - /** - * Gets the NetworkTable entry that contains the data for this widget. - * The widget owns the entry; the returned pointer's lifetime is the same as - * that of the widget. - * - * @param typeString NT type string - */ - nt::GenericEntry* GetEntry(std::string_view typeString); - - void BuildInto(std::shared_ptr parentTable, - std::shared_ptr metaTable) override; - - private: - nt::GenericEntry m_entry; - std::string m_typeString; - - void ForceGenerate(); -}; - -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/SuppliedValueWidget.h b/wpilibc/src/main/native/include/frc/shuffleboard/SuppliedValueWidget.h deleted file mode 100644 index c044f25d351..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/SuppliedValueWidget.h +++ /dev/null @@ -1,58 +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. - -#pragma once - -#include -#include -#include -#include - -#include -#include -#include - -#include "frc/shuffleboard/ShuffleboardComponent.h" -#include "frc/shuffleboard/ShuffleboardComponentBase.h" -#include "frc/shuffleboard/ShuffleboardWidget.h" - -namespace frc { -class ShuffleboardContainer; - -template -class SuppliedValueWidget : public ShuffleboardWidget> { - public: - SuppliedValueWidget(ShuffleboardContainer& parent, std::string_view title, - std::string_view typeString, std::function supplier, - std::function setter) - : ShuffleboardValue(title), - ShuffleboardWidget>(parent, title), - m_typeString(typeString), - m_supplier(supplier), - m_setter(setter) {} - - void BuildInto(std::shared_ptr parentTable, - std::shared_ptr metaTable) override { - this->BuildMetadata(metaTable); - if (!m_controllablePub) { - m_controllablePub = - nt::BooleanTopic{metaTable->GetTopic("Controllable")}.Publish(); - m_controllablePub.Set(false); - } - - if (!m_entry) { - m_entry = - parentTable->GetTopic(this->GetTitle()).GenericPublish(m_typeString); - } - m_setter(m_entry, m_supplier()); - } - - private: - std::string m_typeString; - std::function m_supplier; - std::function m_setter; - nt::BooleanPublisher m_controllablePub; - nt::GenericPublisher m_entry; -}; -} // namespace frc diff --git a/wpilibc/src/main/native/include/frc/shuffleboard/WidgetType.h b/wpilibc/src/main/native/include/frc/shuffleboard/WidgetType.h deleted file mode 100644 index 13805bb85ec..00000000000 --- a/wpilibc/src/main/native/include/frc/shuffleboard/WidgetType.h +++ /dev/null @@ -1,34 +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. - -#pragma once - -#include - -namespace frc { - -/** - * Represents the type of a widget in Shuffleboard. Using this is preferred over - * specifying raw strings, to avoid typos and having to know or look up the - * exact string name for a desired widget. - * - * @see BuiltInWidgets the built-in widget types - */ -class WidgetType { - public: - explicit constexpr WidgetType(const char* widgetName) - : m_widgetName(widgetName) {} - ~WidgetType() = default; - - /** - * Gets the string type of the widget as defined by that widget in - * Shuffleboard. - */ - std::string_view GetWidgetName() const; - - private: - const char* m_widgetName; -}; - -} // namespace frc diff --git a/wpilibc/src/test/native/cpp/shuffleboard/MockActuatorSendable.cpp b/wpilibc/src/test/native/cpp/shuffleboard/MockActuatorSendable.cpp deleted file mode 100644 index 5a9f9938b1c..00000000000 --- a/wpilibc/src/test/native/cpp/shuffleboard/MockActuatorSendable.cpp +++ /dev/null @@ -1,16 +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 "shuffleboard/MockActuatorSendable.h" - -#include -#include - -MockActuatorSendable::MockActuatorSendable(std::string_view name) { - wpi::SendableRegistry::Add(this, name); -} - -void MockActuatorSendable::InitSendable(wpi::SendableBuilder& builder) { - builder.SetActuator(true); -} diff --git a/wpilibc/src/test/native/cpp/shuffleboard/ShuffleboardInstanceTest.cpp b/wpilibc/src/test/native/cpp/shuffleboard/ShuffleboardInstanceTest.cpp deleted file mode 100644 index 6354713d5d4..00000000000 --- a/wpilibc/src/test/native/cpp/shuffleboard/ShuffleboardInstanceTest.cpp +++ /dev/null @@ -1,130 +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" // NOLINT(build/include_order) - -#include - -#include -#include -#include -#include - -#include "shuffleboard/MockActuatorSendable.h" - -class NTWrapper { - public: - NTWrapper() { inst = nt::NetworkTableInstance::Create(); } - - ~NTWrapper() { nt::NetworkTableInstance::Destroy(inst); } - - nt::NetworkTableInstance inst; -}; - -TEST(ShuffleboardInstanceTest, PathFluent) { - NTWrapper ntInst; - frc::detail::ShuffleboardInstance shuffleboardInst{ntInst.inst}; - - auto entry = shuffleboardInst.GetTab("Tab Title") - .GetLayout("List", "List Layout") - .Add("Data", "string") - .WithWidget("Text View") - .GetEntry(); - - EXPECT_EQ("string", entry->GetString("")) << "Wrong entry value"; - EXPECT_EQ("/Shuffleboard/Tab Title/List/Data", entry->GetTopic().GetName()) - << "Entry path generated incorrectly"; -} - -TEST(ShuffleboardInstanceTest, NestedLayoutsFluent) { - NTWrapper ntInst; - frc::detail::ShuffleboardInstance shuffleboardInst{ntInst.inst}; - - auto entry = shuffleboardInst.GetTab("Tab") - .GetLayout("First", "List") - .GetLayout("Second", "List") - .GetLayout("Third", "List") - .GetLayout("Fourth", "List") - .Add("Value", "string") - .GetEntry(); - - EXPECT_EQ("string", entry->GetString("")) << "Wrong entry value"; - EXPECT_EQ("/Shuffleboard/Tab/First/Second/Third/Fourth/Value", - entry->GetTopic().GetName()) - << "Entry path generated incorrectly"; -} - -TEST(ShuffleboardInstanceTest, NestedLayoutsOop) { - NTWrapper ntInst; - frc::detail::ShuffleboardInstance shuffleboardInst{ntInst.inst}; - - frc::ShuffleboardTab& tab = shuffleboardInst.GetTab("Tab"); - frc::ShuffleboardLayout& first = tab.GetLayout("First", "List"); - frc::ShuffleboardLayout& second = first.GetLayout("Second", "List"); - frc::ShuffleboardLayout& third = second.GetLayout("Third", "List"); - frc::ShuffleboardLayout& fourth = third.GetLayout("Fourth", "List"); - frc::SimpleWidget& widget = fourth.Add("Value", "string"); - auto entry = widget.GetEntry(); - - EXPECT_EQ("string", entry->GetString("")) << "Wrong entry value"; - EXPECT_EQ("/Shuffleboard/Tab/First/Second/Third/Fourth/Value", - entry->GetTopic().GetName()) - << "Entry path generated incorrectly"; -} - -TEST(ShuffleboardInstanceTest, LayoutTypeIsSet) { - NTWrapper ntInst; - frc::detail::ShuffleboardInstance shuffleboardInst{ntInst.inst}; - - std::string_view layoutType = "Type"; - shuffleboardInst.GetTab("Tab").GetLayout("Title", layoutType); - shuffleboardInst.Update(); - auto entry = ntInst.inst.GetEntry( - "/Shuffleboard/.metadata/Tab/Title/PreferredComponent"); - EXPECT_EQ(layoutType, entry.GetString("Not Set")) << "Layout type not set"; -} - -TEST(ShuffleboardInstanceTest, NestedActuatorWidgetsAreDisabled) { - NTWrapper ntInst; - frc::detail::ShuffleboardInstance shuffleboardInst{ntInst.inst}; - - MockActuatorSendable sendable("Actuator"); - shuffleboardInst.GetTab("Tab").GetLayout("Title", "Layout").Add(sendable); - auto controllableEntry = - ntInst.inst.GetEntry("/Shuffleboard/Tab/Title/Actuator/.controllable"); - shuffleboardInst.Update(); - - // Note: we use the unsafe `GetBoolean()` method because if the value is NOT - // a boolean, or if it is not present, then something has clearly gone very, - // very wrong - bool controllable = controllableEntry.GetValue().GetBoolean(); - // Sanity check - EXPECT_TRUE(controllable) - << "The nested actuator widget should be enabled by default"; - shuffleboardInst.DisableActuatorWidgets(); - controllable = controllableEntry.GetValue().GetBoolean(); - EXPECT_FALSE(controllable) - << "The nested actuator widget should have been disabled"; -} - -TEST(ShuffleboardInstanceTest, DuplicateSelectTabs) { - NTWrapper ntInst; - frc::detail::ShuffleboardInstance shuffleboardInst{ntInst.inst}; - std::atomic_int counter = 0; - auto subscriber = - ntInst.inst.GetStringTopic("/Shuffleboard/.metadata/Selected") - .Subscribe("", {.keepDuplicates = true}); - ntInst.inst.AddListener( - subscriber, nt::EventFlags::kValueAll | nt::EventFlags::kImmediate, - [&counter](auto& event) { counter++; }); - - // There shouldn't be anything there - EXPECT_EQ(0, counter); - - shuffleboardInst.SelectTab("tab1"); - shuffleboardInst.SelectTab("tab1"); - EXPECT_TRUE(ntInst.inst.WaitForListenerQueue(1.0)) - << "Listener queue timed out!"; - EXPECT_EQ(2, counter); -} diff --git a/wpilibc/src/test/native/cpp/shuffleboard/ShuffleboardTest.cpp b/wpilibc/src/test/native/cpp/shuffleboard/ShuffleboardTest.cpp deleted file mode 100644 index db689db4cea..00000000000 --- a/wpilibc/src/test/native/cpp/shuffleboard/ShuffleboardTest.cpp +++ /dev/null @@ -1,13 +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 - -#include "frc/shuffleboard/Shuffleboard.h" - -TEST(ShuffleboardTest, TabObjectsCached) { - auto& tab1 = frc::Shuffleboard::GetTab("testTabObjectsCached"); - auto& tab2 = frc::Shuffleboard::GetTab("testTabObjectsCached"); - EXPECT_EQ(&tab1, &tab2) << "Tab objects were not cached"; -} diff --git a/wpilibc/src/test/native/cpp/shuffleboard/SuppliedValueWidgetTest.cpp b/wpilibc/src/test/native/cpp/shuffleboard/SuppliedValueWidgetTest.cpp deleted file mode 100644 index 91c68db79aa..00000000000 --- a/wpilibc/src/test/native/cpp/shuffleboard/SuppliedValueWidgetTest.cpp +++ /dev/null @@ -1,110 +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 -#include - -#include -#include -#include - -#include "frc/shuffleboard/ShuffleboardInstance.h" -#include "frc/shuffleboard/ShuffleboardTab.h" - -using namespace frc; - -class NTWrapper { - public: - NTWrapper() { inst = nt::NetworkTableInstance::Create(); } - - ~NTWrapper() { nt::NetworkTableInstance::Destroy(inst); } - - nt::NetworkTableInstance inst; -}; - -class SuppliedValueWidgetTest : public testing::Test { - protected: - NTWrapper m_ntInst; - frc::detail::ShuffleboardInstance m_shuffleboardInst{m_ntInst.inst}; - frc::ShuffleboardTab* m_tab = &(m_shuffleboardInst.GetTab("Tab")); -}; - -TEST_F(SuppliedValueWidgetTest, AddString) { - std::string str = "foo"; - m_tab->AddString("String", [&str]() { return str; }); - auto entry = m_ntInst.inst.GetEntry("/Shuffleboard/Tab/String"); - - m_shuffleboardInst.Update(); - EXPECT_EQ("foo", entry.GetValue().GetString()); -} - -TEST_F(SuppliedValueWidgetTest, AddNumber) { - int num = 0; - m_tab->AddNumber("Num", [&num]() { return ++num; }); - auto entry = m_ntInst.inst.GetEntry("/Shuffleboard/Tab/Num"); - - m_shuffleboardInst.Update(); - EXPECT_FLOAT_EQ(1.0, entry.GetValue().GetDouble()); -} - -TEST_F(SuppliedValueWidgetTest, AddBoolean) { - bool value = true; - m_tab->AddBoolean("Bool", [&value]() { return value; }); - auto entry = m_ntInst.inst.GetEntry("/Shuffleboard/Tab/Bool"); - - m_shuffleboardInst.Update(); - EXPECT_EQ(true, entry.GetValue().GetBoolean()); -} - -TEST_F(SuppliedValueWidgetTest, AddStringArray) { - std::vector strings = {"foo", "bar"}; - m_tab->AddStringArray("Strings", [&strings]() { return strings; }); - auto entry = m_ntInst.inst.GetEntry("/Shuffleboard/Tab/Strings"); - - m_shuffleboardInst.Update(); - auto actual = entry.GetValue().GetStringArray(); - - EXPECT_EQ(strings.size(), actual.size()); - for (size_t i = 0; i < strings.size(); i++) { - EXPECT_EQ(strings[i], actual[i]); - } -} - -TEST_F(SuppliedValueWidgetTest, AddNumberArray) { - std::vector nums = {0, 1, 2, 3}; - m_tab->AddNumberArray("Numbers", [&nums]() { return nums; }); - auto entry = m_ntInst.inst.GetEntry("/Shuffleboard/Tab/Numbers"); - - m_shuffleboardInst.Update(); - auto actual = entry.GetValue().GetDoubleArray(); - - EXPECT_EQ(nums.size(), actual.size()); - for (size_t i = 0; i < nums.size(); i++) { - EXPECT_FLOAT_EQ(nums[i], actual[i]); - } -} - -TEST_F(SuppliedValueWidgetTest, AddBooleanArray) { - std::vector bools = {true, false}; - m_tab->AddBooleanArray("Booleans", [&bools]() { return bools; }); - auto entry = m_ntInst.inst.GetEntry("/Shuffleboard/Tab/Booleans"); - - m_shuffleboardInst.Update(); - auto actual = entry.GetValue().GetBooleanArray(); - - EXPECT_EQ(bools.size(), actual.size()); - for (size_t i = 0; i < bools.size(); i++) { - EXPECT_FLOAT_EQ(bools[i], actual[i]); - } -} - -TEST_F(SuppliedValueWidgetTest, AddRaw) { - std::vector bytes = {1, 2, 3}; - m_tab->AddRaw("Raw", [&bytes]() { return bytes; }); - auto entry = m_ntInst.inst.GetEntry("/Shuffleboard/Tab/Raw"); - - m_shuffleboardInst.Update(); - auto actual = entry.GetValue().GetRaw(); - EXPECT_EQ(bytes, std::vector(actual.begin(), actual.end())); -} diff --git a/wpilibc/src/test/native/include/shuffleboard/MockActuatorSendable.h b/wpilibc/src/test/native/include/shuffleboard/MockActuatorSendable.h deleted file mode 100644 index 8baf2a2db4c..00000000000 --- a/wpilibc/src/test/native/include/shuffleboard/MockActuatorSendable.h +++ /dev/null @@ -1,19 +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. - -#pragma once - -#include - -#include - -/** - * A mock sendable that marks itself as an actuator. - */ -class MockActuatorSendable : public wpi::Sendable { - public: - explicit MockActuatorSendable(std::string_view name); - - void InitSendable(wpi::SendableBuilder& builder) override; -}; diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/RobotContainer.cpp index 76714d86813..04342cd9b6e 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotInlined/cpp/RobotContainer.cpp @@ -4,7 +4,7 @@ #include "RobotContainer.h" -#include +#include RobotContainer::RobotContainer() { // Initialize all of your commands and subsystems here @@ -15,36 +15,10 @@ RobotContainer::RobotContainer() { m_chooser.AddOption("Complex Auto", m_complexAuto.get()); // Put the chooser on the dashboard - frc::Shuffleboard::GetTab("Autonomous").Add(m_chooser); + frc::SmartDashboard::PutData("Autonomous", &m_chooser); // Put subsystems to dashboard. - frc::Shuffleboard::GetTab("Drivetrain").Add(m_drive); - frc::Shuffleboard::GetTab("HatchSubsystem").Add(m_hatch); - - // Log Shuffleboard events for command initialize, execute, finish, interrupt - frc2::CommandScheduler::GetInstance().OnCommandInitialize( - [](const frc2::Command& command) { - frc::Shuffleboard::AddEventMarker( - "Command initialized", command.GetName(), - frc::ShuffleboardEventImportance::kNormal); - }); - frc2::CommandScheduler::GetInstance().OnCommandExecute( - [](const frc2::Command& command) { - frc::Shuffleboard::AddEventMarker( - "Command executed", command.GetName(), - frc::ShuffleboardEventImportance::kNormal); - }); - frc2::CommandScheduler::GetInstance().OnCommandFinish( - [](const frc2::Command& command) { - frc::Shuffleboard::AddEventMarker( - "Command finished", command.GetName(), - frc::ShuffleboardEventImportance::kNormal); - }); - frc2::CommandScheduler::GetInstance().OnCommandInterrupt( - [](const frc2::Command& command) { - frc::Shuffleboard::AddEventMarker( - "Command interrupted", command.GetName(), - frc::ShuffleboardEventImportance::kNormal); - }); + frc::SmartDashboard::PutData("Drivetrain", &m_drive); + frc::SmartDashboard::PutData("HatchSubsystem", &m_hatch); // Configure the button bindings ConfigureButtonBindings(); diff --git a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp index faf9d1f02e8..f87ab6d75b9 100644 --- a/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/HatchbotTraditional/cpp/RobotContainer.cpp @@ -4,7 +4,7 @@ #include "RobotContainer.h" -#include +#include #include #include "commands/DefaultDrive.h" @@ -20,36 +20,10 @@ RobotContainer::RobotContainer() { m_chooser.AddOption("Complex Auto", &m_complexAuto); // Put the chooser on the dashboard - frc::Shuffleboard::GetTab("Autonomous").Add(m_chooser); + frc::SmartDashboard::PutData("Autonomous", &m_chooser); // Put subsystems to dashboard. - frc::Shuffleboard::GetTab("Drivetrain").Add(m_drive); - frc::Shuffleboard::GetTab("HatchSubsystem").Add(m_hatch); - - // Log Shuffleboard events for command initialize, execute, finish, interrupt - frc2::CommandScheduler::GetInstance().OnCommandInitialize( - [](const frc2::Command& command) { - frc::Shuffleboard::AddEventMarker( - "Command initialized", command.GetName(), - frc::ShuffleboardEventImportance::kNormal); - }); - frc2::CommandScheduler::GetInstance().OnCommandExecute( - [](const frc2::Command& command) { - frc::Shuffleboard::AddEventMarker( - "Command executed", command.GetName(), - frc::ShuffleboardEventImportance::kNormal); - }); - frc2::CommandScheduler::GetInstance().OnCommandFinish( - [](const frc2::Command& command) { - frc::Shuffleboard::AddEventMarker( - "Command finished", command.GetName(), - frc::ShuffleboardEventImportance::kNormal); - }); - frc2::CommandScheduler::GetInstance().OnCommandInterrupt( - [](const frc2::Command& command) { - frc::Shuffleboard::AddEventMarker( - "Command interrupted", command.GetName(), - frc::ShuffleboardEventImportance::kNormal); - }); + frc::SmartDashboard::PutData("Drivetrain", &m_drive); + frc::SmartDashboard::PutData("HatchSubsystem", &m_hatch); // Configure the button bindings ConfigureButtonBindings(); diff --git a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp index 0d3db36cb04..427da554018 100644 --- a/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/MecanumControllerCommand/cpp/RobotContainer.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/ShuffleBoard/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/ShuffleBoard/cpp/Robot.cpp deleted file mode 100644 index 61c5dd44964..00000000000 --- a/wpilibcExamples/src/main/cpp/examples/ShuffleBoard/cpp/Robot.cpp +++ /dev/null @@ -1,88 +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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/** - * This sample program provides an example for ShuffleBoard, an alternative - * to SmartDashboard for displaying values and properties of different robot - * parts. - * - * ShuffleBoard can use pre-programmed widgets to display various values, such - * as Boolean Boxes, Sliders, Graphs, and more. In addition, they can display - * things in various Tabs. - * - * For more information on how to create personal layouts and more in - * ShuffleBoard, feel free to reference the official FIRST WPILib documentation - * online. - */ -class Robot : public frc::TimedRobot { - public: - Robot() { - wpi::SendableRegistry::AddChild(&m_robotDrive, &m_left); - wpi::SendableRegistry::AddChild(&m_robotDrive, &m_right); - - // Add a widget titled 'Max Speed' with a number slider. - m_maxSpeed = frc::Shuffleboard::GetTab("Configuration") - .Add("Max Speed", 1) - .WithWidget("Number Slider") - .GetEntry(); - - // Create a 'DriveBase' tab and add the drivetrain object to it. - frc::ShuffleboardTab& driveBaseTab = frc::Shuffleboard::GetTab("DriveBase"); - driveBaseTab.Add("TankDrive", m_robotDrive); - - // Put encoders in a list layout. - frc::ShuffleboardLayout& encoders = - driveBaseTab.GetLayout("Encoders", frc::BuiltInLayouts::kList) - .WithPosition(0, 0) - .WithSize(2, 2); - encoders.Add("Left Encoder", m_leftEncoder); - encoders.Add("Right Encoder", m_rightEncoder); - - // Create a 'Elevator' tab and add the potentiometer and elevator motor to - // it. - frc::ShuffleboardTab& elevatorTab = frc::Shuffleboard::GetTab("Elevator"); - elevatorTab.Add("Motor", m_elevatorMotor); - elevatorTab.Add("Potentiometer", m_ElevatorPot); - } - - void AutonomousInit() override { - // Update the Max Output for the drivetrain. - m_robotDrive.SetMaxOutput(m_maxSpeed->GetDouble(1.0)); - } - - private: - frc::PWMSparkMax m_left{0}; - frc::PWMSparkMax m_right{1}; - frc::PWMSparkMax m_elevatorMotor{2}; - - frc::DifferentialDrive m_robotDrive{ - [&](double output) { m_left.Set(output); }, - [&](double output) { m_right.Set(output); }}; - - frc::Joystick m_stick{0}; - - frc::Encoder m_leftEncoder{0, 1}; - frc::Encoder m_rightEncoder{2, 3}; - frc::AnalogPotentiometer m_ElevatorPot{0}; - - nt::GenericEntry* m_maxSpeed; -}; - -#ifndef RUNNING_FRC_TESTS -int main() { - return frc::StartRobot(); -} -#endif diff --git a/wpilibcExamples/src/main/cpp/examples/Solenoid/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Solenoid/cpp/Robot.cpp index 25311e82d68..e4b51c9e3a7 100644 --- a/wpilibcExamples/src/main/cpp/examples/Solenoid/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/Solenoid/cpp/Robot.cpp @@ -4,41 +4,35 @@ #include "Robot.h" -#include +#include #include Robot::Robot() { // Publish elements to shuffleboard. - frc::ShuffleboardTab& tab = frc::Shuffleboard::GetTab("Pneumatics"); - tab.Add("Single Solenoid", m_solenoid); - tab.Add("Double Solenoid", m_doubleSolenoid); - tab.Add("Compressor", m_compressor); - - // Also publish some raw data - tab.AddDouble("PH Pressure [PSI]", [&] { - // Get the pressure (in PSI) from the analog sensor connected to the PH. - // This function is supported only on the PH! - // On a PCM, this function will return 0. - units::pounds_per_square_inch_t pressure = m_compressor.GetPressure(); - return pressure.value(); - }); - tab.AddDouble("Compressor Current", [&] { - // Get compressor current draw. - units::ampere_t compressorCurrent = m_compressor.GetCurrent(); - return compressorCurrent.value(); - }); - tab.AddBoolean("Compressor Active", [&] { - // Get whether the compressor is active. - return m_compressor.IsEnabled(); - }); - tab.AddBoolean("Pressure Switch", [&] { - // Get the digital pressure switch connected to the PCM/PH. - // The switch is open when the pressure is over ~120 PSI. - return m_compressor.GetPressureSwitchValue(); - }); + frc::SmartDashboard::PutData("Single Solenoid", &m_solenoid); + frc::SmartDashboard::PutData("Double Solenoid", &m_doubleSolenoid); + frc::SmartDashboard::PutData("Compressor", &m_compressor); } void Robot::TeleopPeriodic() { + // Publish some raw data + + // Get the pressure (in PSI) from the analog sensor connected to the PH. + // This function is supported only on the PH! + // On a PCM, this function will return 0. + frc::SmartDashboard::PutNumber("PH Pressure [PSI]", + m_compressor.GetPressure().value()); + // Get compressor current draw. + frc::SmartDashboard::PutNumber("Compressor Current", + m_compressor.GetCurrent().value()); + // Get whether the compressor is active. + frc::SmartDashboard::PutBoolean("Compressor Active", + m_compressor.IsEnabled()); + // Get the digital pressure switch connected to the PCM/PH. + // The switch is open when the pressure is over ~120 PSI. + frc::SmartDashboard::PutBoolean("Pressure Switch", + m_compressor.GetPressureSwitchValue()); + /* * The output of GetRawButton is true/false depending on whether * the button is pressed; Set takes a boolean for whether diff --git a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp index 6c8de057532..8cdada50d5b 100644 --- a/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand/cpp/RobotContainer.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include #include diff --git a/wpilibcExamples/src/main/cpp/examples/Ultrasonic/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/Ultrasonic/cpp/Robot.cpp index 67c5b719b01..fda7fcd00d6 100644 --- a/wpilibcExamples/src/main/cpp/examples/Ultrasonic/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/Ultrasonic/cpp/Robot.cpp @@ -4,14 +4,13 @@ #include "Robot.h" -#include #include #include Robot::Robot() { // Add the ultrasonic on the "Sensors" tab of the dashboard // Data will update automatically - frc::Shuffleboard::GetTab("Sensors").Add(m_rangeFinder); + frc::SmartDashboard::PutData("Sensors", &m_rangeFinder); } void Robot::TeleopPeriodic() { diff --git a/wpilibcExamples/src/main/cpp/examples/examples.json b/wpilibcExamples/src/main/cpp/examples/examples.json index c20ec3d1a45..d4a93ca9dcf 100644 --- a/wpilibcExamples/src/main/cpp/examples/examples.json +++ b/wpilibcExamples/src/main/cpp/examples/examples.json @@ -46,7 +46,6 @@ "tags": [ "Hardware", "Joystick", - "Shuffleboard", "Pneumatics" ], "foldername": "Solenoid", @@ -119,8 +118,7 @@ "tags": [ "Hardware", "Ultrasonic", - "SmartDashboard", - "Shuffleboard" + "SmartDashboard" ], "foldername": "Ultrasonic", "gradlebase": "cpp", @@ -318,21 +316,6 @@ "gradlebase": "c", "commandversion": 2 }, - { - "name": "Shuffleboard", - "description": "Present various data via the Shuffleboard API.", - "tags": [ - "Basic Robot", - "Differential Drive", - "Elevator", - "Analog", - "Encoder", - "Shuffleboard" - ], - "foldername": "ShuffleBoard", - "gradlebase": "cpp", - "commandversion": 2 - }, { "name": "'Traditional' Hatchbot", "description": "A fully-functional command-based hatchbot for the 2019 game, written in the 'traditional' style, i.e. commands are given their own classes.", @@ -341,7 +324,6 @@ "Command-based", "Differential Drive", "Encoder", - "Shuffleboard", "Sendable", "DataLog", "Pneumatics", @@ -359,7 +341,6 @@ "Command-based", "Differential Drive", "Encoder", - "Shuffleboard", "Sendable", "DataLog", "Pneumatics", diff --git a/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp index 850e2e41800..50dbd4eeeb7 100644 --- a/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/templates/robotbaseskeleton/cpp/Robot.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include @@ -47,7 +46,6 @@ void Robot::StartCompetition() { } } else if (IsTest()) { frc::LiveWindow::SetEnabled(true); - frc::Shuffleboard::EnableActuatorWidgets(); modeThread.InTest(true); Test(); modeThread.InTest(false); @@ -55,7 +53,6 @@ void Robot::StartCompetition() { wpi::WaitForObject(event.GetHandle()); } frc::LiveWindow::SetEnabled(false); - frc::Shuffleboard::DisableActuatorWidgets(); } else { modeThread.InTeleop(true); Teleop(); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobotBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobotBase.java index b0c46604283..ed4d9de959f 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobotBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/IterativeRobotBase.java @@ -10,7 +10,6 @@ import edu.wpi.first.hal.HAL; import edu.wpi.first.networktables.NetworkTableInstance; import edu.wpi.first.wpilibj.livewindow.LiveWindow; -import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import java.util.ConcurrentModificationException; @@ -331,7 +330,6 @@ protected void loopFunc() { case kTest -> { if (m_lwEnabledInTest) { LiveWindow.setEnabled(false); - Shuffleboard.disableActuatorWidgets(); } testExit(); } @@ -357,7 +355,6 @@ protected void loopFunc() { case kTest -> { if (m_lwEnabledInTest) { LiveWindow.setEnabled(true); - Shuffleboard.enableActuatorWidgets(); } testInit(); m_watchdog.addEpoch("testInit()"); @@ -404,8 +401,6 @@ protected void loopFunc() { m_watchdog.addEpoch("SmartDashboard.updateValues()"); LiveWindow.updateValues(); m_watchdog.addEpoch("LiveWindow.updateValues()"); - Shuffleboard.update(); - m_watchdog.addEpoch("Shuffleboard.update()"); if (isSimulation()) { HAL.simPeriodicBefore(); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java index e595a5899e6..775562e293c 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java @@ -18,7 +18,6 @@ import edu.wpi.first.networktables.NetworkTableInstance; import edu.wpi.first.util.WPIUtilJNI; import edu.wpi.first.wpilibj.livewindow.LiveWindow; -import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; import edu.wpi.first.wpilibj.util.WPILibVersion; import java.io.File; import java.io.IOException; @@ -227,7 +226,6 @@ protected RobotBase() { }); LiveWindow.setEnabled(false); - Shuffleboard.disableActuatorWidgets(); } /** diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/BuiltInLayouts.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/BuiltInLayouts.java deleted file mode 100644 index fb642ae6ab7..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/BuiltInLayouts.java +++ /dev/null @@ -1,61 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -/** - * The types of layouts bundled with Shuffleboard. - * - *

{@code
- * ShuffleboardLayout myList = Shuffleboard.getTab("My Tab")
- *   .getLayout(BuiltinLayouts.kList, "My List");
- * }
- */ -public enum BuiltInLayouts implements LayoutType { - /** - * Groups components in a vertical list. New widgets added to the layout will be placed at the - * bottom of the list.
- * Custom properties: - * - * - * - * - * - *
NameTypeDefault ValueNotes
Label positionString"BOTTOM"The position of component labels inside the grid. One of - * {@code ["TOP", "LEFT", "BOTTOM", "RIGHT", "HIDDEN"}
- */ - kList("List Layout"), - - /** - * Groups components in an n x m grid. Grid layouts default to 3x3.
- * Custom properties: - * - * - * - * - * - * - * - * - * - * - * - * - *
NameTypeDefault ValueNotes
Number of columnsNumber3Must be in the range [1,15]
Number of rowsNumber3Must be in the range [1,15]
Label positionString"BOTTOM"The position of component labels inside the grid. - * One of {@code ["TOP", "LEFT", "BOTTOM", "RIGHT", "HIDDEN"}
- */ - kGrid("Grid Layout"), - ; - - private final String m_layoutName; - - BuiltInLayouts(String layoutName) { - m_layoutName = layoutName; - } - - @Override - public String getLayoutName() { - return m_layoutName; - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/BuiltInWidgets.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/BuiltInWidgets.java deleted file mode 100644 index 47c6cf821f9..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/BuiltInWidgets.java +++ /dev/null @@ -1,476 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -/** - * The types of the widgets bundled with Shuffleboard. - * - *

For example, setting a number to be displayed with a slider: - * - *

{@code
- * GenericEntry example = Shuffleboard.getTab("My Tab")
- *   .add("My Number", 0)
- *   .withWidget(BuiltInWidgets.kNumberSlider)
- *   .withProperties(Map.of("min", 0, "max", 1))
- *   .getEntry();
- * }
- * - *

Each value in this enum goes into detail on what data types that widget can support, as well - * as the custom properties that widget uses. - */ -public enum BuiltInWidgets implements WidgetType { - /** - * Displays a value with a simple text field.
- * Supported types: - * - *

    - *
  • String - *
  • Number - *
  • Boolean - *
- * - *
- * This widget has no custom properties. - */ - kTextView("Text View"), - /** - * Displays a number with a controllable slider.
- * Supported types: - * - *
    - *
  • Number - *
- * - *
- * Custom properties: - * - * - * - * - * - * - * - *
NameTypeDefault ValueNotes
MinNumber-1.0The minimum value of the slider
MaxNumber1.0The maximum value of the slider
Block incrementNumber0.0625How much to move the slider by with the arrow keys
- */ - kNumberSlider("Number Slider"), - /** - * Displays a number with a view-only bar.
- * Supported types: - * - *
    - *
  • Number - *
- * - *
- * Custom properties: - * - * - * - * - * - * - *
NameTypeDefault ValueNotes
MinNumber-1.0The minimum value of the bar
MaxNumber1.0The maximum value of the bar
CenterNumber0The center ("zero") value of the bar
- */ - kNumberBar("Number Bar"), - /** - * Displays a number with a view-only dial. Displayed values are rounded to the nearest integer. - *
- * Supported types: - * - *
    - *
  • Number - *
- * - *
- * Custom properties: - * - * - * - * - * - * - * - *
NameTypeDefault ValueNotes
MinNumber0The minimum value of the dial
MaxNumber100The maximum value of the dial
Show valueBooleantrueWhether or not to show the value as text
- */ - kDial("Simple Dial"), - /** - * Displays a number with a graph. NOTE: graphs can be taxing on the computer - * running the dashboard. Keep the number of visible data points to a minimum. Making the widget - * smaller also helps with performance, but may cause the graph to become difficult to read.
- * Supported types: - * - *
    - *
  • Number - *
  • Number array - *
- * - *
- * Custom properties: - * - * - * - * - * - *
NameTypeDefault ValueNotes
Visible timeNumber30How long, in seconds, should past data be visible for
- */ - kGraph("Graph"), - /** - * Displays a boolean value as a large colored box.
- * Supported types: - * - *
    - *
  • Boolean - *
- * - *
- * Custom properties: - * - * - * - * - * - * - * - *
NameTypeDefault ValueNotes
Color when trueColor"green"Can be specified as a string ({@code "#00FF00"}) or a rgba integer ({@code 0x00FF0000}) - *
Color when falseColor"red"Can be specified as a string or a number
- */ - kBooleanBox("Boolean Box"), - /** - * Displays a boolean with a large interactive toggle button.
- * Supported types: - * - *
    - *
  • Boolean - *
- * - *
- * This widget has no custom properties. - */ - kToggleButton("Toggle Button"), - /** - * Displays a boolean with a fixed-size toggle switch.
- * Supported types: - * - *
    - *
  • Boolean - *
- * - *
- * This widget has no custom properties. - */ - kToggleSwitch("Toggle Switch"), - /** - * Displays an analog input or a raw number with a number bar.
- * Supported types: - * - *
    - *
  • Number - *
  • {@link edu.wpi.first.wpilibj.AnalogInput} - *
- * - *
- * Custom properties: - * - * - * - * - * - * - * - * - * - * - *
NameTypeDefault ValueNotes
MinNumber0The minimum value of the bar
MaxNumber5The maximum value of the bar
CenterNumber0The center ("zero") value of the bar
OrientationString"HORIZONTAL"The orientation of the bar. One of {@code ["HORIZONTAL", "VERTICAL"]}
Number of tick marksNumber5The number of discrete ticks on the bar
- */ - kVoltageView("Voltage View"), - /** - * Displays a {@link edu.wpi.first.wpilibj.PowerDistribution PowerDistribution}.
- * Supported types: - * - *
    - *
  • {@link edu.wpi.first.wpilibj.PowerDistribution} - *
- * - *
- * Custom properties: - * - * - * - * - * - *
NameTypeDefault ValueNotes
Show voltage and current valuesBooleantrueWhether or not to display the voltage and current draw
- */ - kPowerDistribution("PDP"), - /** - * Displays a {@link edu.wpi.first.wpilibj.smartdashboard.SendableChooser SendableChooser} with a - * dropdown combo box with a list of options.
- * Supported types: - * - *
    - *
  • {@link edu.wpi.first.wpilibj.smartdashboard.SendableChooser} - *
- * - *
- * This widget has no custom properties. - */ - kComboBoxChooser("ComboBox Chooser"), - /** - * Displays a {@link edu.wpi.first.wpilibj.smartdashboard.SendableChooser SendableChooser} with a - * toggle button for each available option.
- * Supported types: - * - *
    - *
  • {@link edu.wpi.first.wpilibj.smartdashboard.SendableChooser} - *
- * - *
- * This widget has no custom properties. - */ - kSplitButtonChooser("Split Button Chooser"), - /** - * Displays an {@link edu.wpi.first.wpilibj.Encoder} displaying its speed, total traveled - * distance, and its distance per tick.
- * Supported types: - * - *
    - *
  • {@link edu.wpi.first.wpilibj.Encoder} - *
- * - *
- * This widget has no custom properties. - */ - kEncoder("Encoder"), - /** - * Displays a {@link edu.wpi.first.wpilibj.motorcontrol.MotorController MotorController}. The - * motor controller will be controllable from the dashboard when test mode is enabled, but will - * otherwise be view-only.
- * Supported types: - * - *
    - *
  • {@link edu.wpi.first.wpilibj.motorcontrol.PWMMotorController} - *
  • {@link edu.wpi.first.wpilibj.motorcontrol.DMC60} - *
  • {@link edu.wpi.first.wpilibj.motorcontrol.Jaguar} - *
  • {@link edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax} - *
  • {@link edu.wpi.first.wpilibj.motorcontrol.PWMTalonFX} - *
  • {@link edu.wpi.first.wpilibj.motorcontrol.PWMTalonSRX} - *
  • {@link edu.wpi.first.wpilibj.motorcontrol.PWMVenom} - *
  • {@link edu.wpi.first.wpilibj.motorcontrol.PWMVictorSPX} - *
  • {@link edu.wpi.first.wpilibj.motorcontrol.SD540} - *
  • {@link edu.wpi.first.wpilibj.motorcontrol.Spark} - *
  • {@link edu.wpi.first.wpilibj.motorcontrol.Talon} - *
  • {@link edu.wpi.first.wpilibj.motorcontrol.Victor} - *
  • {@link edu.wpi.first.wpilibj.motorcontrol.VictorSP} - *
  • {@link edu.wpi.first.wpilibj.motorcontrol.MotorControllerGroup} - *
  • Any custom subclass of {@code MotorController} - *
- * - *
- * Custom properties: - * - * - * - * - * - *
NameTypeDefault ValueNotes
OrientationString"HORIZONTAL"One of {@code ["HORIZONTAL", "VERTICAL"]}
- */ - kMotorController("Motor Controller"), - /** - * Displays a command with a toggle button. Pressing the button will start the command, and the - * button will automatically release when the command completes.
- * Supported types: - * - *
    - *
  • {@link edu.wpi.first.wpilibj2.command.Command} - *
  • Any custom subclass of {@code Command} - *
- * - *
- * This widget has no custom properties. - */ - kCommand("Command"), - /** - * Displays a PID command with a checkbox and an editor for the PIDF constants. Selecting the - * checkbox will start the command, and the checkbox will automatically deselect when the command - * completes.
- * Supported types: - * - *
    - *
  • {@link edu.wpi.first.wpilibj2.command.PIDCommand} - *
  • Any custom subclass of {@code PIDCommand} - *
- * - *
- * This widget has no custom properties. - */ - kPIDCommand("PID Command"), - /** - * Displays a PID controller with an editor for the PIDF constants and a toggle switch for - * enabling and disabling the controller.
- * Supported types: - * - *
    - *
  • {@link edu.wpi.first.math.controller.PIDController} - *
- * - *
- * This widget has no custom properties. - */ - kPIDController("PID Controller"), - /** - * Displays an accelerometer with a number bar displaying the magnitude of the acceleration and - * text displaying the exact value.
- * Custom properties: - * - * - * - * - * - * - * - * - * - * - * - * - * - *
NameTypeDefault ValueNotes
MinNumber-1The minimum acceleration value to display
MaxNumber1The maximum acceleration value to display
Show textBooleantrueShow or hide the acceleration values
PrecisionNumber2How many numbers to display after the decimal point
Show tick marksBooleanfalseShow or hide the tick marks on the number bars
- */ - kAccelerometer("Accelerometer"), - /** - * Displays a 3-axis accelerometer with a number bar for each axis' acceleration.
- * Supported types: - * - *
    - *
  • {@link edu.wpi.first.wpilibj.ADXL345_I2C} - *
- * - *
- * Custom properties: - * - * - * - * - * - * - * - * - * - *
NameTypeDefault ValueNotes
Show valueBooleantrueShow or hide the acceleration values
PrecisionNumber2How many numbers to display after the decimal point
Show tick marksBooleanfalseShow or hide the tick marks on the number bars
- */ - k3AxisAccelerometer("3-Axis Accelerometer"), - /** - * Displays a gyro with a dial from 0 to 360 degrees.
- * Supported types: - * - *
    - *
  • {@link edu.wpi.first.wpilibj.AnalogGyro} - *
  • Any custom subclass of {@code GyroBase} (such as a MXP gyro) - *
- * - *
- * Custom properties: - * - * - * - * - * - * - * - *
NameTypeDefault ValueNotes
Major tick spacingNumber45Degrees
Starting angleNumber180How far to rotate the entire dial, in degrees
Show tick mark ringBooleantrue
- */ - kGyro("Gyro"), - /** - * Displays a relay with toggle buttons for each supported mode (off, on, forward, reverse).
- * This widget has no custom properties. - */ - kRelay("Relay"), - /** - * Displays a differential drive with a widget that displays the speed of each side of the - * drivebase and a vector for the direction and rotation of the drivebase. The widget will be - * controllable if the robot is in test mode.
- * Supported types: - * - *
    - *
  • {@link edu.wpi.first.wpilibj.drive.DifferentialDrive} - *
- * - *
- * Custom properties: - * - * - * - * - * - * - *
NameTypeDefault ValueNotes
Number of wheelsNumber4Must be a positive even integer - *
Wheel diameterNumber80Pixels
Show velocity vectorsBooleantrue
- */ - kDifferentialDrive("Differential Drivebase"), - /** - * Displays a mecanum drive with a widget that displays the speed of each wheel, and vectors for - * the direction and rotation of the drivebase. The widget will be controllable if the robot is in - * test mode.
- * Supported types: - * - *
    - *
  • {@link edu.wpi.first.wpilibj.drive.MecanumDrive} - *
- * - *
- * Custom properties: - * - * - * - * - *
NameTypeDefault ValueNotes
Show velocity vectorsBooleantrue
- */ - kMecanumDrive("Mecanum Drivebase"), - /** - * Displays a camera stream.
- * Supported types: - * - *
    - *
  • {@link edu.wpi.first.cscore.VideoSource} (as long as it is streaming on an MJPEG server) - *
- * - *
- * Custom properties: - * - * - * - * - * - * - * - * - * - * - *
NameTypeDefault ValueNotes
Show crosshairBooleantrueShow or hide a crosshair on the image
Crosshair colorColor"white"Can be a string or a rgba integer
Show controlsBooleantrueShow or hide the stream controls - *
RotationString"NONE"Rotates the displayed image. One of {@code ["NONE", "QUARTER_CW", "QUARTER_CCW", "HALF"]} - *
- */ - kCameraStream("Camera Stream"), - /** - * Displays a Field2d object.
- * Supported types: - * - *
    - *
  • {@link edu.wpi.first.wpilibj.smartdashboard.Field2d} - *
- */ - kField("Field"), - ; - - private final String m_widgetName; - - BuiltInWidgets(String widgetName) { - this.m_widgetName = widgetName; - } - - @Override - public String getWidgetName() { - return m_widgetName; - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ComplexWidget.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ComplexWidget.java deleted file mode 100644 index cef9c0733f1..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ComplexWidget.java +++ /dev/null @@ -1,57 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -import edu.wpi.first.networktables.NetworkTable; -import edu.wpi.first.util.sendable.Sendable; -import edu.wpi.first.wpilibj.smartdashboard.SendableBuilderImpl; - -/** - * A Shuffleboard widget that handles a {@link Sendable} object such as a motor controller or - * sensor. - */ -public final class ComplexWidget extends ShuffleboardWidget { - private final Sendable m_sendable; - private SendableBuilderImpl m_builder; - - ComplexWidget(ShuffleboardContainer parent, String title, Sendable sendable) { - super(parent, title); - m_sendable = sendable; - } - - @Override - public void buildInto(NetworkTable parentTable, NetworkTable metaTable) { - buildMetadata(metaTable); - if (m_builder == null) { - m_builder = new SendableBuilderImpl(); - m_builder.setTable(parentTable.getSubTable(getTitle())); - m_sendable.initSendable(m_builder); - m_builder.startListeners(); - } - m_builder.update(); - } - - /** - * Enables user control of this widget in the Shuffleboard application. This method is - * package-private to prevent users from enabling control themselves. Has no effect if the - * sendable is not marked as an actuator with {@link SendableBuilder#setActuator}. - */ - void enableIfActuator() { - if (m_builder.isActuator()) { - m_builder.startLiveWindowMode(); - } - } - - /** - * Disables user control of this widget in the Shuffleboard application. This method is - * package-private to prevent users from enabling control themselves. Has no effect if the - * sendable is not marked as an actuator with {@link SendableBuilder#setActuator}. - */ - void disableIfActuator() { - if (m_builder.isActuator()) { - m_builder.stopLiveWindowMode(); - } - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ContainerHelper.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ContainerHelper.java deleted file mode 100644 index c8c0731fbc3..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ContainerHelper.java +++ /dev/null @@ -1,190 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -import static edu.wpi.first.util.ErrorMessages.requireNonNullParam; - -import edu.wpi.first.networktables.GenericPublisher; -import edu.wpi.first.networktables.NetworkTableEntry; -import edu.wpi.first.networktables.NetworkTableType; -import edu.wpi.first.util.function.FloatSupplier; -import edu.wpi.first.util.sendable.Sendable; -import edu.wpi.first.util.sendable.SendableRegistry; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Set; -import java.util.function.BiConsumer; -import java.util.function.BooleanSupplier; -import java.util.function.DoubleSupplier; -import java.util.function.LongSupplier; -import java.util.function.Supplier; - -/** A helper class for Shuffleboard containers to handle common child operations. */ -final class ContainerHelper { - private final ShuffleboardContainer m_container; - private final Set m_usedTitles = new HashSet<>(); - private final List> m_components = new ArrayList<>(); - private final Map m_layouts = new LinkedHashMap<>(); - - ContainerHelper(ShuffleboardContainer container) { - m_container = container; - } - - List> getComponents() { - return m_components; - } - - ShuffleboardLayout getLayout(String title, String type) { - if (!m_layouts.containsKey(title)) { - ShuffleboardLayout layout = new ShuffleboardLayout(m_container, title, type); - m_components.add(layout); - m_layouts.put(title, layout); - } - return m_layouts.get(title); - } - - ShuffleboardLayout getLayout(String title) { - ShuffleboardLayout layout = m_layouts.get(title); - if (layout == null) { - throw new NoSuchElementException("No layout has been defined with the title '" + title + "'"); - } - return layout; - } - - ComplexWidget add(String title, Sendable sendable) { - requireNonNullParam(sendable, "sendable", "add"); - checkTitle(title); - ComplexWidget widget = new ComplexWidget(m_container, title, sendable); - m_components.add(widget); - return widget; - } - - ComplexWidget add(Sendable sendable) { - requireNonNullParam(sendable, "sendable", "add"); - String name = SendableRegistry.getName(sendable); - if (name.isEmpty()) { - throw new IllegalArgumentException("Sendable must have a name"); - } - return add(name, sendable); - } - - SimpleWidget add(String title, Object defaultValue) { - requireNonNullParam(defaultValue, "defaultValue", "add"); - return add(title, NetworkTableType.getStringFromObject(defaultValue), defaultValue); - } - - SimpleWidget add(String title, String typeString, Object defaultValue) { - requireNonNullParam(title, "title", "add"); - requireNonNullParam(defaultValue, "defaultValue", "add"); - checkTitle(title); - checkNtType(defaultValue); - - SimpleWidget widget = new SimpleWidget(m_container, title); - m_components.add(widget); - widget.getEntry(typeString).setDefaultValue(defaultValue); - return widget; - } - - SuppliedValueWidget addString(String title, Supplier valueSupplier) { - precheck(title, valueSupplier, "addString"); - return addSupplied(title, "string", valueSupplier, GenericPublisher::setString); - } - - SuppliedValueWidget addNumber(String title, DoubleSupplier valueSupplier) { - requireNonNullParam(title, "title", "addNumber"); - requireNonNullParam(valueSupplier, "valueSupplier", "addNumber"); - return addDouble(title, valueSupplier); - } - - SuppliedValueWidget addDouble(String title, DoubleSupplier valueSupplier) { - precheck(title, valueSupplier, "addDouble"); - return addSupplied(title, "double", valueSupplier::getAsDouble, GenericPublisher::setDouble); - } - - SuppliedValueWidget addFloat(String title, FloatSupplier valueSupplier) { - precheck(title, valueSupplier, "addFloat"); - return addSupplied(title, "float", valueSupplier::getAsFloat, GenericPublisher::setFloat); - } - - SuppliedValueWidget addInteger(String title, LongSupplier valueSupplier) { - precheck(title, valueSupplier, "addInteger"); - return addSupplied(title, "int", valueSupplier::getAsLong, GenericPublisher::setInteger); - } - - SuppliedValueWidget addBoolean(String title, BooleanSupplier valueSupplier) { - precheck(title, valueSupplier, "addBoolean"); - return addSupplied(title, "boolean", valueSupplier::getAsBoolean, GenericPublisher::setBoolean); - } - - SuppliedValueWidget addStringArray(String title, Supplier valueSupplier) { - precheck(title, valueSupplier, "addStringArray"); - return addSupplied(title, "string[]", valueSupplier, GenericPublisher::setStringArray); - } - - SuppliedValueWidget addDoubleArray(String title, Supplier valueSupplier) { - precheck(title, valueSupplier, "addDoubleArray"); - return addSupplied(title, "double[]", valueSupplier, GenericPublisher::setDoubleArray); - } - - SuppliedValueWidget addFloatArray(String title, Supplier valueSupplier) { - precheck(title, valueSupplier, "addFloatArray"); - return addSupplied(title, "float[]", valueSupplier, GenericPublisher::setFloatArray); - } - - SuppliedValueWidget addIntegerArray(String title, Supplier valueSupplier) { - precheck(title, valueSupplier, "addIntegerArray"); - return addSupplied(title, "int[]", valueSupplier, GenericPublisher::setIntegerArray); - } - - SuppliedValueWidget addBooleanArray(String title, Supplier valueSupplier) { - precheck(title, valueSupplier, "addBooleanArray"); - return addSupplied(title, "boolean[]", valueSupplier, GenericPublisher::setBooleanArray); - } - - SuppliedValueWidget addRaw(String title, Supplier valueSupplier) { - return addRaw(title, "raw", valueSupplier); - } - - SuppliedValueWidget addRaw( - String title, String typeString, Supplier valueSupplier) { - precheck(title, valueSupplier, "addRaw"); - return addSupplied(title, typeString, valueSupplier, GenericPublisher::setRaw); - } - - private void precheck(String title, Object valueSupplier, String methodName) { - requireNonNullParam(title, "title", methodName); - requireNonNullParam(valueSupplier, "valueSupplier", methodName); - checkTitle(title); - } - - private SuppliedValueWidget addSupplied( - String title, - String typeString, - Supplier supplier, - BiConsumer setter) { - SuppliedValueWidget widget = - new SuppliedValueWidget<>(m_container, title, typeString, supplier, setter); - m_components.add(widget); - return widget; - } - - private static void checkNtType(Object data) { - if (!NetworkTableEntry.isValidDataType(data)) { - throw new IllegalArgumentException( - "Cannot add data of type " + data.getClass().getName() + " to Shuffleboard"); - } - } - - private void checkTitle(String title) { - if (m_usedTitles.contains(title)) { - throw new IllegalArgumentException("Title is already in use: " + title); - } - m_usedTitles.add(title); - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/EventImportance.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/EventImportance.java deleted file mode 100644 index 0d85ce69dc7..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/EventImportance.java +++ /dev/null @@ -1,49 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -/** - * The importance of an event marker in Shuffleboard. The exact meaning of each importance level is - * up for interpretation on a team-to-team basis, but users should follow the general guidelines of - * the various importance levels. The examples given are for reference and may be ignored or - * considered to be more or less important from team to team. - */ -public enum EventImportance { - // Maintainer note: this enum is mirrored in WPILibC and in Shuffleboard - // Modifying the enum or enum strings requires a corresponding change to the C++ enum - // and the enum in Shuffleboard - - /** A trivial event such as a change in command state. */ - kTrivial("TRIVIAL"), - - /** A low importance event such as acquisition of a game piece. */ - kLow("LOW"), - - /** - * A "normal" importance event, such as a transition from autonomous mode to teleoperated control. - */ - kNormal("NORMAL"), - - /** A high-importance event such as scoring a game piece. */ - kHigh("HIGH"), - - /** A critically important event such as a brownout, component failure, or software deadlock. */ - kCritical("CRITICAL"); - - private final String m_simpleName; - - EventImportance(String simpleName) { - m_simpleName = simpleName; - } - - /** - * Returns name of the given enum. - * - * @return Name of the given enum. - */ - public String getSimpleName() { - return m_simpleName; - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/LayoutType.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/LayoutType.java deleted file mode 100644 index 82ffcbef204..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/LayoutType.java +++ /dev/null @@ -1,20 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -/** - * Represents the type of a layout in Shuffleboard. Using this is preferred over specifying raw - * strings, to avoid typos and having to know or look up the exact string name for a desired layout. - * - * @see BuiltInWidgets the built-in widget types - */ -public interface LayoutType { - /** - * Gets the string type of the layout as defined by that layout in Shuffleboard. - * - * @return The string type of the layout. - */ - String getLayoutName(); -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/RecordingController.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/RecordingController.java deleted file mode 100644 index f8329ddbc1a..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/RecordingController.java +++ /dev/null @@ -1,65 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -import edu.wpi.first.networktables.BooleanPublisher; -import edu.wpi.first.networktables.NetworkTable; -import edu.wpi.first.networktables.NetworkTableInstance; -import edu.wpi.first.networktables.StringPublisher; -import edu.wpi.first.wpilibj.DriverStation; - -/** Controls Shuffleboard recordings via NetworkTables. */ -final class RecordingController { - private static final String kRecordingTableName = "/Shuffleboard/.recording/"; - private static final String kRecordingControlKey = kRecordingTableName + "RecordData"; - private static final String kRecordingFileNameFormatKey = kRecordingTableName + "FileNameFormat"; - private static final String kEventMarkerTableName = kRecordingTableName + "events"; - - private final BooleanPublisher m_recordingControlEntry; - private final StringPublisher m_recordingFileNameFormatEntry; - private final NetworkTable m_eventsTable; - - RecordingController(NetworkTableInstance ntInstance) { - m_recordingControlEntry = ntInstance.getBooleanTopic(kRecordingControlKey).publish(); - m_recordingFileNameFormatEntry = - ntInstance.getStringTopic(kRecordingFileNameFormatKey).publish(); - m_eventsTable = ntInstance.getTable(kEventMarkerTableName); - } - - public void startRecording() { - m_recordingControlEntry.set(true); - } - - public void stopRecording() { - m_recordingControlEntry.set(false); - } - - public void setRecordingFileNameFormat(String format) { - m_recordingFileNameFormatEntry.set(format); - } - - public void clearRecordingFileNameFormat() { - m_recordingFileNameFormatEntry.set(""); - } - - public void addEventMarker(String name, String description, EventImportance importance) { - if (name == null || name.isEmpty()) { - DriverStation.reportError("Shuffleboard event name was not specified", true); - return; - } - - if (importance == null) { - DriverStation.reportError("Shuffleboard event importance was null", true); - return; - } - - String eventDescription = description == null ? "" : description; - - m_eventsTable - .getSubTable(name) - .getEntry("Info") - .setStringArray(new String[] {eventDescription, importance.getSimpleName()}); - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/SendableCameraWrapper.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/SendableCameraWrapper.java deleted file mode 100644 index bd428cdd00b..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/SendableCameraWrapper.java +++ /dev/null @@ -1,138 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -import static edu.wpi.first.util.ErrorMessages.requireNonNullParam; - -import edu.wpi.first.cscore.VideoSource; -import edu.wpi.first.networktables.NetworkTable; -import edu.wpi.first.networktables.NetworkTableInstance; -import edu.wpi.first.networktables.StringArrayPublisher; -import edu.wpi.first.networktables.StringArrayTopic; -import edu.wpi.first.util.sendable.Sendable; -import edu.wpi.first.util.sendable.SendableBuilder; -import edu.wpi.first.util.sendable.SendableRegistry; -import java.util.Map; -import java.util.Objects; -import java.util.WeakHashMap; - -/** A wrapper to make video sources sendable and usable from Shuffleboard. */ -public final class SendableCameraWrapper implements Sendable, AutoCloseable { - private static final String kProtocol = "camera_server://"; - - private static Map m_wrappers = new WeakHashMap<>(); - - private static NetworkTable m_table; - - static { - setNetworkTableInstance(NetworkTableInstance.getDefault()); - } - - private final String m_uri; - private StringArrayPublisher m_streams; - - /** - * Creates a new sendable wrapper. Private constructor to avoid direct instantiation with multiple - * wrappers floating around for the same camera. - * - * @param source the source to wrap - */ - private SendableCameraWrapper(VideoSource source) { - this(source.getName()); - } - - private SendableCameraWrapper(String cameraName) { - SendableRegistry.add(this, cameraName); - m_uri = kProtocol + cameraName; - } - - private SendableCameraWrapper(String cameraName, String[] cameraUrls) { - this(cameraName); - - StringArrayTopic streams = new StringArrayTopic(m_table.getTopic(cameraName + "/streams")); - if (streams.exists()) { - throw new IllegalStateException( - "A camera is already being streamed with the name '" + cameraName + "'"); - } - - m_streams = streams.publish(); - m_streams.set(cameraUrls); - } - - /** Clears all cached wrapper objects. This should only be used in tests. */ - static void clearWrappers() { - m_wrappers.clear(); - } - - @Override - public void close() { - SendableRegistry.remove(this); - if (m_streams != null) { - m_streams.close(); - } - } - - /** - * Sets NetworkTable instance used for camera publisher entries. - * - * @param inst NetworkTable instance - */ - public static synchronized void setNetworkTableInstance(NetworkTableInstance inst) { - m_table = inst.getTable("CameraPublisher"); - } - - /** - * Gets a sendable wrapper object for the given video source, creating the wrapper if one does not - * already exist for the source. - * - * @param source the video source to wrap - * @return a sendable wrapper object for the video source, usable in Shuffleboard via {@link - * ShuffleboardTab#add(Sendable)} and {@link ShuffleboardLayout#add(Sendable)} - */ - public static SendableCameraWrapper wrap(VideoSource source) { - return m_wrappers.computeIfAbsent(source.getName(), name -> new SendableCameraWrapper(source)); - } - - /** - * Creates a wrapper for an arbitrary camera stream. The stream URLs must be specified - * using a host resolvable by a program running on a different host (such as a dashboard); prefer - * using static IP addresses (if known) or DHCP identifiers such as {@code "raspberrypi.local"}. - * - *

If a wrapper already exists for the given camera, that wrapper is returned and the specified - * URLs are ignored. - * - * @param cameraName the name of the camera. Cannot be null or empty - * @param cameraUrls the URLs with which the camera stream may be accessed. At least one URL must - * be specified - * @return a sendable wrapper object for the video source, usable in Shuffleboard via {@link - * ShuffleboardTab#add(Sendable)} and {@link ShuffleboardLayout#add(Sendable)} - */ - public static SendableCameraWrapper wrap(String cameraName, String... cameraUrls) { - if (m_wrappers.containsKey(cameraName)) { - return m_wrappers.get(cameraName); - } - - requireNonNullParam(cameraName, "cameraName", "wrap"); - requireNonNullParam(cameraUrls, "cameraUrls", "wrap"); - if (cameraName.isEmpty()) { - throw new IllegalArgumentException("Camera name not specified"); - } - if (cameraUrls.length == 0) { - throw new IllegalArgumentException("No camera URLs specified"); - } - for (int i = 0; i < cameraUrls.length; i++) { - Objects.requireNonNull(cameraUrls[i], "Camera URL at index " + i + " was null"); - } - - SendableCameraWrapper wrapper = new SendableCameraWrapper(cameraName, cameraUrls); - m_wrappers.put(cameraName, wrapper); - return wrapper; - } - - @Override - public void initSendable(SendableBuilder builder) { - builder.addStringProperty(".ShuffleboardURI", () -> m_uri, null); - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/Shuffleboard.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/Shuffleboard.java deleted file mode 100644 index c08ab6ffeb6..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/Shuffleboard.java +++ /dev/null @@ -1,195 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -import edu.wpi.first.networktables.NetworkTableInstance; - -/** - * The Shuffleboard class provides a mechanism with which data can be added and laid out in the - * Shuffleboard dashboard application from a robot program. Tabs and layouts can be specified, as - * well as choosing which widgets to display with and setting properties of these widgets; for - * example, programmers can specify a specific {@code boolean} value to be displayed with a toggle - * button instead of the default colored box, or set custom colors for that box. - * - *

For example, displaying a boolean entry with a toggle button: - * - *

{@code
- * GenericEntry myBoolean = Shuffleboard.getTab("Example Tab")
- *   .add("My Boolean", false)
- *   .withWidget("Toggle Button")
- *   .getEntry();
- * }
- * - *

Changing the colors of the boolean box: - * - *

{@code
- * GenericEntry myBoolean = Shuffleboard.getTab("Example Tab")
- *   .add("My Boolean", false)
- *   .withWidget("Boolean Box")
- *   .withProperties(Map.of("colorWhenTrue", "green", "colorWhenFalse", "maroon"))
- *   .getEntry();
- * }
- * - *

Specifying a parent layout. Note that the layout type must always be specified, even if - * the layout has already been generated by a previously defined entry. - * - *

{@code
- * GenericEntry myBoolean = Shuffleboard.getTab("Example Tab")
- *   .getLayout("List", "Example List")
- *   .add("My Boolean", false)
- *   .withWidget("Toggle Button")
- *   .getEntry();
- * }
- * - *

Teams are encouraged to set up shuffleboard layouts at the start of the robot program. - */ -public final class Shuffleboard { - /** The name of the base NetworkTable into which all Shuffleboard data will be added. */ - public static final String kBaseTableName = "/Shuffleboard"; - - private static final ShuffleboardRoot root = - new ShuffleboardInstance(NetworkTableInstance.getDefault()); - private static final RecordingController recordingController = - new RecordingController(NetworkTableInstance.getDefault()); - - private Shuffleboard() { - throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); - } - - /** - * Updates all the values in Shuffleboard. Iterative and timed robots are pre-configured to call - * this method in the main robot loop; teams using custom robot base classes, or subclass - * SampleRobot, should make sure to call this repeatedly to keep data on the dashboard up to date. - */ - public static void update() { - root.update(); - } - - /** - * Gets the Shuffleboard tab with the given title, creating it if it does not already exist. - * - * @param title the title of the tab - * @return the tab with the given title - */ - public static ShuffleboardTab getTab(String title) { - return root.getTab(title); - } - - /** - * Selects the tab in the dashboard with the given index in the range [0..n-1], where n is - * the number of tabs in the dashboard at the time this method is called. - * - * @param index the index of the tab to select - */ - public static void selectTab(int index) { - root.selectTab(index); - } - - /** - * Selects the tab in the dashboard with the given title. - * - * @param title the title of the tab to select - */ - public static void selectTab(String title) { - root.selectTab(title); - } - - /** - * Enables user control of widgets containing actuators: motor controllers, relays, etc. This - * should only be used when the robot is in test mode. IterativeRobotBase and SampleRobot are both - * configured to call this method when entering test mode; most users should not need to use this - * method directly. - */ - public static void enableActuatorWidgets() { - root.enableActuatorWidgets(); - } - - /** - * Disables user control of widgets containing actuators. For safety reasons, actuators should - * only be controlled while in test mode. IterativeRobotBase and SampleRobot are both configured - * to call this method when exiting in test mode; most users should not need to use this method - * directly. - */ - public static void disableActuatorWidgets() { - update(); // Need to update to make sure the sendable builders are initialized - root.disableActuatorWidgets(); - } - - /** - * Starts data recording on the dashboard. Has no effect if recording is already in progress. - * - * @see #stopRecording() - */ - public static void startRecording() { - recordingController.startRecording(); - } - - /** - * Stops data recording on the dashboard. Has no effect if no recording is in progress. - * - * @see #startRecording() - */ - public static void stopRecording() { - recordingController.stopRecording(); - } - - /** - * Sets the file name format for new recording files to use. If recording is in progress when this - * method is called, it will continue to use the same file. New recordings will use the format. - * - *

To avoid recording files overwriting each other, make sure to use unique recording file - * names. File name formats accept templates for inserting the date and time when the recording - * started with the {@code ${date}} and {@code ${time}} templates, respectively. For example, the - * default format is {@code "recording-${time}"} and recording files created with it will have - * names like {@code "recording-2018.01.15.sbr"}. Users are strongly recommended - * to use the {@code ${time}} template to ensure unique file names. - * - * @param format the format for the - * @see #clearRecordingFileNameFormat() - */ - public static void setRecordingFileNameFormat(String format) { - recordingController.setRecordingFileNameFormat(format); - } - - /** - * Clears the custom name format for recording files. New recordings will use the default format. - * - * @see #setRecordingFileNameFormat(String) - */ - public static void clearRecordingFileNameFormat() { - recordingController.clearRecordingFileNameFormat(); - } - - /** - * Notifies Shuffleboard of an event. Events can range from as trivial as a change in a command - * state to as critical as a total power loss or component failure. If Shuffleboard is recording, - * the event will also be recorded. - * - *

If {@code name} is {@code null} or empty, or {@code importance} is {@code null}, then no - * event will be sent and an error will be printed to the driver station. - * - * @param name the name of the event - * @param description a description of the event - * @param importance the importance of the event - */ - public static void addEventMarker(String name, String description, EventImportance importance) { - recordingController.addEventMarker(name, description, importance); - } - - /** - * Notifies Shuffleboard of an event. Events can range from as trivial as a change in a command - * state to as critical as a total power loss or component failure. If Shuffleboard is recording, - * the event will also be recorded. - * - *

If {@code name} is {@code null} or empty, or {@code importance} is {@code null}, then no - * event will be sent and an error will be printed to the driver station. - * - * @param name the name of the event - * @param importance the importance of the event - */ - public static void addEventMarker(String name, EventImportance importance) { - addEventMarker(name, "", importance); - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardComponent.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardComponent.java deleted file mode 100644 index 3e1f75acd89..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardComponent.java +++ /dev/null @@ -1,177 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -import static edu.wpi.first.util.ErrorMessages.requireNonNullParam; - -import edu.wpi.first.networktables.NetworkTable; -import java.util.Map; - -/** - * A generic component in Shuffleboard. - * - * @param the self type - */ -public abstract class ShuffleboardComponent> - implements ShuffleboardValue { - private final ShuffleboardContainer m_parent; - private final String m_title; - private String m_type; - private Map m_properties; - private boolean m_metadataDirty = true; - private int m_column = -1; - private int m_row = -1; - private int m_width = -1; - private int m_height = -1; - - /** - * Constructs a ShuffleboardComponent. - * - * @param parent The parent container. - * @param title The component title. - * @param type The component type. - */ - protected ShuffleboardComponent(ShuffleboardContainer parent, String title, String type) { - m_parent = requireNonNullParam(parent, "parent", "ShuffleboardComponent"); - m_title = requireNonNullParam(title, "title", "ShuffleboardComponent"); - m_type = type; - } - - /** - * Constructs a ShuffleboardComponent. - * - * @param parent The parent container. - * @param title The component title. - */ - protected ShuffleboardComponent(ShuffleboardContainer parent, String title) { - this(parent, title, null); - } - - /** - * Returns the parent container. - * - * @return The parent container. - */ - public final ShuffleboardContainer getParent() { - return m_parent; - } - - /** - * Sets the component type. - * - * @param type The component type. - */ - protected final void setType(String type) { - m_type = type; - m_metadataDirty = true; - } - - /** - * Returns the component type. - * - * @return The component type. - */ - public final String getType() { - return m_type; - } - - @Override - public final String getTitle() { - return m_title; - } - - /** Gets the custom properties for this component. May be null. */ - final Map getProperties() { - return m_properties; - } - - /** - * Sets custom properties for this component. Property names are case- and whitespace-insensitive - * (capitalization and spaces do not matter). - * - * @param properties the properties for this component - * @return this component - */ - @SuppressWarnings("unchecked") - public final C withProperties(Map properties) { - m_properties = properties; - m_metadataDirty = true; - return (C) this; - } - - /** - * Sets the position of this component in the tab. This has no effect if this component is inside - * a layout. - * - *

If the position of a single component is set, it is recommended to set the positions of - * all components inside a tab to prevent Shuffleboard from automatically placing another - * component there before the one with the specific position is sent. - * - * @param columnIndex the column in the tab to place this component - * @param rowIndex the row in the tab to place this component - * @return this component - */ - @SuppressWarnings("unchecked") - public final C withPosition(int columnIndex, int rowIndex) { - m_column = columnIndex; - m_row = rowIndex; - m_metadataDirty = true; - return (C) this; - } - - /** - * Sets the size of this component in the tab. This has no effect if this component is inside a - * layout. - * - * @param width how many columns wide the component should be - * @param height how many rows high the component should be - * @return this component - */ - @SuppressWarnings("unchecked") - public final C withSize(int width, int height) { - m_width = width; - m_height = height; - m_metadataDirty = true; - return (C) this; - } - - /** - * Builds NT metadata. - * - * @param metaTable The NT metadata table. - */ - protected final void buildMetadata(NetworkTable metaTable) { - if (!m_metadataDirty) { - return; - } - // Component type - if (getType() == null) { - metaTable.getEntry("PreferredComponent").unpublish(); - } else { - metaTable.getEntry("PreferredComponent").setString(getType()); - } - - // Tile size - if (m_width <= 0 || m_height <= 0) { - metaTable.getEntry("Size").unpublish(); - } else { - metaTable.getEntry("Size").setDoubleArray(new double[] {m_width, m_height}); - } - - // Tile position - if (m_column < 0 || m_row < 0) { - metaTable.getEntry("Position").unpublish(); - } else { - metaTable.getEntry("Position").setDoubleArray(new double[] {m_column, m_row}); - } - - // Custom properties - if (getProperties() != null) { - NetworkTable propTable = metaTable.getSubTable("Properties"); - getProperties().forEach((name, value) -> propTable.getEntry(name).setValue(value)); - } - m_metadataDirty = false; - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardContainer.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardContainer.java deleted file mode 100644 index 5e08d4dfd69..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardContainer.java +++ /dev/null @@ -1,363 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -import edu.wpi.first.cscore.VideoSource; -import edu.wpi.first.networktables.NetworkTableType; -import edu.wpi.first.util.function.FloatSupplier; -import edu.wpi.first.util.sendable.Sendable; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.function.BooleanSupplier; -import java.util.function.DoubleSupplier; -import java.util.function.LongSupplier; -import java.util.function.Supplier; - -/** Common interface for objects that can contain shuffleboard components. */ -public sealed interface ShuffleboardContainer extends ShuffleboardValue - permits ShuffleboardLayout, ShuffleboardTab { - /** - * Gets the components that are direct children of this container. - * - * @return The components that are direct children of this container. - */ - List> getComponents(); - - /** - * Gets the layout with the given type and title, creating it if it does not already exist at the - * time this method is called. Note: this method should only be used to use a layout type that is - * not already built into Shuffleboard. To use a layout built into Shuffleboard, use {@link - * #getLayout(String, LayoutType)} and the layouts in {@link BuiltInLayouts}. - * - * @param title the title of the layout - * @param type the type of the layout, eg "List Layout" or "Grid Layout" - * @return the layout - * @see #getLayout(String, LayoutType) - */ - ShuffleboardLayout getLayout(String title, String type); - - /** - * Gets the layout with the given type and title, creating it if it does not already exist at the - * time this method is called. - * - * @param title the title of the layout - * @param layoutType the type of the layout, eg "List" or "Grid" - * @return the layout - */ - default ShuffleboardLayout getLayout(String title, LayoutType layoutType) { - return getLayout(title, layoutType.getLayoutName()); - } - - /** - * Gets the already-defined layout in this container with the given title. - * - *

{@code
-   * Shuffleboard.getTab("Example Tab")
-   *   .getLayout("My Layout", BuiltInLayouts.kList);
-   *
-   * // Later...
-   * Shuffleboard.getTab("Example Tab")
-   *   .getLayout("My Layout");
-   * }
- * - * @param title the title of the layout to get - * @return the layout with the given title - * @throws NoSuchElementException if no layout has yet been defined with the given title - */ - ShuffleboardLayout getLayout(String title); - - /** - * Adds a widget to this container to display the given sendable. - * - * @param title the title of the widget - * @param sendable the sendable to display - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - */ - ComplexWidget add(String title, Sendable sendable); - - /** - * Adds a widget to this container to display the given video stream. - * - * @param title the title of the widget - * @param video the video stream to display - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - */ - default ComplexWidget add(String title, VideoSource video) { - return add(title, SendableCameraWrapper.wrap(video)); - } - - /** - * Adds a widget to this container to display the given sendable. - * - * @param sendable the sendable to display - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title, or if the sendable's name has not been specified - */ - ComplexWidget add(Sendable sendable); - - /** - * Adds a widget to this container to display the given video stream. - * - * @param video the video to display - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this container with the same - * title as the video source - */ - default ComplexWidget add(VideoSource video) { - return add(SendableCameraWrapper.wrap(video)); - } - - /** - * Adds a widget to this container to display the given data. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - * @see #addPersistent(String, Object) add(String title, Object defaultValue) - */ - SimpleWidget add(String title, Object defaultValue); - - /** - * Adds a widget to this container to display the given data. - * - * @param title the title of the widget - * @param typeString the NT type string - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - * @see #addPersistent(String, Object) add(String title, Object defaultValue) - */ - SimpleWidget add(String title, String typeString, Object defaultValue); - - /** - * Adds a widget to this container to display a video stream. - * - * @param title the title of the widget - * @param cameraName the name of the streamed camera - * @param cameraUrls the URLs with which the dashboard can access the camera stream - * @return a widget to display the camera stream - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - */ - default ComplexWidget addCamera(String title, String cameraName, String... cameraUrls) { - return add(title, SendableCameraWrapper.wrap(cameraName, cameraUrls)); - } - - /** - * Adds a widget to this container. The widget will display the data provided by the value - * supplier. Changes made on the dashboard will not propagate to the widget object, and will be - * overridden by values from the value supplier. - * - * @param title the title of the widget - * @param valueSupplier the supplier for values - * @return a widget to display data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - */ - SuppliedValueWidget addString(String title, Supplier valueSupplier); - - /** - * Adds a widget to this container. The widget will display the data provided by the value - * supplier. Changes made on the dashboard will not propagate to the widget object, and will be - * overridden by values from the value supplier. - * - * @param title the title of the widget - * @param valueSupplier the supplier for values - * @return a widget to display data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - */ - SuppliedValueWidget addNumber(String title, DoubleSupplier valueSupplier); - - /** - * Adds a widget to this container. The widget will display the data provided by the value - * supplier. Changes made on the dashboard will not propagate to the widget object, and will be - * overridden by values from the value supplier. - * - * @param title the title of the widget - * @param valueSupplier the supplier for values - * @return a widget to display data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - */ - SuppliedValueWidget addDouble(String title, DoubleSupplier valueSupplier); - - /** - * Adds a widget to this container. The widget will display the data provided by the value - * supplier. Changes made on the dashboard will not propagate to the widget object, and will be - * overridden by values from the value supplier. - * - * @param title the title of the widget - * @param valueSupplier the supplier for values - * @return a widget to display data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - */ - SuppliedValueWidget addFloat(String title, FloatSupplier valueSupplier); - - /** - * Adds a widget to this container. The widget will display the data provided by the value - * supplier. Changes made on the dashboard will not propagate to the widget object, and will be - * overridden by values from the value supplier. - * - * @param title the title of the widget - * @param valueSupplier the supplier for values - * @return a widget to display data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - */ - SuppliedValueWidget addInteger(String title, LongSupplier valueSupplier); - - /** - * Adds a widget to this container. The widget will display the data provided by the value - * supplier. Changes made on the dashboard will not propagate to the widget object, and will be - * overridden by values from the value supplier. - * - * @param title the title of the widget - * @param valueSupplier the supplier for values - * @return a widget to display data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - */ - SuppliedValueWidget addBoolean(String title, BooleanSupplier valueSupplier); - - /** - * Adds a widget to this container. The widget will display the data provided by the value - * supplier. Changes made on the dashboard will not propagate to the widget object, and will be - * overridden by values from the value supplier. - * - * @param title the title of the widget - * @param valueSupplier the supplier for values - * @return a widget to display data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - */ - SuppliedValueWidget addStringArray(String title, Supplier valueSupplier); - - /** - * Adds a widget to this container. The widget will display the data provided by the value - * supplier. Changes made on the dashboard will not propagate to the widget object, and will be - * overridden by values from the value supplier. - * - * @param title the title of the widget - * @param valueSupplier the supplier for values - * @return a widget to display data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - */ - SuppliedValueWidget addDoubleArray(String title, Supplier valueSupplier); - - /** - * Adds a widget to this container. The widget will display the data provided by the value - * supplier. Changes made on the dashboard will not propagate to the widget object, and will be - * overridden by values from the value supplier. - * - * @param title the title of the widget - * @param valueSupplier the supplier for values - * @return a widget to display data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - */ - SuppliedValueWidget addFloatArray(String title, Supplier valueSupplier); - - /** - * Adds a widget to this container. The widget will display the data provided by the value - * supplier. Changes made on the dashboard will not propagate to the widget object, and will be - * overridden by values from the value supplier. - * - * @param title the title of the widget - * @param valueSupplier the supplier for values - * @return a widget to display data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - */ - SuppliedValueWidget addIntegerArray(String title, Supplier valueSupplier); - - /** - * Adds a widget to this container. The widget will display the data provided by the value - * supplier. Changes made on the dashboard will not propagate to the widget object, and will be - * overridden by values from the value supplier. - * - * @param title the title of the widget - * @param valueSupplier the supplier for values - * @return a widget to display data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - */ - SuppliedValueWidget addBooleanArray(String title, Supplier valueSupplier); - - /** - * Adds a widget to this container. The widget will display the data provided by the value - * supplier. Changes made on the dashboard will not propagate to the widget object, and will be - * overridden by values from the value supplier. - * - * @param title the title of the widget - * @param valueSupplier the supplier for values - * @return a widget to display data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - */ - default SuppliedValueWidget addRaw(String title, Supplier valueSupplier) { - return addRaw(title, "raw", valueSupplier); - } - - /** - * Adds a widget to this container. The widget will display the data provided by the value - * supplier. Changes made on the dashboard will not propagate to the widget object, and will be - * overridden by values from the value supplier. - * - * @param title the title of the widget - * @param typeString the NT type string for the value - * @param valueSupplier the supplier for values - * @return a widget to display data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - */ - SuppliedValueWidget addRaw( - String title, String typeString, Supplier valueSupplier); - - /** - * Adds a widget to this container to display a simple piece of data. Unlike {@link #add(String, - * Object)}, the value in the widget will be saved on the robot and will be used when the robot - * program next starts rather than {@code defaultValue}. - * - * @param title the title of the widget - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - * @see #add(String, Object) add(String title, Object defaultValue) - */ - default SimpleWidget addPersistent(String title, Object defaultValue) { - return addPersistent(title, NetworkTableType.getStringFromObject(defaultValue), defaultValue); - } - - /** - * Adds a widget to this container to display a simple piece of data. Unlike {@link #add(String, - * Object)}, the value in the widget will be saved on the robot and will be used when the robot - * program next starts rather than {@code defaultValue}. - * - * @param title the title of the widget - * @param typeString the NT type string - * @param defaultValue the default value of the widget - * @return a widget to display the sendable data - * @throws IllegalArgumentException if a widget already exists in this container with the given - * title - * @see #add(String, Object) add(String title, Object defaultValue) - */ - default SimpleWidget addPersistent(String title, String typeString, Object defaultValue) { - SimpleWidget widget = add(title, defaultValue); - widget.getEntry(typeString).getTopic().setPersistent(true); - return widget; - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardInstance.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardInstance.java deleted file mode 100644 index fb8a3b5b76f..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardInstance.java +++ /dev/null @@ -1,114 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -import static edu.wpi.first.util.ErrorMessages.requireNonNullParam; - -import edu.wpi.first.hal.FRCNetComm.tResourceType; -import edu.wpi.first.hal.HAL; -import edu.wpi.first.networktables.NetworkTable; -import edu.wpi.first.networktables.NetworkTableInstance; -import edu.wpi.first.networktables.PubSubOption; -import edu.wpi.first.networktables.StringPublisher; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.function.Consumer; - -final class ShuffleboardInstance implements ShuffleboardRoot { - private final Map m_tabs = new LinkedHashMap<>(); - private boolean m_reported = false; // NOPMD redundant field initializer - private boolean m_tabsChanged = false; // NOPMD redundant field initializer - private final NetworkTable m_rootTable; - private final NetworkTable m_rootMetaTable; - private final StringPublisher m_selectedTabPub; - - /** - * Creates a new Shuffleboard instance. - * - * @param ntInstance the NetworkTables instance to use - */ - ShuffleboardInstance(NetworkTableInstance ntInstance) { - requireNonNullParam(ntInstance, "ntInstance", "ShuffleboardInstance"); - m_rootTable = ntInstance.getTable(Shuffleboard.kBaseTableName); - m_rootMetaTable = m_rootTable.getSubTable(".metadata"); - m_selectedTabPub = - m_rootMetaTable.getStringTopic("Selected").publish(PubSubOption.keepDuplicates(true)); - } - - @Override - public ShuffleboardTab getTab(String title) { - requireNonNullParam(title, "title", "getTab"); - if (!m_reported) { - HAL.report(tResourceType.kResourceType_Shuffleboard, 0); - m_reported = true; - } - if (!m_tabs.containsKey(title)) { - m_tabs.put(title, new ShuffleboardTab(this, title)); - m_tabsChanged = true; - } - return m_tabs.get(title); - } - - @Override - public void update() { - if (m_tabsChanged) { - String[] tabTitles = - m_tabs.values().stream().map(ShuffleboardTab::getTitle).toArray(String[]::new); - m_rootMetaTable.getEntry("Tabs").setStringArray(tabTitles); - m_tabsChanged = false; - } - for (ShuffleboardTab tab : m_tabs.values()) { - String title = tab.getTitle(); - tab.buildInto(m_rootTable, m_rootMetaTable.getSubTable(title)); - } - } - - @Override - public void enableActuatorWidgets() { - applyToAllComplexWidgets(ComplexWidget::enableIfActuator); - } - - @Override - public void disableActuatorWidgets() { - applyToAllComplexWidgets(ComplexWidget::disableIfActuator); - } - - @Override - public void selectTab(int index) { - selectTab(Integer.toString(index)); - } - - @Override - public void selectTab(String title) { - m_selectedTabPub.set(title); - } - - /** - * Applies the function {@code func} to all complex widgets in this root, regardless of how they - * are nested. - * - * @param func the function to apply to all complex widgets - */ - private void applyToAllComplexWidgets(Consumer func) { - for (ShuffleboardTab tab : m_tabs.values()) { - apply(tab, func); - } - } - - /** - * Applies the function {@code func} to all complex widgets in {@code container}. Helper method - * for {@link #applyToAllComplexWidgets}. - */ - private void apply(ShuffleboardContainer container, Consumer func) { - for (ShuffleboardComponent component : container.getComponents()) { - if (component instanceof ComplexWidget widget) { - func.accept(widget); - } - if (component instanceof ShuffleboardContainer nestedContainer) { - apply(nestedContainer, func); - } - } - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardLayout.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardLayout.java deleted file mode 100644 index 564f5e42619..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardLayout.java +++ /dev/null @@ -1,141 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -import static edu.wpi.first.util.ErrorMessages.requireNonNullParam; - -import edu.wpi.first.networktables.NetworkTable; -import edu.wpi.first.util.function.FloatSupplier; -import edu.wpi.first.util.sendable.Sendable; -import java.util.List; -import java.util.function.BooleanSupplier; -import java.util.function.DoubleSupplier; -import java.util.function.LongSupplier; -import java.util.function.Supplier; - -/** A layout in a Shuffleboard tab. Layouts can contain widgets and other layouts. */ -public final class ShuffleboardLayout extends ShuffleboardComponent - implements ShuffleboardContainer { - private static final String kSmartDashboardType = "ShuffleboardLayout"; - - private final ContainerHelper m_helper = new ContainerHelper(this); - - ShuffleboardLayout(ShuffleboardContainer parent, String title, String type) { - super(parent, title, requireNonNullParam(type, "type", "ShuffleboardLayout")); - } - - @Override - public List> getComponents() { - return m_helper.getComponents(); - } - - @Override - public ShuffleboardLayout getLayout(String title, String type) { - return m_helper.getLayout(title, type); - } - - @Override - public ShuffleboardLayout getLayout(String title) { - return m_helper.getLayout(title); - } - - @Override - public ComplexWidget add(String title, Sendable sendable) { - return m_helper.add(title, sendable); - } - - @Override - public ComplexWidget add(Sendable sendable) { - return m_helper.add(sendable); - } - - @Override - public SimpleWidget add(String title, Object defaultValue) { - return m_helper.add(title, defaultValue); - } - - @Override - public SimpleWidget add(String title, String typeString, Object defaultValue) { - return m_helper.add(title, typeString, defaultValue); - } - - @Override - public SuppliedValueWidget addString(String title, Supplier valueSupplier) { - return m_helper.addString(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addNumber(String title, DoubleSupplier valueSupplier) { - return m_helper.addNumber(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addDouble(String title, DoubleSupplier valueSupplier) { - return m_helper.addDouble(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addFloat(String title, FloatSupplier valueSupplier) { - return m_helper.addFloat(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addInteger(String title, LongSupplier valueSupplier) { - return m_helper.addInteger(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addBoolean(String title, BooleanSupplier valueSupplier) { - return m_helper.addBoolean(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addStringArray( - String title, Supplier valueSupplier) { - return m_helper.addStringArray(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addDoubleArray( - String title, Supplier valueSupplier) { - return m_helper.addDoubleArray(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addFloatArray(String title, Supplier valueSupplier) { - return m_helper.addFloatArray(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addIntegerArray(String title, Supplier valueSupplier) { - return m_helper.addIntegerArray(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addBooleanArray( - String title, Supplier valueSupplier) { - return m_helper.addBooleanArray(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addRaw( - String title, String typeString, Supplier valueSupplier) { - return m_helper.addRaw(title, typeString, valueSupplier); - } - - @Override - public void buildInto(NetworkTable parentTable, NetworkTable metaTable) { - buildMetadata(metaTable); - NetworkTable table = parentTable.getSubTable(getTitle()); - table.getEntry(".type").setString(kSmartDashboardType); - table - .getEntry(".type") - .getTopic() - .setProperty("SmartDashboard", "\"" + kSmartDashboardType + "\""); - for (ShuffleboardComponent component : getComponents()) { - component.buildInto(table, metaTable.getSubTable(component.getTitle())); - } - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardRoot.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardRoot.java deleted file mode 100644 index fa6cd08deb8..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardRoot.java +++ /dev/null @@ -1,45 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -/** - * The root of the data placed in Shuffleboard. It contains the tabs, but no data is placed directly - * in the root. - * - *

This class is package-private to minimize API surface area. - */ -interface ShuffleboardRoot { - /** - * Gets the tab with the given title, creating it if it does not already exist. - * - * @param title the title of the tab - * @return the tab with the given title - */ - ShuffleboardTab getTab(String title); - - /** Updates all tabs. */ - void update(); - - /** Enables all widgets in Shuffleboard that offer user control over actuators. */ - void enableActuatorWidgets(); - - /** Disables all widgets in Shuffleboard that offer user control over actuators. */ - void disableActuatorWidgets(); - - /** - * Selects the tab in the dashboard with the given index in the range [0..n-1], where n is - * the number of tabs in the dashboard at the time this method is called. - * - * @param index the index of the tab to select - */ - void selectTab(int index); - - /** - * Selects the tab in the dashboard with the given title. - * - * @param title the title of the tab to select - */ - void selectTab(String title); -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardTab.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardTab.java deleted file mode 100644 index b71255de763..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardTab.java +++ /dev/null @@ -1,154 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -import edu.wpi.first.networktables.NetworkTable; -import edu.wpi.first.util.function.FloatSupplier; -import edu.wpi.first.util.sendable.Sendable; -import java.util.List; -import java.util.function.BooleanSupplier; -import java.util.function.DoubleSupplier; -import java.util.function.LongSupplier; -import java.util.function.Supplier; - -/** - * Represents a tab in the Shuffleboard dashboard. Widgets can be added to the tab with {@link - * #add(Sendable)}, {@link #add(String, Object)}, and {@link #add(String, Sendable)}. Widgets can - * also be added to layouts with {@link #getLayout(String, String)}; layouts can be nested - * arbitrarily deep (note that too many levels may make deeper components unusable). - */ -public final class ShuffleboardTab implements ShuffleboardContainer { - private static final String kSmartDashboardType = "ShuffleboardTab"; - - private final ContainerHelper m_helper = new ContainerHelper(this); - private final ShuffleboardRoot m_root; - private final String m_title; - - ShuffleboardTab(ShuffleboardRoot root, String title) { - m_root = root; - m_title = title; - } - - @Override - public String getTitle() { - return m_title; - } - - ShuffleboardRoot getRoot() { - return m_root; - } - - @Override - public List> getComponents() { - return m_helper.getComponents(); - } - - @Override - public ShuffleboardLayout getLayout(String title, String type) { - return m_helper.getLayout(title, type); - } - - @Override - public ShuffleboardLayout getLayout(String title) { - return m_helper.getLayout(title); - } - - @Override - public ComplexWidget add(String title, Sendable sendable) { - return m_helper.add(title, sendable); - } - - @Override - public ComplexWidget add(Sendable sendable) { - return m_helper.add(sendable); - } - - @Override - public SimpleWidget add(String title, Object defaultValue) { - return m_helper.add(title, defaultValue); - } - - @Override - public SimpleWidget add(String title, String typeString, Object defaultValue) { - return m_helper.add(title, typeString, defaultValue); - } - - @Override - public SuppliedValueWidget addString(String title, Supplier valueSupplier) { - return m_helper.addString(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addNumber(String title, DoubleSupplier valueSupplier) { - return m_helper.addNumber(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addDouble(String title, DoubleSupplier valueSupplier) { - return m_helper.addDouble(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addFloat(String title, FloatSupplier valueSupplier) { - return m_helper.addFloat(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addInteger(String title, LongSupplier valueSupplier) { - return m_helper.addInteger(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addBoolean(String title, BooleanSupplier valueSupplier) { - return m_helper.addBoolean(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addStringArray( - String title, Supplier valueSupplier) { - return m_helper.addStringArray(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addDoubleArray( - String title, Supplier valueSupplier) { - return m_helper.addDoubleArray(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addFloatArray(String title, Supplier valueSupplier) { - return m_helper.addFloatArray(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addIntegerArray(String title, Supplier valueSupplier) { - return m_helper.addIntegerArray(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addBooleanArray( - String title, Supplier valueSupplier) { - return m_helper.addBooleanArray(title, valueSupplier); - } - - @Override - public SuppliedValueWidget addRaw( - String title, String typeString, Supplier valueSupplier) { - return m_helper.addRaw(title, typeString, valueSupplier); - } - - @Override - public void buildInto(NetworkTable parentTable, NetworkTable metaTable) { - NetworkTable tabTable = parentTable.getSubTable(m_title); - tabTable.getEntry(".type").setString(kSmartDashboardType); - tabTable - .getEntry(".type") - .getTopic() - .setProperty("SmartDashboard", "\"" + kSmartDashboardType + "\""); - for (ShuffleboardComponent component : m_helper.getComponents()) { - component.buildInto(tabTable, metaTable.getSubTable(component.getTitle())); - } - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardValue.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardValue.java deleted file mode 100644 index 88f43896728..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardValue.java +++ /dev/null @@ -1,27 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -import edu.wpi.first.networktables.NetworkTable; - -interface ShuffleboardValue { - /** - * Gets the title of this Shuffleboard value. - * - * @return The title of this Shuffleboard value. - */ - String getTitle(); - - /** - * Builds the entries for this value. - * - * @param parentTable the table containing all the data for the parent. Values that require a - * complex entry or table structure should call {@code parentTable.getSubTable(getTitle())} to - * get the table to put data into. Values that only use a single entry should call {@code - * parentTable.getEntry(getTitle())} to get that entry. - * @param metaTable the table containing all the metadata for this value and its sub-values - */ - void buildInto(NetworkTable parentTable, NetworkTable metaTable); -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardWidget.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardWidget.java deleted file mode 100644 index 39ce03613e9..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardWidget.java +++ /dev/null @@ -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. - -package edu.wpi.first.wpilibj.shuffleboard; - -/** - * Abstract superclass for widgets. - * - *

This class is package-private to minimize API surface area. - * - * @param the self type - */ -abstract class ShuffleboardWidget> - extends ShuffleboardComponent { - ShuffleboardWidget(ShuffleboardContainer parent, String title) { - super(parent, title); - } - - /** - * Sets the type of widget used to display the data. If not set, the default widget type will be - * used. - * - * @param widgetType the type of the widget used to display the data - * @return this widget object - * @see BuiltInWidgets - */ - public final W withWidget(WidgetType widgetType) { - return withWidget(widgetType.getWidgetName()); - } - - /** - * Sets the type of widget used to display the data. If not set, the default widget type will be - * used. This method should only be used to use a widget that does not come built into - * Shuffleboard (i.e. one that comes with a custom or third-party plugin). To use a widget that is - * built into Shuffleboard, use {@link #withWidget(WidgetType)} and {@link BuiltInWidgets}. - * - * @param widgetType the type of the widget used to display the data - * @return this widget object - */ - @SuppressWarnings("unchecked") - public final W withWidget(String widgetType) { - setType(widgetType); - return (W) this; - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/SimpleWidget.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/SimpleWidget.java deleted file mode 100644 index df914706596..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/SimpleWidget.java +++ /dev/null @@ -1,68 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -import edu.wpi.first.networktables.GenericEntry; -import edu.wpi.first.networktables.NetworkTable; - -/** A Shuffleboard widget that handles a single data point such as a number or string. */ -public final class SimpleWidget extends ShuffleboardWidget implements AutoCloseable { - private String m_typeString = ""; - private GenericEntry m_entry; - - SimpleWidget(ShuffleboardContainer parent, String title) { - super(parent, title); - } - - /** - * Gets the NetworkTable entry that contains the data for this widget. - * - * @return The NetworkTable entry that contains the data for this widget. - */ - public GenericEntry getEntry() { - if (m_entry == null) { - forceGenerate(); - } - return m_entry; - } - - /** - * Gets the NetworkTable entry that contains the data for this widget. - * - * @param typeString NetworkTable type string - * @return The NetworkTable entry that contains the data for this widget. - */ - public GenericEntry getEntry(String typeString) { - if (m_entry == null) { - m_typeString = typeString; - forceGenerate(); - } - return m_entry; - } - - @Override - public void close() { - if (m_entry != null) { - m_entry.close(); - } - } - - @Override - public void buildInto(NetworkTable parentTable, NetworkTable metaTable) { - buildMetadata(metaTable); - if (m_entry == null) { - m_entry = parentTable.getTopic(getTitle()).getGenericEntry(m_typeString); - } - } - - private void forceGenerate() { - ShuffleboardContainer parent = getParent(); - while (parent instanceof ShuffleboardLayout layout) { - parent = layout.getParent(); - } - ShuffleboardTab tab = (ShuffleboardTab) parent; - tab.getRoot().update(); - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/SuppliedValueWidget.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/SuppliedValueWidget.java deleted file mode 100644 index 355f4836886..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/SuppliedValueWidget.java +++ /dev/null @@ -1,71 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -import edu.wpi.first.networktables.BooleanPublisher; -import edu.wpi.first.networktables.BooleanTopic; -import edu.wpi.first.networktables.GenericPublisher; -import edu.wpi.first.networktables.NetworkTable; -import java.util.function.BiConsumer; -import java.util.function.Supplier; - -/** - * A Shuffleboard widget whose value is provided by user code. - * - * @param the type of values in the widget - */ -public final class SuppliedValueWidget extends ShuffleboardWidget> - implements AutoCloseable { - private final String m_typeString; - private final Supplier m_supplier; - private final BiConsumer m_setter; - private BooleanPublisher m_controllablePub; - private GenericPublisher m_entry; - - /** - * Package-private constructor for use by the Shuffleboard API. - * - * @param parent the parent container for the widget - * @param title the title of the widget - * @param typeString the NetworkTables string type - * @param supplier the supplier for values to place in the NetworkTable entry - * @param setter the function for placing values in the NetworkTable entry - */ - SuppliedValueWidget( - ShuffleboardContainer parent, - String title, - String typeString, - Supplier supplier, - BiConsumer setter) { - super(parent, title); - m_typeString = typeString; - m_supplier = supplier; - m_setter = setter; - } - - @Override - public void buildInto(NetworkTable parentTable, NetworkTable metaTable) { - buildMetadata(metaTable); - if (m_controllablePub == null) { - m_controllablePub = new BooleanTopic(metaTable.getTopic("Controllable")).publish(); - m_controllablePub.set(false); - } - - if (m_entry == null) { - m_entry = parentTable.getTopic(getTitle()).genericPublish(m_typeString); - } - m_setter.accept(m_entry, m_supplier.get()); - } - - @Override - public void close() { - if (m_controllablePub != null) { - m_controllablePub.close(); - } - if (m_entry != null) { - m_entry.close(); - } - } -} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/WidgetType.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/WidgetType.java deleted file mode 100644 index 3033f8efc80..00000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/shuffleboard/WidgetType.java +++ /dev/null @@ -1,20 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -/** - * Represents the type of a widget in Shuffleboard. Using this is preferred over specifying raw - * strings, to avoid typos and having to know or look up the exact string name for a desired widget. - * - * @see BuiltInWidgets the built-in widget types - */ -public interface WidgetType { - /** - * Gets the string type of the widget as defined by that widget in Shuffleboard. - * - * @return The string type of the widget. - */ - String getWidgetName(); -} diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/shuffleboard/MockActuatorSendable.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/shuffleboard/MockActuatorSendable.java deleted file mode 100644 index a630c3e1afb..00000000000 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/shuffleboard/MockActuatorSendable.java +++ /dev/null @@ -1,22 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -import edu.wpi.first.util.sendable.Sendable; -import edu.wpi.first.util.sendable.SendableBuilder; -import edu.wpi.first.util.sendable.SendableRegistry; - -/** A mock sendable that marks itself as an actuator. */ -public class MockActuatorSendable implements Sendable { - @SuppressWarnings("this-escape") - public MockActuatorSendable(String name) { - SendableRegistry.add(this, name); - } - - @Override - public void initSendable(SendableBuilder builder) { - builder.setActuator(true); - } -} diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/shuffleboard/SendableCameraWrapperTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/shuffleboard/SendableCameraWrapperTest.java deleted file mode 100644 index ed24453cbaa..00000000000 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/shuffleboard/SendableCameraWrapperTest.java +++ /dev/null @@ -1,65 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import edu.wpi.first.networktables.NetworkTableInstance; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -class SendableCameraWrapperTest { - NetworkTableInstance m_inst; - - @BeforeEach - void setup() { - m_inst = NetworkTableInstance.create(); - SendableCameraWrapper.clearWrappers(); - } - - @AfterEach - void tearDown() { - m_inst.close(); - } - - @Test - void testNullCameraName() { - assertThrows(NullPointerException.class, () -> SendableCameraWrapper.wrap(null, "")); - } - - @Test - void testEmptyCameraName() { - assertThrows(IllegalArgumentException.class, () -> SendableCameraWrapper.wrap("", "")); - } - - @Test - void testNullUrlArray() { - assertThrows( - NullPointerException.class, () -> SendableCameraWrapper.wrap("name", (String[]) null)); - } - - @Test - void testNullUrlInArray() { - assertThrows(NullPointerException.class, () -> SendableCameraWrapper.wrap("name", "url", null)); - } - - @Test - void testEmptyUrlArray() { - assertThrows(IllegalArgumentException.class, () -> SendableCameraWrapper.wrap("name")); - } - - @Test - void testUrlsAddedToNt() { - SendableCameraWrapper.wrap("name", "url1", "url2"); - assertArrayEquals( - new String[] {"url1", "url2"}, - NetworkTableInstance.getDefault() - .getEntry("/CameraPublisher/name/streams") - .getValue() - .getStringArray()); - } -} diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardInstanceTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardInstanceTest.java deleted file mode 100644 index 25b545b9713..00000000000 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardInstanceTest.java +++ /dev/null @@ -1,158 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import edu.wpi.first.networktables.GenericEntry; -import edu.wpi.first.networktables.NetworkTableEntry; -import edu.wpi.first.networktables.NetworkTableEvent.Kind; -import edu.wpi.first.networktables.NetworkTableInstance; -import edu.wpi.first.networktables.PubSubOption; -import edu.wpi.first.networktables.StringSubscriber; -import java.util.EnumSet; -import java.util.concurrent.atomic.AtomicInteger; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -class ShuffleboardInstanceTest { - private NetworkTableInstance m_ntInstance; - private ShuffleboardInstance m_shuffleboardInstance; - - @BeforeEach - void setupInstance() { - m_ntInstance = NetworkTableInstance.create(); - m_shuffleboardInstance = new ShuffleboardInstance(m_ntInstance); - } - - @AfterEach - void tearDownInstance() { - m_ntInstance.close(); - } - - @Test - void testPathFluent() { - GenericEntry entry = - m_shuffleboardInstance - .getTab("Tab Title") - .getLayout("Layout Title", "List Layout") - .add("Data", "string") - .withWidget("Text View") - .getEntry(); - - assertAll( - () -> assertEquals("string", entry.getString(null), "Wrong entry value"), - () -> - assertEquals( - "/Shuffleboard/Tab Title/Layout Title/Data", - entry.getTopic().getName(), - "Entry path generated incorrectly")); - } - - @Test - void testNestedLayoutsFluent() { - GenericEntry entry = - m_shuffleboardInstance - .getTab("Tab") - .getLayout("First", "List") - .getLayout("Second", "List") - .getLayout("Third", "List") - .getLayout("Fourth", "List") - .add("Value", "string") - .getEntry(); - - assertAll( - () -> assertEquals("string", entry.getString(null), "Wrong entry value"), - () -> - assertEquals( - "/Shuffleboard/Tab/First/Second/Third/Fourth/Value", - entry.getTopic().getName(), - "Entry path generated incorrectly")); - } - - @Test - void testNestedLayoutsOop() { - ShuffleboardTab tab = m_shuffleboardInstance.getTab("Tab"); - ShuffleboardLayout first = tab.getLayout("First", "List"); - ShuffleboardLayout second = first.getLayout("Second", "List"); - ShuffleboardLayout third = second.getLayout("Third", "List"); - ShuffleboardLayout fourth = third.getLayout("Fourth", "List"); - SimpleWidget widget = fourth.add("Value", "string"); - GenericEntry entry = widget.getEntry(); - - assertAll( - () -> assertEquals("string", entry.getString(null), "Wrong entry value"), - () -> - assertEquals( - "/Shuffleboard/Tab/First/Second/Third/Fourth/Value", - entry.getTopic().getName(), - "Entry path generated incorrectly")); - } - - @Test - void testLayoutTypeIsSet() { - String layoutType = "Type"; - m_shuffleboardInstance.getTab("Tab").getLayout("Title", layoutType); - m_shuffleboardInstance.update(); - NetworkTableEntry entry = - m_ntInstance.getEntry("/Shuffleboard/.metadata/Tab/Title/PreferredComponent"); - assertEquals(layoutType, entry.getString("Not Set"), "Layout type not set"); - } - - @Test - void testNestedActuatorWidgetsAreDisabled() { - m_shuffleboardInstance - .getTab("Tab") - .getLayout("Title", "Layout") - .add(new MockActuatorSendable("Actuator")); - NetworkTableEntry controllableEntry = - m_ntInstance.getEntry("/Shuffleboard/Tab/Title/Actuator/.controllable"); - - m_shuffleboardInstance.update(); - - // Note: we use the unsafe `getBoolean()` method because if the value is NOT a boolean, or if it - // is not present, then something has clearly gone very, very wrong - boolean controllable = controllableEntry.getValue().getBoolean(); - - // Sanity check - assertTrue(controllable, "The nested actuator widget should be enabled by default"); - m_shuffleboardInstance.disableActuatorWidgets(); - controllable = controllableEntry.getValue().getBoolean(); - assertFalse(controllable, "The nested actuator widget should have been disabled"); - } - - @Disabled("Fails often at counter assertion 'expected: <2> but was: <1>'") - @Test - void testDuplicateSelectTabs() { - int listener = 0; - AtomicInteger counter = new AtomicInteger(); - try (StringSubscriber subscriber = - m_ntInstance - .getStringTopic("/Shuffleboard/.metadata/Selected") - .subscribe("", PubSubOption.keepDuplicates(true))) { - listener = - m_ntInstance.addListener( - subscriber, - EnumSet.of(Kind.kValueAll, Kind.kImmediate), - event -> counter.incrementAndGet()); - - // There shouldn't be anything there - assertEquals(0, counter.get()); - - m_shuffleboardInstance.selectTab("tab1"); - m_shuffleboardInstance.selectTab("tab1"); - assertTrue(m_ntInstance.waitForListenerQueue(1.0), "Listener queue timed out!"); - assertEquals(2, counter.get()); - - } finally { - m_ntInstance.removeListener(listener); - } - } -} diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardTest.java deleted file mode 100644 index f4c8a8fbfd7..00000000000 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/shuffleboard/ShuffleboardTest.java +++ /dev/null @@ -1,25 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -import static org.junit.jupiter.api.Assertions.assertSame; - -import edu.wpi.first.wpilibj.UtilityClassTest; -import org.junit.jupiter.api.Test; - -class ShuffleboardTest extends UtilityClassTest { - ShuffleboardTest() { - super(Shuffleboard.class); - } - - // Most relevant tests are in ShuffleboardTabTest - - @Test - void testTabObjectsCached() { - ShuffleboardTab tab1 = Shuffleboard.getTab("testTabObjectsCached"); - ShuffleboardTab tab2 = Shuffleboard.getTab("testTabObjectsCached"); - assertSame(tab1, tab2, "Tab objects were not cached"); - } -} diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/shuffleboard/SuppliedValueWidgetTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/shuffleboard/SuppliedValueWidgetTest.java deleted file mode 100644 index 794d155b1d9..00000000000 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/shuffleboard/SuppliedValueWidgetTest.java +++ /dev/null @@ -1,112 +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. - -package edu.wpi.first.wpilibj.shuffleboard; - -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import edu.wpi.first.networktables.NetworkTableEntry; -import edu.wpi.first.networktables.NetworkTableInstance; -import java.util.concurrent.atomic.AtomicInteger; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -class SuppliedValueWidgetTest { - private NetworkTableInstance m_ntInstance; - private ShuffleboardInstance m_instance; - - @BeforeEach - void setup() { - m_ntInstance = NetworkTableInstance.create(); - m_instance = new ShuffleboardInstance(m_ntInstance); - } - - @AfterEach - void tearDown() { - m_ntInstance.close(); - } - - @Test - void testAddString() { - AtomicInteger count = new AtomicInteger(0); - m_instance.getTab("Tab").addString("Title", () -> Integer.toString(count.incrementAndGet())); - NetworkTableEntry entry = m_ntInstance.getEntry("/Shuffleboard/Tab/Title"); - - m_instance.update(); - assertEquals("1", entry.getString(null)); - - m_instance.update(); - assertEquals("2", entry.getString(null)); - } - - @Test - void testAddDouble() { - AtomicInteger num = new AtomicInteger(0); - m_instance.getTab("Tab").addNumber("Title", num::incrementAndGet); - NetworkTableEntry entry = m_ntInstance.getEntry("/Shuffleboard/Tab/Title"); - - m_instance.update(); - assertEquals(1, entry.getDouble(0)); - - m_instance.update(); - assertEquals(2, entry.getDouble(0)); - } - - @Test - void testAddBoolean() { - boolean[] bool = {false}; - m_instance.getTab("Tab").addBoolean("Title", () -> bool[0] = !bool[0]); - NetworkTableEntry entry = m_ntInstance.getEntry("/Shuffleboard/Tab/Title"); - - m_instance.update(); - assertTrue(entry.getBoolean(false)); - - m_instance.update(); - assertFalse(entry.getBoolean(true)); - } - - @Test - void testAddStringArray() { - String[] arr = {"foo", "bar"}; - m_instance.getTab("Tab").addStringArray("Title", () -> arr); - NetworkTableEntry entry = m_ntInstance.getEntry("/Shuffleboard/Tab/Title"); - - m_instance.update(); - assertArrayEquals(arr, entry.getStringArray(new String[0])); - } - - @Test - void testAddDoubleArray() { - double[] arr = {0, 1}; - m_instance.getTab("Tab").addDoubleArray("Title", () -> arr); - NetworkTableEntry entry = m_ntInstance.getEntry("/Shuffleboard/Tab/Title"); - - m_instance.update(); - assertArrayEquals(arr, entry.getDoubleArray(new double[0])); - } - - @Test - void testAddBooleanArray() { - boolean[] arr = {true, false}; - m_instance.getTab("Tab").addBooleanArray("Title", () -> arr); - NetworkTableEntry entry = m_ntInstance.getEntry("/Shuffleboard/Tab/Title"); - - m_instance.update(); - assertArrayEquals(arr, entry.getBooleanArray(new boolean[0])); - } - - @Test - void testAddRawBytes() { - byte[] arr = {0, 1, 2, 3}; - m_instance.getTab("Tab").addRaw("Title", () -> arr); - NetworkTableEntry entry = m_ntInstance.getEntry("/Shuffleboard/Tab/Title"); - - m_instance.update(); - assertArrayEquals(arr, entry.getRaw(new byte[0])); - } -} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json index 5fab0669611..ac667693ce7 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json @@ -68,7 +68,6 @@ "tags": [ "Hardware", "Joystick", - "Shuffleboard", "Pneumatics" ], "foldername": "solenoid", @@ -108,8 +107,7 @@ "tags": [ "Hardware", "Ultrasonic", - "SmartDashboard", - "Shuffleboard" + "SmartDashboard" ], "foldername": "ultrasonic", "gradlebase": "java", @@ -308,22 +306,6 @@ "mainclass": "Main", "commandversion": 2 }, - { - "name": "Shuffleboard", - "description": "Present various data via the Shuffleboard API.", - "tags": [ - "Basic Robot", - "Differential Drive", - "Elevator", - "Analog", - "Encoder", - "Shuffleboard" - ], - "foldername": "shuffleboard", - "gradlebase": "java", - "mainclass": "Main", - "commandversion": 2 - }, { "name": "'Traditional' Hatchbot", "description": "A fully-functional command-based hatchbot for the 2019 game, written in the 'traditional' style, i.e. commands are given their own classes.", @@ -333,7 +315,6 @@ "Differential Drive", "Encoder", "Pneumatics", - "Shuffleboard", "Sendable", "DataLog", "XboxController" @@ -352,7 +333,6 @@ "Differential Drive", "Encoder", "Pneumatics", - "Shuffleboard", "Sendable", "DataLog", "PS4Controller" diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/RobotContainer.java index 2d7cedf4682..f4454aa2de5 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/RobotContainer.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbotinlined/RobotContainer.java @@ -9,11 +9,9 @@ import edu.wpi.first.wpilibj.examples.hatchbotinlined.commands.Autos; import edu.wpi.first.wpilibj.examples.hatchbotinlined.subsystems.DriveSubsystem; import edu.wpi.first.wpilibj.examples.hatchbotinlined.subsystems.HatchSubsystem; -import edu.wpi.first.wpilibj.shuffleboard.EventImportance; -import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import edu.wpi.first.wpilibj2.command.Command; -import edu.wpi.first.wpilibj2.command.CommandScheduler; import edu.wpi.first.wpilibj2.command.Commands; import edu.wpi.first.wpilibj2.command.button.CommandPS4Controller; @@ -64,28 +62,11 @@ public RobotContainer() { m_chooser.addOption("Complex Auto", m_complexAuto); // Put the chooser on the dashboard - Shuffleboard.getTab("Autonomous").add(m_chooser); + SmartDashboard.putData("Autonomous", m_chooser); // Put subsystems to dashboard. - Shuffleboard.getTab("Drivetrain").add(m_robotDrive); - Shuffleboard.getTab("HatchSubsystem").add(m_hatchSubsystem); - - // Set the scheduler to log Shuffleboard events for command initialize, interrupt, finish - CommandScheduler.getInstance() - .onCommandInitialize( - command -> - Shuffleboard.addEventMarker( - "Command initialized", command.getName(), EventImportance.kNormal)); - CommandScheduler.getInstance() - .onCommandInterrupt( - command -> - Shuffleboard.addEventMarker( - "Command interrupted", command.getName(), EventImportance.kNormal)); - CommandScheduler.getInstance() - .onCommandFinish( - command -> - Shuffleboard.addEventMarker( - "Command finished", command.getName(), EventImportance.kNormal)); + SmartDashboard.putData("Drivetrain", m_robotDrive); + SmartDashboard.putData("HatchSubsystem", m_hatchSubsystem); } /** diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbottraditional/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbottraditional/RobotContainer.java index 5bf05b4dd4b..24af4abc2f2 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbottraditional/RobotContainer.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/hatchbottraditional/RobotContainer.java @@ -17,11 +17,9 @@ import edu.wpi.first.wpilibj.examples.hatchbottraditional.commands.ReleaseHatch; import edu.wpi.first.wpilibj.examples.hatchbottraditional.subsystems.DriveSubsystem; import edu.wpi.first.wpilibj.examples.hatchbottraditional.subsystems.HatchSubsystem; -import edu.wpi.first.wpilibj.shuffleboard.EventImportance; -import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; import edu.wpi.first.wpilibj2.command.Command; -import edu.wpi.first.wpilibj2.command.CommandScheduler; import edu.wpi.first.wpilibj2.command.button.JoystickButton; /** @@ -71,32 +69,10 @@ public RobotContainer() { m_chooser.addOption("Complex Auto", m_complexAuto); // Put the chooser on the dashboard - Shuffleboard.getTab("Autonomous").add(m_chooser); + SmartDashboard.putData("Autonomous", m_chooser); // Put subsystems to dashboard. - Shuffleboard.getTab("Drivetrain").add(m_robotDrive); - Shuffleboard.getTab("HatchSubsystem").add(m_hatchSubsystem); - - // Log Shuffleboard events for command initialize, execute, finish, interrupt - CommandScheduler.getInstance() - .onCommandInitialize( - command -> - Shuffleboard.addEventMarker( - "Command initialized", command.getName(), EventImportance.kNormal)); - CommandScheduler.getInstance() - .onCommandExecute( - command -> - Shuffleboard.addEventMarker( - "Command executed", command.getName(), EventImportance.kNormal)); - CommandScheduler.getInstance() - .onCommandFinish( - command -> - Shuffleboard.addEventMarker( - "Command finished", command.getName(), EventImportance.kNormal)); - CommandScheduler.getInstance() - .onCommandInterrupt( - command -> - Shuffleboard.addEventMarker( - "Command interrupted", command.getName(), EventImportance.kNormal)); + SmartDashboard.putData("Drivetrain", m_robotDrive); + SmartDashboard.putData("HatchSubsystem", m_hatchSubsystem); } /** diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/shuffleboard/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/shuffleboard/Main.java deleted file mode 100644 index 8a7a1c82c75..00000000000 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/shuffleboard/Main.java +++ /dev/null @@ -1,25 +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. - -package edu.wpi.first.wpilibj.examples.shuffleboard; - -import edu.wpi.first.wpilibj.RobotBase; - -/** - * Do NOT add any static variables to this class, or any initialization at all. Unless you know what - * you are doing, do not modify this file except to change the parameter class to the startRobot - * call. - */ -public final class Main { - private Main() {} - - /** - * Main initialization function. Do not perform any initialization here. - * - *

If you change your main robot class, change the parameter type. - */ - public static void main(String... args) { - RobotBase.startRobot(Robot::new); - } -} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/shuffleboard/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/shuffleboard/Robot.java deleted file mode 100644 index 8825b687444..00000000000 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/shuffleboard/Robot.java +++ /dev/null @@ -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. - -package edu.wpi.first.wpilibj.examples.shuffleboard; - -import edu.wpi.first.networktables.GenericEntry; -import edu.wpi.first.util.sendable.SendableRegistry; -import edu.wpi.first.wpilibj.AnalogPotentiometer; -import edu.wpi.first.wpilibj.Encoder; -import edu.wpi.first.wpilibj.TimedRobot; -import edu.wpi.first.wpilibj.drive.DifferentialDrive; -import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax; -import edu.wpi.first.wpilibj.shuffleboard.BuiltInLayouts; -import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; -import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardLayout; -import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab; - -public class Robot extends TimedRobot { - private final PWMSparkMax m_leftDriveMotor = new PWMSparkMax(0); - private final PWMSparkMax m_rightDriveMotor = new PWMSparkMax(1); - private final DifferentialDrive m_tankDrive = - new DifferentialDrive(m_leftDriveMotor::set, m_rightDriveMotor::set); - private final Encoder m_leftEncoder = new Encoder(0, 1); - private final Encoder m_rightEncoder = new Encoder(2, 3); - - private final PWMSparkMax m_elevatorMotor = new PWMSparkMax(2); - private final AnalogPotentiometer m_elevatorPot = new AnalogPotentiometer(0); - private final GenericEntry m_maxSpeed; - - /** Called once at the beginning of the robot program. */ - public Robot() { - SendableRegistry.addChild(m_tankDrive, m_leftDriveMotor); - SendableRegistry.addChild(m_tankDrive, m_rightDriveMotor); - - // Add a 'max speed' widget to a tab named 'Configuration', using a number slider - // The widget will be placed in the second column and row and will be TWO columns wide - m_maxSpeed = - Shuffleboard.getTab("Configuration") - .add("Max Speed", 1) - .withWidget("Number Slider") - .withPosition(1, 1) - .withSize(2, 1) - .getEntry(); - - // Add the tank drive and encoders to a 'Drivebase' tab - ShuffleboardTab driveBaseTab = Shuffleboard.getTab("Drivebase"); - driveBaseTab.add("Tank Drive", m_tankDrive); - // Put both encoders in a list layout - ShuffleboardLayout encoders = - driveBaseTab.getLayout("Encoders", BuiltInLayouts.kList).withPosition(0, 0).withSize(2, 2); - encoders.add("Left Encoder", m_leftEncoder); - encoders.add("Right Encoder", m_rightEncoder); - - // Add the elevator motor and potentiometer to an 'Elevator' tab - ShuffleboardTab elevatorTab = Shuffleboard.getTab("Elevator"); - elevatorTab.add("Motor", m_elevatorMotor); - elevatorTab.add("Potentiometer", m_elevatorPot); - } - - @Override - public void autonomousInit() { - // Read the value of the 'max speed' widget from the dashboard - m_tankDrive.setMaxOutput(m_maxSpeed.getDouble(1.0)); - } -} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/solenoid/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/solenoid/Robot.java index d4346f02bc7..babff17e808 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/solenoid/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/solenoid/Robot.java @@ -10,8 +10,7 @@ import edu.wpi.first.wpilibj.PneumaticsModuleType; import edu.wpi.first.wpilibj.Solenoid; import edu.wpi.first.wpilibj.TimedRobot; -import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; -import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab; +import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; /** * This is a sample program showing the use of the solenoid classes during operator control. Three @@ -46,29 +45,28 @@ public class Robot extends TimedRobot { /** Called once at the beginning of the robot program. */ public Robot() { - // Publish elements to shuffleboard. - ShuffleboardTab tab = Shuffleboard.getTab("Pneumatics"); - tab.add("Single Solenoid", m_solenoid); - tab.add("Double Solenoid", m_doubleSolenoid); - tab.add("Compressor", m_compressor); + // Publish elements to dashboard. + SmartDashboard.putData("Single Solenoid", m_solenoid); + SmartDashboard.putData("Double Solenoid", m_doubleSolenoid); + SmartDashboard.putData("Compressor", m_compressor); + } - // Also publish some raw data + @SuppressWarnings("PMD.UnconditionalIfStatement") + @Override + public void teleopPeriodic() { + // Publish some raw data // Get the pressure (in PSI) from the analog sensor connected to the PH. // This function is supported only on the PH! // On a PCM, this function will return 0. - tab.addDouble("PH Pressure [PSI]", m_compressor::getPressure); + SmartDashboard.putNumber("PH Pressure [PSI]", m_compressor.getPressure()); // Get compressor current draw. - tab.addDouble("Compressor Current", m_compressor::getCurrent); + SmartDashboard.putNumber("Compressor Current", m_compressor.getCurrent()); // Get whether the compressor is active. - tab.addBoolean("Compressor Active", m_compressor::isEnabled); + SmartDashboard.putBoolean("Compressor Active", m_compressor.isEnabled()); // Get the digital pressure switch connected to the PCM/PH. // The switch is open when the pressure is over ~120 PSI. - tab.addBoolean("Pressure Switch", m_compressor::getPressureSwitchValue); - } + SmartDashboard.putBoolean("Pressure Switch", m_compressor.getPressureSwitchValue()); - @SuppressWarnings("PMD.UnconditionalIfStatement") - @Override - public void teleopPeriodic() { /* * The output of GetRawButton is true/false depending on whether * the button is pressed; Set takes a boolean for whether diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonic/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonic/Robot.java index 602e58abe5b..8727f92ff42 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonic/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonic/Robot.java @@ -6,7 +6,6 @@ import edu.wpi.first.wpilibj.TimedRobot; import edu.wpi.first.wpilibj.Ultrasonic; -import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; /** @@ -21,7 +20,7 @@ public class Robot extends TimedRobot { public Robot() { // Add the ultrasonic on the "Sensors" tab of the dashboard // Data will update automatically - Shuffleboard.getTab("Sensors").add(m_rangeFinder); + SmartDashboard.putData("Sensors", m_rangeFinder); } @Override