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/NTSubsystem.h" |
| 6 | |
| 7 | #include <fmt/format.h> |
| 8 | |
| 9 | using namespace glass; |
| 10 | |
| 11 | NTSubsystemModel::NTSubsystemModel(std::string_view path) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 12 | : NTSubsystemModel(nt::NetworkTableInstance::GetDefault(), path) {} |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 13 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 14 | NTSubsystemModel::NTSubsystemModel(nt::NetworkTableInstance inst, |
| 15 | std::string_view path) |
| 16 | : m_inst{inst}, |
| 17 | m_name{inst.GetStringTopic(fmt::format("{}/.name", path)).Subscribe("")}, |
| 18 | m_defaultCommand{ |
| 19 | inst.GetStringTopic(fmt::format("{}/.default", path)).Subscribe("")}, |
| 20 | m_currentCommand{ |
| 21 | inst.GetStringTopic(fmt::format("{}/.command", path)).Subscribe("")} { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | void NTSubsystemModel::Update() { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 25 | for (auto&& v : m_name.ReadQueue()) { |
| 26 | m_nameValue = std::move(v.value); |
| 27 | } |
| 28 | for (auto&& v : m_defaultCommand.ReadQueue()) { |
| 29 | m_defaultCommandValue = std::move(v.value); |
| 30 | } |
| 31 | for (auto&& v : m_currentCommand.ReadQueue()) { |
| 32 | m_currentCommandValue = std::move(v.value); |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 33 | } |
| 34 | } |
| 35 | |
| 36 | bool NTSubsystemModel::Exists() { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 37 | return m_defaultCommand.Exists(); |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 38 | } |