mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Add braces to C++ single-line loops and conditionals (NFC) (#2973)
This makes code easier to read and more consistent between C++ and Java. Also update clang-format settings to always add a line break (even if no braces are used).
This commit is contained in:
@@ -79,7 +79,9 @@ static inline int BytesToIntBE(uint8_t* buf) {
|
||||
|
||||
uint16_t ADXRS450_Gyro::ReadRegister(int reg) {
|
||||
int cmd = 0x80000000 | static_cast<int>(reg) << 17;
|
||||
if (!CalcParity(cmd)) cmd |= 1u;
|
||||
if (!CalcParity(cmd)) {
|
||||
cmd |= 1u;
|
||||
}
|
||||
|
||||
// big endian
|
||||
uint8_t buf[4] = {static_cast<uint8_t>((cmd >> 24) & 0xff),
|
||||
@@ -89,24 +91,34 @@ uint16_t ADXRS450_Gyro::ReadRegister(int reg) {
|
||||
|
||||
m_spi.Write(buf, 4);
|
||||
m_spi.Read(false, buf, 4);
|
||||
if ((buf[0] & 0xe0) == 0) return 0; // error, return 0
|
||||
if ((buf[0] & 0xe0) == 0) {
|
||||
return 0; // error, return 0
|
||||
}
|
||||
return static_cast<uint16_t>((BytesToIntBE(buf) >> 5) & 0xffff);
|
||||
}
|
||||
|
||||
double ADXRS450_Gyro::GetAngle() const {
|
||||
if (m_simAngle) return m_simAngle.Get();
|
||||
if (m_simAngle) {
|
||||
return m_simAngle.Get();
|
||||
}
|
||||
return m_spi.GetAccumulatorIntegratedValue() * kDegreePerSecondPerLSB;
|
||||
}
|
||||
|
||||
double ADXRS450_Gyro::GetRate() const {
|
||||
if (m_simRate) return m_simRate.Get();
|
||||
if (m_simRate) {
|
||||
return m_simRate.Get();
|
||||
}
|
||||
return static_cast<double>(m_spi.GetAccumulatorLastValue()) *
|
||||
kDegreePerSecondPerLSB;
|
||||
}
|
||||
|
||||
void ADXRS450_Gyro::Reset() {
|
||||
if (m_simAngle) m_simAngle.Set(0.0);
|
||||
if (m_simRate) m_simRate.Set(0.0);
|
||||
if (m_simAngle) {
|
||||
m_simAngle.Set(0.0);
|
||||
}
|
||||
if (m_simRate) {
|
||||
m_simRate.Set(0.0);
|
||||
}
|
||||
m_spi.ResetAccumulator();
|
||||
}
|
||||
|
||||
@@ -122,4 +134,6 @@ void ADXRS450_Gyro::Calibrate() {
|
||||
m_spi.ResetAccumulator();
|
||||
}
|
||||
|
||||
int ADXRS450_Gyro::GetPort() const { return m_port; }
|
||||
int ADXRS450_Gyro::GetPort() const {
|
||||
return m_port;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user