Package edu.wpi.first.wpilibj
Class SynchronousInterrupt
java.lang.Object
edu.wpi.first.wpilibj.SynchronousInterrupt
- All Implemented Interfaces:
AutoCloseable
Class for handling synchronous (blocking) interrupts.
By default, interrupts will occur on rising edge.
Asynchronous interrupts are handled by the AsynchronousInterrupt class.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Event trigger combinations for a synchronous interrupt. -
Constructor Summary
ConstructorDescriptionSynchronousInterrupt
(DigitalSource source) Constructs a new synchronous interrupt using a DigitalSource. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the interrupt.double
Get the timestamp of the last falling edge.double
Get the timestamp of the last rising edge.void
setInterruptEdges
(boolean risingEdge, boolean fallingEdge) Set which edges to trigger the interrupt on.waitForInterrupt
(double timeoutSeconds) Wait for an interrupt, ignoring any previously occurring interrupts.waitForInterrupt
(double timeoutSeconds, boolean ignorePrevious) Wait for an interrupt.void
Force triggering of any waiting interrupt, which will be seen as a timeout.
-
Constructor Details
-
SynchronousInterrupt
Constructs a new synchronous interrupt using a DigitalSource.At construction, the interrupt will trigger on the rising edge.
- Parameters:
source
- The digital source to use.
-
-
Method Details
-
close
Closes the interrupt.This does not close the associated digital source.
- Specified by:
close
in interfaceAutoCloseable
-
waitForInterrupt
public SynchronousInterrupt.WaitResult waitForInterrupt(double timeoutSeconds, boolean ignorePrevious) Wait for an interrupt.- Parameters:
timeoutSeconds
- The timeout in seconds. 0 or less will return immediately.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.- Returns:
- Result of which edges were triggered, or if a timeout occurred.
-
waitForInterrupt
Wait for an interrupt, ignoring any previously occurring interrupts.- Parameters:
timeoutSeconds
- The timeout in seconds. 0 or less will return immediately.- Returns:
- Result of which edges were triggered, or if a timeout occurred.
-
setInterruptEdges
Set which edges to trigger the interrupt on.- Parameters:
risingEdge
- Trigger on rising edgefallingEdge
- Trigger on falling edge
-
getRisingTimestamp
Get the timestamp of the last rising edge.This only works if rising edge was configured using setInterruptEdges.
- Returns:
- the timestamp in seconds relative to getFPGATime
-
getFallingTimestamp
Get the timestamp of the last falling edge.This only works if falling edge was configured using setInterruptEdges.
- Returns:
- the timestamp in seconds relative to getFPGATime
-
wakeupWaitingInterrupt
Force triggering of any waiting interrupt, which will be seen as a timeout.
-