Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */ |
| 5 | /*----------------------------------------------------------------------------*/ |
| 6 | |
| 7 | #include "DigitalInput.h" |
| 8 | #include "WPIErrors.h" |
| 9 | |
| 10 | /** |
| 11 | * Create an instance of a Digital Input class. |
| 12 | * Creates a digital input given a channel and uses the default module. |
| 13 | * |
| 14 | * @param channel The digital channel (1..14). |
| 15 | */ |
| 16 | DigitalInput::DigitalInput(uint32_t channel) |
| 17 | { |
| 18 | char buf[64]; |
| 19 | m_channel = channel; |
| 20 | int n = sprintf(buf, "dio/%d", channel); |
| 21 | m_impl = new SimDigitalInput(buf); |
| 22 | } |
| 23 | |
| 24 | /* |
| 25 | * Get the value from a digital input channel. |
| 26 | * Retrieve the value of a single digital input channel from the FPGA. |
| 27 | */ |
| 28 | uint32_t DigitalInput::Get() const |
| 29 | { |
| 30 | return m_impl->Get(); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @return The GPIO channel number that this object represents. |
| 35 | */ |
| 36 | uint32_t DigitalInput::GetChannel() const |
| 37 | { |
| 38 | return m_channel; |
| 39 | } |
| 40 | |
| 41 | void DigitalInput::UpdateTable() { |
| 42 | if (m_table != nullptr) { |
| 43 | m_table->PutBoolean("Value", Get()); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | void DigitalInput::StartLiveWindowMode() { |
| 48 | |
| 49 | } |
| 50 | |
| 51 | void DigitalInput::StopLiveWindowMode() { |
| 52 | |
| 53 | } |
| 54 | |
| 55 | std::string DigitalInput::GetSmartDashboardType() const { |
| 56 | return "DigitalInput"; |
| 57 | } |
| 58 | |
| 59 | void DigitalInput::InitTable(std::shared_ptr<ITable> subTable) { |
| 60 | m_table = subTable; |
| 61 | UpdateTable(); |
| 62 | } |
| 63 | |
| 64 | std::shared_ptr<ITable> DigitalInput::GetTable() const { |
| 65 | return m_table; |
| 66 | } |