Add HAL specific version of wpi_setError (#2055)

Cleans up error writing, and allows fewer headers to be included in many of the wpilibc cpp files.

This removes all usages of the hal/HAL.h header.
This commit is contained in:
Thad House
2019-11-08 22:53:20 -08:00
committed by Peter Johnson
parent 326aecc9a0
commit 9bcff37b93
84 changed files with 421 additions and 377 deletions

View File

@@ -12,7 +12,7 @@
#include <hal/AnalogGyro.h>
#include <hal/Errors.h>
#include <hal/HAL.h>
#include <hal/FRCUsageReporting.h>
#include "frc/AnalogInput.h"
#include "frc/Timer.h"
@@ -56,7 +56,7 @@ AnalogGyro::AnalogGyro(std::shared_ptr<AnalogInput> channel, int center,
HAL_SetAnalogGyroParameters(m_gyroHandle, kDefaultVoltsPerDegreePerSecond,
offset, center, &status);
if (status != 0) {
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
wpi_setHALError(status);
m_gyroHandle = HAL_kInvalidHandle;
return;
}
@@ -70,7 +70,7 @@ double AnalogGyro::GetAngle() const {
if (StatusIsFatal()) return 0.0;
int32_t status = 0;
double value = HAL_GetAnalogGyroAngle(m_gyroHandle, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
wpi_setHALError(status);
return value;
}
@@ -78,7 +78,7 @@ double AnalogGyro::GetRate() const {
if (StatusIsFatal()) return 0.0;
int32_t status = 0;
double value = HAL_GetAnalogGyroRate(m_gyroHandle, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
wpi_setHALError(status);
return value;
}
@@ -86,7 +86,7 @@ int AnalogGyro::GetCenter() const {
if (StatusIsFatal()) return 0;
int32_t status = 0;
int value = HAL_GetAnalogGyroCenter(m_gyroHandle, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
wpi_setHALError(status);
return value;
}
@@ -94,7 +94,7 @@ double AnalogGyro::GetOffset() const {
if (StatusIsFatal()) return 0.0;
int32_t status = 0;
double value = HAL_GetAnalogGyroOffset(m_gyroHandle, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
wpi_setHALError(status);
return value;
}
@@ -102,21 +102,21 @@ void AnalogGyro::SetSensitivity(double voltsPerDegreePerSecond) {
int32_t status = 0;
HAL_SetAnalogGyroVoltsPerDegreePerSecond(m_gyroHandle,
voltsPerDegreePerSecond, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
wpi_setHALError(status);
}
void AnalogGyro::SetDeadband(double volts) {
if (StatusIsFatal()) return;
int32_t status = 0;
HAL_SetAnalogGyroDeadband(m_gyroHandle, volts, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
wpi_setHALError(status);
}
void AnalogGyro::Reset() {
if (StatusIsFatal()) return;
int32_t status = 0;
HAL_ResetAnalogGyro(m_gyroHandle, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
wpi_setHALError(status);
}
void AnalogGyro::InitGyro() {
@@ -132,7 +132,7 @@ void AnalogGyro::InitGyro() {
return;
}
if (status != 0) {
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
wpi_setHALError(status);
m_analog = nullptr;
m_gyroHandle = HAL_kInvalidHandle;
return;
@@ -142,7 +142,7 @@ void AnalogGyro::InitGyro() {
int32_t status = 0;
HAL_SetupAnalogGyro(m_gyroHandle, &status);
if (status != 0) {
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
wpi_setHALError(status);
m_analog = nullptr;
m_gyroHandle = HAL_kInvalidHandle;
return;
@@ -158,5 +158,5 @@ void AnalogGyro::Calibrate() {
if (StatusIsFatal()) return;
int32_t status = 0;
HAL_CalibrateAnalogGyro(m_gyroHandle, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
wpi_setHALError(status);
}