Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) 2008-2018 FIRST. 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 "frc/AnalogTriggerOutput.h" |
| 9 | |
| 10 | #include <hal/HAL.h> |
| 11 | |
| 12 | #include "frc/AnalogTrigger.h" |
| 13 | #include "frc/WPIErrors.h" |
| 14 | |
| 15 | using namespace frc; |
| 16 | |
| 17 | AnalogTriggerOutput::~AnalogTriggerOutput() { |
| 18 | if (m_interrupt != HAL_kInvalidHandle) { |
| 19 | int32_t status = 0; |
| 20 | HAL_CleanInterrupts(m_interrupt, &status); |
| 21 | // ignore status, as an invalid handle just needs to be ignored. |
| 22 | m_interrupt = HAL_kInvalidHandle; |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | bool AnalogTriggerOutput::Get() const { |
| 27 | int32_t status = 0; |
| 28 | bool result = HAL_GetAnalogTriggerOutput( |
| 29 | m_trigger.m_trigger, static_cast<HAL_AnalogTriggerType>(m_outputType), |
| 30 | &status); |
| 31 | wpi_setErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 32 | return result; |
| 33 | } |
| 34 | |
| 35 | HAL_Handle AnalogTriggerOutput::GetPortHandleForRouting() const { |
| 36 | return m_trigger.m_trigger; |
| 37 | } |
| 38 | |
| 39 | AnalogTriggerType AnalogTriggerOutput::GetAnalogTriggerTypeForRouting() const { |
| 40 | return m_outputType; |
| 41 | } |
| 42 | |
| 43 | bool AnalogTriggerOutput::IsAnalogTrigger() const { return true; } |
| 44 | |
| 45 | int AnalogTriggerOutput::GetChannel() const { return m_trigger.m_index; } |
| 46 | |
| 47 | void AnalogTriggerOutput::InitSendable(SendableBuilder&) {} |
| 48 | |
| 49 | AnalogTriggerOutput::AnalogTriggerOutput(const AnalogTrigger& trigger, |
| 50 | AnalogTriggerType outputType) |
| 51 | : m_trigger(trigger), m_outputType(outputType) { |
| 52 | HAL_Report(HALUsageReporting::kResourceType_AnalogTriggerOutput, |
| 53 | trigger.GetIndex(), static_cast<uint8_t>(outputType)); |
| 54 | } |