mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Use Twine in error checks.
This commit is contained in:
@@ -11,8 +11,6 @@
|
||||
#include <HAL/AnalogInput.h>
|
||||
#include <HAL/HAL.h>
|
||||
#include <HAL/Ports.h>
|
||||
#include <llvm/SmallString.h>
|
||||
#include <llvm/raw_ostream.h>
|
||||
|
||||
#include "SmartDashboard/SendableBuilder.h"
|
||||
#include "Timer.h"
|
||||
@@ -27,12 +25,9 @@ using namespace frc;
|
||||
* on-board 4-7 are on the MXP port.
|
||||
*/
|
||||
AnalogInput::AnalogInput(int channel) {
|
||||
llvm::SmallString<32> str;
|
||||
llvm::raw_svector_ostream buf(str);
|
||||
buf << "Analog Input " << channel;
|
||||
|
||||
if (!SensorBase::CheckAnalogInputChannel(channel)) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
|
||||
"Analog Input " + llvm::Twine(channel));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
|
||||
#include <HAL/HAL.h>
|
||||
#include <HAL/Ports.h>
|
||||
#include <llvm/SmallString.h>
|
||||
#include <llvm/raw_ostream.h>
|
||||
|
||||
#include "SensorBase.h"
|
||||
#include "SmartDashboard/SendableBuilder.h"
|
||||
@@ -28,12 +26,9 @@ using namespace frc;
|
||||
* @param channel The channel number on the roboRIO to represent.
|
||||
*/
|
||||
AnalogOutput::AnalogOutput(int channel) {
|
||||
llvm::SmallString<32> str;
|
||||
llvm::raw_svector_ostream buf(str);
|
||||
buf << "analog output " << channel;
|
||||
|
||||
if (!SensorBase::CheckAnalogOutputChannel(channel)) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
|
||||
"analog output " + llvm::Twine(channel));
|
||||
m_channel = std::numeric_limits<int>::max();
|
||||
m_port = HAL_kInvalidHandle;
|
||||
return;
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
#include <HAL/DIO.h>
|
||||
#include <HAL/HAL.h>
|
||||
#include <HAL/Ports.h>
|
||||
#include <llvm/SmallString.h>
|
||||
#include <llvm/raw_ostream.h>
|
||||
|
||||
#include "SmartDashboard/SendableBuilder.h"
|
||||
#include "WPIErrors.h"
|
||||
@@ -28,12 +26,9 @@ using namespace frc;
|
||||
* @param channel The DIO channel 0-9 are on-board, 10-25 are on the MXP port
|
||||
*/
|
||||
DigitalInput::DigitalInput(int channel) {
|
||||
llvm::SmallString<32> str;
|
||||
llvm::raw_svector_ostream buf(str);
|
||||
|
||||
if (!CheckDigitalChannel(channel)) {
|
||||
buf << "Digital Channel " << channel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
|
||||
"Digital Channel " + llvm::Twine(channel));
|
||||
m_channel = std::numeric_limits<int>::max();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
#include <HAL/DIO.h>
|
||||
#include <HAL/HAL.h>
|
||||
#include <HAL/Ports.h>
|
||||
#include <llvm/SmallString.h>
|
||||
#include <llvm/raw_ostream.h>
|
||||
|
||||
#include "SensorBase.h"
|
||||
#include "SmartDashboard/SendableBuilder.h"
|
||||
@@ -30,13 +28,10 @@ using namespace frc;
|
||||
* port
|
||||
*/
|
||||
DigitalOutput::DigitalOutput(int channel) {
|
||||
llvm::SmallString<32> str;
|
||||
llvm::raw_svector_ostream buf(str);
|
||||
|
||||
m_pwmGenerator = HAL_kInvalidHandle;
|
||||
if (!SensorBase::CheckDigitalChannel(channel)) {
|
||||
buf << "Digital Channel " << channel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
|
||||
"Digital Channel " + llvm::Twine(channel));
|
||||
m_channel = std::numeric_limits<int>::max();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
#include <HAL/HAL.h>
|
||||
#include <HAL/Ports.h>
|
||||
#include <HAL/Solenoid.h>
|
||||
#include <llvm/SmallString.h>
|
||||
#include <llvm/raw_ostream.h>
|
||||
|
||||
#include "SensorBase.h"
|
||||
#include "SmartDashboard/SendableBuilder.h"
|
||||
@@ -43,21 +41,22 @@ DoubleSolenoid::DoubleSolenoid(int moduleNumber, int forwardChannel,
|
||||
: SolenoidBase(moduleNumber),
|
||||
m_forwardChannel(forwardChannel),
|
||||
m_reverseChannel(reverseChannel) {
|
||||
llvm::SmallString<32> str;
|
||||
llvm::raw_svector_ostream buf(str);
|
||||
if (!SensorBase::CheckSolenoidModule(m_moduleNumber)) {
|
||||
buf << "Solenoid Module " << m_moduleNumber;
|
||||
wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf.str());
|
||||
wpi_setWPIErrorWithContext(
|
||||
ModuleIndexOutOfRange,
|
||||
"Solenoid Module " + llvm::Twine(m_moduleNumber));
|
||||
return;
|
||||
}
|
||||
if (!SensorBase::CheckSolenoidChannel(m_forwardChannel)) {
|
||||
buf << "Solenoid Module " << m_forwardChannel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
wpi_setWPIErrorWithContext(
|
||||
ChannelIndexOutOfRange,
|
||||
"Solenoid Channel " + llvm::Twine(m_forwardChannel));
|
||||
return;
|
||||
}
|
||||
if (!SensorBase::CheckSolenoidChannel(m_reverseChannel)) {
|
||||
buf << "Solenoid Module " << m_reverseChannel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
wpi_setWPIErrorWithContext(
|
||||
ChannelIndexOutOfRange,
|
||||
"Solenoid Channel " + llvm::Twine(m_reverseChannel));
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
#include "Error.h"
|
||||
|
||||
#include <llvm/Path.h>
|
||||
#include <llvm/SmallString.h>
|
||||
#include <llvm/raw_ostream.h>
|
||||
|
||||
#include "DriverStation.h"
|
||||
#include "Timer.h"
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
#include <HAL/HAL.h>
|
||||
#include <HAL/PWM.h>
|
||||
#include <HAL/Ports.h>
|
||||
#include <llvm/SmallString.h>
|
||||
#include <llvm/raw_ostream.h>
|
||||
|
||||
#include "SensorBase.h"
|
||||
#include "SmartDashboard/SendableBuilder.h"
|
||||
@@ -31,12 +29,9 @@ using namespace frc;
|
||||
* MXP port
|
||||
*/
|
||||
PWM::PWM(int channel) {
|
||||
llvm::SmallString<32> str;
|
||||
llvm::raw_svector_ostream buf(str);
|
||||
|
||||
if (!SensorBase::CheckPWMChannel(channel)) {
|
||||
buf << "PWM Channel " << channel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
|
||||
"PWM Channel " + llvm::Twine(channel));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <HAL/HAL.h>
|
||||
#include <HAL/Ports.h>
|
||||
#include <HAL/Relay.h>
|
||||
#include <llvm/SmallString.h>
|
||||
#include <llvm/raw_ostream.h>
|
||||
|
||||
#include "MotorSafetyHelper.h"
|
||||
#include "SensorBase.h"
|
||||
@@ -30,11 +30,9 @@ using namespace frc;
|
||||
*/
|
||||
Relay::Relay(int channel, Relay::Direction direction)
|
||||
: m_channel(channel), m_direction(direction) {
|
||||
llvm::SmallString<128> str;
|
||||
llvm::raw_svector_ostream buf(str);
|
||||
if (!SensorBase::CheckRelayChannel(m_channel)) {
|
||||
buf << "Relay Channel " << m_channel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
|
||||
"Relay Channel " + llvm::Twine(m_channel));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
#include <HAL/HAL.h>
|
||||
#include <HAL/Ports.h>
|
||||
#include <HAL/Solenoid.h>
|
||||
#include <llvm/SmallString.h>
|
||||
#include <llvm/raw_ostream.h>
|
||||
|
||||
#include "SensorBase.h"
|
||||
#include "SmartDashboard/SendableBuilder.h"
|
||||
@@ -35,16 +33,15 @@ Solenoid::Solenoid(int channel)
|
||||
*/
|
||||
Solenoid::Solenoid(int moduleNumber, int channel)
|
||||
: SolenoidBase(moduleNumber), m_channel(channel) {
|
||||
llvm::SmallString<32> str;
|
||||
llvm::raw_svector_ostream buf(str);
|
||||
if (!SensorBase::CheckSolenoidModule(m_moduleNumber)) {
|
||||
buf << "Solenoid Module " << m_moduleNumber;
|
||||
wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf.str());
|
||||
wpi_setWPIErrorWithContext(
|
||||
ModuleIndexOutOfRange,
|
||||
"Solenoid Module " + llvm::Twine(m_moduleNumber));
|
||||
return;
|
||||
}
|
||||
if (!SensorBase::CheckSolenoidChannel(m_channel)) {
|
||||
buf << "Solenoid Module " << m_channel;
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
|
||||
"Solenoid Channel " + llvm::Twine(m_channel));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user