Fixes warnings thrown by cpplint.py (#154)

* Fixed cpplint.py [runtime/int] warnings

* Fixed cpplint.py [readability/casting] warnings

* Fixed cpplint.py [readability/namespace] warnings

* Fixed cpplint.py [readability/braces] warnings

* Fixed cpplint.py [whitespace/braces] warnings

* Fixed cpplint.py [runtime/explicit] warnings

* Fixed cpplint.py [runtime/printf] warnings

* Fixed cpplint.py [readability/inheritance] warnings

* Fixed cpplint.py [whitespace/tab] warnings

* Fixed cpplint.py [build/storage_class] warnings

* Fixed cpplint.py [readability/multiline_comment] warnings

* Fixed cpplint.py [whitespace/semicolon] warnings

* Fixed cpplint.py [readability/check] warnings

* Fixed cpplint.py [runtime/arrays] warnings

* Ran format.py
This commit is contained in:
Tyler Veness
2016-07-10 17:47:44 -07:00
committed by Peter Johnson
parent e44a6e227a
commit 0cb288ffba
141 changed files with 670 additions and 626 deletions

View File

@@ -53,8 +53,8 @@ double ADXL345_I2C::GetZ() { return GetAcceleration(kAxis_Z); }
*/
double ADXL345_I2C::GetAcceleration(ADXL345_I2C::Axes axis) {
int16_t rawAccel = 0;
m_i2c.Read(kDataRegister + (uint8_t)axis, sizeof(rawAccel),
(uint8_t*)&rawAccel);
m_i2c.Read(kDataRegister + static_cast<uint8_t>(axis), sizeof(rawAccel),
reinterpret_cast<uint8_t*>(&rawAccel));
return rawAccel * kGsPerLSB;
}
@@ -67,7 +67,8 @@ double ADXL345_I2C::GetAcceleration(ADXL345_I2C::Axes axis) {
ADXL345_I2C::AllAxes ADXL345_I2C::GetAccelerations() {
AllAxes data = AllAxes();
int16_t rawData[3];
m_i2c.Read(kDataRegister, sizeof(rawData), (uint8_t*)rawData);
m_i2c.Read(kDataRegister, sizeof(rawData),
reinterpret_cast<uint8_t*>(rawData));
data.XAxis = rawData[0] * kGsPerLSB;
data.YAxis = rawData[1] * kGsPerLSB;

View File

@@ -133,8 +133,8 @@ void ADXRS450_Gyro::Reset() { m_spi.ResetAccumulator(); }
* integration of the returned rate from the gyro.
*/
float ADXRS450_Gyro::GetAngle() const {
return (float)(m_spi.GetAccumulatorValue() * kDegreePerSecondPerLSB *
kSamplePeriod);
return static_cast<float>(m_spi.GetAccumulatorValue() *
kDegreePerSecondPerLSB * kSamplePeriod);
}
/**
@@ -145,5 +145,6 @@ float ADXRS450_Gyro::GetAngle() const {
* @return the current rate in degrees per second
*/
double ADXRS450_Gyro::GetRate() const {
return (double)m_spi.GetAccumulatorLastValue() * kDegreePerSecondPerLSB;
return static_cast<double>(m_spi.GetAccumulatorLastValue()) *
kDegreePerSecondPerLSB;
}

View File

@@ -343,58 +343,58 @@ void CANJaguar::PIDWrite(float output) {
}
uint8_t CANJaguar::packPercentage(uint8_t* buffer, double value) {
int16_t intValue = (int16_t)(value * 32767.0);
*((int16_t*)buffer) = swap16(intValue);
int16_t intValue = static_cast<int16_t>(value * 32767.0);
*reinterpret_cast<int16_t*>(buffer) = swap16(intValue);
return sizeof(int16_t);
}
uint8_t CANJaguar::packFXP8_8(uint8_t* buffer, double value) {
int16_t intValue = (int16_t)(value * 256.0);
*((int16_t*)buffer) = swap16(intValue);
int16_t intValue = static_cast<int16_t>(value * 256.0);
*reinterpret_cast<int16_t*>(buffer) = swap16(intValue);
return sizeof(int16_t);
}
uint8_t CANJaguar::packFXP16_16(uint8_t* buffer, double value) {
int32_t intValue = (int32_t)(value * 65536.0);
*((int32_t*)buffer) = swap32(intValue);
int32_t intValue = static_cast<int32_t>(value * 65536.0);
*reinterpret_cast<int32_t*>(buffer) = swap32(intValue);
return sizeof(int32_t);
}
uint8_t CANJaguar::packint16_t(uint8_t* buffer, int16_t value) {
*((int16_t*)buffer) = swap16(value);
*reinterpret_cast<int16_t*>(buffer) = swap16(value);
return sizeof(int16_t);
}
uint8_t CANJaguar::packint32_t(uint8_t* buffer, int32_t value) {
*((int32_t*)buffer) = swap32(value);
*reinterpret_cast<int32_t*>(buffer) = swap32(value);
return sizeof(int32_t);
}
double CANJaguar::unpackPercentage(uint8_t* buffer) const {
int16_t value = *((int16_t*)buffer);
int16_t value = *reinterpret_cast<int16_t*>(buffer);
value = swap16(value);
return value / 32767.0;
}
double CANJaguar::unpackFXP8_8(uint8_t* buffer) const {
int16_t value = *((int16_t*)buffer);
int16_t value = *reinterpret_cast<int16_t*>(buffer);
value = swap16(value);
return value / 256.0;
}
double CANJaguar::unpackFXP16_16(uint8_t* buffer) const {
int32_t value = *((int32_t*)buffer);
int32_t value = *reinterpret_cast<int32_t*>(buffer);
value = swap32(value);
return value / 65536.0;
}
int16_t CANJaguar::unpackint16_t(uint8_t* buffer) const {
int16_t value = *((int16_t*)buffer);
int16_t value = *reinterpret_cast<int16_t*>(buffer);
return swap16(value);
}
int32_t CANJaguar::unpackint32_t(uint8_t* buffer) const {
int32_t value = *((int32_t*)buffer);
int32_t value = *reinterpret_cast<int32_t*>(buffer);
return swap32(value);
}
@@ -552,7 +552,7 @@ void CANJaguar::verify() {
// If the Jaguar lost power, everything should be considered unverified.
if (getMessage(LM_API_STATUS_POWER, CAN_MSGID_FULL_M, dataBuffer,
&dataSize)) {
bool powerCycled = (bool)dataBuffer[0];
bool powerCycled = static_cast<bool>(dataBuffer[0]);
if (powerCycled) {
// Clear the power cycled bit
@@ -667,13 +667,13 @@ void CANJaguar::verify() {
if (!m_pVerified) {
uint32_t message = 0;
if (m_controlMode == kSpeed)
if (m_controlMode == kSpeed) {
message = LM_API_SPD_PC;
else if (m_controlMode == kPosition)
} else if (m_controlMode == kPosition) {
message = LM_API_POS_PC;
else if (m_controlMode == kCurrent)
} else if (m_controlMode == kCurrent) {
message = LM_API_ICTRL_PC;
else {
} else {
wpi_setWPIErrorWithContext(
IncompatibleMode,
"PID constants only apply in Speed, Position, and Current mode");
@@ -697,13 +697,13 @@ void CANJaguar::verify() {
if (!m_iVerified) {
uint32_t message = 0;
if (m_controlMode == kSpeed)
if (m_controlMode == kSpeed) {
message = LM_API_SPD_IC;
else if (m_controlMode == kPosition)
} else if (m_controlMode == kPosition) {
message = LM_API_POS_IC;
else if (m_controlMode == kCurrent)
} else if (m_controlMode == kCurrent) {
message = LM_API_ICTRL_IC;
else {
} else {
wpi_setWPIErrorWithContext(
IncompatibleMode,
"PID constants only apply in Speed, Position, and Current mode");
@@ -727,13 +727,13 @@ void CANJaguar::verify() {
if (!m_dVerified) {
uint32_t message = 0;
if (m_controlMode == kSpeed)
if (m_controlMode == kSpeed) {
message = LM_API_SPD_DC;
else if (m_controlMode == kPosition)
} else if (m_controlMode == kPosition) {
message = LM_API_POS_DC;
else if (m_controlMode == kCurrent)
} else if (m_controlMode == kCurrent) {
message = LM_API_ICTRL_DC;
else {
} else {
wpi_setWPIErrorWithContext(
IncompatibleMode,
"PID constants only apply in Speed, Position, and Current mode");
@@ -807,9 +807,9 @@ void CANJaguar::verify() {
&dataSize)) {
LimitMode mode = (LimitMode)dataBuffer[0];
if (mode == m_limitMode)
if (mode == m_limitMode) {
m_limitModeVerified = true;
else {
} else {
// It's wrong - set it again
ConfigLimitMode(m_limitMode);
}
@@ -824,9 +824,9 @@ void CANJaguar::verify() {
&dataSize)) {
double limit = unpackFXP16_16(dataBuffer);
if (FXP16_EQ(limit, m_forwardLimit))
if (FXP16_EQ(limit, m_forwardLimit)) {
m_forwardLimitVerified = true;
else {
} else {
// It's wrong - set it again
ConfigForwardLimit(m_forwardLimit);
}
@@ -841,9 +841,9 @@ void CANJaguar::verify() {
&dataSize)) {
double limit = unpackFXP16_16(dataBuffer);
if (FXP16_EQ(limit, m_reverseLimit))
if (FXP16_EQ(limit, m_reverseLimit)) {
m_reverseLimitVerified = true;
else {
} else {
// It's wrong - set it again
ConfigReverseLimit(m_reverseLimit);
}
@@ -861,9 +861,9 @@ void CANJaguar::verify() {
// The returned max output voltage is sometimes slightly higher or
// lower than what was sent. This should not trigger resending
// the message.
if (std::abs(voltage - m_maxOutputVoltage) < 0.1)
if (std::abs(voltage - m_maxOutputVoltage) < 0.1) {
m_maxOutputVoltageVerified = true;
else {
} else {
// It's wrong - set it again
ConfigMaxOutputVoltage(m_maxOutputVoltage);
}
@@ -879,9 +879,9 @@ void CANJaguar::verify() {
&dataSize)) {
double rate = unpackPercentage(dataBuffer);
if (FXP16_EQ(rate, m_voltageRampRate))
if (FXP16_EQ(rate, m_voltageRampRate)) {
m_voltageRampRateVerified = true;
else {
} else {
// It's wrong - set it again
SetVoltageRampRate(m_voltageRampRate);
}
@@ -894,9 +894,9 @@ void CANJaguar::verify() {
&dataSize)) {
double rate = unpackFXP8_8(dataBuffer);
if (FXP8_EQ(rate, m_voltageRampRate))
if (FXP8_EQ(rate, m_voltageRampRate)) {
m_voltageRampRateVerified = true;
else {
} else {
// It's wrong - set it again
SetVoltageRampRate(m_voltageRampRate);
}
@@ -912,9 +912,9 @@ void CANJaguar::verify() {
&dataSize)) {
uint16_t faultTime = unpackint16_t(dataBuffer);
if ((uint16_t)(m_faultTime * 1000.0) == faultTime)
if ((uint16_t)(m_faultTime * 1000.0) == faultTime) {
m_faultTimeVerified = true;
else {
} else {
// It's wrong - set it again
ConfigFaultTime(m_faultTime);
}

View File

@@ -119,7 +119,7 @@ float CANTalon::Get() const {
case kFollower:
default:
m_impl->GetAppliedThrottle(value);
return (float)value / 1023.0;
return static_cast<float>(value) / 1023.0;
}
}
@@ -156,11 +156,11 @@ void CANTalon::Set(float value) {
status = CTR_OKAY;
} break;
case CANSpeedController::kFollower: {
status = m_impl->SetDemand((int)value);
status = m_impl->SetDemand(static_cast<int>(value));
} break;
case CANSpeedController::kVoltage: {
// Voltage is an 8.8 fixed point number.
int volts = int((m_isInverted ? -value : value) * 256);
int volts = static_cast<int>((m_isInverted ? -value : value) * 256);
status = m_impl->SetDemand(volts);
} break;
case CANSpeedController::kSpeed:
@@ -177,7 +177,7 @@ void CANTalon::Set(float value) {
status = m_impl->SetDemand(milliamperes);
} break;
case CANSpeedController::kMotionProfile: {
status = m_impl->SetDemand((int)value);
status = m_impl->SetDemand(static_cast<int>(value));
} break;
default:
wpi_setWPIErrorWithContext(
@@ -216,7 +216,7 @@ void CANTalon::Reset() {
* for more information).
*/
void CANTalon::Disable() {
m_impl->SetModeSelect((int)CANTalon::kDisabled);
m_impl->SetModeSelect(static_cast<int>(CANTalon::kDisabled));
m_controlEnabled = false;
}
@@ -358,7 +358,8 @@ void CANTalon::SetFeedbackDevice(FeedbackDevice feedbackDevice) {
*/
m_feedbackDevice = feedbackDevice;
/* pass feedback to actual CAN frame */
CTR_Code status = m_impl->SetFeedbackDeviceSelect((int)feedbackDevice);
CTR_Code status =
m_impl->SetFeedbackDeviceSelect(static_cast<int>(feedbackDevice));
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
@@ -368,7 +369,8 @@ void CANTalon::SetFeedbackDevice(FeedbackDevice feedbackDevice) {
* Select the feedback device to use in closed-loop
*/
void CANTalon::SetStatusFrameRateMs(StatusFrameRate stateFrame, int periodMs) {
CTR_Code status = m_impl->SetStatusFrameRate((int)stateFrame, periodMs);
CTR_Code status =
m_impl->SetStatusFrameRate(static_cast<int>(stateFrame), periodMs);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
@@ -518,7 +520,7 @@ float CANTalon::GetBusVoltage() const {
float CANTalon::GetOutputVoltage() const {
int throttle11;
CTR_Code status = m_impl->GetAppliedThrottle(throttle11);
float voltage = GetBusVoltage() * (float(throttle11) / 1023.0);
float voltage = GetBusVoltage() * (static_cast<float>(throttle11) / 1023.0);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
@@ -1086,7 +1088,8 @@ void CANTalon::SetVoltageRampRate(double rampRate) {
Talon's throttle ramp is in dThrot/d10ms. 1023 is full fwd, -1023 is
full rev. */
double rampRatedThrotPer10ms = (rampRate * 1023.0 / 12.0) / 100;
CTR_Code status = m_impl->SetRampThrottle((int)rampRatedThrotPer10ms);
CTR_Code status =
m_impl->SetRampThrottle(static_cast<int>(rampRatedThrotPer10ms));
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
@@ -1180,8 +1183,8 @@ void CANTalon::ConfigNeutralMode(NeutralMode mode) {
CTR_Code status = CTR_OKAY;
switch (mode) {
default:
case kNeutralMode_Jumper: /* use default setting in flash based on
webdash/BrakeCal button selection */
case kNeutralMode_Jumper:
// use default setting in flash based on webdash/BrakeCal button selection
status = m_impl->SetOverrideBrakeType(
CanTalonSRX::kBrakeOverride_UseDefaultsFromFlash);
break;
@@ -1347,8 +1350,9 @@ void CANTalon::ConfigLimitMode(LimitMode mode) {
}
break;
case kLimitMode_SrxDisableSwitchInputs: /** disable both limit switches and
soft limits */
case kLimitMode_SrxDisableSwitchInputs:
// disable both limit switches and soft limits
/* turn on both limits. SRX has individual enables and polarity for each
* limit switch.*/
status = m_impl->SetForwardSoftEnable(false);
@@ -1586,7 +1590,7 @@ void CANTalon::ApplyControlMode(CANSpeedController::ControlMode mode) {
break;
}
// Keep the talon disabled until Set() is called.
CTR_Code status = m_impl->SetModeSelect((int)kDisabled);
CTR_Code status = m_impl->SetModeSelect(static_cast<int>(kDisabled));
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
@@ -1647,14 +1651,13 @@ double CANTalon::GetNativeUnitsPerRotationScalar(
CTR_Code status = CTR_OKAY;
double retval = 0;
switch (devToLookup) {
case QuadEncoder: { /* When caller wants to lookup Quadrature, the QEI may
* be in 1x if the selected feedback is edge counter.
* Additionally if the quadrature source is the CTRE Mag
* encoder, then the CPR is known.
* This is nice in that the calling app does not require
* knowing the CPR at all.
* So do both checks here.
*/
case QuadEncoder: {
/* When caller wants to lookup Quadrature, the QEI may be in 1x if the
* selected feedback is edge counter. Additionally if the quadrature
* source is the CTRE Mag encoder, then the CPR is known. This is nice in
* that the calling app does not require knowing the CPR at all. So do
* both checks here.
*/
int32_t qeiPulsePerCount = 4; /* default to 4x */
switch (m_feedbackDevice) {
case CtreMagEncoder_Relative:
@@ -1669,8 +1672,8 @@ double CANTalon::GetNativeUnitsPerRotationScalar(
qeiPulsePerCount = 1;
break;
case QuadEncoder: /* Talon's QEI is 4x */
default: /* pulse width and everything else, assume its regular quad
use. */
default:
// pulse width and everything else, assume its regular quad use.
break;
}
if (scalingAvail) {
@@ -1710,7 +1713,8 @@ double CANTalon::GetNativeUnitsPerRotationScalar(
* bottom of this func.
*/
} else {
retval = (double)kNativeAdcUnitsPerRotation / m_numPotTurns;
retval =
static_cast<double>(kNativeAdcUnitsPerRotation) / m_numPotTurns;
scalingAvail = true;
}
break;
@@ -1746,11 +1750,11 @@ double CANTalon::GetNativeUnitsPerRotationScalar(
int32_t CANTalon::ScaleRotationsToNativeUnits(FeedbackDevice devToLookup,
double fullRotations) const {
/* first assume we don't have config info, prep the default return */
int32_t retval = (int32_t)fullRotations;
int32_t retval = static_cast<int32_t>(fullRotations);
/* retrieve scaling info */
double scalar = GetNativeUnitsPerRotationScalar(devToLookup);
/* apply scalar if its available */
if (scalar > 0) retval = (int32_t)(fullRotations * scalar);
if (scalar > 0) retval = static_cast<int32_t>(fullRotations * scalar);
return retval;
}
@@ -1768,11 +1772,13 @@ int32_t CANTalon::ScaleRotationsToNativeUnits(FeedbackDevice devToLookup,
int32_t CANTalon::ScaleVelocityToNativeUnits(FeedbackDevice devToLookup,
double rpm) const {
/* first assume we don't have config info, prep the default return */
int32_t retval = (int32_t)rpm;
int32_t retval = static_cast<int32_t>(rpm);
/* retrieve scaling info */
double scalar = GetNativeUnitsPerRotationScalar(devToLookup);
/* apply scalar if its available */
if (scalar > 0) retval = (int32_t)(rpm * kMinutesPer100msUnit * scalar);
if (scalar > 0) {
retval = static_cast<int32_t>(rpm * kMinutesPer100msUnit * scalar);
}
return retval;
}
@@ -1789,11 +1795,11 @@ int32_t CANTalon::ScaleVelocityToNativeUnits(FeedbackDevice devToLookup,
double CANTalon::ScaleNativeUnitsToRotations(FeedbackDevice devToLookup,
int32_t nativePos) const {
/* first assume we don't have config info, prep the default return */
double retval = (double)nativePos;
double retval = static_cast<double>(nativePos);
/* retrieve scaling info */
double scalar = GetNativeUnitsPerRotationScalar(devToLookup);
/* apply scalar if its available */
if (scalar > 0) retval = ((double)nativePos) / scalar;
if (scalar > 0) retval = static_cast<double>(nativePos) / scalar;
return retval;
}
@@ -1810,12 +1816,12 @@ double CANTalon::ScaleNativeUnitsToRotations(FeedbackDevice devToLookup,
double CANTalon::ScaleNativeUnitsToRpm(FeedbackDevice devToLookup,
int32_t nativeVel) const {
/* first assume we don't have config info, prep the default return */
double retval = (double)nativeVel;
double retval = static_cast<double>(nativeVel);
/* retrieve scaling info */
double scalar = GetNativeUnitsPerRotationScalar(devToLookup);
/* apply scalar if its available */
if (scalar > 0)
retval = (double)(nativeVel) / (scalar * kMinutesPer100msUnit);
retval = static_cast<double>(nativeVel) / (scalar * kMinutesPer100msUnit);
return retval;
}

View File

@@ -41,9 +41,9 @@ CameraServer::CameraServer()
void CameraServer::FreeImageData(
std::tuple<uint8_t*, unsigned int, unsigned int, bool> imageData) {
if (std::get<3>(imageData))
if (std::get<3>(imageData)) {
imaqDispose(std::get<0>(imageData));
else if (std::get<0>(imageData) != nullptr) {
} else if (std::get<0>(imageData) != nullptr) {
std::lock_guard<priority_recursive_mutex> lock(m_imageMutex);
m_dataPool.push_back(std::get<0>(imageData));
}
@@ -59,9 +59,9 @@ void CameraServer::SetImageData(uint8_t* data, unsigned int size,
void CameraServer::SetImage(Image const* image) {
unsigned int dataSize = 0;
uint8_t* data =
(uint8_t*)imaqFlatten(image, IMAQ_FLATTEN_IMAGE, IMAQ_COMPRESSION_JPEG,
10 * m_quality, &dataSize);
uint8_t* data = reinterpret_cast<uint8_t*>(
imaqFlatten(image, IMAQ_FLATTEN_IMAGE, IMAQ_COMPRESSION_JPEG,
10 * m_quality, &dataSize));
// If we're using a HW camera, then find the start of the data
bool hwClient;

View File

@@ -210,7 +210,7 @@ int DriverStation::GetJoystickType(uint32_t stick) const {
return -1;
}
std::lock_guard<priority_mutex> lock(m_joystickDataMutex);
return (int)m_joystickDescriptor[stick].type;
return static_cast<int>(m_joystickDescriptor[stick].type);
}
/**
@@ -225,7 +225,7 @@ bool DriverStation::GetJoystickIsXbox(uint32_t stick) const {
return false;
}
std::lock_guard<priority_mutex> lock(m_joystickDataMutex);
return (bool)m_joystickDescriptor[stick].isXbox;
return static_cast<bool>(m_joystickDescriptor[stick].isXbox);
}
/**

View File

@@ -214,7 +214,6 @@ void Encoder::Reset() {
int32_t status = 0;
HAL_ResetEncoder(m_encoder, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
;
}
/**

View File

@@ -582,9 +582,9 @@ std::string PIDController::GetSmartDashboardType() const {
return "PIDController";
}
void PIDController::InitTable(std::shared_ptr<ITable> table) {
void PIDController::InitTable(std::shared_ptr<ITable> subtable) {
if (m_table != nullptr) m_table->RemoveTableListener(this);
m_table = table;
m_table = subtable;
if (m_table != nullptr) {
m_table->PutNumber(kP, GetP());
m_table->PutNumber(kI, GetI());

View File

@@ -231,7 +231,7 @@ float PWM::GetSpeed() const {
*
* @param value Raw PWM value.
*/
void PWM::SetRaw(unsigned short value) {
void PWM::SetRaw(uint16_t value) {
if (StatusIsFatal()) return;
int32_t status = 0;
@@ -246,11 +246,11 @@ void PWM::SetRaw(unsigned short value) {
*
* @return Raw PWM control value.
*/
unsigned short PWM::GetRaw() const {
uint16_t PWM::GetRaw() const {
if (StatusIsFatal()) return 0;
int32_t status = 0;
unsigned short value = HAL_GetPWMRaw(m_handle, &status);
uint16_t value = HAL_GetPWMRaw(m_handle, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return value;

View File

@@ -49,8 +49,9 @@ void SPI::SetClockRate(double hz) { HAL_SetSPISpeed(m_port, hz); }
*/
void SPI::SetMSBFirst() {
m_msbFirst = true;
HAL_SetSPIOpts(m_port, (int)m_msbFirst, (int)m_sampleOnTrailing,
(int)m_clk_idle_high);
HAL_SetSPIOpts(m_port, static_cast<int>(m_msbFirst),
static_cast<int>(m_sampleOnTrailing),
static_cast<int>(m_clk_idle_high));
}
/**
@@ -59,8 +60,9 @@ void SPI::SetMSBFirst() {
*/
void SPI::SetLSBFirst() {
m_msbFirst = false;
HAL_SetSPIOpts(m_port, (int)m_msbFirst, (int)m_sampleOnTrailing,
(int)m_clk_idle_high);
HAL_SetSPIOpts(m_port, static_cast<int>(m_msbFirst),
static_cast<int>(m_sampleOnTrailing),
static_cast<int>(m_clk_idle_high));
}
/**
@@ -69,8 +71,9 @@ void SPI::SetLSBFirst() {
*/
void SPI::SetSampleDataOnFalling() {
m_sampleOnTrailing = true;
HAL_SetSPIOpts(m_port, (int)m_msbFirst, (int)m_sampleOnTrailing,
(int)m_clk_idle_high);
HAL_SetSPIOpts(m_port, static_cast<int>(m_msbFirst),
static_cast<int>(m_sampleOnTrailing),
static_cast<int>(m_clk_idle_high));
}
/**
@@ -79,8 +82,9 @@ void SPI::SetSampleDataOnFalling() {
*/
void SPI::SetSampleDataOnRising() {
m_sampleOnTrailing = false;
HAL_SetSPIOpts(m_port, (int)m_msbFirst, (int)m_sampleOnTrailing,
(int)m_clk_idle_high);
HAL_SetSPIOpts(m_port, static_cast<int>(m_msbFirst),
static_cast<int>(m_sampleOnTrailing),
static_cast<int>(m_clk_idle_high));
}
/**
@@ -89,8 +93,9 @@ void SPI::SetSampleDataOnRising() {
*/
void SPI::SetClockActiveLow() {
m_clk_idle_high = true;
HAL_SetSPIOpts(m_port, (int)m_msbFirst, (int)m_sampleOnTrailing,
(int)m_clk_idle_high);
HAL_SetSPIOpts(m_port, static_cast<int>(m_msbFirst),
static_cast<int>(m_sampleOnTrailing),
static_cast<int>(m_clk_idle_high));
}
/**
@@ -99,8 +104,9 @@ void SPI::SetClockActiveLow() {
*/
void SPI::SetClockActiveHigh() {
m_clk_idle_high = false;
HAL_SetSPIOpts(m_port, (int)m_msbFirst, (int)m_sampleOnTrailing,
(int)m_clk_idle_high);
HAL_SetSPIOpts(m_port, static_cast<int>(m_msbFirst),
static_cast<int>(m_sampleOnTrailing),
static_cast<int>(m_clk_idle_high));
}
/**
@@ -153,8 +159,9 @@ int32_t SPI::Read(bool initiate, uint8_t* dataReceived, uint8_t size) {
auto dataToSend = new uint8_t[size];
std::memset(dataToSend, 0, size);
retVal = HAL_TransactionSPI(m_port, dataToSend, dataReceived, size);
} else
} else {
retVal = HAL_ReadSPI(m_port, dataReceived, size);
}
return retVal;
}
@@ -192,9 +199,9 @@ void SPI::InitAccumulator(double period, uint32_t cmd, uint8_t xfer_size,
uint8_t data_shift, uint8_t data_size, bool is_signed,
bool big_endian) {
int32_t status = 0;
HAL_InitSPIAccumulator(m_port, (uint32_t)(period * 1e6), cmd, xfer_size,
valid_mask, valid_value, data_shift, data_size,
is_signed, big_endian, &status);
HAL_InitSPIAccumulator(m_port, static_cast<uint32_t>(period * 1e6), cmd,
xfer_size, valid_mask, valid_value, data_shift,
data_size, is_signed, big_endian, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}

View File

@@ -83,7 +83,8 @@ void Servo::SetAngle(float degrees) {
degrees = kMaxServoAngle;
}
SetPosition(((float)(degrees - kMinServoAngle)) / GetServoAngleRange());
SetPosition(static_cast<float>(degrees - kMinServoAngle) /
GetServoAngleRange());
}
/**
@@ -95,7 +96,8 @@ void Servo::SetAngle(float degrees) {
* @return The angle in degrees to which the servo is set.
*/
float Servo::GetAngle() const {
return (float)GetPosition() * GetServoAngleRange() + kMinServoAngle;
return static_cast<float>(GetPosition()) * GetServoAngleRange() +
kMinServoAngle;
}
void Servo::ValueChanged(ITable* source, llvm::StringRef key,

View File

@@ -34,7 +34,7 @@
* the SOS flag explanation.
*/
unsigned int USBCamera::GetJpegSize(void* buffer, unsigned int buffSize) {
uint8_t* data = (uint8_t*)buffer;
uint8_t* data = static_cast<uint8_t*>(buffer);
if (!wpi_assert(data[0] == 0xff && data[1] == 0xd8)) return 0;
unsigned int pos = 2;
while (pos < buffSize) {
@@ -201,7 +201,8 @@ void USBCamera::UpdateSettings() {
IMAQdxValueTypeF64, &minv);
SAFE_IMAQ_CALL(IMAQdxGetAttributeMaximum, m_id, ATTR_EX_VALUE,
IMAQdxValueTypeF64, &maxv);
double val = minv + ((maxv - minv) * ((double)m_exposureValue / 100.0));
double val =
minv + (maxv - minv) * (static_cast<double>(m_exposureValue) / 100.0);
SAFE_IMAQ_CALL(IMAQdxSetAttribute, m_id, ATTR_EX_VALUE,
IMAQdxValueTypeF64, val);
}
@@ -215,7 +216,8 @@ void USBCamera::UpdateSettings() {
IMAQdxValueTypeF64, &minv);
SAFE_IMAQ_CALL(IMAQdxGetAttributeMaximum, m_id, ATTR_BR_VALUE,
IMAQdxValueTypeF64, &maxv);
double val = minv + ((maxv - minv) * ((double)m_brightness / 100.0));
double val =
minv + (maxv - minv) * (static_cast<double>(m_brightness) / 100.0);
SAFE_IMAQ_CALL(IMAQdxSetAttribute, m_id, ATTR_BR_VALUE, IMAQdxValueTypeF64,
val);

View File

@@ -133,9 +133,8 @@ int AxisCamera::CopyJPEG(char** destImage, unsigned int& destImageSize,
if (m_imageData.size() == 0) return 0; // if no source image
if (destImageBufferSize <
m_imageData.size()) // if current destination buffer too small
{
// if current destination buffer too small
if (destImageBufferSize < m_imageData.size()) {
if (*destImage != nullptr) delete[] * destImage;
destImageBufferSize = m_imageData.size() + kImageBufferAllocationIncrement;
*destImage = new char[destImageBufferSize];
@@ -148,7 +147,7 @@ int AxisCamera::CopyJPEG(char** destImage, unsigned int& destImageSize,
std::copy(m_imageData.begin(), m_imageData.end(), *destImage);
destImageSize = m_imageData.size();
;
return 1;
}

View File

@@ -45,8 +45,7 @@ void SetDebugFlag(DebugOutputType flag) { dprintfFlag = flag; }
*
* @param tempString The format string.
*/
void dprintf(const char* tempString, ...) /* Variable argument list */
{
void dprintf(const char* tempString, ...) {
va_list args; /* Input argument list */
int line_number; /* Line number passed in argument */
int type;
@@ -166,7 +165,7 @@ void dprintf(const char* tempString, ...) /* Variable argument list */
* @return The normalized position from -1 to +1
*/
double RangeToNormalized(double position, int range) {
return (((position * 2.0) / (double)range) - 1.0);
return position * 2.0 / static_cast<double>(range) - 1.0;
}
/**
@@ -179,11 +178,11 @@ double RangeToNormalized(double position, int range) {
*/
float NormalizeToRange(float normalizedValue, float minRange, float maxRange) {
float range = maxRange - minRange;
float temp = (float)((normalizedValue / 2.0) + 0.5) * range;
float temp = static_cast<float>(normalizedValue / 2.0 + 0.5) * range;
return (temp + minRange);
}
float NormalizeToRange(float normalizedValue) {
return (float)((normalizedValue / 2.0) + 0.5);
return static_cast<float>(normalizedValue / 2.0 + 0.5);
}
/**
@@ -274,7 +273,8 @@ void panInit(double period) {
void panForTarget(Servo* panServo) { panForTarget(panServo, 0.0); }
void panForTarget(Servo* panServo, double sinStart) {
float normalizedSinPosition = (float)SinPosition(nullptr, sinStart);
float normalizedSinPosition =
static_cast<float>(SinPosition(nullptr, sinStart));
float newServoPosition = NormalizeToRange(normalizedSinPosition);
panServo->Set(newServoPosition);
// ShowActivity ("pan x: normalized %f newServoPosition = %f" ,
@@ -295,8 +295,8 @@ void panForTarget(Servo* panServo, double sinStart) {
**/
int processFile(char* inputFile, char* outputString, int lineNumber) {
FILE* infile;
const int stringSize = 80; // max size of one line in file
char inputStr[stringSize];
const int kStringSize = 80; // max size of one line in file
char inputStr[kStringSize];
inputStr[0] = '\0';
int lineCount = 0;
@@ -308,16 +308,16 @@ int processFile(char* inputFile, char* outputString, int lineNumber) {
}
while (!std::feof(infile)) {
if (std::fgets(inputStr, stringSize, infile) != nullptr) {
if (std::fgets(inputStr, kStringSize, infile) != nullptr) {
// Skip empty lines
if (emptyString(inputStr)) continue;
// Skip comment lines
if (inputStr[0] == '#' || inputStr[0] == '!') continue;
lineCount++;
if (lineNumber == 0)
if (lineNumber == 0) {
continue;
else {
} else {
if (lineCount == lineNumber) break;
}
}

View File

@@ -157,7 +157,7 @@ bool BinaryImage::ParticleMeasurement(int particleNumber,
double resultDouble;
bool success =
ParticleMeasurement(particleNumber, whatToMeasure, &resultDouble);
*result = (int)resultDouble;
*result = static_cast<int>(resultDouble);
return success;
}
@@ -184,7 +184,7 @@ bool BinaryImage::ParticleMeasurement(int particleNumber,
// Normalizes to [-1,1]
double BinaryImage::NormalizeFromRange(double position, int range) {
return (position * 2.0 / (double)range) - 1.0;
return position * 2.0 / static_cast<double>(range) - 1.0;
}
/**

View File

@@ -57,8 +57,7 @@ int frcDispose(void* object) { return imaqDispose(object); }
* @return On success: 1. On failure: 0. To get extended error information, call
* GetLastError().
*/
int frcDispose(const char* functionName, ...) /* Variable argument list */
{
int frcDispose(const char* functionName, ...) {
va_list disposalPtrList; /* Input argument list */
void* disposalPtr; /* For iteration */
int success, returnValue = 1;
@@ -281,7 +280,9 @@ ColorHistogramReport* frcColorHistogram(const Image* image, int numClasses,
ColorHistogramReport* frcColorHistogram(const Image* image, int numClasses,
ColorMode mode, Image* mask) {
return imaqColorHistogram2((Image*)image, numClasses, mode, nullptr, mask);
return imaqColorHistogram2(
const_cast<Image*>(reinterpret_cast<const Image*>(image)), numClasses,
mode, nullptr, mask);
}
/**
@@ -451,14 +452,14 @@ int frcParticleAnalysis(Image* image, int particleNumber,
if (!success) {
return success;
}
par->center_mass_x = (int)returnDouble; // pixel
par->center_mass_x = static_cast<int>(returnDouble); // pixel
success = imaqMeasureParticle(image, particleNumber, 0,
IMAQ_MT_CENTER_OF_MASS_Y, &returnDouble);
if (!success) {
return success;
}
par->center_mass_y = (int)returnDouble; // pixel
par->center_mass_y = static_cast<int>(returnDouble); // pixel
/* particle size statistics */
success = imaqMeasureParticle(image, particleNumber, 0, IMAQ_MT_AREA,
@@ -473,28 +474,28 @@ int frcParticleAnalysis(Image* image, int particleNumber,
if (!success) {
return success;
}
par->boundingRect.top = (int)returnDouble;
par->boundingRect.top = static_cast<int>(returnDouble);
success = imaqMeasureParticle(image, particleNumber, 0,
IMAQ_MT_BOUNDING_RECT_LEFT, &returnDouble);
if (!success) {
return success;
}
par->boundingRect.left = (int)returnDouble;
par->boundingRect.left = static_cast<int>(returnDouble);
success = imaqMeasureParticle(image, particleNumber, 0,
IMAQ_MT_BOUNDING_RECT_HEIGHT, &returnDouble);
if (!success) {
return success;
}
par->boundingRect.height = (int)returnDouble;
par->boundingRect.height = static_cast<int>(returnDouble);
success = imaqMeasureParticle(image, particleNumber, 0,
IMAQ_MT_BOUNDING_RECT_WIDTH, &returnDouble);
if (!success) {
return success;
}
par->boundingRect.width = (int)returnDouble;
par->boundingRect.width = static_cast<int>(returnDouble);
/* particle quality statistics */
success = imaqMeasureParticle(image, particleNumber, 0,