jerrym | f157933 | 2013-02-07 01:56:28 +0000 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/
|
| 2 | /* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */
|
| 5 | /*----------------------------------------------------------------------------*/
|
| 6 |
|
| 7 | #include "AnalogTriggerOutput.h"
|
| 8 | #include "AnalogTrigger.h"
|
| 9 | #include "NetworkCommunication/UsageReporting.h"
|
| 10 | #include "WPIErrors.h"
|
| 11 |
|
| 12 | /**
|
| 13 | * Create an object that represents one of the four outputs from an analog trigger.
|
| 14 | *
|
| 15 | * Because this class derives from DigitalSource, it can be passed into routing functions
|
| 16 | * for Counter, Encoder, etc.
|
| 17 | *
|
| 18 | * @param trigger A pointer to the trigger for which this is an output.
|
| 19 | * @param outputType An enum that specifies the output on the trigger to represent.
|
| 20 | */
|
| 21 | AnalogTriggerOutput::AnalogTriggerOutput(AnalogTrigger *trigger, AnalogTriggerOutput::Type outputType)
|
| 22 | : m_trigger (trigger)
|
| 23 | , m_outputType (outputType)
|
| 24 | {
|
| 25 | nUsageReporting::report(nUsageReporting::kResourceType_AnalogTriggerOutput, trigger->GetIndex(), outputType);
|
| 26 | }
|
| 27 |
|
| 28 | AnalogTriggerOutput::~AnalogTriggerOutput()
|
| 29 | {
|
| 30 | }
|
| 31 |
|
| 32 | /**
|
| 33 | * Get the state of the analog trigger output.
|
| 34 | * @return The state of the analog trigger output.
|
| 35 | */
|
| 36 | bool AnalogTriggerOutput::Get()
|
| 37 | {
|
| 38 | tRioStatusCode localStatus = NiFpga_Status_Success;
|
| 39 | bool result = false;
|
| 40 | switch(m_outputType)
|
| 41 | {
|
| 42 | case kInWindow:
|
| 43 | result = m_trigger->m_trigger->readOutput_InHysteresis(m_trigger->m_index, &localStatus);
|
| 44 | case kState:
|
| 45 | result = m_trigger->m_trigger->readOutput_OverLimit(m_trigger->m_index, &localStatus);
|
| 46 | case kRisingPulse:
|
| 47 | case kFallingPulse:
|
| 48 | wpi_setWPIError(AnalogTriggerPulseOutputError);
|
| 49 | return false;
|
| 50 | }
|
| 51 | wpi_setError(localStatus);
|
| 52 | return result;
|
| 53 | }
|
| 54 |
|
| 55 | /**
|
| 56 | * @return The value to be written to the channel field of a routing mux.
|
| 57 | */
|
| 58 | UINT32 AnalogTriggerOutput::GetChannelForRouting()
|
| 59 | {
|
| 60 | return (m_trigger->m_index << 2) + m_outputType;
|
| 61 | }
|
| 62 |
|
| 63 | /**
|
| 64 | * @return The value to be written to the module field of a routing mux.
|
| 65 | */
|
| 66 | UINT32 AnalogTriggerOutput::GetModuleForRouting()
|
| 67 | {
|
| 68 | return m_trigger->m_index >> 2;
|
| 69 | }
|
| 70 |
|
| 71 | /**
|
| 72 | * @return The value to be written to the module field of a routing mux.
|
| 73 | */
|
| 74 | bool AnalogTriggerOutput::GetAnalogTriggerForRouting()
|
| 75 | {
|
| 76 | return true;
|
| 77 | }
|
| 78 |
|
| 79 | /**
|
| 80 | * Request interrupts asynchronously on this analog trigger output.
|
| 81 | * TODO: Hardware supports interrupts on Analog Trigger outputs... WPILib should too
|
| 82 | */
|
| 83 | void AnalogTriggerOutput::RequestInterrupts(tInterruptHandler handler, void *param)
|
| 84 | {
|
| 85 | }
|
| 86 |
|
| 87 | /**
|
| 88 | * Request interrupts synchronously on this analog trigger output.
|
| 89 | * TODO: Hardware supports interrupts on Analog Trigger outputs... WPILib should too
|
| 90 | */
|
| 91 | void AnalogTriggerOutput::RequestInterrupts()
|
| 92 | {
|
| 93 | }
|
| 94 |
|