WPILibC++  unspecified
LiveWindow.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2012-2017 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <map>
11 #include <memory>
12 #include <string>
13 #include <vector>
14 
15 #include "Commands/Scheduler.h"
16 #include "LiveWindow/LiveWindowSendable.h"
17 #include "networktables/NetworkTable.h"
18 #include "networktables/NetworkTableEntry.h"
19 
20 namespace frc {
21 
23  std::string subsystem;
24  std::string name;
25  bool isSensor = false;
26 
27  LiveWindowComponent() = default;
28  LiveWindowComponent(std::string subsystem, std::string name, bool isSensor) {
29  this->subsystem = subsystem;
30  this->name = name;
31  this->isSensor = isSensor;
32  }
33 };
34 
40 class LiveWindow {
41  public:
42  static LiveWindow* GetInstance();
43  void Run();
44  void AddSensor(const std::string& subsystem, const std::string& name,
45  LiveWindowSendable* component);
46  void AddSensor(const std::string& subsystem, const std::string& name,
47  LiveWindowSendable& component);
48  void AddSensor(const std::string& subsystem, const std::string& name,
49  std::shared_ptr<LiveWindowSendable> component);
50  void AddActuator(const std::string& subsystem, const std::string& name,
51  LiveWindowSendable* component);
52  void AddActuator(const std::string& subsystem, const std::string& name,
53  LiveWindowSendable& component);
54  void AddActuator(const std::string& subsystem, const std::string& name,
55  std::shared_ptr<LiveWindowSendable> component);
56 
57  void AddSensor(std::string type, int channel, LiveWindowSendable* component);
58  void AddActuator(std::string type, int channel,
59  LiveWindowSendable* component);
60  void AddActuator(std::string type, int module, int channel,
61  LiveWindowSendable* component);
62 
63  bool IsEnabled() const { return m_enabled; }
64  void SetEnabled(bool enabled);
65 
66  protected:
67  LiveWindow();
68  virtual ~LiveWindow() = default;
69 
70  private:
71  void UpdateValues();
72  void Initialize();
73  void InitializeLiveWindowComponents();
74 
75  std::vector<std::shared_ptr<LiveWindowSendable>> m_sensors;
76  std::map<std::shared_ptr<LiveWindowSendable>, LiveWindowComponent>
77  m_components;
78 
79  std::shared_ptr<nt::NetworkTable> m_liveWindowTable;
80  std::shared_ptr<nt::NetworkTable> m_statusTable;
81  nt::NetworkTableEntry m_enabledEntry;
82 
83  Scheduler* m_scheduler;
84 
85  bool m_enabled = false;
86  bool m_firstTime = true;
87 };
88 
89 } // namespace frc
Definition: Timer.cpp:18
Live Window Sendable is a special type of object sendable to the live window.
Definition: LiveWindowSendable.h:17
The LiveWindow class is the public interface for putting sensors and actuators on the LiveWindow...
Definition: LiveWindow.h:40
Definition: LiveWindow.h:22
NetworkTables Entry.
Definition: NetworkTableEntry.h:30
Definition: Scheduler.h:30