Brian Silverman | f7f267a | 2017-02-04 16:16:08 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 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 | |
| 14 | using 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 | */ |
| 22 | DigitalInput::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 | */ |
| 32 | int DigitalInput::Get() const { return m_impl->Get(); } |
| 33 | |
| 34 | /** |
| 35 | * @return The GPIO channel number that this object represents. |
| 36 | */ |
| 37 | int DigitalInput::GetChannel() const { return m_channel; } |
| 38 | |
| 39 | void DigitalInput::UpdateTable() { |
| 40 | if (m_table != nullptr) { |
| 41 | m_table->PutBoolean("Value", Get()); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | void DigitalInput::StartLiveWindowMode() {} |
| 46 | |
| 47 | void DigitalInput::StopLiveWindowMode() {} |
| 48 | |
| 49 | std::string DigitalInput::GetSmartDashboardType() const { |
| 50 | return "DigitalInput"; |
| 51 | } |
| 52 | |
| 53 | void DigitalInput::InitTable(std::shared_ptr<ITable> subTable) { |
| 54 | m_table = subTable; |
| 55 | UpdateTable(); |
| 56 | } |
| 57 | |
| 58 | std::shared_ptr<ITable> DigitalInput::GetTable() const { return m_table; } |