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 #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 "tables/ITable.h"
18 
19 namespace frc {
20 
22  std::string subsystem;
23  std::string name;
24  bool isSensor = false;
25 
26  LiveWindowComponent() = default;
27  LiveWindowComponent(std::string subsystem, std::string name, bool isSensor) {
28  this->subsystem = subsystem;
29  this->name = name;
30  this->isSensor = isSensor;
31  }
32 };
33 
39 class LiveWindow {
40  public:
41  static LiveWindow* GetInstance();
42  void Run();
43  void AddSensor(const std::string& subsystem, const std::string& name,
44  LiveWindowSendable* component);
45  void AddSensor(const std::string& subsystem, const std::string& name,
46  LiveWindowSendable& component);
47  void AddSensor(const std::string& subsystem, const std::string& name,
48  std::shared_ptr<LiveWindowSendable> component);
49  void AddActuator(const std::string& subsystem, const std::string& name,
50  LiveWindowSendable* component);
51  void AddActuator(const std::string& subsystem, const std::string& name,
52  LiveWindowSendable& component);
53  void AddActuator(const std::string& subsystem, const std::string& name,
54  std::shared_ptr<LiveWindowSendable> component);
55 
56  void AddSensor(std::string type, int channel, LiveWindowSendable* component);
57  void AddActuator(std::string type, int channel,
58  LiveWindowSendable* component);
59  void AddActuator(std::string type, int module, int channel,
60  LiveWindowSendable* component);
61 
62  bool IsEnabled() const { return m_enabled; }
63  void SetEnabled(bool enabled);
64 
65  protected:
66  LiveWindow();
67  virtual ~LiveWindow() = default;
68 
69  private:
70  void UpdateValues();
71  void Initialize();
72  void InitializeLiveWindowComponents();
73 
74  std::vector<std::shared_ptr<LiveWindowSendable>> m_sensors;
75  std::map<std::shared_ptr<LiveWindowSendable>, LiveWindowComponent>
76  m_components;
77 
78  std::shared_ptr<ITable> m_liveWindowTable;
79  std::shared_ptr<ITable> m_statusTable;
80 
81  Scheduler* m_scheduler;
82 
83  bool m_enabled = false;
84  bool m_firstTime = true;
85 };
86 
87 } // namespace frc
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:39
void SetEnabled(bool enabled)
Change the enabled status of LiveWindow.
Definition: LiveWindow.cpp:43
void AddSensor(const std::string &subsystem, const std::string &name, LiveWindowSendable *component)
Use a raw pointer to the LiveWindow.
Definition: LiveWindow.cpp:100
Definition: LiveWindow.h:21
void Run()
This method is called periodically to cause the sensors to send new values to the SmartDashboard...
Definition: LiveWindow.cpp:207
void AddActuator(const std::string &subsystem, const std::string &name, LiveWindowSendable *component)
Use a raw pointer to the LiveWindow.
Definition: LiveWindow.cpp:143
static LiveWindow * GetInstance()
Get an instance of the LiveWindow main class.
Definition: LiveWindow.cpp:23
LiveWindow()
LiveWindow constructor.
Definition: LiveWindow.cpp:33
Definition: Scheduler.h:29