brians | 343bc11 | 2013-02-10 01:53:46 +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); |
brians | fe046f4 | 2013-03-03 23:16:58 +0000 | [diff] [blame] | 44 | break; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 45 | case kState: |
| 46 | result = m_trigger->m_trigger->readOutput_OverLimit(m_trigger->m_index, &localStatus); |
brians | fe046f4 | 2013-03-03 23:16:58 +0000 | [diff] [blame] | 47 | break; |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 48 | case kRisingPulse: |
| 49 | case kFallingPulse: |
| 50 | wpi_setWPIError(AnalogTriggerPulseOutputError); |
| 51 | return false; |
| 52 | } |
| 53 | wpi_setError(localStatus); |
| 54 | return result; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @return The value to be written to the channel field of a routing mux. |
| 59 | */ |
Brian Silverman | 6874947 | 2014-01-05 14:50:00 -0800 | [diff] [blame] | 60 | uint32_t AnalogTriggerOutput::GetChannelForRouting() |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 61 | { |
| 62 | return (m_trigger->m_index << 2) + m_outputType; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @return The value to be written to the module field of a routing mux. |
| 67 | */ |
Brian Silverman | 6874947 | 2014-01-05 14:50:00 -0800 | [diff] [blame] | 68 | uint32_t AnalogTriggerOutput::GetModuleForRouting() |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 69 | { |
| 70 | return m_trigger->m_index >> 2; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @return The value to be written to the module field of a routing mux. |
| 75 | */ |
| 76 | bool AnalogTriggerOutput::GetAnalogTriggerForRouting() |
| 77 | { |
| 78 | return true; |
| 79 | } |