2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "SensorBase.h"
|
|
|
|
|
|
2017-08-27 00:11:52 -07:00
|
|
|
#include <HAL/AnalogInput.h>
|
|
|
|
|
#include <HAL/AnalogOutput.h>
|
|
|
|
|
#include <HAL/DIO.h>
|
|
|
|
|
#include <HAL/HAL.h>
|
|
|
|
|
#include <HAL/PDP.h>
|
|
|
|
|
#include <HAL/PWM.h>
|
|
|
|
|
#include <HAL/Ports.h>
|
|
|
|
|
#include <HAL/Relay.h>
|
|
|
|
|
#include <HAL/Solenoid.h>
|
|
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
#include "WPIErrors.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
using namespace frc;
|
|
|
|
|
|
2016-08-12 13:45:28 -07:00
|
|
|
const int SensorBase::kDigitalChannels = HAL_GetNumDigitalChannels();
|
2016-07-20 22:47:29 -07:00
|
|
|
const int SensorBase::kAnalogInputs = HAL_GetNumAnalogInputs();
|
2016-08-12 13:45:28 -07:00
|
|
|
const int SensorBase::kSolenoidChannels = HAL_GetNumSolenoidChannels();
|
2016-07-20 22:47:29 -07:00
|
|
|
const int SensorBase::kSolenoidModules = HAL_GetNumPCMModules();
|
2016-08-12 13:45:28 -07:00
|
|
|
const int SensorBase::kPwmChannels = HAL_GetNumPWMChannels();
|
2016-07-20 22:47:29 -07:00
|
|
|
const int SensorBase::kRelayChannels = HAL_GetNumRelayHeaders();
|
|
|
|
|
const int SensorBase::kPDPChannels = HAL_GetNumPDPChannels();
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check that the solenoid module number is valid.
|
2014-06-12 18:07:45 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return Solenoid module is valid and present
|
|
|
|
|
*/
|
2016-07-20 22:47:29 -07:00
|
|
|
bool SensorBase::CheckSolenoidModule(int moduleNumber) {
|
|
|
|
|
return HAL_CheckSolenoidModule(moduleNumber);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check that the digital channel number is valid.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Verify that the channel number is one of the legal channel numbers. Channel
|
2016-05-20 17:30:37 -07:00
|
|
|
* numbers are 1-based.
|
2014-06-12 18:07:45 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return Digital channel is valid
|
|
|
|
|
*/
|
2016-07-20 22:47:29 -07:00
|
|
|
bool SensorBase::CheckDigitalChannel(int channel) {
|
|
|
|
|
return HAL_CheckDIOChannel(channel);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-06-29 18:58:14 -07:00
|
|
|
* Check that the relay channel number is valid.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Verify that the channel number is one of the legal channel numbers. Channel
|
2016-06-29 18:58:14 -07:00
|
|
|
* numbers are 0-based.
|
2014-06-12 18:07:45 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return Relay channel is valid
|
|
|
|
|
*/
|
2016-07-20 22:47:29 -07:00
|
|
|
bool SensorBase::CheckRelayChannel(int channel) {
|
|
|
|
|
return HAL_CheckRelayChannel(channel);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check that the digital channel number is valid.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Verify that the channel number is one of the legal channel numbers. Channel
|
2016-05-20 17:30:37 -07:00
|
|
|
* numbers are 1-based.
|
2014-06-12 18:07:45 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return PWM channel is valid
|
|
|
|
|
*/
|
2016-07-20 22:47:29 -07:00
|
|
|
bool SensorBase::CheckPWMChannel(int channel) {
|
|
|
|
|
return HAL_CheckPWMChannel(channel);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-06-12 18:07:45 -04:00
|
|
|
* Check that the analog input number is value.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Verify that the analog input number is one of the legal channel numbers.
|
2016-05-20 17:30:37 -07:00
|
|
|
* Channel numbers are 0-based.
|
2014-06-12 18:07:45 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return Analog channel is valid
|
|
|
|
|
*/
|
2016-07-21 23:24:06 -07:00
|
|
|
bool SensorBase::CheckAnalogInputChannel(int channel) {
|
2016-07-20 22:47:29 -07:00
|
|
|
return HAL_CheckAnalogInputChannel(channel);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2014-06-12 18:07:45 -04:00
|
|
|
/**
|
2014-06-24 10:37:02 -07:00
|
|
|
* Check that the analog output number is valid.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Verify that the analog output number is one of the legal channel numbers.
|
2016-05-20 17:30:37 -07:00
|
|
|
* Channel numbers are 0-based.
|
2014-06-12 18:07:45 -04:00
|
|
|
*
|
|
|
|
|
* @return Analog channel is valid
|
|
|
|
|
*/
|
2016-07-21 23:24:06 -07:00
|
|
|
bool SensorBase::CheckAnalogOutputChannel(int channel) {
|
2016-07-20 22:47:29 -07:00
|
|
|
return HAL_CheckAnalogOutputChannel(channel);
|
2014-06-12 18:07:45 -04:00
|
|
|
}
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
|
|
|
|
* Verify that the solenoid channel number is within limits.
|
2014-06-12 18:07:45 -04:00
|
|
|
*
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return Solenoid channel is valid
|
|
|
|
|
*/
|
2016-07-20 22:47:29 -07:00
|
|
|
bool SensorBase::CheckSolenoidChannel(int channel) {
|
|
|
|
|
return HAL_CheckSolenoidChannel(channel);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2014-05-30 14:04:05 -04:00
|
|
|
/**
|
|
|
|
|
* Verify that the power distribution channel number is within limits.
|
2014-06-12 18:07:45 -04:00
|
|
|
*
|
2014-06-24 10:37:02 -07:00
|
|
|
* @return PDP channel is valid
|
2014-05-30 14:04:05 -04:00
|
|
|
*/
|
2016-07-20 22:47:29 -07:00
|
|
|
bool SensorBase::CheckPDPChannel(int channel) {
|
|
|
|
|
return HAL_CheckPDPModule(channel);
|
2014-05-30 14:04:05 -04:00
|
|
|
}
|