[wpilibj] Fix AsynchronousInterrupt (#6564)

This commit is contained in:
Thad House
2024-04-29 21:04:24 -07:00
committed by GitHub
parent 9cae707065
commit eec99eb653
2 changed files with 22 additions and 18 deletions

View File

@@ -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);
}
}
}

View File

@@ -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.
*