[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

@@ -130,8 +130,6 @@ public class TimedRobot extends IterativeRobotBase {
System.out.println("********** Robot program startup complete **********");
DriverStationJNI.observeUserProgramStarting();
boolean 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
@@ -139,12 +137,7 @@ public class TimedRobot extends IterativeRobotBase {
// at the end of the loop.
var callback = m_callbacks.poll();
if (first) {
first = false;
NotifierJNI.setNotifierAlarm(m_notifier, callback.expirationTime, 0, true);
} else {
NotifierJNI.acknowledgeNotifierAlarm(m_notifier, true, callback.expirationTime, 0, true);
}
NotifierJNI.setNotifierAlarm(m_notifier, callback.expirationTime, 0, true, true);
try {
WPIUtilJNI.waitForObject(m_notifier);

View File

@@ -95,7 +95,7 @@ public class Notifier implements AutoCloseable {
}
// Acknowledge the alarm
NotifierJNI.acknowledgeNotifierAlarm(notifier, false, 0, 0, false);
NotifierJNI.acknowledgeNotifierAlarm(notifier);
}
});
m_thread.setName("Notifier");
@@ -148,7 +148,7 @@ public class Notifier implements AutoCloseable {
* @param delay Time in seconds to wait before the callback is called.
*/
public void startSingle(double delay) {
NotifierJNI.setNotifierAlarm(m_notifier.get(), (long) (delay * 1e6), 0, false);
NotifierJNI.setNotifierAlarm(m_notifier.get(), (long) (delay * 1e6), 0, false, false);
}
/**
@@ -171,7 +171,7 @@ public class Notifier implements AutoCloseable {
*/
public void startPeriodic(double period) {
long periodMicroS = (long) (period * 1e6);
NotifierJNI.setNotifierAlarm(m_notifier.get(), periodMicroS, periodMicroS, false);
NotifierJNI.setNotifierAlarm(m_notifier.get(), periodMicroS, periodMicroS, false, false);
}
/**
@@ -205,12 +205,9 @@ public class Notifier implements AutoCloseable {
*
* <p>No further periodic callbacks will occur. Single invocations will also be cancelled if they
* haven't yet occurred.
*
* <p>If a callback invocation is in progress, this function will block until the callback is
* complete.
*/
public void stop() {
NotifierJNI.cancelNotifierAlarm(m_notifier.get());
NotifierJNI.cancelNotifierAlarm(m_notifier.get(), false);
}
/**

View File

@@ -225,13 +225,10 @@ public class Watchdog implements Closeable, Comparable<Watchdog> {
@SuppressWarnings("resource")
private static void updateAlarm(boolean acknowledge) {
if (m_watchdogs.isEmpty()) {
NotifierJNI.cancelNotifierAlarm(m_notifier);
} else if (acknowledge) {
NotifierJNI.acknowledgeNotifierAlarm(
m_notifier, true, (long) (m_watchdogs.peek().m_expirationTime * 1e6), 0, true);
NotifierJNI.cancelNotifierAlarm(m_notifier, acknowledge);
} else {
NotifierJNI.setNotifierAlarm(
m_notifier, (long) (m_watchdogs.peek().m_expirationTime * 1e6), 0, true);
m_notifier, (long) (m_watchdogs.peek().m_expirationTime * 1e6), 0, true, acknowledge);
}
}