[hal] Refactor C++ handle closing; check for invalid handle before closing (#7016)

Adds a close function pointer template parameter to hal::Handle.  This allows default destructors in many places.
The status parameter has been removed from close functions; in most places it was not used. Where it was, an error is printed instead.
This commit is contained in:
Ryan Blue
2024-09-07 13:58:15 -04:00
committed by GitHub
parent 80f3813908
commit 496e7c1bba
94 changed files with 247 additions and 425 deletions

View File

@@ -29,19 +29,12 @@ AddressableLED::AddressableLED(int port) : m_port{port} {
m_handle = HAL_InitializeAddressableLED(m_pwmHandle, &status);
FRC_CheckErrorStatus(status, "Port {}", port);
if (m_handle == HAL_kInvalidHandle) {
HAL_FreePWMPort(m_pwmHandle, &status);
HAL_FreePWMPort(m_pwmHandle);
}
HAL_Report(HALUsageReporting::kResourceType_AddressableLEDs, port + 1);
}
AddressableLED::~AddressableLED() {
HAL_FreeAddressableLED(m_handle);
int32_t status = 0;
HAL_FreePWMPort(m_pwmHandle, &status);
FRC_ReportError(status, "Port {}", m_port);
}
void AddressableLED::SetLength(int length) {
int32_t status = 0;
HAL_SetAddressableLEDLength(m_handle, length, &status);

View File

@@ -58,10 +58,6 @@ AnalogGyro::AnalogGyro(std::shared_ptr<AnalogInput> channel, int center,
Reset();
}
AnalogGyro::~AnalogGyro() {
HAL_FreeAnalogGyro(m_gyroHandle);
}
double AnalogGyro::GetAngle() const {
int32_t status = 0;
double value = HAL_GetAnalogGyroAngle(m_gyroHandle, &status);

View File

@@ -37,10 +37,6 @@ AnalogInput::AnalogInput(int channel) {
wpi::SendableRegistry::AddLW(this, "AnalogInput", channel);
}
AnalogInput::~AnalogInput() {
HAL_FreeAnalogInputPort(m_port);
}
int AnalogInput::GetValue() const {
int32_t status = 0;
int value = HAL_GetAnalogValue(m_port, &status);

View File

@@ -37,10 +37,6 @@ AnalogOutput::AnalogOutput(int channel) {
wpi::SendableRegistry::AddLW(this, "AnalogOutput", m_channel);
}
AnalogOutput::~AnalogOutput() {
HAL_FreeAnalogOutputPort(m_port);
}
void AnalogOutput::SetVoltage(double voltage) {
int32_t status = 0;
HAL_SetAnalogOutput(m_port, voltage, &status);

View File

@@ -57,12 +57,6 @@ AnalogTrigger::AnalogTrigger(std::shared_ptr<DutyCycle> input)
wpi::SendableRegistry::AddLW(this, "AnalogTrigger", index);
}
AnalogTrigger::~AnalogTrigger() {
int32_t status = 0;
HAL_CleanAnalogTrigger(m_trigger, &status);
FRC_ReportError(status, "Channel {}", GetSourceChannel());
}
void AnalogTrigger::SetLimitsVoltage(double lower, double upper) {
int32_t status = 0;
HAL_SetAnalogTriggerLimitsVoltage(m_trigger, lower, upper, &status);

View File

@@ -35,13 +35,6 @@ CAN::CAN(int deviceId, int deviceManufacturer, int deviceType) {
HAL_Report(HALUsageReporting::kResourceType_CAN, deviceId + 1);
}
CAN::~CAN() {
if (m_handle != HAL_kInvalidHandle) {
HAL_CleanCAN(m_handle);
m_handle = HAL_kInvalidHandle;
}
}
void CAN::WritePacket(const uint8_t* data, int length, int apiId) {
int32_t status = 0;
HAL_WriteCANPacket(m_handle, data, length, apiId, &status);

View File

@@ -89,10 +89,6 @@ Counter::~Counter() {
} catch (const RuntimeError& e) {
e.Report();
}
int32_t status = 0;
HAL_FreeCounter(m_counter, &status);
FRC_ReportError(status, "Counter destructor");
}
void Counter::SetUpSource(int channel) {

View File

@@ -30,10 +30,6 @@ DMA::DMA() {
FRC_CheckErrorStatus(status, "InitializeDMA");
}
DMA::~DMA() {
HAL_FreeDMA(dmaHandle);
}
void DMA::SetPause(bool pause) {
int32_t status = 0;
HAL_SetDMAPause(dmaHandle, pause, &status);

View File

@@ -35,10 +35,6 @@ DigitalInput::DigitalInput(int channel) {
wpi::SendableRegistry::AddLW(this, "DigitalInput", channel);
}
DigitalInput::~DigitalInput() {
HAL_FreeDIOPort(m_handle);
}
bool DigitalInput::Get() const {
int32_t status = 0;
bool value = HAL_GetDIO(m_handle, &status);

View File

@@ -43,8 +43,6 @@ DigitalOutput::~DigitalOutput() {
} catch (const RuntimeError& e) {
e.Report();
}
HAL_FreeDIOPort(m_handle);
}
void DigitalOutput::Set(bool value) {
@@ -141,8 +139,7 @@ void DigitalOutput::DisablePWM() {
&status);
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
HAL_FreeDigitalPWM(m_pwmGenerator, &status);
FRC_CheckErrorStatus(status, "Channel {}", m_channel);
HAL_FreeDigitalPWM(m_pwmGenerator);
m_pwmGenerator = HAL_kInvalidHandle;
}

View File

@@ -35,10 +35,6 @@ DutyCycle::DutyCycle(std::shared_ptr<DigitalSource> source)
InitDutyCycle();
}
DutyCycle::~DutyCycle() {
HAL_FreeDutyCycle(m_handle);
}
void DutyCycle::InitDutyCycle() {
int32_t status = 0;
m_handle =

View File

@@ -59,12 +59,6 @@ Encoder::Encoder(std::shared_ptr<DigitalSource> aSource,
InitEncoder(reverseDirection, encodingType);
}
Encoder::~Encoder() {
int32_t status = 0;
HAL_FreeEncoder(m_encoder, &status);
FRC_ReportError(status, "FreeEncoder");
}
int Encoder::Get() const {
int32_t status = 0;
int value = HAL_GetEncoder(m_encoder, &status);

View File

@@ -31,10 +31,6 @@ I2C::I2C(Port port, int deviceAddress)
HAL_Report(HALUsageReporting::kResourceType_I2C, deviceAddress);
}
I2C::~I2C() {
HAL_CloseI2C(m_port);
}
I2C::Port I2C::GetPort() const {
return static_cast<Port>(static_cast<int>(m_port));
}

View File

@@ -128,7 +128,7 @@ Notifier::~Notifier() {
m_thread.join();
}
HAL_CleanNotifier(handle, &status);
HAL_CleanNotifier(handle);
}
Notifier::Notifier(Notifier&& rhs)

View File

@@ -46,12 +46,8 @@ PWM::PWM(int channel, bool registerSendable) {
PWM::~PWM() {
int32_t status = 0;
HAL_SetPWMDisabled(m_handle, &status);
FRC_ReportError(status, "Channel {}", m_channel);
HAL_FreePWMPort(m_handle, &status);
FRC_ReportError(status, "Channel {}", m_channel);
}
void PWM::SetPulseTime(units::microsecond_t time) {

View File

@@ -57,13 +57,6 @@ PowerDistribution::PowerDistribution(int module, ModuleType moduleType) {
wpi::SendableRegistry::AddLW(this, "PowerDistribution", m_module);
}
PowerDistribution::~PowerDistribution() {
if (m_handle != HAL_kInvalidHandle) {
HAL_CleanPowerDistribution(m_handle);
m_handle = HAL_kInvalidHandle;
}
}
int PowerDistribution::GetNumChannels() const {
int32_t status = 0;
int32_t size = HAL_GetPowerDistributionNumChannels(m_handle, &status);

View File

@@ -63,13 +63,6 @@ Relay::~Relay() {
int32_t status = 0;
HAL_SetRelay(m_forwardHandle, false, &status);
HAL_SetRelay(m_reverseHandle, false, &status);
// ignore errors, as we want to make sure a free happens.
if (m_forwardHandle != HAL_kInvalidHandle) {
HAL_FreeRelayPort(m_forwardHandle);
}
if (m_reverseHandle != HAL_kInvalidHandle) {
HAL_FreeRelayPort(m_reverseHandle);
}
}
void Relay::Set(Relay::Value value) {

View File

@@ -165,9 +165,7 @@ SPI::SPI(Port port) : m_port(static_cast<HAL_SPIPort>(port)) {
static_cast<uint8_t>(port) + 1);
}
SPI::~SPI() {
HAL_CloseSPI(m_port);
}
SPI::~SPI() = default;
SPI::Port SPI::GetPort() const {
return static_cast<Port>(static_cast<int>(m_port));

View File

@@ -74,12 +74,6 @@ SerialPort::SerialPort(int baudRate, std::string_view portName, Port port,
static_cast<uint8_t>(port) + 1);
}
SerialPort::~SerialPort() {
int32_t status = 0;
HAL_CloseSerial(m_portHandle, &status);
FRC_ReportError(status, "CloseSerial");
}
void SerialPort::SetFlowControl(SerialPort::FlowControl flowControl) {
int32_t status = 0;
HAL_SetSerialFlowControl(m_portHandle, flowControl, &status);

View File

@@ -49,10 +49,6 @@ void SynchronousInterrupt::InitSynchronousInterrupt() {
FRC_CheckErrorStatus(status, "Interrupt setting up source edge failed");
}
SynchronousInterrupt::~SynchronousInterrupt() {
HAL_CleanInterrupts(m_handle);
}
inline SynchronousInterrupt::WaitResult operator|(
SynchronousInterrupt::WaitResult lhs,
SynchronousInterrupt::WaitResult rhs) {

View File

@@ -94,8 +94,6 @@ TimedRobot::~TimedRobot() {
HAL_StopNotifier(m_notifier, &status);
FRC_ReportError(status, "StopNotifier");
HAL_CleanNotifier(m_notifier, &status);
}
void TimedRobot::AddPeriodic(std::function<void()> callback,

View File

@@ -65,7 +65,7 @@ Watchdog::Impl::~Impl() {
m_thread.join();
}
HAL_CleanNotifier(handle, &status);
HAL_CleanNotifier(handle);
}
void Watchdog::Impl::UpdateAlarm() {

View File

@@ -61,11 +61,6 @@ ExternalDirectionCounter::ExternalDirectionCounter(
wpi::SendableRegistry::AddLW(this, "External Direction Counter", m_index);
}
ExternalDirectionCounter::~ExternalDirectionCounter() {
int32_t status = 0;
HAL_FreeCounter(m_handle, &status);
}
int ExternalDirectionCounter::GetCount() const {
int32_t status = 0;
int val = HAL_GetCounter(m_handle, &status);

View File

@@ -37,11 +37,6 @@ Tachometer::Tachometer(std::shared_ptr<DigitalSource> source) {
wpi::SendableRegistry::AddLW(this, "Tachometer", m_index);
}
Tachometer::~Tachometer() {
int32_t status = 0;
HAL_FreeCounter(m_handle, &status);
}
units::hertz_t Tachometer::GetFrequency() const {
auto period = GetPeriod();
if (period.value() == 0) {

View File

@@ -55,11 +55,6 @@ UpDownCounter::UpDownCounter(std::shared_ptr<DigitalSource> upSource,
wpi::SendableRegistry::AddLW(this, "UpDown Counter", m_index);
}
UpDownCounter::~UpDownCounter() {
int32_t status = 0;
HAL_FreeCounter(m_handle, &status);
}
int UpDownCounter::GetCount() const {
int32_t status = 0;
int val = HAL_GetCounter(m_handle, &status);

View File

@@ -7,7 +7,9 @@
#include <initializer_list>
#include <span>
#include <hal/AddressableLED.h>
#include <hal/AddressableLEDTypes.h>
#include <hal/PWM.h>
#include <hal/Types.h>
#include <units/time.h>
@@ -93,8 +95,6 @@ class AddressableLED {
AddressableLED(AddressableLED&&) = default;
AddressableLED& operator=(AddressableLED&&) = default;
~AddressableLED();
/**
* Sets the length of the LED strip.
*
@@ -165,8 +165,8 @@ class AddressableLED {
void Stop();
private:
hal::Handle<HAL_DigitalHandle> m_pwmHandle;
hal::Handle<HAL_AddressableLEDHandle> m_handle;
hal::Handle<HAL_DigitalHandle, HAL_FreePWMPort> m_pwmHandle;
hal::Handle<HAL_AddressableLEDHandle, HAL_FreeAddressableLED> m_handle;
int m_port;
};
} // namespace frc

View File

@@ -6,6 +6,7 @@
#include <memory>
#include <hal/AnalogGyro.h>
#include <hal/Types.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
@@ -100,11 +101,11 @@ class AnalogGyro : public wpi::Sendable,
*/
AnalogGyro(std::shared_ptr<AnalogInput> channel, int center, double offset);
~AnalogGyro() override;
AnalogGyro(AnalogGyro&& rhs) = default;
AnalogGyro& operator=(AnalogGyro&& rhs) = default;
~AnalogGyro() override = default;
/**
* Return the actual angle in degrees that the robot is currently facing.
*
@@ -220,7 +221,7 @@ class AnalogGyro : public wpi::Sendable,
private:
std::shared_ptr<AnalogInput> m_analog;
hal::Handle<HAL_GyroHandle> m_gyroHandle;
hal::Handle<HAL_GyroHandle, HAL_FreeAnalogGyro> m_gyroHandle;
};
} // namespace frc

View File

@@ -6,6 +6,7 @@
#include <stdint.h>
#include <hal/AnalogInput.h>
#include <hal/Types.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
@@ -47,11 +48,11 @@ class AnalogInput : public wpi::Sendable,
*/
explicit AnalogInput(int channel);
~AnalogInput() override;
AnalogInput(AnalogInput&&) = default;
AnalogInput& operator=(AnalogInput&&) = default;
~AnalogInput() override = default;
/**
* Get a sample straight from this channel.
*
@@ -284,7 +285,7 @@ class AnalogInput : public wpi::Sendable,
private:
int m_channel;
hal::Handle<HAL_AnalogInputHandle> m_port;
hal::Handle<HAL_AnalogInputHandle, HAL_FreeAnalogInputPort> m_port;
int64_t m_accumulatorOffset;
};

View File

@@ -4,6 +4,7 @@
#pragma once
#include <hal/AnalogOutput.h>
#include <hal/Types.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
@@ -25,11 +26,11 @@ class AnalogOutput : public wpi::Sendable,
*/
explicit AnalogOutput(int channel);
~AnalogOutput() override;
AnalogOutput(AnalogOutput&&) = default;
AnalogOutput& operator=(AnalogOutput&&) = default;
~AnalogOutput() override = default;
/**
* Set the value of the analog output.
*
@@ -53,7 +54,7 @@ class AnalogOutput : public wpi::Sendable,
protected:
int m_channel;
hal::Handle<HAL_AnalogOutputHandle> m_port;
hal::Handle<HAL_AnalogOutputHandle, HAL_FreeAnalogOutputPort> m_port;
};
} // namespace frc

View File

@@ -6,6 +6,7 @@
#include <memory>
#include <hal/AnalogTrigger.h>
#include <hal/Types.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
@@ -84,7 +85,7 @@ class AnalogTrigger : public wpi::Sendable,
AnalogTrigger(AnalogTrigger&&) = default;
AnalogTrigger& operator=(AnalogTrigger&&) = default;
~AnalogTrigger() override;
~AnalogTrigger() override = default;
/**
* Set the upper and lower limits of the analog trigger.
@@ -186,7 +187,7 @@ class AnalogTrigger : public wpi::Sendable,
std::shared_ptr<AnalogInput> m_analogInput;
std::shared_ptr<DutyCycle> m_dutyCycle;
hal::Handle<HAL_AnalogTriggerHandle> m_trigger;
hal::Handle<HAL_AnalogTriggerHandle, HAL_CleanAnalogTrigger> m_trigger;
bool m_ownsAnalog = false;
};

View File

@@ -6,7 +6,7 @@
#include <stdint.h>
#include <hal/CANAPITypes.h>
#include <hal/CANAPI.h>
namespace frc {
struct CANData {
@@ -50,11 +50,6 @@ class CAN {
*/
CAN(int deviceId, int deviceManufacturer, int deviceType);
/**
* Closes the CAN communication.
*/
~CAN();
CAN(CAN&&) = default;
CAN& operator=(CAN&&) = default;
@@ -178,6 +173,6 @@ class CAN {
HAL_CAN_Dev_kMiscellaneous;
private:
hal::Handle<HAL_CANHandle> m_handle;
hal::Handle<HAL_CANHandle, HAL_CleanCAN> m_handle;
};
} // namespace frc

View File

@@ -6,6 +6,7 @@
#include <memory>
#include <hal/Counter.h>
#include <hal/Types.h>
#include <units/time.h>
#include <wpi/sendable/Sendable.h>
@@ -142,11 +143,11 @@ class Counter : public CounterBase,
Counter(EncodingType encodingType, std::shared_ptr<DigitalSource> upSource,
std::shared_ptr<DigitalSource> downSource, bool inverted);
~Counter() override;
Counter(Counter&&) = default;
Counter& operator=(Counter&&) = default;
~Counter() override;
/**
* Set the up source for the counter as a digital input channel.
*
@@ -458,7 +459,7 @@ class Counter : public CounterBase,
std::shared_ptr<DigitalSource> m_downSource;
/// The FPGA counter object
hal::Handle<HAL_CounterHandle> m_counter;
hal::Handle<HAL_CounterHandle, HAL_FreeCounter> m_counter;
private:
/// The index of this counter.

View File

@@ -4,7 +4,7 @@
#pragma once
#include <hal/Types.h>
#include <hal/DMA.h>
#include <units/time.h>
namespace frc {
@@ -25,7 +25,6 @@ class DMA {
public:
DMA();
~DMA();
DMA& operator=(DMA&& other) = default;
DMA(DMA&& other) = default;
@@ -189,6 +188,6 @@ class DMA {
void Stop();
private:
hal::Handle<HAL_DMAHandle> dmaHandle;
hal::Handle<HAL_DMAHandle, HAL_FreeDMA> dmaHandle;
};
} // namespace frc

View File

@@ -4,6 +4,7 @@
#pragma once
#include <hal/DIO.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
@@ -35,11 +36,11 @@ class DigitalInput : public DigitalSource,
*/
explicit DigitalInput(int channel);
~DigitalInput() override;
DigitalInput(DigitalInput&&) = default;
DigitalInput& operator=(DigitalInput&&) = default;
~DigitalInput() override = default;
/**
* Get the value from a digital input channel.
*
@@ -79,7 +80,7 @@ class DigitalInput : public DigitalSource,
private:
int m_channel;
hal::Handle<HAL_DigitalHandle> m_handle;
hal::Handle<HAL_DigitalHandle, HAL_FreeDIOPort> m_handle;
friend class DigitalGlitchFilter;
};

View File

@@ -4,6 +4,7 @@
#pragma once
#include <hal/DIO.h>
#include <hal/Types.h>
#include <units/time.h>
#include <wpi/sendable/Sendable.h>
@@ -34,11 +35,11 @@ class DigitalOutput : public DigitalSource,
*/
explicit DigitalOutput(int channel);
~DigitalOutput() override;
DigitalOutput(DigitalOutput&&) = default;
DigitalOutput& operator=(DigitalOutput&&) = default;
~DigitalOutput() override;
/**
* Set the value of a digital output.
*
@@ -161,7 +162,7 @@ class DigitalOutput : public DigitalSource,
private:
int m_channel;
hal::Handle<HAL_DigitalHandle> m_handle;
hal::Handle<HAL_DigitalHandle, HAL_FreeDIOPort> m_handle;
hal::Handle<HAL_DigitalPWMHandle> m_pwmGenerator;
};

View File

@@ -6,6 +6,7 @@
#include <memory>
#include <hal/DutyCycle.h>
#include <hal/Types.h>
#include <units/time.h>
#include <wpi/sendable/Sendable.h>
@@ -59,13 +60,13 @@ class DutyCycle : public wpi::Sendable, public wpi::SendableHelper<DutyCycle> {
*/
explicit DutyCycle(std::shared_ptr<DigitalSource> source);
DutyCycle(DutyCycle&&) = default;
DutyCycle& operator=(DutyCycle&&) = default;
/**
* Close the DutyCycle and free all resources.
*/
~DutyCycle() override;
DutyCycle(DutyCycle&&) = default;
DutyCycle& operator=(DutyCycle&&) = default;
~DutyCycle() override = default;
/**
* Get the frequency of the duty cycle signal.
@@ -121,6 +122,6 @@ class DutyCycle : public wpi::Sendable, public wpi::SendableHelper<DutyCycle> {
private:
void InitDutyCycle();
std::shared_ptr<DigitalSource> m_source;
hal::Handle<HAL_DutyCycleHandle> m_handle;
hal::Handle<HAL_DutyCycleHandle, HAL_FreeDutyCycle> m_handle;
};
} // namespace frc

View File

@@ -6,6 +6,7 @@
#include <memory>
#include <hal/Encoder.h>
#include <hal/Types.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
@@ -138,11 +139,11 @@ class Encoder : public CounterBase,
std::shared_ptr<DigitalSource> bSource, bool reverseDirection = false,
EncodingType encodingType = k4X);
~Encoder() override;
Encoder(Encoder&&) = default;
Encoder& operator=(Encoder&&) = default;
~Encoder() override = default;
// CounterBase interface
/**
* Gets the current count.
@@ -378,7 +379,7 @@ class Encoder : public CounterBase,
std::shared_ptr<DigitalSource> m_aSource; // The A phase of the quad encoder
std::shared_ptr<DigitalSource> m_bSource; // The B phase of the quad encoder
std::shared_ptr<DigitalSource> m_indexSource = nullptr;
hal::Handle<HAL_EncoderHandle> m_encoder;
hal::Handle<HAL_EncoderHandle, HAL_FreeEncoder> m_encoder;
friend class DigitalGlitchFilter;
};

View File

@@ -40,8 +40,6 @@ class I2C {
*/
I2C(Port port, int deviceAddress);
~I2C();
I2C(I2C&&) = default;
I2C& operator=(I2C&&) = default;

View File

@@ -6,6 +6,7 @@
#include <stdint.h>
#include <hal/PWM.h>
#include <hal/Types.h>
#include <units/time.h>
#include <wpi/sendable/Sendable.h>
@@ -59,6 +60,9 @@ class PWM : public wpi::Sendable, public wpi::SendableHelper<PWM> {
*/
explicit PWM(int channel, bool registerSendable = true);
PWM(PWM&&) = default;
PWM& operator=(PWM&&) = default;
/**
* Free the PWM channel.
*
@@ -66,9 +70,6 @@ class PWM : public wpi::Sendable, public wpi::SendableHelper<PWM> {
*/
~PWM() override;
PWM(PWM&&) = default;
PWM& operator=(PWM&&) = default;
/**
* Set the PWM pulse time directly to the hardware.
*
@@ -206,7 +207,7 @@ class PWM : public wpi::Sendable, public wpi::SendableHelper<PWM> {
private:
int m_channel;
hal::Handle<HAL_DigitalHandle> m_handle;
hal::Handle<HAL_DigitalHandle, HAL_FreePWMPort> m_handle;
};
} // namespace frc

View File

@@ -6,6 +6,7 @@
#include <vector>
#include <hal/PowerDistribution.h>
#include <hal/Types.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
@@ -48,10 +49,11 @@ class PowerDistribution : public wpi::Sendable,
*/
PowerDistribution(int module, ModuleType moduleType);
~PowerDistribution() override;
PowerDistribution(PowerDistribution&&) = default;
PowerDistribution& operator=(PowerDistribution&&) = default;
~PowerDistribution() override = default;
/**
* Gets the number of channels for this power distribution object.
*
@@ -341,7 +343,7 @@ class PowerDistribution : public wpi::Sendable,
void InitSendable(wpi::SendableBuilder& builder) override;
private:
hal::Handle<HAL_PowerDistributionHandle> m_handle;
hal::Handle<HAL_PowerDistributionHandle, HAL_CleanPowerDistribution> m_handle;
int m_module;
};

View File

@@ -7,6 +7,7 @@
#include <memory>
#include <string>
#include <hal/Relay.h>
#include <hal/Types.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
@@ -68,6 +69,9 @@ class Relay : public MotorSafety,
*/
explicit Relay(int channel, Direction direction = kBothDirections);
Relay(Relay&&) = default;
Relay& operator=(Relay&&) = default;
/**
* Free the resource associated with a relay.
*
@@ -75,9 +79,6 @@ class Relay : public MotorSafety,
*/
~Relay() override;
Relay(Relay&&) = default;
Relay& operator=(Relay&&) = default;
/**
* Set the relay state.
*
@@ -120,8 +121,8 @@ class Relay : public MotorSafety,
int m_channel;
Direction m_direction;
hal::Handle<HAL_RelayHandle> m_forwardHandle;
hal::Handle<HAL_RelayHandle> m_reverseHandle;
hal::Handle<HAL_RelayHandle, HAL_FreeRelayPort> m_forwardHandle;
hal::Handle<HAL_RelayHandle, HAL_FreeRelayPort> m_reverseHandle;
};
} // namespace frc

View File

@@ -62,11 +62,11 @@ class SPI {
*/
explicit SPI(Port port);
~SPI();
SPI(SPI&&) = default;
SPI& operator=(SPI&&) = default;
~SPI();
/**
* Returns the SPI port.
*

View File

@@ -7,6 +7,7 @@
#include <string>
#include <string_view>
#include <hal/SerialPort.h>
#include <hal/Types.h>
#include <units/time.h>
@@ -128,8 +129,6 @@ class SerialPort {
int dataBits = 8, Parity parity = kParity_None,
StopBits stopBits = kStopBits_One);
~SerialPort();
SerialPort(SerialPort&& rhs) = default;
SerialPort& operator=(SerialPort&& rhs) = default;
@@ -255,7 +254,7 @@ class SerialPort {
void Reset();
private:
hal::Handle<HAL_SerialPortHandle> m_portHandle;
hal::Handle<HAL_SerialPortHandle, HAL_CloseSerial> m_portHandle;
};
} // namespace frc

View File

@@ -6,6 +6,7 @@
#include <memory>
#include <hal/Interrupts.h>
#include <hal/Types.h>
#include <units/time.h>
@@ -56,8 +57,6 @@ class SynchronousInterrupt {
*/
explicit SynchronousInterrupt(std::shared_ptr<DigitalSource> source);
~SynchronousInterrupt();
SynchronousInterrupt(SynchronousInterrupt&&) = default;
SynchronousInterrupt& operator=(SynchronousInterrupt&&) = default;
@@ -108,6 +107,6 @@ class SynchronousInterrupt {
private:
void InitSynchronousInterrupt();
std::shared_ptr<DigitalSource> m_source;
hal::Handle<HAL_InterruptHandle> m_handle;
hal::Handle<HAL_InterruptHandle, HAL_CleanInterrupts> m_handle;
};
} // namespace frc

View File

@@ -9,6 +9,7 @@
#include <utility>
#include <vector>
#include <hal/Notifier.h>
#include <hal/Types.h>
#include <units/math.h>
#include <units/time.h>
@@ -50,11 +51,11 @@ class TimedRobot : public IterativeRobotBase {
*/
explicit TimedRobot(units::second_t period = kDefaultPeriod);
~TimedRobot() override;
TimedRobot(TimedRobot&&) = default;
TimedRobot& operator=(TimedRobot&&) = default;
~TimedRobot() override;
/**
* Add a callback to run at a specific period with a starting time offset.
*
@@ -100,7 +101,7 @@ class TimedRobot : public IterativeRobotBase {
}
};
hal::Handle<HAL_NotifierHandle> m_notifier;
hal::Handle<HAL_NotifierHandle, HAL_CleanNotifier> m_notifier;
std::chrono::microseconds m_startTime;
wpi::priority_queue<Callback, std::vector<Callback>, std::greater<Callback>>

View File

@@ -6,6 +6,7 @@
#include <memory>
#include <hal/Counter.h>
#include <hal/Types.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
@@ -43,11 +44,11 @@ class ExternalDirectionCounter
ExternalDirectionCounter(std::shared_ptr<DigitalSource> countSource,
std::shared_ptr<DigitalSource> directionSource);
~ExternalDirectionCounter() override;
ExternalDirectionCounter(ExternalDirectionCounter&&) = default;
ExternalDirectionCounter& operator=(ExternalDirectionCounter&&) = default;
~ExternalDirectionCounter() override = default;
/**
* Gets the current count.
*
@@ -78,7 +79,7 @@ class ExternalDirectionCounter
private:
std::shared_ptr<DigitalSource> m_countSource;
std::shared_ptr<DigitalSource> m_directionSource;
hal::Handle<HAL_CounterHandle> m_handle;
hal::Handle<HAL_CounterHandle, HAL_FreeCounter> m_handle;
int32_t m_index = 0;
};
} // namespace frc

View File

@@ -6,6 +6,7 @@
#include <memory>
#include <hal/Counter.h>
#include <hal/Types.h>
#include <units/angular_velocity.h>
#include <units/frequency.h>
@@ -42,11 +43,11 @@ class Tachometer : public wpi::Sendable,
*/
explicit Tachometer(std::shared_ptr<DigitalSource> source);
~Tachometer() override;
Tachometer(Tachometer&&) = default;
Tachometer& operator=(Tachometer&&) = default;
~Tachometer() override = default;
/**
* Gets the tachometer frequency.
*
@@ -133,7 +134,7 @@ class Tachometer : public wpi::Sendable,
private:
std::shared_ptr<DigitalSource> m_source;
hal::Handle<HAL_CounterHandle> m_handle;
hal::Handle<HAL_CounterHandle, HAL_FreeCounter> m_handle;
int m_edgesPerRevolution;
int32_t m_index;
};

View File

@@ -6,6 +6,7 @@
#include <memory>
#include <hal/Counter.h>
#include <hal/Types.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
@@ -41,11 +42,11 @@ class UpDownCounter : public wpi::Sendable,
UpDownCounter(std::shared_ptr<DigitalSource> upSource,
std::shared_ptr<DigitalSource> downSource);
~UpDownCounter() override;
UpDownCounter(UpDownCounter&&) = default;
UpDownCounter& operator=(UpDownCounter&&) = default;
~UpDownCounter() override = default;
/**
* Gets the current count.
*
@@ -84,7 +85,7 @@ class UpDownCounter : public wpi::Sendable,
void InitUpDownCounter();
std::shared_ptr<DigitalSource> m_upSource;
std::shared_ptr<DigitalSource> m_downSource;
hal::Handle<HAL_CounterHandle> m_handle;
hal::Handle<HAL_CounterHandle, HAL_FreeCounter> m_handle;
int32_t m_index = 0;
};
} // namespace frc