[wpilib] Improve interrupt docs (NFC) (#3679)

This commit is contained in:
sciencewhiz
2021-10-26 23:35:01 -07:00
committed by GitHub
parent 558151061e
commit d1842ea8fb
4 changed files with 62 additions and 26 deletions

View File

@@ -10,7 +10,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BiConsumer;
/**
* Class for handling asynchrounous interrupts.
* Class for handling asynchronous interrupts using a callback thread.
*
* <p>By default, interrupts will occur on rising edge. Callbacks are disabled by default, and
* enable() must be called before they will occur.
@@ -18,7 +18,7 @@ import java.util.function.BiConsumer;
* <p>Both rising and falling edges can be indicated in one callback if both a rising and falling
* edge occurred since the previous callback.
*
* <p>Synchronous interrupts are handled by the SynchronousInterrupt class.
* <p>Synchronous (blocking) interrupts are handled by the SynchronousInterrupt class.
*/
public class AsynchronousInterrupt implements AutoCloseable {
private final BiConsumer<Boolean, Boolean> m_callback;
@@ -34,6 +34,9 @@ public class AsynchronousInterrupt implements AutoCloseable {
*
* <p>Callbacks will not be triggered until enable() is called.
*
* <p>The first bool in the callback indicates the rising edge triggered the interrupt, the second
* bool is falling edge.
*
* @param source The digital source to use.
* @param callback The callback to call on an interrupt
*/

View File

@@ -9,7 +9,7 @@ import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
import edu.wpi.first.hal.InterruptJNI;
/**
* Class for handling sychronous interrupts.
* Class for handling synchronous (blocking) interrupts.
*
* <p>By default, interrupts will occur on rising edge.
*
@@ -36,11 +36,11 @@ public class SynchronousInterrupt implements AutoCloseable {
}
/**
* Create a wait result.
* Create a wait result enum.
*
* @param rising True if a rising edge occured.
* @param falling True if a falling edge occured.
* @return A wait result.
* @param rising True if a rising edge occurred.
* @param falling True if a falling edge occurred.
* @return A wait result enum.
*/
public static WaitResult getValue(boolean rising, boolean falling) {
if (rising && falling) {
@@ -83,11 +83,11 @@ public class SynchronousInterrupt implements AutoCloseable {
/**
* Wait for interrupt that returns the raw result value from the hardware.
*
* <p>Used by AsynchronousInterrupt. Users prefer to use waitForInterrupt.
* <p>Used by AsynchronousInterrupt. Users should use waitForInterrupt.
*
* @param timeoutSeconds The timeout in seconds. 0 or less will return immediately.
* @param ignorePrevious True to ignore if a previous interrupt has occured, and only wait for a
* new trigger. False will consider if an interrupt has occured since the last time the
* @param ignorePrevious True to ignore if a previous interrupt has occurred, and only wait for a
* new trigger. False will consider if an interrupt has occurred since the last time the
* interrupt was read.
* @return The raw hardware interrupt result
*/
@@ -99,10 +99,10 @@ public class SynchronousInterrupt implements AutoCloseable {
* Wait for an interrupt.
*
* @param timeoutSeconds The timeout in seconds. 0 or less will return immediately.
* @param ignorePrevious True to ignore if a previous interrupt has occured, and only wait for a
* new trigger. False will consider if an interrupt has occured since the last time the
* @param ignorePrevious True to ignore if a previous interrupt has occurred, and only wait for a
* new trigger. False will consider if an interrupt has occurred since the last time the
* interrupt was read.
* @return Result of which edges were triggered, or if an timeout occured.
* @return Result of which edges were triggered, or if an timeout occurred.
*/
public WaitResult waitForInterrupt(double timeoutSeconds, boolean ignorePrevious) {
int result = InterruptJNI.waitForInterrupt(m_handle, timeoutSeconds, ignorePrevious);
@@ -117,10 +117,10 @@ public class SynchronousInterrupt implements AutoCloseable {
}
/**
* Wait for an interrupt, ingoring any previously occuring interrupts.
* Wait for an interrupt, ignoring any previously occurring interrupts.
*
* @param timeoutSeconds The timeout in seconds. 0 or less will return immediately.
* @return Result of which edges were triggered, or if an timeout occured.
* @return Result of which edges were triggered, or if an timeout occurred.
*/
public WaitResult waitForInterrupt(double timeoutSeconds) {
return waitForInterrupt(timeoutSeconds, true);