blob: a560761b6f9a90a59a6355968baa8451b4a0f4b8 [file] [log] [blame]
Brian Silvermanf7f267a2017-02-04 16:16:08 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008-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#include "DigitalInput.h"
9
10#include <sstream>
11
12#include "WPIErrors.h"
13
14using namespace frc;
15
16/**
17 * Create an instance of a Digital Input class.
18 * Creates a digital input given a channel and uses the default module.
19 *
20 * @param channel The digital channel (1..14).
21 */
22DigitalInput::DigitalInput(int channel) : m_channel(channel) {
23 std::stringstream ss;
24 ss << "dio/" << channel;
25 m_impl = new SimDigitalInput(ss.str());
26}
27
28/**
29 * Get the value from a digital input channel.
30 * Retrieve the value of a single digital input channel from the FPGA.
31 */
32int DigitalInput::Get() const { return m_impl->Get(); }
33
34/**
35 * @return The GPIO channel number that this object represents.
36 */
37int DigitalInput::GetChannel() const { return m_channel; }
38
39void DigitalInput::UpdateTable() {
40 if (m_table != nullptr) {
41 m_table->PutBoolean("Value", Get());
42 }
43}
44
45void DigitalInput::StartLiveWindowMode() {}
46
47void DigitalInput::StopLiveWindowMode() {}
48
49std::string DigitalInput::GetSmartDashboardType() const {
50 return "DigitalInput";
51}
52
53void DigitalInput::InitTable(std::shared_ptr<ITable> subTable) {
54 m_table = subTable;
55 UpdateTable();
56}
57
58std::shared_ptr<ITable> DigitalInput::GetTable() const { return m_table; }