mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[wpilibj] Fix AsynchronousInterrupt (#6564)
This commit is contained in:
@@ -6,6 +6,7 @@ package edu.wpi.first.wpilibj;
|
||||
|
||||
import static edu.wpi.first.util.ErrorMessages.requireNonNullParam;
|
||||
|
||||
import edu.wpi.first.wpilibj.SynchronousInterrupt.WaitResult;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@@ -127,14 +128,32 @@ public class AsynchronousInterrupt implements AutoCloseable {
|
||||
|
||||
private void threadMain() {
|
||||
while (m_keepRunning.get()) {
|
||||
var result = m_interrupt.waitForInterruptRaw(10, false);
|
||||
var result = m_interrupt.waitForInterrupt(10, false);
|
||||
if (!m_keepRunning.get()) {
|
||||
break;
|
||||
}
|
||||
if (result == 0) {
|
||||
if (result == WaitResult.kTimeout) {
|
||||
continue;
|
||||
}
|
||||
m_callback.accept((result & 0x1) != 0, (result & 0x100) != 0);
|
||||
|
||||
boolean rising = false;
|
||||
boolean falling = false;
|
||||
switch (result) {
|
||||
case kBoth:
|
||||
rising = true;
|
||||
falling = true;
|
||||
break;
|
||||
case kFallingEdge:
|
||||
falling = true;
|
||||
break;
|
||||
case kRisingEdge:
|
||||
rising = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
m_callback.accept(rising, falling);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,21 +84,6 @@ public class SynchronousInterrupt implements AutoCloseable {
|
||||
InterruptJNI.cleanInterrupts(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for interrupt that returns the raw result value from the hardware.
|
||||
*
|
||||
* <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 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
|
||||
*/
|
||||
long waitForInterruptRaw(double timeoutSeconds, boolean ignorePrevious) {
|
||||
return InterruptJNI.waitForInterrupt(m_handle, timeoutSeconds, ignorePrevious);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for an interrupt.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user