Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 1 | // 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 | |
| 10 | using namespace glass; |
| 11 | |
| 12 | NTGyroModel::NTGyroModel(std::string_view path) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 13 | : NTGyroModel(nt::NetworkTableInstance::GetDefault(), path) {} |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 14 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 15 | NTGyroModel::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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 21 | |
| 22 | void NTGyroModel::Update() { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 23 | 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 Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 28 | } |
| 29 | } |
| 30 | |
| 31 | bool NTGyroModel::Exists() { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 32 | return m_angle.Exists(); |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 33 | } |