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

@@ -9,7 +9,8 @@
#include <utility>
#include <hal/HAL.h>
#include <hal/FRCUsageReporting.h>
#include <hal/HALBase.h>
#include <hal/Ports.h>
#include <hal/Solenoid.h>
@@ -40,8 +41,7 @@ Solenoid::Solenoid(int moduleNumber, int channel)
m_solenoidHandle = HAL_InitializeSolenoidPort(
HAL_GetPortWithModule(moduleNumber, channel), &status);
if (status != 0) {
wpi_setErrorWithContextRange(status, 0, HAL_GetNumSolenoidChannels(),
channel, HAL_GetErrorMessage(status));
wpi_setHALErrorWithRange(status, 0, HAL_GetNumSolenoidChannels(), channel);
m_solenoidHandle = HAL_kInvalidHandle;
return;
}
@@ -58,14 +58,14 @@ void Solenoid::Set(bool on) {
if (StatusIsFatal()) return;
int32_t status = 0;
HAL_SetSolenoid(m_solenoidHandle, on, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
wpi_setHALError(status);
}
bool Solenoid::Get() const {
if (StatusIsFatal()) return false;
int32_t status = 0;
bool value = HAL_GetSolenoid(m_solenoidHandle, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
wpi_setHALError(status);
return value;
}
@@ -79,14 +79,14 @@ void Solenoid::SetPulseDuration(double durationSeconds) {
if (StatusIsFatal()) return;
int32_t status = 0;
HAL_SetOneShotDuration(m_solenoidHandle, durationMS, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
wpi_setHALError(status);
}
void Solenoid::StartPulse() {
if (StatusIsFatal()) return;
int32_t status = 0;
HAL_FireOneShot(m_solenoidHandle, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
wpi_setHALError(status);
}
void Solenoid::InitSendable(SendableBuilder& builder) {