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