mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
Moves Interrupts over to Handles instead of pointers (#99)
This commit is contained in:
committed by
Peter Johnson
parent
74fc10999b
commit
046e043c4e
@@ -9,7 +9,7 @@ package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.InterruptJNI;
|
||||
import edu.wpi.first.wpilibj.util.AllocationException;
|
||||
import edu.wpi.first.wpilibj.util.CheckedAllocationException;
|
||||
|
||||
|
||||
/**
|
||||
* Base for sensors to be used with interrupts.
|
||||
@@ -42,22 +42,13 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
/**
|
||||
* The interrupt resource.
|
||||
*/
|
||||
protected long m_interrupt = 0;
|
||||
protected int m_interrupt = InterruptJNI.HalInvalidHandle;
|
||||
|
||||
/**
|
||||
* Flags if the interrupt being allocated is synchronous.
|
||||
*/
|
||||
protected boolean m_isSynchronousInterrupt = false;
|
||||
|
||||
/**
|
||||
* The index of the interrupt.
|
||||
*/
|
||||
protected int m_interruptIndex;
|
||||
/**
|
||||
* Resource manager.
|
||||
*/
|
||||
protected static Resource m_interrupts = new Resource(8);
|
||||
|
||||
/**
|
||||
* Create a new InterrupatableSensorBase.
|
||||
*/
|
||||
@@ -138,15 +129,9 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
* have to explicitly wait for the interrupt to occur.
|
||||
*/
|
||||
protected void allocateInterrupts(boolean watcher) {
|
||||
try {
|
||||
m_interruptIndex = m_interrupts.allocate();
|
||||
} catch (CheckedAllocationException ex) {
|
||||
throw new AllocationException("No interrupts are left to be allocated");
|
||||
}
|
||||
m_isSynchronousInterrupt = watcher;
|
||||
|
||||
m_interrupt =
|
||||
InterruptJNI.initializeInterrupts(m_interruptIndex, watcher);
|
||||
|
||||
m_interrupt = InterruptJNI.initializeInterrupts(watcher);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,7 +144,6 @@ public abstract class InterruptableSensorBase extends SensorBase {
|
||||
}
|
||||
InterruptJNI.cleanInterrupts(m_interrupt);
|
||||
m_interrupt = 0;
|
||||
m_interrupts.free(m_interruptIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,32 +8,34 @@
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
public class InterruptJNI extends JNIWrapper {
|
||||
public static final int HalInvalidHandle = 0;
|
||||
|
||||
public interface InterruptJNIHandlerFunction {
|
||||
void apply(int interruptAssertedMask, Object param);
|
||||
}
|
||||
|
||||
public static native long initializeInterrupts(int interruptIndex, boolean watcher);
|
||||
public static native int initializeInterrupts(boolean watcher);
|
||||
|
||||
public static native void cleanInterrupts(long interruptPointer);
|
||||
public static native void cleanInterrupts(int interruptHandle);
|
||||
|
||||
public static native int waitForInterrupt(long interruptPointer, double timeout,
|
||||
public static native int waitForInterrupt(int interruptHandle, double timeout,
|
||||
boolean ignorePrevious);
|
||||
|
||||
public static native void enableInterrupts(long interruptPointer);
|
||||
public static native void enableInterrupts(int interruptHandle);
|
||||
|
||||
public static native void disableInterrupts(long interruptPointer);
|
||||
public static native void disableInterrupts(int interruptHandle);
|
||||
|
||||
public static native double readRisingTimestamp(long interruptPointer);
|
||||
public static native double readRisingTimestamp(int interruptHandle);
|
||||
|
||||
public static native double readFallingTimestamp(long interruptPointer);
|
||||
public static native double readFallingTimestamp(int interruptHandle);
|
||||
|
||||
public static native void requestInterrupts(long interruptPointer, byte routingModule,
|
||||
public static native void requestInterrupts(int interruptHandle, byte routingModule,
|
||||
int routingPin, boolean routingAnalogTrigger);
|
||||
|
||||
public static native void attachInterruptHandler(long interruptPointer,
|
||||
public static native void attachInterruptHandler(int interruptHandle,
|
||||
InterruptJNIHandlerFunction handler,
|
||||
Object param);
|
||||
|
||||
public static native void setInterruptUpSourceEdge(long interruptPointer, boolean risingEdge,
|
||||
public static native void setInterruptUpSourceEdge(int interruptHandle, boolean risingEdge,
|
||||
boolean fallingEdge);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user