Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   How do you get interrupt when digital input is set (http://www.chiefdelphi.com/forums/showthread.php?t=134323)

ericalbers 10-02-2015 20:42

How do you get interrupt when digital input is set
 
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.

Thanks

Ben Wolsieffer 10-02-2015 20:52

Re: How do you get interrupt when digital input is set
 
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.

Code:

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();


ericalbers 10-02-2015 20:55

Re: How do you get interrupt when digital input is set
 
Thanks, actually the private part is what was reallly killing me, I just could not get the thing to be happy I had the same code...

testinput =new DigitalInput(0);


testinput.requestInterrupts(new InterruptHandlerFunction<Object>()
{

@Override
public void interruptFired(int interruptAssertedMask, Object param)
{

}
});

I just couldn't get it to like the interruptFired no matter how I set it up...the base class having an error explains it though
Thanks

Ether 11-02-2015 17:06

Re: How do you get interrupt when digital input is set
 
Quote:

Originally Posted by ericalbers (Post 1441529)
Is there code showing how to get a interrupt when say a limit switch is hit?

How much code do you plan to put into the interrupt routine?




All times are GMT -5. The time now is 10:52.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi