2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2015-06-25 15:07:55 -04:00
|
|
|
/* Copyright (c) FIRST 2008. All Rights Reserved.
|
|
|
|
|
*/
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "AnalogTriggerOutput.h"
|
|
|
|
|
#include "AnalogTrigger.h"
|
2014-01-06 10:12:21 -05:00
|
|
|
//#include "NetworkCommunication/UsageReporting.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
|
|
|
|
|
* functions
|
2013-12-15 18:30:16 -05:00
|
|
|
* for Counter, Encoder, etc.
|
2014-07-23 16:55:45 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05: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
|
|
|
|
|
* represent.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
AnalogTriggerOutput::AnalogTriggerOutput(AnalogTrigger *trigger,
|
|
|
|
|
AnalogTriggerType outputType)
|
|
|
|
|
: m_trigger(trigger), m_outputType(outputType) {
|
|
|
|
|
HALReport(HALUsageReporting::kResourceType_AnalogTriggerOutput,
|
|
|
|
|
trigger->GetIndex(), outputType);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
AnalogTriggerOutput::~AnalogTriggerOutput() {
|
|
|
|
|
if (m_interrupt != NULL) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
cleanInterrupts(m_interrupt, &status);
|
|
|
|
|
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
|
|
|
|
m_interrupt = NULL;
|
|
|
|
|
m_interrupts->Free(m_interruptIndex);
|
|
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the state of the analog trigger output.
|
|
|
|
|
* @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;
|
2015-06-25 15:07:55 -04:00
|
|
|
bool result =
|
|
|
|
|
getAnalogTriggerOutput(m_trigger->m_trigger, m_outputType, &status);
|
2013-12-15 18:30:16 -05:00
|
|
|
wpi_setErrorWithContext(status, getHALErrorMessage(status));
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return The value to be written to the channel field of a routing mux.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
uint32_t AnalogTriggerOutput::GetChannelForRouting() const {
|
|
|
|
|
return (m_trigger->m_index << 2) + m_outputType;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return The value to be written to the module field of a routing mux.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
uint32_t AnalogTriggerOutput::GetModuleForRouting() const { return 0; }
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return The value to be written to the module field of a routing mux.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool AnalogTriggerOutput::GetAnalogTriggerForRouting() const { return true; }
|