Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 2 | /* Copyright (c) FIRST 2008-2016. All Rights Reserved. */ |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 6 | /*----------------------------------------------------------------------------*/ |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 7 | |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 8 | #pragma once |
| 9 | |
| 10 | #include "DigitalSource.h" |
| 11 | #include "LiveWindow/LiveWindowSendable.h" |
| 12 | #include "tables/ITableListener.h" |
| 13 | |
| 14 | #include <memory> |
| 15 | |
| 16 | /** |
| 17 | * Class to write to digital outputs. |
| 18 | * Write values to the digital output channels. Other devices implemented |
| 19 | * elsewhere will allocate |
| 20 | * channels automatically so for those devices it shouldn't be done here. |
| 21 | */ |
| 22 | class DigitalOutput : public DigitalSource, |
| 23 | public ITableListener, |
| 24 | public LiveWindowSendable { |
| 25 | public: |
| 26 | explicit DigitalOutput(uint32_t channel); |
| 27 | virtual ~DigitalOutput(); |
| 28 | void Set(uint32_t value); |
| 29 | uint32_t GetChannel() const; |
| 30 | void Pulse(float length); |
| 31 | bool IsPulsing() const; |
| 32 | void SetPWMRate(float rate); |
| 33 | void EnablePWM(float initialDutyCycle); |
| 34 | void DisablePWM(); |
| 35 | void UpdateDutyCycle(float dutyCycle); |
| 36 | |
| 37 | // Digital Source Interface |
| 38 | virtual uint32_t GetChannelForRouting() const; |
| 39 | virtual uint32_t GetModuleForRouting() const; |
| 40 | virtual bool GetAnalogTriggerForRouting() const; |
| 41 | |
| 42 | virtual void ValueChanged(ITable* source, llvm::StringRef key, |
| 43 | std::shared_ptr<nt::Value> value, bool isNew); |
| 44 | void UpdateTable(); |
| 45 | void StartLiveWindowMode(); |
| 46 | void StopLiveWindowMode(); |
| 47 | std::string GetSmartDashboardType() const; |
| 48 | void InitTable(std::shared_ptr<ITable> subTable); |
| 49 | std::shared_ptr<ITable> GetTable() const; |
| 50 | |
| 51 | private: |
| 52 | uint32_t m_channel; |
| 53 | void *m_pwmGenerator; |
| 54 | |
| 55 | std::shared_ptr<ITable> m_table; |
| 56 | }; |