blob: a036b39c53d7a52af40a2f12509f215126cde8b7 [file] [log] [blame]
Austin Schuh812d0d12021-11-04 20:16:48 -07001// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#include "glass/networktables/NTGyro.h"
6
7#include <fmt/format.h>
8#include <wpi/StringExtras.h>
9
10using namespace glass;
11
12NTGyroModel::NTGyroModel(std::string_view path)
James Kuszmaulcf324122023-01-14 14:07:17 -080013 : NTGyroModel(nt::NetworkTableInstance::GetDefault(), path) {}
Austin Schuh812d0d12021-11-04 20:16:48 -070014
James Kuszmaulcf324122023-01-14 14:07:17 -080015NTGyroModel::NTGyroModel(nt::NetworkTableInstance inst, std::string_view path)
16 : m_inst{inst},
17 m_angle{inst.GetDoubleTopic(fmt::format("{}/Value", path)).Subscribe(0)},
18 m_name{inst.GetStringTopic(fmt::format("{}/.name", path)).Subscribe({})},
19 m_angleData{fmt::format("NT_Gyro:{}", path)},
20 m_nameValue{wpi::rsplit(path, '/').second} {}
Austin Schuh812d0d12021-11-04 20:16:48 -070021
22void NTGyroModel::Update() {
James Kuszmaulcf324122023-01-14 14:07:17 -080023 for (auto&& v : m_name.ReadQueue()) {
24 m_nameValue = std::move(v.value);
25 }
26 for (auto&& v : m_angle.ReadQueue()) {
27 m_angleData.SetValue(v.value, v.time);
Austin Schuh812d0d12021-11-04 20:16:48 -070028 }
29}
30
31bool NTGyroModel::Exists() {
James Kuszmaulcf324122023-01-14 14:07:17 -080032 return m_angle.Exists();
Austin Schuh812d0d12021-11-04 20:16:48 -070033}