blob: eb67d3612efce414be92efa5794991f90835b173 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05002/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
Brian Silverman26e4e522015-12-17 01:56:40 -05003/* Open Source Software - may be modified and shared by FRC teams. The code */
Brian Silverman1a675112016-02-20 20:42:49 -05004/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
Brian Silverman26e4e522015-12-17 01:56:40 -05006/*----------------------------------------------------------------------------*/
7
8#include "AnalogTriggerOutput.h"
9#include "AnalogTrigger.h"
10#include "WPIErrors.h"
11
12/**
13 * Create an object that represents one of the four outputs from an analog
14 * trigger.
15 *
16 * Because this class derives from DigitalSource, it can be passed into routing
17 * functions
18 * for Counter, Encoder, etc.
19 *
20 * @param trigger A pointer to the trigger for which this is an output.
21 * @param outputType An enum that specifies the output on the trigger to
22 * represent.
23 */
24AnalogTriggerOutput::AnalogTriggerOutput(const AnalogTrigger &trigger,
25 AnalogTriggerType outputType)
26 : m_trigger(trigger), m_outputType(outputType) {
27 HALReport(HALUsageReporting::kResourceType_AnalogTriggerOutput,
28 trigger.GetIndex(), outputType);
29}
30
31AnalogTriggerOutput::~AnalogTriggerOutput() {
32 if (m_interrupt != nullptr) {
33 int32_t status = 0;
34 cleanInterrupts(m_interrupt, &status);
35 wpi_setErrorWithContext(status, getHALErrorMessage(status));
36 m_interrupt = nullptr;
37 m_interrupts->Free(m_interruptIndex);
38 }
39}
40
41/**
42 * Get the state of the analog trigger output.
43 * @return The state of the analog trigger output.
44 */
45bool AnalogTriggerOutput::Get() const {
46 int32_t status = 0;
47 bool result =
48 getAnalogTriggerOutput(m_trigger.m_trigger, m_outputType, &status);
49 wpi_setErrorWithContext(status, getHALErrorMessage(status));
50 return result;
51}
52
53/**
54 * @return The value to be written to the channel field of a routing mux.
55 */
56uint32_t AnalogTriggerOutput::GetChannelForRouting() const {
57 return (m_trigger.m_index << 2) + m_outputType;
58}
59
60/**
61 * @return The value to be written to the module field of a routing mux.
62 */
63uint32_t AnalogTriggerOutput::GetModuleForRouting() const { return 0; }
64
65/**
66 * @return The value to be written to the module field of a routing mux.
67 */
68bool AnalogTriggerOutput::GetAnalogTriggerForRouting() const { return true; }