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/Notifier.h>
#include "frc/Timer.h"
#include "frc/Utility.h"
@@ -23,7 +24,7 @@ Notifier::Notifier(std::function<void()> handler) {
m_handler = handler;
int32_t status = 0;
m_notifier = HAL_InitializeNotifier(&status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
wpi_setHALError(status);
m_thread = std::thread([=] {
for (;;) {
@@ -57,7 +58,7 @@ Notifier::~Notifier() {
// atomically set handle to 0, then clean
HAL_NotifierHandle handle = m_notifier.exchange(0);
HAL_StopNotifier(handle, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
wpi_setHALError(status);
// Join the thread to ensure the handler has exited.
if (m_thread.joinable()) m_thread.join();
@@ -122,7 +123,7 @@ void Notifier::StartPeriodic(units::second_t period) {
void Notifier::Stop() {
int32_t status = 0;
HAL_CancelNotifierAlarm(m_notifier, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
wpi_setHALError(status);
}
void Notifier::UpdateAlarm(uint64_t triggerTime) {
@@ -131,7 +132,7 @@ void Notifier::UpdateAlarm(uint64_t triggerTime) {
auto notifier = m_notifier.load();
if (notifier == 0) return;
HAL_UpdateNotifierAlarm(notifier, triggerTime, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
wpi_setHALError(status);
}
void Notifier::UpdateAlarm() {