Is there code showing how to get a interrupt when say a limit switch is hit?
I see the
public abstract class InterruptHandlerFunction<T>
is there example code of how to implement this for the requestInterrupts off DigitalInputs?
I’m having trouble with how to define the polymorphism of the function properly.
This is how I used interrupt handlers in a gyro driver. The really wierd part about it is that the interruptFired() method is package private, so any class that uses it needs to be in the edu.wpi.first.wpilibj package. I think this was an oversight on the part of the authors of WPILib.
DigitalInput interrupt = new DigitalInput(0);
// Register an interrupt handler
interrupt.requestInterrupts(new InterruptHandlerFunction<Object>() {
@Override
public void interruptFired(int interruptAssertedMask, Object param) {
// Do stuff
}
});
// Listen for a falling edge
interrupt.setUpSourceEdge(false, true);
// Enable digital interrupt pin
interrupt.enableInterrupts();