blob: 17817a9aecd6ea15decdd9bbdc32b2f6dced4953 [file] [log] [blame]
Brian Silverman1a675112016-02-20 20:42:49 -05001/*----------------------------------------------------------------------------*/
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
Brian Silverman26e4e522015-12-17 01:56:40 -05008#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
18struct LiveWindowComponent {
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
31/**
32 * The LiveWindow class is the public interface for putting sensors and
33 * actuators
34 * on the LiveWindow.
35 *
36 * @author Brad Miller
37 */
38class 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