Files
allwpilib/glass/src/libnt/native/cpp/NTGyro.cpp

35 lines
1.1 KiB
C++
Raw Normal View History

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.
#include "glass/networktables/NTGyro.h"
#include <fmt/format.h>
#include <wpi/StringExtras.h>
using namespace glass;
NTGyroModel::NTGyroModel(std::string_view path)
2022-10-08 10:01:31 -07:00
: NTGyroModel(nt::NetworkTableInstance::GetDefault(), path) {}
2022-10-08 10:01:31 -07:00
NTGyroModel::NTGyroModel(nt::NetworkTableInstance inst, std::string_view path)
: m_inst{inst},
m_angle{inst.GetDoubleTopic(fmt::format("{}/Value", path))
.Subscribe(0, {{nt::PubSubOption::SendAll(true)}})},
m_name{inst.GetStringTopic(fmt::format("{}/.name", path)).Subscribe({})},
m_angleData{fmt::format("NT_Gyro:{}", path)},
m_nameValue{wpi::rsplit(path, '/').second} {}
void NTGyroModel::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_angle.ReadQueue()) {
m_angleData.SetValue(v.value, v.time);
}
}
bool NTGyroModel::Exists() {
2022-10-08 10:01:31 -07:00
return m_inst.IsConnected() && m_angle.Exists();
}