[hal] Fix clang-tidy warnings (#5401)

This commit is contained in:
Tyler Veness
2023-06-19 22:59:07 -07:00
committed by GitHub
parent 5fc4aee2d2
commit 2ce248f66c
5 changed files with 39 additions and 21 deletions

View File

@@ -4,6 +4,7 @@
#include "hal/AnalogGyro.h" #include "hal/AnalogGyro.h"
#include <cmath>
#include <string> #include <string>
#include <thread> #include <thread>
@@ -204,8 +205,8 @@ void HAL_CalibrateAnalogGyro(HAL_GyroHandle handle, int32_t* status) {
return; return;
} }
gyro->center = static_cast<int32_t>( gyro->center =
static_cast<double>(value) / static_cast<double>(count) + 0.5); std::round(static_cast<double>(value) / static_cast<double>(count));
gyro->offset = static_cast<double>(value) / static_cast<double>(count) - gyro->offset = static_cast<double>(value) / static_cast<double>(count) -
static_cast<double>(gyro->center); static_cast<double>(gyro->center);

View File

@@ -230,12 +230,13 @@ void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
// frequencies. // frequencies.
rawDutyCycle = rawDutyCycle / std::pow(2.0, 4 - pwmPeriodPower); rawDutyCycle = rawDutyCycle / std::pow(2.0, 4 - pwmPeriodPower);
} }
if (id < 4) if (id < 4) {
digitalSystem->writePWMDutyCycleA(id, static_cast<uint8_t>(rawDutyCycle), digitalSystem->writePWMDutyCycleA(id, static_cast<uint8_t>(rawDutyCycle),
status); status);
else } else {
digitalSystem->writePWMDutyCycleB( digitalSystem->writePWMDutyCycleB(
id - 4, static_cast<uint8_t>(rawDutyCycle), status); 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); std::scoped_lock lock(digitalPwmMutex);
if (id < 4) if (id < 4) {
digitalSystem->writePWMDutyCycleA(id, static_cast<uint8_t>(rawDutyCycle), digitalSystem->writePWMDutyCycleA(id, static_cast<uint8_t>(rawDutyCycle),
status); status);
else } else {
digitalSystem->writePWMDutyCycleB( digitalSystem->writePWMDutyCycleB(
id - 4, static_cast<uint8_t>(rawDutyCycle), status); id - 4, static_cast<uint8_t>(rawDutyCycle), status);
}
} }
} }

View File

@@ -128,8 +128,9 @@ static void notifierThreadMain() {
static void cleanupNotifierAtExit() { static void cleanupNotifierAtExit() {
int32_t status = 0; int32_t status = 0;
if (notifierAlarm) if (notifierAlarm) {
notifierAlarm->writeEnable(false, &status); notifierAlarm->writeEnable(false, &status);
}
notifierAlarm = nullptr; notifierAlarm = nullptr;
notifierRunning = false; notifierRunning = false;
hal::ReleaseFPGAInterrupt(kTimerInterruptNumber); 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 // here (the atomic fetch_sub will prevent multiple parallel entries
// into this function) // into this function)
if (notifierAlarm) if (notifierAlarm) {
notifierAlarm->writeEnable(false, status); notifierAlarm->writeEnable(false, status);
}
notifierRunning = false; notifierRunning = false;
hal::ReleaseFPGAInterrupt(kTimerInterruptNumber); hal::ReleaseFPGAInterrupt(kTimerInterruptNumber);
if (notifierThread.joinable()) { if (notifierThread.joinable()) {
@@ -272,8 +274,9 @@ void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifierHandle,
notifierAlarm->writeTriggerTime(static_cast<uint32_t>(closestTrigger), notifierAlarm->writeTriggerTime(static_cast<uint32_t>(closestTrigger),
status); status);
// Enable the alarm. // Enable the alarm.
if (!wasActive) if (!wasActive) {
notifierAlarm->writeEnable(true, status); notifierAlarm->writeEnable(true, status);
}
} }
} }

View File

@@ -643,8 +643,9 @@ void HAL_SetSPIAutoTransmitData(HAL_SPIPort port, const uint8_t* dataToSend,
} }
// set tx data registers // 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); spiSystem->writeAutoTx(i >> 2, i & 3, dataToSend[i], status);
}
// set byte counts // set byte counts
tSPI::tAutoByteCount config; tSPI::tAutoByteCount config;

View File

@@ -192,45 +192,54 @@ void SerialHelper::QueryHubPaths(int32_t* status) {
// Open the resource, grab its interface name, and close it. // Open the resource, grab its interface name, and close it.
ViSession vSession; ViSession vSession;
*status = viOpen(m_resourceHandle, desc, VI_NULL, VI_NULL, &vSession); *status = viOpen(m_resourceHandle, desc, VI_NULL, VI_NULL, &vSession);
if (*status < 0) if (*status < 0) {
continue; continue;
}
*status = 0; *status = 0;
*status = viGetAttribute(vSession, VI_ATTR_INTF_INST_NAME, &osName); *status = viGetAttribute(vSession, VI_ATTR_INTF_INST_NAME, &osName);
// Ignore an error here, as we want to close the session on an error // Ignore an error here, as we want to close the session on an error
// Use a separate close variable so we can check // Use a separate close variable so we can check
ViStatus closeStatus = viClose(vSession); ViStatus closeStatus = viClose(vSession);
if (*status < 0) if (*status < 0) {
continue; continue;
if (closeStatus < 0) }
if (closeStatus < 0) {
continue; continue;
}
*status = 0; *status = 0;
// split until (/dev/ // split until (/dev/
std::string_view devNameRef = wpi::split(osName, "(/dev/").second; std::string_view devNameRef = wpi::split(osName, "(/dev/").second;
// String not found, continue // String not found, continue
if (wpi::equals(devNameRef, "")) if (wpi::equals(devNameRef, "")) {
continue; continue;
}
// Split at ) // Split at )
std::string_view matchString = wpi::split(devNameRef, ')').first; std::string_view matchString = wpi::split(devNameRef, ')').first;
if (wpi::equals(matchString, devNameRef)) if (wpi::equals(matchString, devNameRef)) {
continue; continue;
}
// Search directories to get a list of system accessors // Search directories to get a list of system accessors
// The directories we need are not symbolic, so we can safely // The directories we need are not symbolic, so we can safely
// disable symbolic links. // disable symbolic links.
std::error_code ec; std::error_code ec;
for (auto& p : fs::recursive_directory_iterator("/sys/devices/soc0", ec)) { for (auto& p : fs::recursive_directory_iterator("/sys/devices/soc0", ec)) {
if (ec) if (ec) {
break; break;
}
std::string path = p.path(); std::string path = p.path();
if (path.find("amba") == std::string::npos) if (path.find("amba") == std::string::npos) {
continue; continue;
if (path.find("usb") == std::string::npos) }
if (path.find("usb") == std::string::npos) {
continue; continue;
if (path.find(matchString) == std::string::npos) }
if (path.find(matchString) == std::string::npos) {
continue; continue;
}
wpi::SmallVector<std::string_view, 16> pathSplitVec; wpi::SmallVector<std::string_view, 16> pathSplitVec;
// Split path into individual directories // Split path into individual directories
@@ -254,13 +263,15 @@ void SerialHelper::QueryHubPaths(int32_t* status) {
// Get the index for our device // Get the index for our device
int hubIndex = findtty; int hubIndex = findtty;
if (findtty == -1) if (findtty == -1) {
hubIndex = findregex; hubIndex = findregex;
}
int devStart = findusb + 1; int devStart = findusb + 1;
if (hubIndex < devStart) if (hubIndex < devStart) {
continue; continue;
}
// Add our devices to our list // Add our devices to our list
m_unsortedHubPath.emplace_back( m_unsortedHubPath.emplace_back(