blob: 7b40f670a72edba4b2f07fdc31111c3928682c16 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001#ifndef _LIVE_WINDOW_H
2#define _LIVE_WINDOW_H
3
4#include "LiveWindow/LiveWindowSendable.h"
5#include "tables/ITable.h"
6#include "Commands/Scheduler.h"
7#include <vector>
8#include <map>
9#include <memory>
10
11struct LiveWindowComponent {
12 std::string subsystem;
13 std::string name;
14 bool isSensor = false;
15
16 LiveWindowComponent() = default;
17 LiveWindowComponent(std::string subsystem, std::string name, bool isSensor) {
18 this->subsystem = subsystem;
19 this->name = name;
20 this->isSensor = isSensor;
21 }
22};
23
24/**
25 * The LiveWindow class is the public interface for putting sensors and
26 * actuators
27 * on the LiveWindow.
28 *
29 * @author Brad Miller
30 */
31class LiveWindow {
32 public:
33 static LiveWindow *GetInstance();
34 void Run();
35 void AddSensor(const std::string &subsystem, const std::string &name,
36 LiveWindowSendable *component);
37 void AddSensor(const std::string &subsystem, const std::string &name,
38 LiveWindowSendable &component);
39 void AddSensor(const std::string &subsystem, const std::string &name,
40 std::shared_ptr<LiveWindowSendable> component);
41 void AddActuator(const std::string &subsystem, const std::string &name,
42 LiveWindowSendable *component);
43 void AddActuator(const std::string &subsystem, const std::string &name,
44 LiveWindowSendable &component);
45 void AddActuator(const std::string &subsystem, const std::string &name,
46 std::shared_ptr<LiveWindowSendable> component);
47
48 void AddSensor(std::string type, int channel, LiveWindowSendable *component);
49 void AddActuator(std::string type, int channel,
50 LiveWindowSendable *component);
51 void AddActuator(std::string type, int module, int channel,
52 LiveWindowSendable *component);
53
54 bool IsEnabled() const { return m_enabled; }
55 void SetEnabled(bool enabled);
56
57 protected:
58 LiveWindow();
59 virtual ~LiveWindow() = default;
60
61 private:
62 void UpdateValues();
63 void Initialize();
64 void InitializeLiveWindowComponents();
65
66 std::vector<std::shared_ptr<LiveWindowSendable>> m_sensors;
67 std::map<std::shared_ptr<LiveWindowSendable>, LiveWindowComponent> m_components;
68
69 std::shared_ptr<ITable> m_liveWindowTable;
70 std::shared_ptr<ITable> m_statusTable;
71
72 Scheduler *m_scheduler;
73
74 bool m_enabled = false;
75 bool m_firstTime = true;
76};
77
78#endif