mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[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:
@@ -25,8 +25,6 @@ void TimedRobot::StartCompetition() {
|
||||
std::puts("\n********** Robot program startup complete **********");
|
||||
HAL_ObserveUserProgramStarting();
|
||||
|
||||
bool first = true;
|
||||
|
||||
// Loop forever, calling the appropriate mode-dependent function
|
||||
while (true) {
|
||||
// We don't have to check there's an element in the queue first because
|
||||
@@ -35,16 +33,9 @@ void TimedRobot::StartCompetition() {
|
||||
auto callback = m_callbacks.pop();
|
||||
|
||||
int32_t status = 0;
|
||||
if (first) {
|
||||
first = false;
|
||||
HAL_SetNotifierAlarm(m_notifier, callback.expirationTime.count(), 0, true,
|
||||
&status);
|
||||
WPILIB_CheckErrorStatus(status, "SetNotifierAlarm");
|
||||
} else {
|
||||
HAL_AcknowledgeNotifierAlarm(
|
||||
m_notifier, true, callback.expirationTime.count(), 0, true, &status);
|
||||
WPILIB_CheckErrorStatus(status, "AcknowledgeNotifierAlarm");
|
||||
}
|
||||
HAL_SetNotifierAlarm(m_notifier, callback.expirationTime.count(), 0, true,
|
||||
true, &status);
|
||||
WPILIB_CheckErrorStatus(status, "SetNotifierAlarm");
|
||||
|
||||
if (WPI_WaitForObject(m_notifier) == 0) {
|
||||
break;
|
||||
|
||||
@@ -46,7 +46,7 @@ Notifier::Notifier(std::function<void()> callback) {
|
||||
}
|
||||
|
||||
// Ack notifier
|
||||
HAL_AcknowledgeNotifierAlarm(notifier, false, 0, 0, false, &status);
|
||||
HAL_AcknowledgeNotifierAlarm(notifier, &status);
|
||||
WPILIB_CheckErrorStatus(status, "AcknowledgeNotifier");
|
||||
}
|
||||
});
|
||||
@@ -99,7 +99,7 @@ Notifier::Notifier(int priority, std::function<void()> callback) {
|
||||
}
|
||||
|
||||
// Ack notifier
|
||||
HAL_AcknowledgeNotifierAlarm(notifier, false, 0, 0, false, &status);
|
||||
HAL_AcknowledgeNotifierAlarm(notifier, &status);
|
||||
WPILIB_CheckErrorStatus(status, "AcknowledgeNotifier");
|
||||
}
|
||||
});
|
||||
@@ -144,13 +144,14 @@ void Notifier::SetCallback(std::function<void()> callback) {
|
||||
void Notifier::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);
|
||||
}
|
||||
|
||||
void Notifier::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);
|
||||
}
|
||||
|
||||
void Notifier::StartPeriodic(wpi::units::hertz_t frequency) {
|
||||
@@ -159,7 +160,7 @@ void Notifier::StartPeriodic(wpi::units::hertz_t frequency) {
|
||||
|
||||
void Notifier::Stop() {
|
||||
int32_t status = 0;
|
||||
HAL_CancelNotifierAlarm(m_notifier, &status);
|
||||
HAL_CancelNotifierAlarm(m_notifier, false, &status);
|
||||
WPILIB_CheckErrorStatus(status, "CancelNotifierAlarm");
|
||||
}
|
||||
|
||||
|
||||
@@ -75,18 +75,12 @@ void Watchdog::Impl::UpdateAlarm(bool acknowledge) {
|
||||
return;
|
||||
}
|
||||
if (m_watchdogs.empty()) {
|
||||
HAL_CancelNotifierAlarm(notifier, &status);
|
||||
} else if (acknowledge) {
|
||||
HAL_AcknowledgeNotifierAlarm(
|
||||
notifier, true,
|
||||
static_cast<uint64_t>(m_watchdogs.top()->m_expirationTime.value() *
|
||||
1e6),
|
||||
0, true, &status);
|
||||
HAL_CancelNotifierAlarm(notifier, acknowledge, &status);
|
||||
} else {
|
||||
HAL_SetNotifierAlarm(notifier,
|
||||
static_cast<uint64_t>(
|
||||
m_watchdogs.top()->m_expirationTime.value() * 1e6),
|
||||
0, true, &status);
|
||||
0, true, acknowledge, &status);
|
||||
}
|
||||
WPILIB_CheckErrorStatus(status, "updating watchdog notifier alarm");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user