diff --git a/wpilibc/src/main/native/cpp/ADXL345_I2C.cpp b/wpilibc/src/main/native/cpp/ADXL345_I2C.cpp index 49c7aac228..64011ce68c 100644 --- a/wpilibc/src/main/native/cpp/ADXL345_I2C.cpp +++ b/wpilibc/src/main/native/cpp/ADXL345_I2C.cpp @@ -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. * diff --git a/wpilibc/src/main/native/cpp/ADXL345_SPI.cpp b/wpilibc/src/main/native/cpp/ADXL345_SPI.cpp index 022c598666..03ae558a65 100644 --- a/wpilibc/src/main/native/cpp/ADXL345_SPI.cpp +++ b/wpilibc/src/main/native/cpp/ADXL345_SPI.cpp @@ -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. * diff --git a/wpilibc/src/main/native/cpp/AnalogGyro.cpp b/wpilibc/src/main/native/cpp/AnalogGyro.cpp index 440d6a1529..45ae83ed6b 100644 --- a/wpilibc/src/main/native/cpp/AnalogGyro.cpp +++ b/wpilibc/src/main/native/cpp/AnalogGyro.cpp @@ -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. * diff --git a/wpilibc/src/main/native/cpp/AnalogInput.cpp b/wpilibc/src/main/native/cpp/AnalogInput.cpp index 3e425b69c3..11668c780a 100644 --- a/wpilibc/src/main/native/cpp/AnalogInput.cpp +++ b/wpilibc/src/main/native/cpp/AnalogInput.cpp @@ -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. * diff --git a/wpilibc/src/main/native/cpp/DriverStation.cpp b/wpilibc/src/main/native/cpp/DriverStation.cpp index 963ce3174c..5b49cfea84 100644 --- a/wpilibc/src/main/native/cpp/DriverStation.cpp +++ b/wpilibc/src/main/native/cpp/DriverStation.cpp @@ -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; } } diff --git a/wpilibc/src/main/native/cpp/RobotDrive.cpp b/wpilibc/src/main/native/cpp/RobotDrive.cpp index ab307d896b..c07804bd2b 100644 --- a/wpilibc/src/main/native/cpp/RobotDrive.cpp +++ b/wpilibc/src/main/native/cpp/RobotDrive.cpp @@ -20,8 +20,6 @@ using namespace frc; -const int RobotDrive::kMaxNumberOfMotors; - static std::shared_ptr make_shared_nodelete( SpeedController* ptr) { return std::shared_ptr(ptr, NullDeleter()); diff --git a/wpilibc/src/main/native/cpp/Ultrasonic.cpp b/wpilibc/src/main/native/cpp/Ultrasonic.cpp index 10180fe76f..72d84071b0 100644 --- a/wpilibc/src/main/native/cpp/Ultrasonic.cpp +++ b/wpilibc/src/main/native/cpp/Ultrasonic.cpp @@ -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 Ultrasonic::m_automaticEnabled{false}; std::set Ultrasonic::m_sensors; diff --git a/wpilibc/src/main/native/include/ADXL345_I2C.h b/wpilibc/src/main/native/include/ADXL345_I2C.h index 307936b249..456ada7f9c 100644 --- a/wpilibc/src/main/native/include/ADXL345_I2C.h +++ b/wpilibc/src/main/native/include/ADXL345_I2C.h @@ -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 { diff --git a/wpilibc/src/main/native/include/ADXL345_SPI.h b/wpilibc/src/main/native/include/ADXL345_SPI.h index 1699867178..4531b2ea5d 100644 --- a/wpilibc/src/main/native/include/ADXL345_SPI.h +++ b/wpilibc/src/main/native/include/ADXL345_SPI.h @@ -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 }; diff --git a/wpilibc/src/main/native/include/AnalogGyro.h b/wpilibc/src/main/native/include/AnalogGyro.h index 8a324def7b..c8e85a7a90 100644 --- a/wpilibc/src/main/native/include/AnalogGyro.h +++ b/wpilibc/src/main/native/include/AnalogGyro.h @@ -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; diff --git a/wpilibc/src/main/native/include/AnalogInput.h b/wpilibc/src/main/native/include/AnalogInput.h index 3452c7cac0..8b7e50ce6e 100644 --- a/wpilibc/src/main/native/include/AnalogInput.h +++ b/wpilibc/src/main/native/include/AnalogInput.h @@ -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(); diff --git a/wpilibc/src/main/native/include/DriverStation.h b/wpilibc/src/main/native/include/DriverStation.h index f93c71c3fc..c7da010d31 100644 --- a/wpilibc/src/main/native/include/DriverStation.h +++ b/wpilibc/src/main/native/include/DriverStation.h @@ -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); diff --git a/wpilibc/src/main/native/include/RobotDrive.h b/wpilibc/src/main/native/include/RobotDrive.h index 5d0dbffe2c..bff04390d7 100644 --- a/wpilibc/src/main/native/include/RobotDrive.h +++ b/wpilibc/src/main/native/include/RobotDrive.h @@ -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; diff --git a/wpilibc/src/main/native/include/SolenoidBase.h b/wpilibc/src/main/native/include/SolenoidBase.h index 6d83581ade..7edc933eba 100644 --- a/wpilibc/src/main/native/include/SolenoidBase.h +++ b/wpilibc/src/main/native/include/SolenoidBase.h @@ -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 }; diff --git a/wpilibc/src/main/native/include/Ultrasonic.h b/wpilibc/src/main/native/include/Ultrasonic.h index 48d77601be..8e1ee1c86f 100644 --- a/wpilibc/src/main/native/include/Ultrasonic.h +++ b/wpilibc/src/main/native/include/Ultrasonic.h @@ -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; diff --git a/wpilibc/src/main/native/include/WPIErrors.h b/wpilibc/src/main/native/include/WPIErrors.h index b14a1c5b7a..f65f241bcf 100644 --- a/wpilibc/src/main/native/include/WPIErrors.h +++ b/wpilibc/src/main/native/include/WPIErrors.h @@ -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