mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Merge branch '2022'
This commit is contained in:
@@ -10,10 +10,11 @@
|
||||
#include <hal/HALBase.h>
|
||||
#include <hal/Ports.h>
|
||||
#include <hal/Relay.h>
|
||||
#include <wpi/StackTrace.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc/smartdashboard/SendableBuilder.h"
|
||||
#include "frc/smartdashboard/SendableRegistry.h"
|
||||
|
||||
@@ -22,8 +23,8 @@ using namespace frc;
|
||||
Relay::Relay(int channel, Relay::Direction direction)
|
||||
: m_channel(channel), m_direction(direction) {
|
||||
if (!SensorUtil::CheckRelayChannel(m_channel)) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange,
|
||||
"Relay Channel " + wpi::Twine(m_channel));
|
||||
throw FRC_MakeError(err::ChannelIndexOutOfRange,
|
||||
"Relay Channel " + wpi::Twine{m_channel});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -31,46 +32,29 @@ Relay::Relay(int channel, Relay::Direction direction)
|
||||
|
||||
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
|
||||
int32_t status = 0;
|
||||
m_forwardHandle = HAL_InitializeRelayPort(portHandle, true, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALErrorWithRange(status, 0, HAL_GetNumRelayChannels(), channel);
|
||||
m_forwardHandle = HAL_kInvalidHandle;
|
||||
m_reverseHandle = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
m_forwardHandle =
|
||||
HAL_InitializeRelayPort(portHandle, true, stackTrace.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel});
|
||||
HAL_Report(HALUsageReporting::kResourceType_Relay, m_channel + 1);
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kReverseOnly) {
|
||||
int32_t status = 0;
|
||||
m_reverseHandle = HAL_InitializeRelayPort(portHandle, false, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALErrorWithRange(status, 0, HAL_GetNumRelayChannels(), channel);
|
||||
m_forwardHandle = HAL_kInvalidHandle;
|
||||
m_reverseHandle = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
|
||||
std::string stackTrace = wpi::GetStackTrace(1);
|
||||
m_reverseHandle =
|
||||
HAL_InitializeRelayPort(portHandle, false, stackTrace.c_str(), &status);
|
||||
FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel});
|
||||
HAL_Report(HALUsageReporting::kResourceType_Relay, m_channel + 128);
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
if (m_forwardHandle != HAL_kInvalidHandle) {
|
||||
HAL_SetRelay(m_forwardHandle, false, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALError(status);
|
||||
m_forwardHandle = HAL_kInvalidHandle;
|
||||
m_reverseHandle = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel});
|
||||
}
|
||||
if (m_reverseHandle != HAL_kInvalidHandle) {
|
||||
HAL_SetRelay(m_reverseHandle, false, &status);
|
||||
if (status != 0) {
|
||||
wpi_setHALError(status);
|
||||
m_forwardHandle = HAL_kInvalidHandle;
|
||||
m_reverseHandle = HAL_kInvalidHandle;
|
||||
return;
|
||||
}
|
||||
FRC_CheckErrorStatus(status, "Relay Channel " + wpi::Twine{m_channel});
|
||||
}
|
||||
|
||||
SendableRegistry::GetInstance().AddLW(this, "Relay", m_channel);
|
||||
@@ -90,10 +74,6 @@ Relay::~Relay() {
|
||||
}
|
||||
|
||||
void Relay::Set(Relay::Value value) {
|
||||
if (StatusIsFatal()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
|
||||
switch (value) {
|
||||
@@ -115,7 +95,7 @@ void Relay::Set(Relay::Value value) {
|
||||
break;
|
||||
case kForward:
|
||||
if (m_direction == kReverseOnly) {
|
||||
wpi_setWPIError(IncompatibleMode);
|
||||
FRC_ReportError(err::IncompatibleMode, "setting forward");
|
||||
break;
|
||||
}
|
||||
if (m_direction == kBothDirections || m_direction == kForwardOnly) {
|
||||
@@ -127,7 +107,7 @@ void Relay::Set(Relay::Value value) {
|
||||
break;
|
||||
case kReverse:
|
||||
if (m_direction == kForwardOnly) {
|
||||
wpi_setWPIError(IncompatibleMode);
|
||||
FRC_ReportError(err::IncompatibleMode, "setting reverse");
|
||||
break;
|
||||
}
|
||||
if (m_direction == kBothDirections) {
|
||||
@@ -139,7 +119,7 @@ void Relay::Set(Relay::Value value) {
|
||||
break;
|
||||
}
|
||||
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Set");
|
||||
}
|
||||
|
||||
Relay::Value Relay::Get() const {
|
||||
@@ -174,7 +154,7 @@ Relay::Value Relay::Get() const {
|
||||
}
|
||||
}
|
||||
|
||||
wpi_setHALError(status);
|
||||
FRC_CheckErrorStatus(status, "Get");
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user