blob: 3078f87fc40c2b8af84d236e3d13d2e2f34b0170 [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/NTSubsystem.h"
6
7#include <fmt/format.h>
8
9using namespace glass;
10
11NTSubsystemModel::NTSubsystemModel(std::string_view path)
James Kuszmaulcf324122023-01-14 14:07:17 -080012 : NTSubsystemModel(nt::NetworkTableInstance::GetDefault(), path) {}
Austin Schuh812d0d12021-11-04 20:16:48 -070013
James Kuszmaulcf324122023-01-14 14:07:17 -080014NTSubsystemModel::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 Schuh812d0d12021-11-04 20:16:48 -070022}
23
24void NTSubsystemModel::Update() {
James Kuszmaulcf324122023-01-14 14:07:17 -080025 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 Schuh812d0d12021-11-04 20:16:48 -070033 }
34}
35
36bool NTSubsystemModel::Exists() {
James Kuszmaulcf324122023-01-14 14:07:17 -080037 return m_defaultCommand.Exists();
Austin Schuh812d0d12021-11-04 20:16:48 -070038}