Skip to content

Commit

Permalink
convert all classes currently using hal::Handle
Browse files Browse the repository at this point in the history
  • Loading branch information
rzblue committed Aug 29, 2024
1 parent 895f6e1 commit 574c1ff
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 45 deletions.
7 changes: 0 additions & 7 deletions wpilibc/src/main/native/cpp/Relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 0 additions & 4 deletions wpilibc/src/main/native/cpp/SerialPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ SerialPort::SerialPort(int baudRate, std::string_view portName, Port port,
static_cast<uint8_t>(port) + 1);
}

SerialPort::~SerialPort() {
HAL_CloseSerial(m_portHandle);
}

void SerialPort::SetFlowControl(SerialPort::FlowControl flowControl) {
int32_t status = 0;
HAL_SetSerialFlowControl(m_portHandle, flowControl, &status);
Expand Down
4 changes: 0 additions & 4 deletions wpilibc/src/main/native/cpp/SynchronousInterrupt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions wpilibc/src/main/native/cpp/TimedRobot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ TimedRobot::~TimedRobot() {

HAL_StopNotifier(m_notifier, &status);
FRC_ReportError(status, "StopNotifier");

HAL_CleanNotifier(m_notifier);
}

void TimedRobot::AddPeriodic(std::function<void()> callback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ ExternalDirectionCounter::ExternalDirectionCounter(
wpi::SendableRegistry::AddLW(this, "External Direction Counter", m_index);
}

ExternalDirectionCounter::~ExternalDirectionCounter() {
HAL_FreeCounter(m_handle);
}

int ExternalDirectionCounter::GetCount() const {
int32_t status = 0;
int val = HAL_GetCounter(m_handle, &status);
Expand Down
4 changes: 0 additions & 4 deletions wpilibc/src/main/native/cpp/counter/Tachometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ Tachometer::Tachometer(std::shared_ptr<DigitalSource> source) {
wpi::SendableRegistry::AddLW(this, "Tachometer", m_index);
}

Tachometer::~Tachometer() {
HAL_FreeCounter(m_handle);
}

units::hertz_t Tachometer::GetFrequency() const {
auto period = GetPeriod();
if (period.value() == 0) {
Expand Down
11 changes: 6 additions & 5 deletions wpilibc/src/main/native/include/frc/Relay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -68,16 +69,16 @@ 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.
*
* The relay channels are set to free and the relay output is turned off.
*/
~Relay() override;

Relay(Relay&&) = default;
Relay& operator=(Relay&&) = default;

/**
* Set the relay state.
*
Expand Down Expand Up @@ -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
5 changes: 2 additions & 3 deletions wpilibc/src/main/native/include/frc/SerialPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string>
#include <string_view>

#include <hal/SerialPort.h>
#include <hal/Types.h>
#include <units/time.h>

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
5 changes: 2 additions & 3 deletions wpilibc/src/main/native/include/frc/SynchronousInterrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <memory>

#include <hal/Interrupts.h>
#include <hal/Types.h>
#include <units/time.h>

Expand Down Expand Up @@ -56,8 +57,6 @@ class SynchronousInterrupt {
*/
explicit SynchronousInterrupt(std::shared_ptr<DigitalSource> source);

~SynchronousInterrupt();

SynchronousInterrupt(SynchronousInterrupt&&) = default;
SynchronousInterrupt& operator=(SynchronousInterrupt&&) = default;

Expand Down Expand Up @@ -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
7 changes: 4 additions & 3 deletions wpilibc/src/main/native/include/frc/TimedRobot.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <utility>
#include <vector>

#include <hal/Notifier.h>
#include <hal/Types.h>
#include <units/math.h>
#include <units/time.h>
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <memory>

#include <hal/Counter.h>
#include <hal/Types.h>
#include <wpi/sendable/Sendable.h>
#include <wpi/sendable/SendableHelper.h>
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
7 changes: 4 additions & 3 deletions wpilibc/src/main/native/include/frc/counter/Tachometer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <memory>

#include <hal/Counter.h>
#include <hal/Types.h>
#include <units/angular_velocity.h>
#include <units/frequency.h>
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
};
Expand Down

0 comments on commit 574c1ff

Please sign in to comment.