mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Refactor HAL handle move construction/assignment (#1845)
A templated hal::Handle class is used to wrap handles to make them move-only. This eliminates a lot of boilerplate move constructor/assignment code in the main WPILib classes. HAL_SPIPort and HAL_I2CPort are also wrapped. The wrapper class does not implement destruction. This would require the wrapper class to be handle-specific (rather than generic) and would result in more code added than it removed, plus would add header dependencies on more HAL headers. In addition, some HAL handle release functions are more complex (e.g. have return values) and can't be easily mapped to a destructor.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -65,20 +65,6 @@ AnalogGyro::AnalogGyro(std::shared_ptr<AnalogInput> channel, int center,
|
||||
|
||||
AnalogGyro::~AnalogGyro() { HAL_FreeAnalogGyro(m_gyroHandle); }
|
||||
|
||||
AnalogGyro::AnalogGyro(AnalogGyro&& rhs)
|
||||
: GyroBase(std::move(rhs)), m_analog(std::move(rhs.m_analog)) {
|
||||
std::swap(m_gyroHandle, rhs.m_gyroHandle);
|
||||
}
|
||||
|
||||
AnalogGyro& AnalogGyro::operator=(AnalogGyro&& rhs) {
|
||||
GyroBase::operator=(std::move(rhs));
|
||||
|
||||
m_analog = std::move(rhs.m_analog);
|
||||
std::swap(m_gyroHandle, rhs.m_gyroHandle);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
double AnalogGyro::GetAngle() const {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
int32_t status = 0;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -47,27 +47,6 @@ AnalogInput::AnalogInput(int channel) {
|
||||
|
||||
AnalogInput::~AnalogInput() { HAL_FreeAnalogInputPort(m_port); }
|
||||
|
||||
AnalogInput::AnalogInput(AnalogInput&& rhs)
|
||||
: ErrorBase(std::move(rhs)),
|
||||
SendableBase(std::move(rhs)),
|
||||
PIDSource(std::move(rhs)),
|
||||
m_channel(std::move(rhs.m_channel)),
|
||||
m_accumulatorOffset(std::move(rhs.m_accumulatorOffset)) {
|
||||
std::swap(m_port, rhs.m_port);
|
||||
}
|
||||
|
||||
AnalogInput& AnalogInput::operator=(AnalogInput&& rhs) {
|
||||
ErrorBase::operator=(std::move(rhs));
|
||||
SendableBase::operator=(std::move(rhs));
|
||||
PIDSource::operator=(std::move(rhs));
|
||||
|
||||
m_channel = std::move(rhs.m_channel);
|
||||
std::swap(m_port, rhs.m_port);
|
||||
m_accumulatorOffset = std::move(rhs.m_accumulatorOffset);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
int AnalogInput::GetValue() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2014-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -47,23 +47,6 @@ AnalogOutput::AnalogOutput(int channel) {
|
||||
|
||||
AnalogOutput::~AnalogOutput() { HAL_FreeAnalogOutputPort(m_port); }
|
||||
|
||||
AnalogOutput::AnalogOutput(AnalogOutput&& rhs)
|
||||
: ErrorBase(std::move(rhs)),
|
||||
SendableBase(std::move(rhs)),
|
||||
m_channel(std::move(rhs.m_channel)) {
|
||||
std::swap(m_port, rhs.m_port);
|
||||
}
|
||||
|
||||
AnalogOutput& AnalogOutput::operator=(AnalogOutput&& rhs) {
|
||||
ErrorBase::operator=(std::move(rhs));
|
||||
SendableBase::operator=(std::move(rhs));
|
||||
|
||||
m_channel = std::move(rhs.m_channel);
|
||||
std::swap(m_port, rhs.m_port);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void AnalogOutput::SetVoltage(double voltage) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogOutput(m_port, voltage, &status);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -51,8 +51,8 @@ AnalogTrigger::~AnalogTrigger() {
|
||||
AnalogTrigger::AnalogTrigger(AnalogTrigger&& rhs)
|
||||
: ErrorBase(std::move(rhs)),
|
||||
SendableBase(std::move(rhs)),
|
||||
m_index(std::move(rhs.m_index)) {
|
||||
std::swap(m_trigger, rhs.m_trigger);
|
||||
m_index(std::move(rhs.m_index)),
|
||||
m_trigger(std::move(rhs.m_trigger)) {
|
||||
std::swap(m_analogInput, rhs.m_analogInput);
|
||||
std::swap(m_ownsAnalog, rhs.m_ownsAnalog);
|
||||
}
|
||||
@@ -62,7 +62,7 @@ AnalogTrigger& AnalogTrigger::operator=(AnalogTrigger&& rhs) {
|
||||
SendableBase::operator=(std::move(rhs));
|
||||
|
||||
m_index = std::move(rhs.m_index);
|
||||
std::swap(m_trigger, rhs.m_trigger);
|
||||
m_trigger = std::move(rhs.m_trigger);
|
||||
std::swap(m_analogInput, rhs.m_analogInput);
|
||||
std::swap(m_ownsAnalog, rhs.m_ownsAnalog);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -14,26 +14,17 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
AnalogTriggerOutput::~AnalogTriggerOutput() {
|
||||
if (m_interrupt != HAL_kInvalidHandle) {
|
||||
int32_t status = 0;
|
||||
HAL_CleanInterrupts(m_interrupt, &status);
|
||||
// ignore status, as an invalid handle just needs to be ignored.
|
||||
m_interrupt = HAL_kInvalidHandle;
|
||||
}
|
||||
}
|
||||
|
||||
bool AnalogTriggerOutput::Get() const {
|
||||
int32_t status = 0;
|
||||
bool result = HAL_GetAnalogTriggerOutput(
|
||||
m_trigger.m_trigger, static_cast<HAL_AnalogTriggerType>(m_outputType),
|
||||
m_trigger->m_trigger, static_cast<HAL_AnalogTriggerType>(m_outputType),
|
||||
&status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return result;
|
||||
}
|
||||
|
||||
HAL_Handle AnalogTriggerOutput::GetPortHandleForRouting() const {
|
||||
return m_trigger.m_trigger;
|
||||
return m_trigger->m_trigger;
|
||||
}
|
||||
|
||||
AnalogTriggerType AnalogTriggerOutput::GetAnalogTriggerTypeForRouting() const {
|
||||
@@ -42,13 +33,13 @@ AnalogTriggerType AnalogTriggerOutput::GetAnalogTriggerTypeForRouting() const {
|
||||
|
||||
bool AnalogTriggerOutput::IsAnalogTrigger() const { return true; }
|
||||
|
||||
int AnalogTriggerOutput::GetChannel() const { return m_trigger.m_index; }
|
||||
int AnalogTriggerOutput::GetChannel() const { return m_trigger->m_index; }
|
||||
|
||||
void AnalogTriggerOutput::InitSendable(SendableBuilder&) {}
|
||||
|
||||
AnalogTriggerOutput::AnalogTriggerOutput(const AnalogTrigger& trigger,
|
||||
AnalogTriggerType outputType)
|
||||
: m_trigger(trigger), m_outputType(outputType) {
|
||||
: m_trigger(&trigger), m_outputType(outputType) {
|
||||
HAL_Report(HALUsageReporting::kResourceType_AnalogTriggerOutput,
|
||||
trigger.GetIndex(), static_cast<uint8_t>(outputType));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -52,18 +52,6 @@ CAN::~CAN() {
|
||||
}
|
||||
}
|
||||
|
||||
CAN::CAN(CAN&& rhs) : ErrorBase(std::move(rhs)) {
|
||||
std::swap(m_handle, rhs.m_handle);
|
||||
}
|
||||
|
||||
CAN& CAN::operator=(CAN&& rhs) {
|
||||
ErrorBase::operator=(std::move(rhs));
|
||||
|
||||
std::swap(m_handle, rhs.m_handle);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void CAN::WritePacket(const uint8_t* data, int length, int apiId) {
|
||||
int32_t status = 0;
|
||||
HAL_WriteCANPacket(m_handle, data, length, apiId, &status);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -90,30 +90,6 @@ Counter::~Counter() {
|
||||
int32_t status = 0;
|
||||
HAL_FreeCounter(m_counter, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
m_counter = HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
Counter::Counter(Counter&& rhs)
|
||||
: ErrorBase(std::move(rhs)),
|
||||
SendableBase(std::move(rhs)),
|
||||
CounterBase(std::move(rhs)),
|
||||
m_upSource(std::move(rhs.m_upSource)),
|
||||
m_downSource(std::move(rhs.m_downSource)),
|
||||
m_index(std::move(rhs.m_index)) {
|
||||
std::swap(m_counter, rhs.m_counter);
|
||||
}
|
||||
|
||||
Counter& Counter::operator=(Counter&& rhs) {
|
||||
ErrorBase::operator=(std::move(rhs));
|
||||
SendableBase::operator=(std::move(rhs));
|
||||
CounterBase::operator=(std::move(rhs));
|
||||
|
||||
m_upSource = std::move(rhs.m_upSource);
|
||||
m_downSource = std::move(rhs.m_downSource);
|
||||
std::swap(m_counter, rhs.m_counter);
|
||||
m_index = std::move(rhs.m_index);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Counter::SetUpSource(int channel) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -45,30 +45,9 @@ DigitalInput::DigitalInput(int channel) {
|
||||
|
||||
DigitalInput::~DigitalInput() {
|
||||
if (StatusIsFatal()) return;
|
||||
if (m_interrupt != HAL_kInvalidHandle) {
|
||||
int32_t status = 0;
|
||||
HAL_CleanInterrupts(m_interrupt, &status);
|
||||
// Ignore status, as an invalid handle just needs to be ignored.
|
||||
m_interrupt = HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
HAL_FreeDIOPort(m_handle);
|
||||
}
|
||||
|
||||
DigitalInput::DigitalInput(DigitalInput&& rhs)
|
||||
: DigitalSource(std::move(rhs)), m_channel(std::move(rhs.m_channel)) {
|
||||
std::swap(m_handle, rhs.m_handle);
|
||||
}
|
||||
|
||||
DigitalInput& DigitalInput::operator=(DigitalInput&& rhs) {
|
||||
DigitalSource::operator=(std::move(rhs));
|
||||
|
||||
m_channel = std::move(rhs.m_channel);
|
||||
std::swap(m_handle, rhs.m_handle);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool DigitalInput::Get() const {
|
||||
if (StatusIsFatal()) return false;
|
||||
int32_t status = 0;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -52,25 +52,6 @@ DigitalOutput::~DigitalOutput() {
|
||||
HAL_FreeDIOPort(m_handle);
|
||||
}
|
||||
|
||||
DigitalOutput::DigitalOutput(DigitalOutput&& rhs)
|
||||
: ErrorBase(std::move(rhs)),
|
||||
SendableBase(std::move(rhs)),
|
||||
m_channel(std::move(rhs.m_channel)),
|
||||
m_pwmGenerator(std::move(rhs.m_pwmGenerator)) {
|
||||
std::swap(m_handle, rhs.m_handle);
|
||||
}
|
||||
|
||||
DigitalOutput& DigitalOutput::operator=(DigitalOutput&& rhs) {
|
||||
ErrorBase::operator=(std::move(rhs));
|
||||
SendableBase::operator=(std::move(rhs));
|
||||
|
||||
m_channel = std::move(rhs.m_channel);
|
||||
std::swap(m_handle, rhs.m_handle);
|
||||
m_pwmGenerator = std::move(rhs.m_pwmGenerator);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void DigitalOutput::Set(bool value) {
|
||||
if (StatusIsFatal()) return;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -83,29 +83,6 @@ DoubleSolenoid::~DoubleSolenoid() {
|
||||
HAL_FreeSolenoidPort(m_reverseHandle);
|
||||
}
|
||||
|
||||
DoubleSolenoid::DoubleSolenoid(DoubleSolenoid&& rhs)
|
||||
: SolenoidBase(std::move(rhs)),
|
||||
m_forwardChannel(std::move(rhs.m_forwardChannel)),
|
||||
m_reverseChannel(std::move(rhs.m_reverseChannel)),
|
||||
m_forwardMask(std::move(rhs.m_forwardMask)),
|
||||
m_reverseMask(std::move(rhs.m_reverseMask)) {
|
||||
std::swap(m_forwardHandle, rhs.m_forwardHandle);
|
||||
std::swap(m_reverseHandle, rhs.m_reverseHandle);
|
||||
}
|
||||
|
||||
DoubleSolenoid& DoubleSolenoid::operator=(DoubleSolenoid&& rhs) {
|
||||
SolenoidBase::operator=(std::move(rhs));
|
||||
|
||||
m_forwardChannel = std::move(rhs.m_forwardChannel);
|
||||
m_reverseChannel = std::move(rhs.m_reverseChannel);
|
||||
m_forwardMask = std::move(rhs.m_forwardMask);
|
||||
m_reverseMask = std::move(rhs.m_reverseMask);
|
||||
std::swap(m_forwardHandle, rhs.m_forwardHandle);
|
||||
std::swap(m_reverseHandle, rhs.m_reverseHandle);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void DoubleSolenoid::Set(Value value) {
|
||||
if (StatusIsFatal()) return;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -61,31 +61,6 @@ Encoder::~Encoder() {
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
}
|
||||
|
||||
Encoder::Encoder(Encoder&& rhs)
|
||||
: ErrorBase(std::move(rhs)),
|
||||
SendableBase(std::move(rhs)),
|
||||
CounterBase(std::move(rhs)),
|
||||
PIDSource(std::move(rhs)),
|
||||
m_aSource(std::move(rhs.m_aSource)),
|
||||
m_bSource(std::move(rhs.m_bSource)),
|
||||
m_indexSource(std::move(rhs.m_indexSource)) {
|
||||
std::swap(m_encoder, rhs.m_encoder);
|
||||
}
|
||||
|
||||
Encoder& Encoder::operator=(Encoder&& rhs) {
|
||||
ErrorBase::operator=(std::move(rhs));
|
||||
SendableBase::operator=(std::move(rhs));
|
||||
CounterBase::operator=(std::move(rhs));
|
||||
PIDSource::operator=(std::move(rhs));
|
||||
|
||||
m_aSource = std::move(rhs.m_aSource);
|
||||
m_bSource = std::move(rhs.m_bSource);
|
||||
m_indexSource = std::move(rhs.m_indexSource);
|
||||
std::swap(m_encoder, rhs.m_encoder);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
int Encoder::Get() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -27,21 +27,6 @@ I2C::I2C(Port port, int deviceAddress)
|
||||
|
||||
I2C::~I2C() { HAL_CloseI2C(m_port); }
|
||||
|
||||
I2C::I2C(I2C&& rhs)
|
||||
: ErrorBase(std::move(rhs)),
|
||||
m_deviceAddress(std::move(rhs.m_deviceAddress)) {
|
||||
std::swap(m_port, rhs.m_port);
|
||||
}
|
||||
|
||||
I2C& I2C::operator=(I2C&& rhs) {
|
||||
ErrorBase::operator=(std::move(rhs));
|
||||
|
||||
std::swap(m_port, rhs.m_port);
|
||||
m_deviceAddress = std::move(rhs.m_deviceAddress);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool I2C::Transaction(uint8_t* dataToSend, int sendSize, uint8_t* dataReceived,
|
||||
int receiveSize) {
|
||||
int32_t status = 0;
|
||||
|
||||
@@ -21,26 +21,6 @@ InterruptableSensorBase::~InterruptableSensorBase() {
|
||||
// Ignore status, as an invalid handle just needs to be ignored.
|
||||
}
|
||||
|
||||
InterruptableSensorBase::InterruptableSensorBase(InterruptableSensorBase&& rhs)
|
||||
: ErrorBase(std::move(rhs)),
|
||||
m_interrupt(rhs.m_interrupt),
|
||||
m_interruptHandler{std::move(rhs.m_interruptHandler)} {
|
||||
rhs.m_interrupt = HAL_kInvalidHandle;
|
||||
rhs.m_interruptHandler = nullptr;
|
||||
}
|
||||
|
||||
InterruptableSensorBase& InterruptableSensorBase::operator=(
|
||||
InterruptableSensorBase&& rhs) {
|
||||
ErrorBase::operator=(std::move(rhs));
|
||||
|
||||
m_interrupt = rhs.m_interrupt;
|
||||
m_interruptHandler = std::move(rhs.m_interruptHandler);
|
||||
rhs.m_interrupt = HAL_kInvalidHandle;
|
||||
rhs.m_interruptHandler = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void InterruptableSensorBase::RequestInterrupts(
|
||||
HAL_InterruptHandlerFunction handler, void* param) {
|
||||
if (StatusIsFatal()) return;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -61,23 +61,6 @@ PWM::~PWM() {
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
}
|
||||
|
||||
PWM::PWM(PWM&& rhs)
|
||||
: MotorSafety(std::move(rhs)),
|
||||
SendableBase(std::move(rhs)),
|
||||
m_channel(std::move(rhs.m_channel)) {
|
||||
std::swap(m_handle, rhs.m_handle);
|
||||
}
|
||||
|
||||
PWM& PWM::operator=(PWM&& rhs) {
|
||||
ErrorBase::operator=(std::move(rhs));
|
||||
SendableBase::operator=(std::move(rhs));
|
||||
|
||||
m_channel = std::move(rhs.m_channel);
|
||||
std::swap(m_handle, rhs.m_handle);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void PWM::StopMotor() { SetDisabled(); }
|
||||
|
||||
void PWM::GetDescription(wpi::raw_ostream& desc) const {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -88,27 +88,6 @@ Relay::~Relay() {
|
||||
if (m_reverseHandle != HAL_kInvalidHandle) HAL_FreeRelayPort(m_reverseHandle);
|
||||
}
|
||||
|
||||
Relay::Relay(Relay&& rhs)
|
||||
: MotorSafety(std::move(rhs)),
|
||||
SendableBase(std::move(rhs)),
|
||||
m_channel(std::move(rhs.m_channel)),
|
||||
m_direction(std::move(rhs.m_direction)) {
|
||||
std::swap(m_forwardHandle, rhs.m_forwardHandle);
|
||||
std::swap(m_reverseHandle, rhs.m_reverseHandle);
|
||||
}
|
||||
|
||||
Relay& Relay::operator=(Relay&& rhs) {
|
||||
MotorSafety::operator=(std::move(rhs));
|
||||
SendableBase::operator=(std::move(rhs));
|
||||
|
||||
m_channel = std::move(rhs.m_channel);
|
||||
m_direction = std::move(rhs.m_direction);
|
||||
std::swap(m_forwardHandle, rhs.m_forwardHandle);
|
||||
std::swap(m_reverseHandle, rhs.m_reverseHandle);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Relay::Set(Relay::Value value) {
|
||||
if (StatusIsFatal()) return;
|
||||
|
||||
|
||||
@@ -162,27 +162,6 @@ SPI::SPI(Port port) : m_port(static_cast<HAL_SPIPort>(port)) {
|
||||
|
||||
SPI::~SPI() { HAL_CloseSPI(m_port); }
|
||||
|
||||
SPI::SPI(SPI&& rhs)
|
||||
: ErrorBase(std::move(rhs)),
|
||||
m_msbFirst(std::move(rhs.m_msbFirst)),
|
||||
m_sampleOnTrailing(std::move(rhs.m_sampleOnTrailing)),
|
||||
m_clockIdleHigh(std::move(rhs.m_clockIdleHigh)),
|
||||
m_accum(std::move(rhs.m_accum)) {
|
||||
std::swap(m_port, rhs.m_port);
|
||||
}
|
||||
|
||||
SPI& SPI::operator=(SPI&& rhs) {
|
||||
ErrorBase::operator=(std::move(rhs));
|
||||
|
||||
std::swap(m_port, rhs.m_port);
|
||||
m_msbFirst = std::move(rhs.m_msbFirst);
|
||||
m_sampleOnTrailing = std::move(rhs.m_sampleOnTrailing);
|
||||
m_clockIdleHigh = std::move(rhs.m_clockIdleHigh);
|
||||
m_accum = std::move(rhs.m_accum);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void SPI::SetClockRate(int hz) { HAL_SetSPISpeed(m_port, hz); }
|
||||
|
||||
void SPI::SetMSBFirst() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -52,20 +52,6 @@ Solenoid::Solenoid(int moduleNumber, int channel)
|
||||
|
||||
Solenoid::~Solenoid() { HAL_FreeSolenoidPort(m_solenoidHandle); }
|
||||
|
||||
Solenoid::Solenoid(Solenoid&& rhs)
|
||||
: SolenoidBase(std::move(rhs)), m_channel(std::move(rhs.m_channel)) {
|
||||
std::swap(m_solenoidHandle, rhs.m_solenoidHandle);
|
||||
}
|
||||
|
||||
Solenoid& Solenoid::operator=(Solenoid&& rhs) {
|
||||
SolenoidBase::operator=(std::move(rhs));
|
||||
|
||||
std::swap(m_solenoidHandle, rhs.m_solenoidHandle);
|
||||
m_channel = std::move(rhs.m_channel);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Solenoid::Set(bool on) {
|
||||
if (StatusIsFatal()) return;
|
||||
int32_t status = 0;
|
||||
|
||||
@@ -67,22 +67,6 @@ TimedRobot::~TimedRobot() {
|
||||
HAL_CleanNotifier(m_notifier, &status);
|
||||
}
|
||||
|
||||
TimedRobot::TimedRobot(TimedRobot&& rhs)
|
||||
: IterativeRobotBase(std::move(rhs)),
|
||||
m_expirationTime(std::move(rhs.m_expirationTime)) {
|
||||
std::swap(m_notifier, rhs.m_notifier);
|
||||
}
|
||||
|
||||
TimedRobot& TimedRobot::operator=(TimedRobot&& rhs) {
|
||||
IterativeRobotBase::operator=(std::move(rhs));
|
||||
ErrorBase::operator=(std::move(rhs));
|
||||
|
||||
std::swap(m_notifier, rhs.m_notifier);
|
||||
m_expirationTime = std::move(rhs.m_expirationTime);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void TimedRobot::UpdateAlarm() {
|
||||
int32_t status = 0;
|
||||
HAL_UpdateNotifierAlarm(
|
||||
|
||||
Reference in New Issue
Block a user