Just some ideas for the custom button & joystick event listener

This commit is contained in:
jancoow
2015-05-04 00:33:08 +02:00
parent 2c7c917d02
commit d8dbcc0719
7 changed files with 103 additions and 4 deletions
+16
View File
@@ -0,0 +1,16 @@
package control;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.Pin;
public class Button {
private GpioPinDigitalInput input;
public Button(int buttonId, Pin pin){
input = GpioFactory.getInstance().provisionDigitalInputPin(pin , "Button:"+buttonId);
}
public boolean getState(){
return input.getState().isLow();
}
}
+28
View File
@@ -0,0 +1,28 @@
package control;
public class ButtonEvent {
private Button button;
private Long now;
public ButtonEvent(Button button, Long now){
this.button = button;
this.now = now;
}
/**
* @return the button
*/
public Button getButton() {
return button;
}
/**
* @return the time when event was triggered
*/
public Long getNow() {
return now;
}
}
+21
View File
@@ -0,0 +1,21 @@
package control;
import java.util.EventListener;
public interface ButtonsListener extends EventListener {
/**
* Invoked when a button has been pressed.
*/
public void buttonPressed(ButtonEvent e);
/**
* Invoked when a button has been released.
*/
public void buttonReleased(ButtonEvent e);
/**
* Invoked when a button is held down.
*/
public void buttonHeld(ButtonEvent e);
}
+3
View File
@@ -1,5 +1,8 @@
package control;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyListener;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalInput;
+10
View File
@@ -0,0 +1,10 @@
package control;
import java.util.EventListener;
public interface JoystickListener extends EventListener {
/**
* Invoked when the joystick has been moved.
*/
public void joystickMoved(Joystickevent e);
}
+5
View File
@@ -0,0 +1,5 @@
package control;
public class Joystickevent {
}