Loading [MathJax]/extensions/tex2jax.js
WPILibC++ 2025.3.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
SuppliedValueWidget.h
Go to the documentation of this file.
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#pragma once
6
7#include <functional>
8#include <memory>
9#include <string>
10#include <string_view>
11
15
19
20namespace frc {
21class ShuffleboardContainer;
22
23template <typename T>
24class SuppliedValueWidget : public ShuffleboardWidget<SuppliedValueWidget<T>> {
25 public:
26 SuppliedValueWidget(ShuffleboardContainer& parent, std::string_view title,
27 std::string_view typeString, std::function<T()> supplier,
28 std::function<void(nt::GenericPublisher&, T)> setter)
29 : ShuffleboardValue(title),
30 ShuffleboardWidget<SuppliedValueWidget<T>>(parent, title),
31 m_typeString(typeString),
32 m_supplier(supplier),
33 m_setter(setter) {}
34
35 void BuildInto(std::shared_ptr<nt::NetworkTable> parentTable,
36 std::shared_ptr<nt::NetworkTable> metaTable) override {
37 this->BuildMetadata(metaTable);
38 if (!m_controllablePub) {
39 m_controllablePub =
40 nt::BooleanTopic{metaTable->GetTopic("Controllable")}.Publish();
41 m_controllablePub.Set(false);
42 }
43
44 if (!m_entry) {
45 m_entry =
46 parentTable->GetTopic(this->GetTitle()).GenericPublish(m_typeString);
47 }
48 m_setter(m_entry, m_supplier());
49 }
50
51 private:
52 std::string m_typeString;
53 std::function<T()> m_supplier;
54 std::function<void(nt::GenericPublisher&, T)> m_setter;
55 nt::BooleanPublisher m_controllablePub;
57};
58} // namespace frc
void BuildMetadata(std::shared_ptr< nt::NetworkTable > metaTable)
Common interface for objects that can contain shuffleboard components.
Definition ShuffleboardContainer.h:42
Definition ShuffleboardValue.h:15
const std::string & GetTitle() const
Gets the title of this Shuffleboard value.
Definition ShuffleboardValue.h:27
Abstract superclass for widgets.
Definition ShuffleboardWidget.h:29
Definition SuppliedValueWidget.h:24
void BuildInto(std::shared_ptr< nt::NetworkTable > parentTable, std::shared_ptr< nt::NetworkTable > metaTable) override
Builds the entries for this value.
Definition SuppliedValueWidget.h:35
SuppliedValueWidget(ShuffleboardContainer &parent, std::string_view title, std::string_view typeString, std::function< T()> supplier, std::function< void(nt::GenericPublisher &, T)> setter)
Definition SuppliedValueWidget.h:26
NetworkTables Boolean publisher.
Definition BooleanTopic.h:127
void Set(ParamType value, int64_t time=0)
Publish a new value.
Definition BooleanTopic.h:151
NetworkTables Boolean topic.
Definition BooleanTopic.h:235
PublisherType Publish(const PubSubOptions &options=kDefaultPubSubOptions)
Create a new publisher to the topic.
Definition BooleanTopic.h:327
NetworkTables generic publisher.
Definition GenericEntry.h:219
TopicType GetTopic() const
Get the corresponding topic.
Definition GenericEntry.h:501
GenericPublisher GenericPublish(std::string_view typeString, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new publisher to the topic.
Definition CAN.h:11