2020-12-26 14:31:24 -08:00
|
|
|
// 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.
|
2020-12-23 00:07:44 -05:00
|
|
|
|
|
|
|
|
#include "glass/networktables/NTSubsystem.h"
|
|
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
|
2020-12-23 00:07:44 -05:00
|
|
|
using namespace glass;
|
|
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
NTSubsystemModel::NTSubsystemModel(std::string_view path)
|
2022-10-08 10:01:31 -07:00
|
|
|
: NTSubsystemModel(nt::NetworkTableInstance::GetDefault(), path) {}
|
2020-12-23 00:07:44 -05:00
|
|
|
|
2022-10-08 10:01:31 -07:00
|
|
|
NTSubsystemModel::NTSubsystemModel(nt::NetworkTableInstance inst,
|
|
|
|
|
std::string_view path)
|
|
|
|
|
: m_inst{inst},
|
|
|
|
|
m_name{inst.GetStringTopic(fmt::format("{}/.name", path)).Subscribe("")},
|
|
|
|
|
m_defaultCommand{
|
|
|
|
|
inst.GetStringTopic(fmt::format("{}/.default", path)).Subscribe("")},
|
|
|
|
|
m_currentCommand{
|
|
|
|
|
inst.GetStringTopic(fmt::format("{}/.command", path)).Subscribe("")} {
|
2020-12-23 00:07:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NTSubsystemModel::Update() {
|
2022-10-08 10:01:31 -07:00
|
|
|
for (auto&& v : m_name.ReadQueue()) {
|
|
|
|
|
m_nameValue = std::move(v.value);
|
|
|
|
|
}
|
|
|
|
|
for (auto&& v : m_defaultCommand.ReadQueue()) {
|
|
|
|
|
m_defaultCommandValue = std::move(v.value);
|
|
|
|
|
}
|
|
|
|
|
for (auto&& v : m_currentCommand.ReadQueue()) {
|
|
|
|
|
m_currentCommandValue = std::move(v.value);
|
2020-12-23 00:07:44 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NTSubsystemModel::Exists() {
|
2022-10-08 10:01:31 -07:00
|
|
|
return m_inst.IsConnected() && m_defaultCommand.Exists();
|
2020-12-23 00:07:44 -05:00
|
|
|
}
|