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 | #pragma once |
| 9 | |
| 10 | #include <memory> |
| 11 | #include <string> |
| 12 | |
| 13 | #include "LiveWindow/LiveWindowSendable.h" |
| 14 | #include "simulation/SimDigitalInput.h" |
| 15 | |
| 16 | namespace frc { |
| 17 | |
| 18 | /** |
| 19 | * Class to read a digital input. |
| 20 | * |
| 21 | * This class will read digital inputs and return the current value on the |
| 22 | * channel. Other devices such as encoders, gear tooth sensors, etc. that are |
| 23 | * implemented elsewhere will automatically allocate digital inputs and outputs |
| 24 | * as required. This class is only for devices like switches etc. that aren't |
| 25 | * implemented anywhere else. |
| 26 | */ |
| 27 | class DigitalInput : public LiveWindowSendable { |
| 28 | public: |
| 29 | explicit DigitalInput(int channel); |
| 30 | virtual ~DigitalInput() = default; |
| 31 | int Get() const; |
| 32 | int GetChannel() const; |
| 33 | |
| 34 | void UpdateTable() override; |
| 35 | void StartLiveWindowMode() override; |
| 36 | void StopLiveWindowMode() override; |
| 37 | std::string GetSmartDashboardType() const override; |
| 38 | void InitTable(std::shared_ptr<ITable> subTable) override; |
| 39 | std::shared_ptr<ITable> GetTable() const override; |
| 40 | |
| 41 | private: |
| 42 | int m_channel; |
| 43 | bool m_lastValue; |
| 44 | SimDigitalInput* m_impl; |
| 45 | |
| 46 | std::shared_ptr<ITable> m_table; |
| 47 | }; |
| 48 | |
| 49 | } // namespace frc |