blob: aa9200dc7055c6f3a6b009cee30dddcfc08c2d6d [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/NTDigitalOutput.h"
6
7#include <fmt/format.h>
8
9using namespace glass;
10
11NTDigitalOutputModel::NTDigitalOutputModel(std::string_view path)
James Kuszmaulcf324122023-01-14 14:07:17 -080012 : NTDigitalOutputModel{nt::NetworkTableInstance::GetDefault(), path} {}
Austin Schuh812d0d12021-11-04 20:16:48 -070013
James Kuszmaulcf324122023-01-14 14:07:17 -080014NTDigitalOutputModel::NTDigitalOutputModel(nt::NetworkTableInstance inst,
15 std::string_view path)
16 : m_inst{inst},
17 m_value{
18 inst.GetBooleanTopic(fmt::format("{}/Value", path)).GetEntry(false)},
19 m_name{inst.GetStringTopic(fmt::format("{}/.name", path)).Subscribe("")},
20 m_controllable{inst.GetBooleanTopic(fmt::format("{}/.controllable", path))
21 .Subscribe(false)},
Austin Schuh812d0d12021-11-04 20:16:48 -070022 m_valueData{fmt::format("NT_DOut:{}", path)} {
Austin Schuh812d0d12021-11-04 20:16:48 -070023 m_valueData.SetDigital(true);
24}
25
26void NTDigitalOutputModel::SetValue(bool val) {
James Kuszmaulcf324122023-01-14 14:07:17 -080027 m_value.Set(val);
Austin Schuh812d0d12021-11-04 20:16:48 -070028}
29
30void NTDigitalOutputModel::Update() {
James Kuszmaulcf324122023-01-14 14:07:17 -080031 for (auto&& v : m_value.ReadQueue()) {
32 m_valueData.SetValue(v.value, v.time);
33 }
34 for (auto&& v : m_name.ReadQueue()) {
35 m_nameValue = std::move(v.value);
36 }
37 for (auto&& v : m_controllable.ReadQueue()) {
38 m_controllableValue = v.value;
Austin Schuh812d0d12021-11-04 20:16:48 -070039 }
40}
41
42bool NTDigitalOutputModel::Exists() {
James Kuszmaulcf324122023-01-14 14:07:17 -080043 return m_value.Exists();
Austin Schuh812d0d12021-11-04 20:16:48 -070044}