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:
Peter Johnson
2020-12-28 12:58:06 -08:00
committed by GitHub
parent 0291a3ff56
commit 2aed432b4b
634 changed files with 10716 additions and 3938 deletions

View File

@@ -35,7 +35,9 @@ extern "C" {
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
HAL_Bool input, int32_t* status) {
hal::init::CheckInit();
if (*status != 0) return HAL_kInvalidHandle;
if (*status != 0) {
return HAL_kInvalidHandle;
}
int16_t channel = getPortHandleChannel(portHandle);
if (channel == InvalidHandleIndex) {
@@ -46,8 +48,9 @@ HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
auto handle =
digitalChannelHandles->Allocate(channel, HAL_HandleEnum::DIO, status);
if (*status != 0)
if (*status != 0) {
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}
auto port = digitalChannelHandles->Get(handle, HAL_HandleEnum::DIO);
if (port == nullptr) { // would only occur on thread issue.
@@ -72,13 +75,17 @@ void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle) {
auto port = digitalChannelHandles->Get(dioPortHandle, HAL_HandleEnum::DIO);
// no status, so no need to check for a proper free.
digitalChannelHandles->Free(dioPortHandle, HAL_HandleEnum::DIO);
if (port == nullptr) return;
if (port == nullptr) {
return;
}
SimDIOData[port->channel].initialized = false;
}
void HAL_SetDIOSimDevice(HAL_DigitalHandle handle, HAL_SimDeviceHandle device) {
auto port = digitalChannelHandles->Get(handle, HAL_HandleEnum::DIO);
if (port == nullptr) return;
if (port == nullptr) {
return;
}
SimDIOData[port->channel].simDevice = device;
}
@@ -104,7 +111,9 @@ HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t* status) {
void HAL_FreeDigitalPWM(HAL_DigitalPWMHandle pwmGenerator, int32_t* status) {
auto port = digitalPWMHandles->Get(pwmGenerator);
digitalPWMHandles->Free(pwmGenerator);
if (port == nullptr) return;
if (port == nullptr) {
return;
}
int32_t id = *port;
SimDigitalPWMData[id].initialized = false;
}
@@ -129,8 +138,12 @@ void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
return;
}
int32_t id = *port;
if (dutyCycle > 1.0) dutyCycle = 1.0;
if (dutyCycle < 0.0) dutyCycle = 0.0;
if (dutyCycle > 1.0) {
dutyCycle = 1.0;
}
if (dutyCycle < 0.0) {
dutyCycle = 0.0;
}
SimDigitalPWMData[id].dutyCycle = dutyCycle;
}
@@ -153,7 +166,9 @@ void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
return;
}
if (value != 0 && value != 1) {
if (value != 0) value = 1;
if (value != 0) {
value = 1;
}
}
SimDIOData[port->channel].value = value;
}
@@ -176,8 +191,12 @@ HAL_Bool HAL_GetDIO(HAL_DigitalHandle dioPortHandle, int32_t* status) {
return false;
}
HAL_Bool value = SimDIOData[port->channel].value;
if (value > 1) value = 1;
if (value < 0) value = 0;
if (value > 1) {
value = 1;
}
if (value < 0) {
value = 0;
}
return value;
}
@@ -188,8 +207,12 @@ HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dioPortHandle, int32_t* status) {
return false;
}
HAL_Bool value = SimDIOData[port->channel].isInput;
if (value > 1) value = 1;
if (value < 0) value = 0;
if (value > 1) {
value = 1;
}
if (value < 0) {
value = 0;
}
return value;
}