mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpilibc] Remove ErrorBase (#3306)
Replace with new exception-based error reporting, consistent with Java. This also builds stacktraces into the reporting/exceptions.
This commit is contained in:
@@ -12,8 +12,8 @@
|
||||
#include <hal/HALBase.h>
|
||||
#include <hal/Ports.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -21,11 +21,8 @@ using namespace frc;
|
||||
|
||||
AnalogOutput::AnalogOutput(int channel) {
|
||||
if (!SensorUtil::CheckAnalogOutputChannel(channel)) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
|
||||
"analog output " + wpi::Twine(channel));
|
||||
m_channel = std::numeric_limits<int>::max();
|
||||
m_port = HAL_kInvalidHandle;
|
||||
return;
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"analog output " + wpi::Twine(channel));
|
||||
}
|
||||
|
||||
m_channel = channel;
|
||||
@@ -33,12 +30,7 @@ AnalogOutput::AnalogOutput(int channel) {
|
||||
HAL_PortHandle port = HAL_GetPort(m_channel);
|
||||
int32_t status = 0;
|
||||
m_port = HAL_InitializeAnalogOutputPort(port, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALErrorWithRange(status, 0, HAL_GetNumAnalogOutputs(), channel);
|
||||
m_channel = std::numeric_limits<int>::max();
|
||||
m_port = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "analog output " + wpi::Twine(channel));
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_AnalogOutput, m_channel + 1);
|
||||
SendableRegistry::GetInstance().AddLW(this, "AnalogOutput", m_channel);
|
||||
@@ -51,16 +43,13 @@ AnalogOutput::~AnalogOutput() {
|
||||
void AnalogOutput::SetVoltage(double voltage) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogOutput(m_port, voltage, &status);
|
||||
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "SetVoltage");
|
||||
}
|
||||
|
||||
double AnalogOutput::GetVoltage() const {
|
||||
int32_t status = 0;
|
||||
double voltage = HAL_GetAnalogOutput(m_port, &status);
|
||||
|
||||
wpi_setHALError(status);
|
||||
|
||||
FRC_CheckErrorStatus(status, "GetVoltage");
|
||||
return voltage;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user