blob: 1a4987ce68a642f2f90eab9a58f1597c58d0731d [file] [log] [blame]
Brian Silvermanf7f267a2017-02-04 16:16:08 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008-2017. 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 the root directory of */
5/* the project. */
6/*----------------------------------------------------------------------------*/
7
8#include "SensorBase.h"
9
10#include "FRC_NetworkCommunication/LoadOut.h"
11#include "HAL/AnalogInput.h"
12#include "HAL/AnalogOutput.h"
13#include "HAL/DIO.h"
14#include "HAL/HAL.h"
15#include "HAL/PDP.h"
16#include "HAL/PWM.h"
17#include "HAL/Ports.h"
18#include "HAL/Relay.h"
19#include "HAL/Solenoid.h"
20#include "WPIErrors.h"
21
22using namespace frc;
23
24const int SensorBase::kDigitalChannels = HAL_GetNumDigitalChannels();
25const int SensorBase::kAnalogInputs = HAL_GetNumAnalogInputs();
26const int SensorBase::kSolenoidChannels = HAL_GetNumSolenoidChannels();
27const int SensorBase::kSolenoidModules = HAL_GetNumPCMModules();
28const int SensorBase::kPwmChannels = HAL_GetNumPWMChannels();
29const int SensorBase::kRelayChannels = HAL_GetNumRelayHeaders();
30const int SensorBase::kPDPChannels = HAL_GetNumPDPChannels();
31
32/**
33 * Check that the solenoid module number is valid.
34 *
35 * @return Solenoid module is valid and present
36 */
37bool SensorBase::CheckSolenoidModule(int moduleNumber) {
38 return HAL_CheckSolenoidModule(moduleNumber);
39}
40
41/**
42 * Check that the digital channel number is valid.
43 *
44 * Verify that the channel number is one of the legal channel numbers. Channel
45 * numbers are 1-based.
46 *
47 * @return Digital channel is valid
48 */
49bool SensorBase::CheckDigitalChannel(int channel) {
50 return HAL_CheckDIOChannel(channel);
51}
52
53/**
54 * Check that the relay channel number is valid.
55 *
56 * Verify that the channel number is one of the legal channel numbers. Channel
57 * numbers are 0-based.
58 *
59 * @return Relay channel is valid
60 */
61bool SensorBase::CheckRelayChannel(int channel) {
62 return HAL_CheckRelayChannel(channel);
63}
64
65/**
66 * Check that the digital channel number is valid.
67 *
68 * Verify that the channel number is one of the legal channel numbers. Channel
69 * numbers are 1-based.
70 *
71 * @return PWM channel is valid
72 */
73bool SensorBase::CheckPWMChannel(int channel) {
74 return HAL_CheckPWMChannel(channel);
75}
76
77/**
78 * Check that the analog input number is value.
79 *
80 * Verify that the analog input number is one of the legal channel numbers.
81 * Channel numbers are 0-based.
82 *
83 * @return Analog channel is valid
84 */
85bool SensorBase::CheckAnalogInputChannel(int channel) {
86 return HAL_CheckAnalogInputChannel(channel);
87}
88
89/**
90 * Check that the analog output number is valid.
91 *
92 * Verify that the analog output number is one of the legal channel numbers.
93 * Channel numbers are 0-based.
94 *
95 * @return Analog channel is valid
96 */
97bool SensorBase::CheckAnalogOutputChannel(int channel) {
98 return HAL_CheckAnalogOutputChannel(channel);
99}
100
101/**
102 * Verify that the solenoid channel number is within limits.
103 *
104 * @return Solenoid channel is valid
105 */
106bool SensorBase::CheckSolenoidChannel(int channel) {
107 return HAL_CheckSolenoidChannel(channel);
108}
109
110/**
111 * Verify that the power distribution channel number is within limits.
112 *
113 * @return PDP channel is valid
114 */
115bool SensorBase::CheckPDPChannel(int channel) {
116 return HAL_CheckPDPModule(channel);
117}