WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
LiveWindow.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2012-2016. 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 #ifndef _LIVE_WINDOW_H
9 #define _LIVE_WINDOW_H
10 
11 #include "LiveWindow/LiveWindowSendable.h"
12 #include "tables/ITable.h"
13 #include "Commands/Scheduler.h"
14 #include <vector>
15 #include <map>
16 #include <memory>
17 
19  std::string subsystem;
20  std::string name;
21  bool isSensor = false;
22 
23  LiveWindowComponent() = default;
24  LiveWindowComponent(std::string subsystem, std::string name, bool isSensor) {
25  this->subsystem = subsystem;
26  this->name = name;
27  this->isSensor = isSensor;
28  }
29 };
30 
38 class LiveWindow {
39  public:
40  static LiveWindow *GetInstance();
41  void Run();
42  void AddSensor(const std::string &subsystem, const std::string &name,
43  LiveWindowSendable *component);
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  std::shared_ptr<LiveWindowSendable> component);
48  void AddActuator(const std::string &subsystem, const std::string &name,
49  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  std::shared_ptr<LiveWindowSendable> component);
54 
55  void AddSensor(std::string type, int channel, LiveWindowSendable *component);
56  void AddActuator(std::string type, int channel,
57  LiveWindowSendable *component);
58  void AddActuator(std::string type, int module, int channel,
59  LiveWindowSendable *component);
60 
61  bool IsEnabled() const { return m_enabled; }
62  void SetEnabled(bool enabled);
63 
64  protected:
65  LiveWindow();
66  virtual ~LiveWindow() = default;
67 
68  private:
69  void UpdateValues();
70  void Initialize();
71  void InitializeLiveWindowComponents();
72 
73  std::vector<std::shared_ptr<LiveWindowSendable>> m_sensors;
74  std::map<std::shared_ptr<LiveWindowSendable>, LiveWindowComponent> m_components;
75 
76  std::shared_ptr<ITable> m_liveWindowTable;
77  std::shared_ptr<ITable> m_statusTable;
78 
79  Scheduler *m_scheduler;
80 
81  bool m_enabled = false;
82  bool m_firstTime = true;
83 };
84 
85 #endif
Definition: Scheduler.h:27
Live Window Sendable is a special type of object sendable to the live window.
Definition: LiveWindowSendable.h:18
void AddSensor(const std::string &subsystem, const std::string &name, LiveWindowSendable *component)
Use a raw pointer to the LiveWindow.
Definition: LiveWindow.cpp:91
The LiveWindow class is the public interface for putting sensors and actuators on the LiveWindow...
Definition: LiveWindow.h:38
static LiveWindow * GetInstance()
Get an instance of the LiveWindow main class This is a singleton to guarantee that there is only a si...
Definition: LiveWindow.cpp:19
void SetEnabled(bool enabled)
Change the enabled status of LiveWindow If it changes to enabled, start livewindow running otherwise ...
Definition: LiveWindow.cpp:37
LiveWindow()
LiveWindow constructor.
Definition: LiveWindow.cpp:28
void Run()
This method is called periodically to cause the sensors to send new values to the SmartDashboard...
Definition: LiveWindow.cpp:191
void AddActuator(const std::string &subsystem, const std::string &name, LiveWindowSendable *component)
Use a raw pointer to the LiveWindow.
Definition: LiveWindow.cpp:131
Definition: LiveWindow.h:18