blob: c2be96a9fbeb2d69287efd6b61923427dbff01f5 [file] [log] [blame]
Brian Silvermanf7f267a2017-02-04 16:16:08 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2012-2017. 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
19namespace frc {
20
21struct LiveWindowComponent {
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
34/**
35 * The LiveWindow class is the public interface for putting sensors and
36 * actuators
37 * on the LiveWindow.
38 */
39class 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