2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "AnalogTriggerOutput.h"
|
|
|
|
|
#include "AnalogTrigger.h"
|
2016-05-25 22:38:11 -07:00
|
|
|
#include "HAL/HAL.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
#include "WPIErrors.h"
|
|
|
|
|
|
|
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* Create an object that represents one of the four outputs from an analog
|
|
|
|
|
* trigger.
|
2014-07-23 16:55:45 -04:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Because this class derives from DigitalSource, it can be passed into routing
|
2016-05-20 17:30:37 -07:00
|
|
|
* functions for Counter, Encoder, etc.
|
2014-07-23 16:55:45 -04:00
|
|
|
*
|
2016-05-20 17:30:37 -07:00
|
|
|
* @param trigger A pointer to the trigger for which this is an output.
|
2015-06-25 15:07:55 -04:00
|
|
|
* @param outputType An enum that specifies the output on the trigger to
|
2016-05-20 17:30:37 -07:00
|
|
|
* represent.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2016-05-20 17:30:37 -07:00
|
|
|
AnalogTriggerOutput::AnalogTriggerOutput(const AnalogTrigger& trigger,
|
2015-06-25 15:07:55 -04:00
|
|
|
AnalogTriggerType outputType)
|
|
|
|
|
: m_trigger(trigger), m_outputType(outputType) {
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_Report(HALUsageReporting::kResourceType_AnalogTriggerOutput,
|
2016-08-11 23:38:45 -07:00
|
|
|
trigger.GetIndex(), static_cast<uint8_t>(outputType));
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
AnalogTriggerOutput::~AnalogTriggerOutput() {
|
2016-07-09 00:24:26 -07:00
|
|
|
if (m_interrupt != HAL_kInvalidHandle) {
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_CleanInterrupts(m_interrupt, &status);
|
2016-06-20 23:22:49 -07:00
|
|
|
// ignore status, as an invalid handle just needs to be ignored.
|
2016-07-09 00:24:26 -07:00
|
|
|
m_interrupt = HAL_kInvalidHandle;
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the state of the analog trigger output.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return The state of the analog trigger output.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool AnalogTriggerOutput::Get() const {
|
2013-12-15 18:30:16 -05:00
|
|
|
int32_t status = 0;
|
2016-07-09 00:24:26 -07:00
|
|
|
bool result = HAL_GetAnalogTriggerOutput(
|
|
|
|
|
m_trigger.m_trigger, (HAL_AnalogTriggerType)m_outputType, &status);
|
|
|
|
|
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
2013-12-15 18:30:16 -05:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-07-07 21:43:55 -07:00
|
|
|
* @return The HAL Handle to the specified source.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2016-07-09 00:24:26 -07:00
|
|
|
HAL_Handle AnalogTriggerOutput::GetPortHandleForRouting() const {
|
2016-07-07 21:43:55 -07:00
|
|
|
return m_trigger.m_trigger;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-07-07 21:43:55 -07:00
|
|
|
* Is source an AnalogTrigger
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2016-07-07 21:43:55 -07:00
|
|
|
bool AnalogTriggerOutput::IsAnalogTrigger() const { return true; }
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
/**
|
2016-07-07 21:43:55 -07:00
|
|
|
* @return The type of analog trigger output to be used.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2016-07-07 21:43:55 -07:00
|
|
|
AnalogTriggerType AnalogTriggerOutput::GetAnalogTriggerTypeForRouting() const {
|
|
|
|
|
return m_outputType;
|
|
|
|
|
}
|
2016-06-30 21:39:09 -07:00
|
|
|
|
|
|
|
|
/**
|
2016-07-07 21:43:55 -07:00
|
|
|
* @return The channel of the source.
|
2016-06-30 21:39:09 -07:00
|
|
|
*/
|
2016-07-07 21:43:55 -07:00
|
|
|
uint32_t AnalogTriggerOutput::GetChannel() const { return m_trigger.m_index; }
|