type tInterruptHandler doesn't seem to exist

Hello,

I’m trying to implement the following behavior on my team’s bot:
We have a forklift. This forklift has two limit switches at the top and bottom of the track. We would like to stop the forklift motor and reset/re-calibrate the class we’re using to handle the encoder attached to the motor as well whenever one of these limit switches are tripped.

To handle all of the Forklift stuff, I’ve created a Forklift class, which has the limit switches as members in the form of DigitalInputs. In order to get the behavior described above to occur within the Forklift class, I’m trying to use something similar to the Java Observer Pattern. It looks like the way to do this with the WPI lib is to use DigitalInput.requestInterrupts(Object handler, Object param). The documentation for this method states that the handler Object should be:
“The address of the interrupt handler function of type tInterruptHandler that will be called whenever there is an interrupt on the digitial input port. Request interrupts in synchronus mode where the user program interrupt handler will be called when an interrupt occurs. The default is interrupt on rising edges only.”

However, I cannot find the type tInterruptHandler anywhere in the API or the documentation.

My questions are:

  1. Has anyone here been successful at implementing this type of behavior inside of a class other than IterativeRobot, using interrupts or otherwise?
  2. If not, what is the proper way to use DigitalInput.requestInterrupts(handler, param) so that I can make it do what I want it to?

My background is in Android programming, so I am very comfortable with the pattern adding change listeners to objects, then implementing an abstract method within those change listeners in order to receive callbacks when a change occurs. I figured it would be similar with the WPI interrupts, except that I haven’t been able to figure it out because of the missing tInterruptHandler.

Thanks!

Anyone? I’m drawing a blank here.

Even if you don’t have the answer, if you have contact info for someone at WPI who you think might be able to help, it would be awesome if you could PM that to me.

The “callback” version of requestInterrupts() was not fully implemented, but you should be able to use the synchronous version of requestInterrupts().

You can then have your interrupt handling code in a loop that first calls waitForInterrupt(). Roughly:

digIn.requestInterrupts();
while (true) { // or some condition 
	digIn.waitForInterrupt(300.0);

	// ...do your interrupt handling code...

}
digIn.cancelInterrupts();

That loop can be pushed off to another Java thread.