mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
SCRIPT namespace replacements
This commit is contained in:
committed by
Peter Johnson
parent
ae6c043632
commit
9aca8e0fd6
@@ -11,13 +11,13 @@
|
||||
#include "wpi/nt/NTSendableBuilder.hpp"
|
||||
#include "wpi/util/sendable/SendableRegistry.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
Field2d::Field2d() {
|
||||
m_objects.emplace_back(
|
||||
std::make_unique<FieldObject2d>("Robot", FieldObject2d::private_init{}));
|
||||
m_objects[0]->SetPose(Pose2d{});
|
||||
wpi::SendableRegistry::Add(this, "Field");
|
||||
m_objects[0]->SetPose(wpi::math::Pose2d{});
|
||||
wpi::util::SendableRegistry::Add(this, "Field");
|
||||
}
|
||||
|
||||
Field2d::Field2d(Field2d&& rhs) : SendableHelper(std::move(rhs)) {
|
||||
@@ -34,18 +34,18 @@ Field2d& Field2d::operator=(Field2d&& rhs) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Field2d::SetRobotPose(const Pose2d& pose) {
|
||||
void Field2d::SetRobotPose(const wpi::math::Pose2d& pose) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
m_objects[0]->SetPose(pose);
|
||||
}
|
||||
|
||||
void Field2d::SetRobotPose(units::meter_t x, units::meter_t y,
|
||||
Rotation2d rotation) {
|
||||
void Field2d::SetRobotPose(wpi::units::meter_t x, wpi::units::meter_t y,
|
||||
wpi::math::Rotation2d rotation) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
m_objects[0]->SetPose(x, y, rotation);
|
||||
}
|
||||
|
||||
Pose2d Field2d::GetRobotPose() const {
|
||||
wpi::math::Pose2d Field2d::GetRobotPose() const {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
return m_objects[0]->GetPose();
|
||||
}
|
||||
@@ -71,7 +71,7 @@ FieldObject2d* Field2d::GetRobotObject() {
|
||||
return m_objects[0].get();
|
||||
}
|
||||
|
||||
void Field2d::InitSendable(nt::NTSendableBuilder& builder) {
|
||||
void Field2d::InitSendable(wpi::nt::NTSendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Field2d");
|
||||
|
||||
std::scoped_lock lock(m_mutex);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "wpi/math/trajectory/Trajectory.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
FieldObject2d::FieldObject2d(FieldObject2d&& rhs) {
|
||||
std::swap(m_name, rhs.m_name);
|
||||
@@ -25,16 +25,16 @@ FieldObject2d& FieldObject2d::operator=(FieldObject2d&& rhs) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
void FieldObject2d::SetPose(const Pose2d& pose) {
|
||||
void FieldObject2d::SetPose(const wpi::math::Pose2d& pose) {
|
||||
SetPoses({pose});
|
||||
}
|
||||
|
||||
void FieldObject2d::SetPose(units::meter_t x, units::meter_t y,
|
||||
Rotation2d rotation) {
|
||||
void FieldObject2d::SetPose(wpi::units::meter_t x, wpi::units::meter_t y,
|
||||
wpi::math::Rotation2d rotation) {
|
||||
SetPoses({{x, y, rotation}});
|
||||
}
|
||||
|
||||
Pose2d FieldObject2d::GetPose() const {
|
||||
wpi::math::Pose2d FieldObject2d::GetPose() const {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
UpdateFromEntry();
|
||||
if (m_poses.empty()) {
|
||||
@@ -43,17 +43,17 @@ Pose2d FieldObject2d::GetPose() const {
|
||||
return m_poses[0];
|
||||
}
|
||||
|
||||
void FieldObject2d::SetPoses(std::span<const Pose2d> poses) {
|
||||
void FieldObject2d::SetPoses(std::span<const wpi::math::Pose2d> poses) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
m_poses.assign(poses.begin(), poses.end());
|
||||
UpdateEntry();
|
||||
}
|
||||
|
||||
void FieldObject2d::SetPoses(std::initializer_list<Pose2d> poses) {
|
||||
void FieldObject2d::SetPoses(std::initializer_list<wpi::math::Pose2d> poses) {
|
||||
SetPoses({poses.begin(), poses.end()});
|
||||
}
|
||||
|
||||
void FieldObject2d::SetTrajectory(const Trajectory& trajectory) {
|
||||
void FieldObject2d::SetTrajectory(const wpi::math::Trajectory& trajectory) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
m_poses.clear();
|
||||
m_poses.reserve(trajectory.States().size());
|
||||
@@ -63,14 +63,14 @@ void FieldObject2d::SetTrajectory(const Trajectory& trajectory) {
|
||||
UpdateEntry();
|
||||
}
|
||||
|
||||
std::vector<Pose2d> FieldObject2d::GetPoses() const {
|
||||
std::vector<wpi::math::Pose2d> FieldObject2d::GetPoses() const {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
UpdateFromEntry();
|
||||
return std::vector<Pose2d>(m_poses.begin(), m_poses.end());
|
||||
return std::vector<wpi::math::Pose2d>(m_poses.begin(), m_poses.end());
|
||||
}
|
||||
|
||||
std::span<const Pose2d> FieldObject2d::GetPoses(
|
||||
wpi::SmallVectorImpl<Pose2d>& out) const {
|
||||
std::span<const wpi::math::Pose2d> FieldObject2d::GetPoses(
|
||||
wpi::util::SmallVectorImpl<wpi::math::Pose2d>& out) const {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
UpdateFromEntry();
|
||||
out.assign(m_poses.begin(), m_poses.end());
|
||||
@@ -81,7 +81,7 @@ void FieldObject2d::UpdateEntry(bool setDefault) {
|
||||
if (!m_entry) {
|
||||
return;
|
||||
}
|
||||
wpi::SmallVector<double, 9> arr;
|
||||
wpi::util::SmallVector<double, 9> arr;
|
||||
for (auto&& pose : m_poses) {
|
||||
auto& translation = pose.Translation();
|
||||
arr.push_back(translation.X().value());
|
||||
@@ -107,7 +107,7 @@ void FieldObject2d::UpdateFromEntry() const {
|
||||
m_poses.resize(size / 3);
|
||||
for (size_t i = 0; i < size / 3; ++i) {
|
||||
m_poses[i] =
|
||||
Pose2d{units::meter_t{arr[i * 3 + 0]}, units::meter_t{arr[i * 3 + 1]},
|
||||
units::degree_t{arr[i * 3 + 2]}};
|
||||
wpi::math::Pose2d{wpi::units::meter_t{arr[i * 3 + 0]}, wpi::units::meter_t{arr[i * 3 + 1]},
|
||||
wpi::units::degree_t{arr[i * 3 + 2]}};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
using namespace frc::detail;
|
||||
using namespace wpi::detail;
|
||||
|
||||
void ListenerExecutor::Execute(std::function<void()> task) {
|
||||
std::scoped_lock lock(m_lock);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "wpi/nt/NTSendableBuilder.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
static constexpr std::string_view kBackgroundColor = "backgroundColor";
|
||||
static constexpr std::string_view kDims = "dims";
|
||||
@@ -37,7 +37,7 @@ void Mechanism2d::SetBackgroundColor(const Color8Bit& color) {
|
||||
}
|
||||
}
|
||||
|
||||
void Mechanism2d::InitSendable(nt::NTSendableBuilder& builder) {
|
||||
void Mechanism2d::InitSendable(wpi::nt::NTSendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Mechanism2d");
|
||||
|
||||
std::scoped_lock lock(m_mutex);
|
||||
|
||||
@@ -10,14 +10,14 @@
|
||||
#include "wpi/util/StringExtras.hpp"
|
||||
#include "wpi/util/json.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
static constexpr std::string_view kSmartDashboardType = "line";
|
||||
|
||||
MechanismLigament2d::MechanismLigament2d(std::string_view name, double length,
|
||||
units::degree_t angle,
|
||||
wpi::units::degree_t angle,
|
||||
double lineWeight,
|
||||
const frc::Color8Bit& color)
|
||||
const wpi::Color8Bit& color)
|
||||
: MechanismObject2d{name},
|
||||
m_length{length},
|
||||
m_angle{angle.value()},
|
||||
@@ -26,9 +26,9 @@ MechanismLigament2d::MechanismLigament2d(std::string_view name, double length,
|
||||
}
|
||||
|
||||
void MechanismLigament2d::UpdateEntries(
|
||||
std::shared_ptr<nt::NetworkTable> table) {
|
||||
std::shared_ptr<wpi::nt::NetworkTable> table) {
|
||||
m_typePub = table->GetStringTopic(".type").PublishEx(
|
||||
nt::StringTopic::kTypeString, {{"SmartDashboard", kSmartDashboardType}});
|
||||
wpi::nt::StringTopic::kTypeString, {{"SmartDashboard", kSmartDashboardType}});
|
||||
m_typePub.Set(kSmartDashboardType);
|
||||
|
||||
m_colorEntry = table->GetStringTopic("color").GetEntry("");
|
||||
@@ -44,7 +44,7 @@ void MechanismLigament2d::UpdateEntries(
|
||||
void MechanismLigament2d::SetColor(const Color8Bit& color) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
|
||||
wpi::format_to_n_c_str(m_color, sizeof(m_color), "#{:02X}{:02X}{:02X}",
|
||||
wpi::util::format_to_n_c_str(m_color, sizeof(m_color), "#{:02X}{:02X}{:02X}",
|
||||
color.red, color.green, color.blue);
|
||||
|
||||
if (m_colorEntry) {
|
||||
@@ -52,7 +52,7 @@ void MechanismLigament2d::SetColor(const Color8Bit& color) {
|
||||
}
|
||||
}
|
||||
|
||||
void MechanismLigament2d::SetAngle(units::degree_t angle) {
|
||||
void MechanismLigament2d::SetAngle(wpi::units::degree_t angle) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
m_angle = angle.value();
|
||||
if (m_angleEntry) {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
MechanismObject2d::MechanismObject2d(std::string_view name) : m_name{name} {}
|
||||
|
||||
@@ -14,7 +14,7 @@ const std::string& MechanismObject2d::GetName() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void MechanismObject2d::Update(std::shared_ptr<nt::NetworkTable> table) {
|
||||
void MechanismObject2d::Update(std::shared_ptr<wpi::nt::NetworkTable> table) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
m_table = table;
|
||||
UpdateEntries(m_table);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "wpi/util/Color8Bit.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
MechanismRoot2d::MechanismRoot2d(std::string_view name, double x, double y,
|
||||
const private_init&)
|
||||
@@ -19,7 +19,7 @@ void MechanismRoot2d::SetPosition(double x, double y) {
|
||||
Flush();
|
||||
}
|
||||
|
||||
void MechanismRoot2d::UpdateEntries(std::shared_ptr<nt::NetworkTable> table) {
|
||||
void MechanismRoot2d::UpdateEntries(std::shared_ptr<wpi::nt::NetworkTable> table) {
|
||||
m_xPub = table->GetDoubleTopic("x").Publish();
|
||||
m_yPub = table->GetDoubleTopic("y").Publish();
|
||||
Flush();
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "wpi/util/SmallVector.hpp"
|
||||
#include "wpi/util/json.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
template <typename Topic>
|
||||
void SendableBuilderImpl::PropertyImpl<Topic>::Update(bool controllable,
|
||||
@@ -35,13 +35,13 @@ void SendableBuilderImpl::PropertyImpl<Topic>::Update(bool controllable,
|
||||
}
|
||||
}
|
||||
|
||||
void SendableBuilderImpl::SetTable(std::shared_ptr<nt::NetworkTable> table) {
|
||||
void SendableBuilderImpl::SetTable(std::shared_ptr<wpi::nt::NetworkTable> table) {
|
||||
m_table = table;
|
||||
m_controllablePublisher = table->GetBooleanTopic(".controllable").Publish();
|
||||
m_controllablePublisher.SetDefault(false);
|
||||
}
|
||||
|
||||
std::shared_ptr<nt::NetworkTable> SendableBuilderImpl::GetTable() {
|
||||
std::shared_ptr<wpi::nt::NetworkTable> SendableBuilderImpl::GetTable() {
|
||||
return m_table;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ bool SendableBuilderImpl::IsActuator() const {
|
||||
}
|
||||
|
||||
void SendableBuilderImpl::Update() {
|
||||
uint64_t time = nt::Now();
|
||||
uint64_t time = wpi::nt::Now();
|
||||
for (auto& property : m_properties) {
|
||||
property->Update(m_controllable, time);
|
||||
}
|
||||
@@ -84,7 +84,7 @@ void SendableBuilderImpl::ClearProperties() {
|
||||
void SendableBuilderImpl::SetSmartDashboardType(std::string_view type) {
|
||||
if (!m_typePublisher) {
|
||||
m_typePublisher = m_table->GetStringTopic(".type").PublishEx(
|
||||
nt::StringTopic::kTypeString, {{"SmartDashboard", type}});
|
||||
wpi::nt::StringTopic::kTypeString, {{"SmartDashboard", type}});
|
||||
}
|
||||
m_typePublisher.Set(type);
|
||||
}
|
||||
@@ -97,11 +97,11 @@ void SendableBuilderImpl::SetActuator(bool value) {
|
||||
m_actuator = value;
|
||||
}
|
||||
|
||||
void SendableBuilderImpl::SetUpdateTable(wpi::unique_function<void()> func) {
|
||||
void SendableBuilderImpl::SetUpdateTable(wpi::util::unique_function<void()> func) {
|
||||
m_updateTables.emplace_back(std::move(func));
|
||||
}
|
||||
|
||||
nt::Topic SendableBuilderImpl::GetTopic(std::string_view key) {
|
||||
wpi::nt::Topic SendableBuilderImpl::GetTopic(std::string_view key) {
|
||||
return m_table->GetTopic(key);
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ void SendableBuilderImpl::AddRawProperty(
|
||||
std::function<std::vector<uint8_t>()> getter,
|
||||
std::function<void(std::span<const uint8_t>)> setter) {
|
||||
auto topic = m_table->GetRawTopic(key);
|
||||
auto prop = std::make_unique<PropertyImpl<nt::RawTopic>>();
|
||||
auto prop = std::make_unique<PropertyImpl<wpi::nt::RawTopic>>();
|
||||
if (getter) {
|
||||
prop->pub = topic.Publish(typeString);
|
||||
prop->updateNetwork = [=](auto& pub, int64_t time) {
|
||||
@@ -282,7 +282,7 @@ void SendableBuilderImpl::PublishConstRaw(std::string_view key,
|
||||
std::string_view typeString,
|
||||
std::span<const uint8_t> value) {
|
||||
auto topic = m_table->GetRawTopic(key);
|
||||
auto prop = std::make_unique<PropertyImpl<nt::RawTopic>>();
|
||||
auto prop = std::make_unique<PropertyImpl<wpi::nt::RawTopic>>();
|
||||
prop->pub = topic.Publish(typeString);
|
||||
prop->pub.Set(value);
|
||||
m_properties.emplace_back(std::move(prop));
|
||||
@@ -296,7 +296,7 @@ void SendableBuilderImpl::AddSmallPropertyImpl(Topic topic, Getter getter,
|
||||
if (getter) {
|
||||
prop->pub = topic.Publish();
|
||||
prop->updateNetwork = [=](auto& pub, int64_t time) {
|
||||
wpi::SmallVector<T, Size> buf;
|
||||
wpi::util::SmallVector<T, Size> buf;
|
||||
pub.Set(getter(buf), time);
|
||||
};
|
||||
}
|
||||
@@ -314,7 +314,7 @@ void SendableBuilderImpl::AddSmallPropertyImpl(Topic topic, Getter getter,
|
||||
|
||||
void SendableBuilderImpl::AddSmallStringProperty(
|
||||
std::string_view key,
|
||||
std::function<std::string_view(wpi::SmallVectorImpl<char>& buf)> getter,
|
||||
std::function<std::string_view(wpi::util::SmallVectorImpl<char>& buf)> getter,
|
||||
std::function<void(std::string_view)> setter) {
|
||||
AddSmallPropertyImpl<char, 128>(m_table->GetStringTopic(key),
|
||||
std::move(getter), std::move(setter));
|
||||
@@ -322,7 +322,7 @@ void SendableBuilderImpl::AddSmallStringProperty(
|
||||
|
||||
void SendableBuilderImpl::AddSmallBooleanArrayProperty(
|
||||
std::string_view key,
|
||||
std::function<std::span<const int>(wpi::SmallVectorImpl<int>& buf)> getter,
|
||||
std::function<std::span<const int>(wpi::util::SmallVectorImpl<int>& buf)> getter,
|
||||
std::function<void(std::span<const int>)> setter) {
|
||||
AddSmallPropertyImpl<int, 16>(m_table->GetBooleanArrayTopic(key),
|
||||
std::move(getter), std::move(setter));
|
||||
@@ -330,7 +330,7 @@ void SendableBuilderImpl::AddSmallBooleanArrayProperty(
|
||||
|
||||
void SendableBuilderImpl::AddSmallIntegerArrayProperty(
|
||||
std::string_view key,
|
||||
std::function<std::span<const int64_t>(wpi::SmallVectorImpl<int64_t>& buf)>
|
||||
std::function<std::span<const int64_t>(wpi::util::SmallVectorImpl<int64_t>& buf)>
|
||||
getter,
|
||||
std::function<void(std::span<const int64_t>)> setter) {
|
||||
AddSmallPropertyImpl<int64_t, 16>(m_table->GetIntegerArrayTopic(key),
|
||||
@@ -339,7 +339,7 @@ void SendableBuilderImpl::AddSmallIntegerArrayProperty(
|
||||
|
||||
void SendableBuilderImpl::AddSmallFloatArrayProperty(
|
||||
std::string_view key,
|
||||
std::function<std::span<const float>(wpi::SmallVectorImpl<float>& buf)>
|
||||
std::function<std::span<const float>(wpi::util::SmallVectorImpl<float>& buf)>
|
||||
getter,
|
||||
std::function<void(std::span<const float>)> setter) {
|
||||
AddSmallPropertyImpl<float, 16>(m_table->GetFloatArrayTopic(key),
|
||||
@@ -348,7 +348,7 @@ void SendableBuilderImpl::AddSmallFloatArrayProperty(
|
||||
|
||||
void SendableBuilderImpl::AddSmallDoubleArrayProperty(
|
||||
std::string_view key,
|
||||
std::function<std::span<const double>(wpi::SmallVectorImpl<double>& buf)>
|
||||
std::function<std::span<const double>(wpi::util::SmallVectorImpl<double>& buf)>
|
||||
getter,
|
||||
std::function<void(std::span<const double>)> setter) {
|
||||
AddSmallPropertyImpl<double, 16>(m_table->GetDoubleArrayTopic(key),
|
||||
@@ -358,7 +358,7 @@ void SendableBuilderImpl::AddSmallDoubleArrayProperty(
|
||||
void SendableBuilderImpl::AddSmallStringArrayProperty(
|
||||
std::string_view key,
|
||||
std::function<
|
||||
std::span<const std::string>(wpi::SmallVectorImpl<std::string>& buf)>
|
||||
std::span<const std::string>(wpi::util::SmallVectorImpl<std::string>& buf)>
|
||||
getter,
|
||||
std::function<void(std::span<const std::string>)> setter) {
|
||||
AddSmallPropertyImpl<std::string, 16>(m_table->GetStringArrayTopic(key),
|
||||
@@ -367,15 +367,15 @@ void SendableBuilderImpl::AddSmallStringArrayProperty(
|
||||
|
||||
void SendableBuilderImpl::AddSmallRawProperty(
|
||||
std::string_view key, std::string_view typeString,
|
||||
std::function<std::span<uint8_t>(wpi::SmallVectorImpl<uint8_t>& buf)>
|
||||
std::function<std::span<uint8_t>(wpi::util::SmallVectorImpl<uint8_t>& buf)>
|
||||
getter,
|
||||
std::function<void(std::span<const uint8_t>)> setter) {
|
||||
auto topic = m_table->GetRawTopic(key);
|
||||
auto prop = std::make_unique<PropertyImpl<nt::RawTopic>>();
|
||||
auto prop = std::make_unique<PropertyImpl<wpi::nt::RawTopic>>();
|
||||
if (getter) {
|
||||
prop->pub = topic.Publish(typeString);
|
||||
prop->updateNetwork = [=](auto& pub, int64_t time) {
|
||||
wpi::SmallVector<uint8_t, 128> buf;
|
||||
wpi::util::SmallVector<uint8_t, 128> buf;
|
||||
pub.Set(getter(buf), time);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
|
||||
#include "wpi/util/sendable/SendableRegistry.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
std::atomic_int SendableChooserBase::s_instances{0};
|
||||
|
||||
SendableChooserBase::SendableChooserBase() : m_instance{s_instances++} {
|
||||
wpi::SendableRegistry::Add(this, "SendableChooser", m_instance);
|
||||
wpi::util::SendableRegistry::Add(this, "SendableChooser", m_instance);
|
||||
}
|
||||
|
||||
SendableChooserBase::SendableChooserBase(SendableChooserBase&& oth)
|
||||
|
||||
@@ -19,15 +19,15 @@
|
||||
#include "wpi/util/mutex.hpp"
|
||||
#include "wpi/util/sendable/SendableRegistry.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
namespace {
|
||||
struct Instance {
|
||||
detail::ListenerExecutor listenerExecutor;
|
||||
std::shared_ptr<nt::NetworkTable> table =
|
||||
nt::NetworkTableInstance::GetDefault().GetTable("SmartDashboard");
|
||||
wpi::StringMap<wpi::SendableRegistry::UID> tablesToData;
|
||||
wpi::mutex tablesToDataMutex;
|
||||
std::shared_ptr<wpi::nt::NetworkTable> table =
|
||||
wpi::nt::NetworkTableInstance::GetDefault().GetTable("SmartDashboard");
|
||||
wpi::util::StringMap<wpi::util::SendableRegistry::UID> tablesToData;
|
||||
wpi::util::mutex tablesToDataMutex;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
@@ -41,11 +41,11 @@ static Instance& GetInstance() {
|
||||
}
|
||||
|
||||
#ifndef __FRC_SYSTEMCORE__
|
||||
namespace frc::impl {
|
||||
namespace wpi::impl {
|
||||
void ResetSmartDashboardInstance() {
|
||||
std::make_unique<Instance>().swap(GetInstanceHolder());
|
||||
}
|
||||
} // namespace frc::impl
|
||||
} // namespace wpi::impl
|
||||
#endif
|
||||
|
||||
static bool gReported = false;
|
||||
@@ -74,7 +74,7 @@ bool SmartDashboard::IsPersistent(std::string_view key) {
|
||||
return GetEntry(key).IsPersistent();
|
||||
}
|
||||
|
||||
nt::NetworkTableEntry SmartDashboard::GetEntry(std::string_view key) {
|
||||
wpi::nt::NetworkTableEntry SmartDashboard::GetEntry(std::string_view key) {
|
||||
if (!gReported) {
|
||||
HAL_ReportUsage("SmartDashboard", "");
|
||||
gReported = true;
|
||||
@@ -82,7 +82,7 @@ nt::NetworkTableEntry SmartDashboard::GetEntry(std::string_view key) {
|
||||
return GetInstance().table->GetEntry(key);
|
||||
}
|
||||
|
||||
void SmartDashboard::PutData(std::string_view key, wpi::Sendable* data) {
|
||||
void SmartDashboard::PutData(std::string_view key, wpi::util::Sendable* data) {
|
||||
if (!data) {
|
||||
throw FRC_MakeError(err::NullParameter, "value");
|
||||
}
|
||||
@@ -93,37 +93,37 @@ void SmartDashboard::PutData(std::string_view key, wpi::Sendable* data) {
|
||||
auto& inst = GetInstance();
|
||||
std::scoped_lock lock(inst.tablesToDataMutex);
|
||||
auto& uid = inst.tablesToData[key];
|
||||
wpi::Sendable* sddata = wpi::SendableRegistry::GetSendable(uid);
|
||||
wpi::util::Sendable* sddata = wpi::util::SendableRegistry::GetSendable(uid);
|
||||
if (sddata != data) {
|
||||
uid = wpi::SendableRegistry::GetUniqueId(data);
|
||||
uid = wpi::util::SendableRegistry::GetUniqueId(data);
|
||||
auto dataTable = inst.table->GetSubTable(key);
|
||||
auto builder = std::make_unique<SendableBuilderImpl>();
|
||||
auto builderPtr = builder.get();
|
||||
builderPtr->SetTable(dataTable);
|
||||
wpi::SendableRegistry::Publish(uid, std::move(builder));
|
||||
wpi::util::SendableRegistry::Publish(uid, std::move(builder));
|
||||
builderPtr->StartListeners();
|
||||
dataTable->GetEntry(".name").SetString(key);
|
||||
}
|
||||
}
|
||||
|
||||
void SmartDashboard::PutData(wpi::Sendable* value) {
|
||||
void SmartDashboard::PutData(wpi::util::Sendable* value) {
|
||||
if (!value) {
|
||||
throw FRC_MakeError(err::NullParameter, "value");
|
||||
}
|
||||
auto name = wpi::SendableRegistry::GetName(value);
|
||||
auto name = wpi::util::SendableRegistry::GetName(value);
|
||||
if (!name.empty()) {
|
||||
PutData(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
wpi::Sendable* SmartDashboard::GetData(std::string_view key) {
|
||||
wpi::util::Sendable* SmartDashboard::GetData(std::string_view key) {
|
||||
auto& inst = GetInstance();
|
||||
std::scoped_lock lock(inst.tablesToDataMutex);
|
||||
auto it = inst.tablesToData.find(key);
|
||||
if (it == inst.tablesToData.end()) {
|
||||
throw FRC_MakeError(err::SmartDashboardMissingKey, "{}", key);
|
||||
}
|
||||
return wpi::SendableRegistry::GetSendable(it->second);
|
||||
return wpi::util::SendableRegistry::GetSendable(it->second);
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutBoolean(std::string_view keyName, bool value) {
|
||||
@@ -229,16 +229,16 @@ std::vector<uint8_t> SmartDashboard::GetRaw(
|
||||
}
|
||||
|
||||
bool SmartDashboard::PutValue(std::string_view keyName,
|
||||
const nt::Value& value) {
|
||||
const wpi::nt::Value& value) {
|
||||
return GetInstance().table->GetEntry(keyName).SetValue(value);
|
||||
}
|
||||
|
||||
bool SmartDashboard::SetDefaultValue(std::string_view key,
|
||||
const nt::Value& defaultValue) {
|
||||
const wpi::nt::Value& defaultValue) {
|
||||
return GetEntry(key).SetDefaultValue(defaultValue);
|
||||
}
|
||||
|
||||
nt::Value SmartDashboard::GetValue(std::string_view keyName) {
|
||||
wpi::nt::Value SmartDashboard::GetValue(std::string_view keyName) {
|
||||
return GetInstance().table->GetEntry(keyName).GetValue();
|
||||
}
|
||||
|
||||
@@ -251,6 +251,6 @@ void SmartDashboard::UpdateValues() {
|
||||
inst.listenerExecutor.RunListenerTasks();
|
||||
std::scoped_lock lock(inst.tablesToDataMutex);
|
||||
for (auto& i : inst.tablesToData) {
|
||||
wpi::SendableRegistry::Update(i.second);
|
||||
wpi::util::SendableRegistry::Update(i.second);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user