mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[hal] Fix clang-tidy warnings (#5401)
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "hal/AnalogGyro.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
@@ -204,8 +205,8 @@ void HAL_CalibrateAnalogGyro(HAL_GyroHandle handle, int32_t* status) {
|
||||
return;
|
||||
}
|
||||
|
||||
gyro->center = static_cast<int32_t>(
|
||||
static_cast<double>(value) / static_cast<double>(count) + 0.5);
|
||||
gyro->center =
|
||||
std::round(static_cast<double>(value) / static_cast<double>(count));
|
||||
|
||||
gyro->offset = static_cast<double>(value) / static_cast<double>(count) -
|
||||
static_cast<double>(gyro->center);
|
||||
|
||||
@@ -230,12 +230,13 @@ void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
|
||||
// frequencies.
|
||||
rawDutyCycle = rawDutyCycle / std::pow(2.0, 4 - pwmPeriodPower);
|
||||
}
|
||||
if (id < 4)
|
||||
if (id < 4) {
|
||||
digitalSystem->writePWMDutyCycleA(id, static_cast<uint8_t>(rawDutyCycle),
|
||||
status);
|
||||
else
|
||||
} else {
|
||||
digitalSystem->writePWMDutyCycleB(
|
||||
id - 4, static_cast<uint8_t>(rawDutyCycle), status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,12 +255,13 @@ void HAL_SetDigitalPWMPPS(HAL_DigitalPWMHandle pwmGenerator, double dutyCycle,
|
||||
}
|
||||
{
|
||||
std::scoped_lock lock(digitalPwmMutex);
|
||||
if (id < 4)
|
||||
if (id < 4) {
|
||||
digitalSystem->writePWMDutyCycleA(id, static_cast<uint8_t>(rawDutyCycle),
|
||||
status);
|
||||
else
|
||||
} else {
|
||||
digitalSystem->writePWMDutyCycleB(
|
||||
id - 4, static_cast<uint8_t>(rawDutyCycle), status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -128,8 +128,9 @@ static void notifierThreadMain() {
|
||||
|
||||
static void cleanupNotifierAtExit() {
|
||||
int32_t status = 0;
|
||||
if (notifierAlarm)
|
||||
if (notifierAlarm) {
|
||||
notifierAlarm->writeEnable(false, &status);
|
||||
}
|
||||
notifierAlarm = nullptr;
|
||||
notifierRunning = false;
|
||||
hal::ReleaseFPGAInterrupt(kTimerInterruptNumber);
|
||||
@@ -236,8 +237,9 @@ void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
||||
// here (the atomic fetch_sub will prevent multiple parallel entries
|
||||
// into this function)
|
||||
|
||||
if (notifierAlarm)
|
||||
if (notifierAlarm) {
|
||||
notifierAlarm->writeEnable(false, status);
|
||||
}
|
||||
notifierRunning = false;
|
||||
hal::ReleaseFPGAInterrupt(kTimerInterruptNumber);
|
||||
if (notifierThread.joinable()) {
|
||||
@@ -272,8 +274,9 @@ void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
notifierAlarm->writeTriggerTime(static_cast<uint32_t>(closestTrigger),
|
||||
status);
|
||||
// Enable the alarm.
|
||||
if (!wasActive)
|
||||
if (!wasActive) {
|
||||
notifierAlarm->writeEnable(true, status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -643,8 +643,9 @@ void HAL_SetSPIAutoTransmitData(HAL_SPIPort port, const uint8_t* dataToSend,
|
||||
}
|
||||
|
||||
// set tx data registers
|
||||
for (int32_t i = 0; i < dataSize; ++i)
|
||||
for (int32_t i = 0; i < dataSize; ++i) {
|
||||
spiSystem->writeAutoTx(i >> 2, i & 3, dataToSend[i], status);
|
||||
}
|
||||
|
||||
// set byte counts
|
||||
tSPI::tAutoByteCount config;
|
||||
|
||||
@@ -192,45 +192,54 @@ void SerialHelper::QueryHubPaths(int32_t* status) {
|
||||
// Open the resource, grab its interface name, and close it.
|
||||
ViSession vSession;
|
||||
*status = viOpen(m_resourceHandle, desc, VI_NULL, VI_NULL, &vSession);
|
||||
if (*status < 0)
|
||||
if (*status < 0) {
|
||||
continue;
|
||||
}
|
||||
*status = 0;
|
||||
|
||||
*status = viGetAttribute(vSession, VI_ATTR_INTF_INST_NAME, &osName);
|
||||
// Ignore an error here, as we want to close the session on an error
|
||||
// Use a separate close variable so we can check
|
||||
ViStatus closeStatus = viClose(vSession);
|
||||
if (*status < 0)
|
||||
if (*status < 0) {
|
||||
continue;
|
||||
if (closeStatus < 0)
|
||||
}
|
||||
if (closeStatus < 0) {
|
||||
continue;
|
||||
}
|
||||
*status = 0;
|
||||
|
||||
// split until (/dev/
|
||||
std::string_view devNameRef = wpi::split(osName, "(/dev/").second;
|
||||
// String not found, continue
|
||||
if (wpi::equals(devNameRef, ""))
|
||||
if (wpi::equals(devNameRef, "")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Split at )
|
||||
std::string_view matchString = wpi::split(devNameRef, ')').first;
|
||||
if (wpi::equals(matchString, devNameRef))
|
||||
if (wpi::equals(matchString, devNameRef)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Search directories to get a list of system accessors
|
||||
// The directories we need are not symbolic, so we can safely
|
||||
// disable symbolic links.
|
||||
std::error_code ec;
|
||||
for (auto& p : fs::recursive_directory_iterator("/sys/devices/soc0", ec)) {
|
||||
if (ec)
|
||||
if (ec) {
|
||||
break;
|
||||
}
|
||||
std::string path = p.path();
|
||||
if (path.find("amba") == std::string::npos)
|
||||
if (path.find("amba") == std::string::npos) {
|
||||
continue;
|
||||
if (path.find("usb") == std::string::npos)
|
||||
}
|
||||
if (path.find("usb") == std::string::npos) {
|
||||
continue;
|
||||
if (path.find(matchString) == std::string::npos)
|
||||
}
|
||||
if (path.find(matchString) == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
|
||||
wpi::SmallVector<std::string_view, 16> pathSplitVec;
|
||||
// Split path into individual directories
|
||||
@@ -254,13 +263,15 @@ void SerialHelper::QueryHubPaths(int32_t* status) {
|
||||
|
||||
// Get the index for our device
|
||||
int hubIndex = findtty;
|
||||
if (findtty == -1)
|
||||
if (findtty == -1) {
|
||||
hubIndex = findregex;
|
||||
}
|
||||
|
||||
int devStart = findusb + 1;
|
||||
|
||||
if (hubIndex < devStart)
|
||||
if (hubIndex < devStart) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add our devices to our list
|
||||
m_unsortedHubPath.emplace_back(
|
||||
|
||||
Reference in New Issue
Block a user