Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2008. All Rights Reserved. |
| 3 | */ |
| 4 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 5 | /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #include "AnalogTriggerOutput.h" |
| 9 | #include "AnalogTrigger.h" |
| 10 | #include "WPIErrors.h" |
| 11 | |
| 12 | /** |
| 13 | * Create an object that represents one of the four outputs from an analog |
| 14 | * trigger. |
| 15 | * |
| 16 | * Because this class derives from DigitalSource, it can be passed into routing |
| 17 | * functions |
| 18 | * for Counter, Encoder, etc. |
| 19 | * |
| 20 | * @param trigger A pointer to the trigger for which this is an output. |
| 21 | * @param outputType An enum that specifies the output on the trigger to |
| 22 | * represent. |
| 23 | */ |
| 24 | AnalogTriggerOutput::AnalogTriggerOutput(const AnalogTrigger &trigger, |
| 25 | AnalogTriggerType outputType) |
| 26 | : m_trigger(trigger), m_outputType(outputType) { |
| 27 | HALReport(HALUsageReporting::kResourceType_AnalogTriggerOutput, |
| 28 | trigger.GetIndex(), outputType); |
| 29 | } |
| 30 | |
| 31 | AnalogTriggerOutput::~AnalogTriggerOutput() { |
| 32 | if (m_interrupt != nullptr) { |
| 33 | int32_t status = 0; |
| 34 | cleanInterrupts(m_interrupt, &status); |
| 35 | wpi_setErrorWithContext(status, getHALErrorMessage(status)); |
| 36 | m_interrupt = nullptr; |
| 37 | m_interrupts->Free(m_interruptIndex); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Get the state of the analog trigger output. |
| 43 | * @return The state of the analog trigger output. |
| 44 | */ |
| 45 | bool AnalogTriggerOutput::Get() const { |
| 46 | int32_t status = 0; |
| 47 | bool result = |
| 48 | getAnalogTriggerOutput(m_trigger.m_trigger, m_outputType, &status); |
| 49 | wpi_setErrorWithContext(status, getHALErrorMessage(status)); |
| 50 | return result; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * @return The value to be written to the channel field of a routing mux. |
| 55 | */ |
| 56 | uint32_t AnalogTriggerOutput::GetChannelForRouting() const { |
| 57 | return (m_trigger.m_index << 2) + m_outputType; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @return The value to be written to the module field of a routing mux. |
| 62 | */ |
| 63 | uint32_t AnalogTriggerOutput::GetModuleForRouting() const { return 0; } |
| 64 | |
| 65 | /** |
| 66 | * @return The value to be written to the module field of a routing mux. |
| 67 | */ |
| 68 | bool AnalogTriggerOutput::GetAnalogTriggerForRouting() const { return true; } |