mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +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:
@@ -125,18 +125,30 @@ static void ProcessInterruptDigitalSynchronous(const char* name, void* param,
|
||||
SynchronousWaitDataHandle handle =
|
||||
static_cast<SynchronousWaitDataHandle>(handleTmp);
|
||||
auto interruptData = synchronousInterruptHandles->Get(handle);
|
||||
if (interruptData == nullptr) return;
|
||||
if (interruptData == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto interrupt = interruptHandles->Get(interruptData->interruptHandle);
|
||||
if (interrupt == nullptr) return;
|
||||
if (interrupt == nullptr) {
|
||||
return;
|
||||
}
|
||||
// Have a valid interrupt
|
||||
if (value->type != HAL_Type::HAL_BOOLEAN) return;
|
||||
if (value->type != HAL_Type::HAL_BOOLEAN) {
|
||||
return;
|
||||
}
|
||||
bool retVal = value->data.v_boolean;
|
||||
// If no change in interrupt, return;
|
||||
if (retVal == interrupt->previousState) return;
|
||||
if (retVal == interrupt->previousState) {
|
||||
return;
|
||||
}
|
||||
// If its a falling change, and we dont fire on falling return
|
||||
if (interrupt->previousState && !interrupt->fireOnDown) return;
|
||||
if (interrupt->previousState && !interrupt->fireOnDown) {
|
||||
return;
|
||||
}
|
||||
// If its a rising change, and we dont fire on rising return.
|
||||
if (!interrupt->previousState && !interrupt->fireOnUp) return;
|
||||
if (!interrupt->previousState && !interrupt->fireOnUp) {
|
||||
return;
|
||||
}
|
||||
|
||||
interruptData->waitPredicate = true;
|
||||
|
||||
@@ -158,11 +170,17 @@ static void ProcessInterruptAnalogSynchronous(const char* name, void* param,
|
||||
SynchronousWaitDataHandle handle =
|
||||
static_cast<SynchronousWaitDataHandle>(handleTmp);
|
||||
auto interruptData = synchronousInterruptHandles->Get(handle);
|
||||
if (interruptData == nullptr) return;
|
||||
if (interruptData == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto interrupt = interruptHandles->Get(interruptData->interruptHandle);
|
||||
if (interrupt == nullptr) return;
|
||||
if (interrupt == nullptr) {
|
||||
return;
|
||||
}
|
||||
// Have a valid interrupt
|
||||
if (value->type != HAL_Type::HAL_DOUBLE) return;
|
||||
if (value->type != HAL_Type::HAL_DOUBLE) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool retVal = GetAnalogTriggerValue(interrupt->portHandle,
|
||||
interrupt->trigType, &status);
|
||||
@@ -173,11 +191,17 @@ static void ProcessInterruptAnalogSynchronous(const char* name, void* param,
|
||||
interruptData->waitCond.notify_all();
|
||||
}
|
||||
// If no change in interrupt, return;
|
||||
if (retVal == interrupt->previousState) return;
|
||||
if (retVal == interrupt->previousState) {
|
||||
return;
|
||||
}
|
||||
// If its a falling change, and we dont fire on falling return
|
||||
if (interrupt->previousState && !interrupt->fireOnDown) return;
|
||||
if (interrupt->previousState && !interrupt->fireOnDown) {
|
||||
return;
|
||||
}
|
||||
// If its a rising change, and we dont fire on rising return.
|
||||
if (!interrupt->previousState && !interrupt->fireOnUp) return;
|
||||
if (!interrupt->previousState && !interrupt->fireOnUp) {
|
||||
return;
|
||||
}
|
||||
|
||||
interruptData->waitPredicate = true;
|
||||
|
||||
@@ -204,7 +228,9 @@ static int64_t WaitForInterruptDigital(HAL_InterruptHandle handle,
|
||||
|
||||
int32_t digitalIndex = GetDigitalInputChannel(interrupt->portHandle, &status);
|
||||
|
||||
if (status != 0) return WaitResult::Timeout;
|
||||
if (status != 0) {
|
||||
return WaitResult::Timeout;
|
||||
}
|
||||
|
||||
interrupt->previousState = SimDIOData[digitalIndex].value;
|
||||
|
||||
@@ -235,7 +261,9 @@ static int64_t WaitForInterruptDigital(HAL_InterruptHandle handle,
|
||||
(void)synchronousInterruptHandles->Free(dataHandle);
|
||||
|
||||
// Check for what to return
|
||||
if (timedOut) return WaitResult::Timeout;
|
||||
if (timedOut) {
|
||||
return WaitResult::Timeout;
|
||||
}
|
||||
// True => false, Falling
|
||||
if (interrupt->previousState) {
|
||||
// Set our return value and our timestamps
|
||||
@@ -265,12 +293,16 @@ static int64_t WaitForInterruptAnalog(HAL_InterruptHandle handle,
|
||||
interrupt->previousState = GetAnalogTriggerValue(
|
||||
interrupt->portHandle, interrupt->trigType, &status);
|
||||
|
||||
if (status != 0) return WaitResult::Timeout;
|
||||
if (status != 0) {
|
||||
return WaitResult::Timeout;
|
||||
}
|
||||
|
||||
int32_t analogIndex =
|
||||
GetAnalogTriggerInputIndex(interrupt->portHandle, &status);
|
||||
|
||||
if (status != 0) return WaitResult::Timeout;
|
||||
if (status != 0) {
|
||||
return WaitResult::Timeout;
|
||||
}
|
||||
|
||||
int32_t uid = SimAnalogInData[analogIndex].voltage.RegisterCallback(
|
||||
&ProcessInterruptAnalogSynchronous,
|
||||
@@ -299,7 +331,9 @@ static int64_t WaitForInterruptAnalog(HAL_InterruptHandle handle,
|
||||
(void)synchronousInterruptHandles->Free(dataHandle);
|
||||
|
||||
// Check for what to return
|
||||
if (timedOut) return WaitResult::Timeout;
|
||||
if (timedOut) {
|
||||
return WaitResult::Timeout;
|
||||
}
|
||||
// True => false, Falling
|
||||
if (interrupt->previousState) {
|
||||
// Set our return value and our timestamps
|
||||
@@ -342,28 +376,40 @@ static void ProcessInterruptDigitalAsynchronous(const char* name, void* param,
|
||||
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
|
||||
HAL_InterruptHandle handle = static_cast<HAL_InterruptHandle>(handleTmp);
|
||||
auto interrupt = interruptHandles->Get(handle);
|
||||
if (interrupt == nullptr) return;
|
||||
if (interrupt == nullptr) {
|
||||
return;
|
||||
}
|
||||
// Have a valid interrupt
|
||||
if (value->type != HAL_Type::HAL_BOOLEAN) return;
|
||||
if (value->type != HAL_Type::HAL_BOOLEAN) {
|
||||
return;
|
||||
}
|
||||
bool retVal = value->data.v_boolean;
|
||||
// If no change in interrupt, return;
|
||||
if (retVal == interrupt->previousState) return;
|
||||
if (retVal == interrupt->previousState) {
|
||||
return;
|
||||
}
|
||||
int32_t mask = 0;
|
||||
if (interrupt->previousState) {
|
||||
interrupt->previousState = retVal;
|
||||
interrupt->fallingTimestamp = hal::GetFPGATime();
|
||||
mask = 1 << (8 + interrupt->index);
|
||||
if (!interrupt->fireOnDown) return;
|
||||
if (!interrupt->fireOnDown) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
interrupt->previousState = retVal;
|
||||
interrupt->risingTimestamp = hal::GetFPGATime();
|
||||
mask = 1 << (interrupt->index);
|
||||
if (!interrupt->fireOnUp) return;
|
||||
if (!interrupt->fireOnUp) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// run callback
|
||||
auto callback = interrupt->callbackFunction;
|
||||
if (callback == nullptr) return;
|
||||
if (callback == nullptr) {
|
||||
return;
|
||||
}
|
||||
callback(mask, interrupt->callbackParam);
|
||||
}
|
||||
|
||||
@@ -374,31 +420,45 @@ static void ProcessInterruptAnalogAsynchronous(const char* name, void* param,
|
||||
uintptr_t handleTmp = reinterpret_cast<uintptr_t>(param);
|
||||
HAL_InterruptHandle handle = static_cast<HAL_InterruptHandle>(handleTmp);
|
||||
auto interrupt = interruptHandles->Get(handle);
|
||||
if (interrupt == nullptr) return;
|
||||
if (interrupt == nullptr) {
|
||||
return;
|
||||
}
|
||||
// Have a valid interrupt
|
||||
if (value->type != HAL_Type::HAL_DOUBLE) return;
|
||||
if (value->type != HAL_Type::HAL_DOUBLE) {
|
||||
return;
|
||||
}
|
||||
int32_t status = 0;
|
||||
bool retVal = GetAnalogTriggerValue(interrupt->portHandle,
|
||||
interrupt->trigType, &status);
|
||||
if (status != 0) return;
|
||||
if (status != 0) {
|
||||
return;
|
||||
}
|
||||
// If no change in interrupt, return;
|
||||
if (retVal == interrupt->previousState) return;
|
||||
if (retVal == interrupt->previousState) {
|
||||
return;
|
||||
}
|
||||
int mask = 0;
|
||||
if (interrupt->previousState) {
|
||||
interrupt->previousState = retVal;
|
||||
interrupt->fallingTimestamp = hal::GetFPGATime();
|
||||
if (!interrupt->fireOnDown) return;
|
||||
if (!interrupt->fireOnDown) {
|
||||
return;
|
||||
}
|
||||
mask = 1 << (8 + interrupt->index);
|
||||
} else {
|
||||
interrupt->previousState = retVal;
|
||||
interrupt->risingTimestamp = hal::GetFPGATime();
|
||||
if (!interrupt->fireOnUp) return;
|
||||
if (!interrupt->fireOnUp) {
|
||||
return;
|
||||
}
|
||||
mask = 1 << (interrupt->index);
|
||||
}
|
||||
|
||||
// run callback
|
||||
auto callback = interrupt->callbackFunction;
|
||||
if (callback == nullptr) return;
|
||||
if (callback == nullptr) {
|
||||
return;
|
||||
}
|
||||
callback(mask, interrupt->callbackParam);
|
||||
}
|
||||
|
||||
@@ -406,7 +466,9 @@ static void EnableInterruptsDigital(HAL_InterruptHandle handle,
|
||||
Interrupt* interrupt) {
|
||||
int32_t status = 0;
|
||||
int32_t digitalIndex = GetDigitalInputChannel(interrupt->portHandle, &status);
|
||||
if (status != 0) return;
|
||||
if (status != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
interrupt->previousState = SimDIOData[digitalIndex].value;
|
||||
|
||||
@@ -421,12 +483,16 @@ static void EnableInterruptsAnalog(HAL_InterruptHandle handle,
|
||||
int32_t status = 0;
|
||||
int32_t analogIndex =
|
||||
GetAnalogTriggerInputIndex(interrupt->portHandle, &status);
|
||||
if (status != 0) return;
|
||||
if (status != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
status = 0;
|
||||
interrupt->previousState = GetAnalogTriggerValue(
|
||||
interrupt->portHandle, interrupt->trigType, &status);
|
||||
if (status != 0) return;
|
||||
if (status != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t uid = SimAnalogInData[analogIndex].voltage.RegisterCallback(
|
||||
&ProcessInterruptAnalogAsynchronous,
|
||||
@@ -469,20 +535,26 @@ void HAL_DisableInterrupts(HAL_InterruptHandle interruptHandle,
|
||||
}
|
||||
|
||||
// No need to disable if we are already disabled
|
||||
if (interrupt->callbackId < 0) return;
|
||||
if (interrupt->callbackId < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (interrupt->isAnalog) {
|
||||
// Do analog
|
||||
int32_t status = 0;
|
||||
int32_t analogIndex =
|
||||
GetAnalogTriggerInputIndex(interrupt->portHandle, &status);
|
||||
if (status != 0) return;
|
||||
if (status != 0) {
|
||||
return;
|
||||
}
|
||||
SimAnalogInData[analogIndex].voltage.CancelCallback(interrupt->callbackId);
|
||||
} else {
|
||||
int32_t status = 0;
|
||||
int32_t digitalIndex =
|
||||
GetDigitalInputChannel(interrupt->portHandle, &status);
|
||||
if (status != 0) return;
|
||||
if (status != 0) {
|
||||
return;
|
||||
}
|
||||
SimDIOData[digitalIndex].value.CancelCallback(interrupt->callbackId);
|
||||
}
|
||||
interrupt->callbackId = -1;
|
||||
|
||||
Reference in New Issue
Block a user