mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Replaced const variables with constexpr (#731)
This commit is contained in:
committed by
Peter Johnson
parent
259461aee9
commit
5af0c9c101
@@ -14,12 +14,6 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
const int ADXL345_I2C::kAddress;
|
||||
const int ADXL345_I2C::kPowerCtlRegister;
|
||||
const int ADXL345_I2C::kDataFormatRegister;
|
||||
const int ADXL345_I2C::kDataRegister;
|
||||
constexpr double ADXL345_I2C::kGsPerLSB;
|
||||
|
||||
/**
|
||||
* Constructs the ADXL345 Accelerometer over I2C.
|
||||
*
|
||||
|
||||
@@ -15,11 +15,6 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
const int ADXL345_SPI::kPowerCtlRegister;
|
||||
const int ADXL345_SPI::kDataFormatRegister;
|
||||
const int ADXL345_SPI::kDataRegister;
|
||||
constexpr double ADXL345_SPI::kGsPerLSB;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
||||
@@ -20,12 +20,6 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
const int AnalogGyro::kOversampleBits;
|
||||
const int AnalogGyro::kAverageBits;
|
||||
constexpr double AnalogGyro::kSamplesPerSecond;
|
||||
constexpr double AnalogGyro::kCalibrationSampleTime;
|
||||
constexpr double AnalogGyro::kDefaultVoltsPerDegreePerSecond;
|
||||
|
||||
/**
|
||||
* Gyro constructor using the Analog Input channel number.
|
||||
*
|
||||
|
||||
@@ -20,10 +20,6 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
const int AnalogInput::kAccumulatorModuleNumber;
|
||||
const int AnalogInput::kAccumulatorNumChannels;
|
||||
const int AnalogInput::kAccumulatorChannels[] = {0, 1};
|
||||
|
||||
/**
|
||||
* Construct an analog input.
|
||||
*
|
||||
|
||||
@@ -32,9 +32,7 @@ struct MatchInfoData {
|
||||
|
||||
using namespace frc;
|
||||
|
||||
const double JOYSTICK_UNPLUGGED_MESSAGE_INTERVAL = 1.0;
|
||||
|
||||
const int DriverStation::kJoystickPorts;
|
||||
static constexpr double kJoystickUnpluggedMessageInterval = 1.0;
|
||||
|
||||
DriverStation::~DriverStation() {
|
||||
m_isRunning = false;
|
||||
@@ -721,7 +719,7 @@ void DriverStation::ReportJoystickUnpluggedError(llvm::StringRef message) {
|
||||
double currentTime = Timer::GetFPGATimestamp();
|
||||
if (currentTime > m_nextMessageTime) {
|
||||
ReportError(message);
|
||||
m_nextMessageTime = currentTime + JOYSTICK_UNPLUGGED_MESSAGE_INTERVAL;
|
||||
m_nextMessageTime = currentTime + kJoystickUnpluggedMessageInterval;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -734,7 +732,7 @@ void DriverStation::ReportJoystickUnpluggedWarning(llvm::StringRef message) {
|
||||
double currentTime = Timer::GetFPGATimestamp();
|
||||
if (currentTime > m_nextMessageTime) {
|
||||
ReportWarning(message);
|
||||
m_nextMessageTime = currentTime + JOYSTICK_UNPLUGGED_MESSAGE_INTERVAL;
|
||||
m_nextMessageTime = currentTime + kJoystickUnpluggedMessageInterval;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
const int RobotDrive::kMaxNumberOfMotors;
|
||||
|
||||
static std::shared_ptr<SpeedController> make_shared_nodelete(
|
||||
SpeedController* ptr) {
|
||||
return std::shared_ptr<SpeedController>(ptr, NullDeleter<SpeedController>());
|
||||
|
||||
@@ -19,17 +19,7 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
// Time (sec) for the ping trigger pulse.
|
||||
constexpr double Ultrasonic::kPingTime;
|
||||
|
||||
// Priority that the ultrasonic round robin task runs.
|
||||
const int Ultrasonic::kPriority;
|
||||
|
||||
// Max time (ms) between readings.
|
||||
constexpr double Ultrasonic::kMaxUltrasonicTime;
|
||||
constexpr double Ultrasonic::kSpeedOfSoundInchesPerSec;
|
||||
|
||||
// Automatic round robin mode.
|
||||
// Automatic round robin mode
|
||||
std::atomic<bool> Ultrasonic::m_automaticEnabled{false};
|
||||
|
||||
std::set<Ultrasonic*> Ultrasonic::m_sensors;
|
||||
|
||||
@@ -59,10 +59,10 @@ class ADXL345_I2C : public Accelerometer, public LiveWindowSendable {
|
||||
protected:
|
||||
I2C m_i2c;
|
||||
|
||||
static const int kAddress = 0x1D;
|
||||
static const int kPowerCtlRegister = 0x2D;
|
||||
static const int kDataFormatRegister = 0x31;
|
||||
static const int kDataRegister = 0x32;
|
||||
static constexpr int kAddress = 0x1D;
|
||||
static constexpr int kPowerCtlRegister = 0x2D;
|
||||
static constexpr int kDataFormatRegister = 0x31;
|
||||
static constexpr int kDataRegister = 0x32;
|
||||
static constexpr double kGsPerLSB = 0.00390625;
|
||||
|
||||
enum PowerCtlFields {
|
||||
|
||||
@@ -37,7 +37,6 @@ class ADXL345_SPI : public Accelerometer, public LiveWindowSendable {
|
||||
double ZAxis;
|
||||
};
|
||||
|
||||
public:
|
||||
explicit ADXL345_SPI(SPI::Port port, Range range = kRange_2G);
|
||||
virtual ~ADXL345_SPI() = default;
|
||||
|
||||
@@ -62,9 +61,9 @@ class ADXL345_SPI : public Accelerometer, public LiveWindowSendable {
|
||||
protected:
|
||||
SPI m_spi;
|
||||
|
||||
static const int kPowerCtlRegister = 0x2D;
|
||||
static const int kDataFormatRegister = 0x31;
|
||||
static const int kDataRegister = 0x32;
|
||||
static constexpr int kPowerCtlRegister = 0x2D;
|
||||
static constexpr int kDataFormatRegister = 0x31;
|
||||
static constexpr int kDataRegister = 0x32;
|
||||
static constexpr double kGsPerLSB = 0.00390625;
|
||||
|
||||
enum SPIAddressFields { kAddress_Read = 0x80, kAddress_MultiByte = 0x40 };
|
||||
|
||||
@@ -32,8 +32,8 @@ class AnalogInput;
|
||||
*/
|
||||
class AnalogGyro : public GyroBase {
|
||||
public:
|
||||
static const int kOversampleBits = 10;
|
||||
static const int kAverageBits = 0;
|
||||
static constexpr int kOversampleBits = 10;
|
||||
static constexpr int kAverageBits = 0;
|
||||
static constexpr double kSamplesPerSecond = 50.0;
|
||||
static constexpr double kCalibrationSampleTime = 5.0;
|
||||
static constexpr double kDefaultVoltsPerDegreePerSecond = 0.007;
|
||||
|
||||
@@ -40,9 +40,9 @@ class AnalogInput : public SensorBase,
|
||||
friend class AnalogGyro;
|
||||
|
||||
public:
|
||||
static const int kAccumulatorModuleNumber = 1;
|
||||
static const int kAccumulatorNumChannels = 2;
|
||||
static const int kAccumulatorChannels[kAccumulatorNumChannels];
|
||||
static constexpr int kAccumulatorModuleNumber = 1;
|
||||
static constexpr int kAccumulatorNumChannels = 2;
|
||||
static constexpr int kAccumulatorChannels[kAccumulatorNumChannels] = {0, 1};
|
||||
|
||||
explicit AnalogInput(int channel);
|
||||
virtual ~AnalogInput();
|
||||
|
||||
@@ -40,7 +40,7 @@ class DriverStation : public SensorBase, public RobotStateInterface {
|
||||
static void ReportError(bool is_error, int code, llvm::StringRef error,
|
||||
llvm::StringRef location, llvm::StringRef stack);
|
||||
|
||||
static const int kJoystickPorts = 6;
|
||||
static constexpr int kJoystickPorts = 6;
|
||||
|
||||
bool GetStickButton(int stick, int button);
|
||||
bool GetStickButtonPressed(int stick, int button);
|
||||
|
||||
@@ -113,7 +113,8 @@ class RobotDrive : public MotorSafety, public ErrorBase {
|
||||
void Normalize(double* wheelSpeeds);
|
||||
void RotateVector(double& x, double& y, double angle);
|
||||
|
||||
static const int kMaxNumberOfMotors = 4;
|
||||
static constexpr int kMaxNumberOfMotors = 4;
|
||||
|
||||
double m_sensitivity = 0.5;
|
||||
double m_maxOutput = 1.0;
|
||||
|
||||
|
||||
@@ -32,8 +32,10 @@ class SolenoidBase : public SensorBase {
|
||||
|
||||
protected:
|
||||
explicit SolenoidBase(int pcmID);
|
||||
static const int m_maxModules = 63;
|
||||
static const int m_maxPorts = 8;
|
||||
|
||||
static constexpr int m_maxModules = 63;
|
||||
static constexpr int m_maxPorts = 8;
|
||||
|
||||
int m_moduleNumber; // PCM module number
|
||||
};
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ class Ultrasonic : public SensorBase,
|
||||
static constexpr double kPingTime = 10 * 1e-6;
|
||||
|
||||
// Priority that the ultrasonic round robin task runs.
|
||||
static const int kPriority = 64;
|
||||
static constexpr int kPriority = 64;
|
||||
|
||||
// Max time (ms) between readings.
|
||||
static constexpr double kMaxUltrasonicTime = 0.1;
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
#ifdef WPI_ERRORS_DEFINE_STRINGS
|
||||
#define S(label, offset, message) \
|
||||
const char* wpi_error_s_##label = message; \
|
||||
const int wpi_error_value_##label = offset
|
||||
constexpr int wpi_error_value_##label = offset
|
||||
#else
|
||||
#define S(label, offset, message) \
|
||||
extern const char* wpi_error_s_##label; \
|
||||
const int wpi_error_value_##label = offset
|
||||
constexpr int wpi_error_value_##label = offset
|
||||
#endif
|
||||
|
||||
// Fatal errors
|
||||
|
||||
Reference in New Issue
Block a user