blob: 415e3f9d96f2696cbe81e117635783b8fa546105 [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001/*----------------------------------------------------------------------------*/
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 */
21AnalogTriggerOutput::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
28AnalogTriggerOutput::~AnalogTriggerOutput()
29{
30}
31
32/**
33 * Get the state of the analog trigger output.
34 * @return The state of the analog trigger output.
35 */
36bool 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);
briansfe046f42013-03-03 23:16:58 +000044 break;
brians343bc112013-02-10 01:53:46 +000045 case kState:
46 result = m_trigger->m_trigger->readOutput_OverLimit(m_trigger->m_index, &localStatus);
briansfe046f42013-03-03 23:16:58 +000047 break;
brians343bc112013-02-10 01:53:46 +000048 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 Silverman68749472014-01-05 14:50:00 -080060uint32_t AnalogTriggerOutput::GetChannelForRouting()
brians343bc112013-02-10 01:53:46 +000061{
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 Silverman68749472014-01-05 14:50:00 -080068uint32_t AnalogTriggerOutput::GetModuleForRouting()
brians343bc112013-02-10 01:53:46 +000069{
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 */
76bool AnalogTriggerOutput::GetAnalogTriggerForRouting()
77{
78 return true;
79}