[hal] Notifier: simplify ack API (#8457)

Adding an ack parameter to both set and cancel is cleaner than adding
all the set alarm parameters to the ack function. It also provides an
ack-and-cancel method.
This commit is contained in:
Peter Johnson
2025-12-09 20:28:15 -07:00
committed by GitHub
parent 936be71a7d
commit 06a9a055b3
12 changed files with 111 additions and 177 deletions

View File

@@ -71,7 +71,7 @@ PyNotifier::PyNotifier(std::function<void()> handler) {
}
// Ack notifier
HAL_AcknowledgeNotifierAlarm(notifier, false, 0, 0, false, &status);
HAL_AcknowledgeNotifierAlarm(notifier, &status);
WPILIB_CheckErrorStatus(status, "AcknowledgeNotifier");
}
} catch (...) {
@@ -120,6 +120,7 @@ PyNotifier &PyNotifier::operator=(PyNotifier &&rhs) {
void PyNotifier::SetName(std::string_view name) {
int32_t status = 0;
HAL_SetNotifierName(m_notifier, name, &status);
WPILIB_CheckErrorStatus(status, "SetNotifierName");
}
void PyNotifier::SetCallback(std::function<void()> handler) {
@@ -130,18 +131,21 @@ void PyNotifier::SetCallback(std::function<void()> handler) {
void PyNotifier::StartSingle(wpi::units::second_t delay) {
int32_t status = 0;
HAL_SetNotifierAlarm(m_notifier, static_cast<uint64_t>(delay * 1e6), 0, false,
&status);
false, &status);
WPILIB_CheckErrorStatus(status, "SetNotifierAlarm");
}
void PyNotifier::StartPeriodic(wpi::units::second_t period) {
int32_t status = 0;
HAL_SetNotifierAlarm(m_notifier, static_cast<uint64_t>(period * 1e6),
static_cast<uint64_t>(period * 1e6), false, &status);
static_cast<uint64_t>(period * 1e6), false, false,
&status);
WPILIB_CheckErrorStatus(status, "SetNotifierAlarm");
}
void PyNotifier::Stop() {
int32_t status = 0;
HAL_CancelNotifierAlarm(m_notifier, &status);
HAL_CancelNotifierAlarm(m_notifier, false, &status);
WPILIB_CheckErrorStatus(status, "CancelNotifierAlarm");
}