work in progress for 0.12 before large renaming of events
git-svn-id: http://wiiusej.googlecode.com/svn/trunk@132 ae48ae66-6a45-0410-b38e-211266189506
This commit is contained in:
@@ -516,7 +516,7 @@ public class WiiUseApiManager extends Thread {
|
||||
* Notify WiiUseApiListeners that an event occured.
|
||||
*
|
||||
* @param evt
|
||||
* WiimoteEvent occured
|
||||
* GenericEvent occured
|
||||
*/
|
||||
private void notifyWiiUseApiListener(WiiUseApiEvent evt) {
|
||||
for (WiiUseApiListener listener : getWiiUseApiListeners()) {
|
||||
|
||||
@@ -19,7 +19,7 @@ package wiiusej;
|
||||
import javax.swing.event.EventListenerList;
|
||||
|
||||
import wiiusej.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiuseapievents.GenericEvent;
|
||||
import wiiusej.wiiuseapievents.WiimoteEvent;
|
||||
import wiiusej.wiiuseapievents.StatusEvent;
|
||||
import wiiusej.wiiuseapievents.WiiUseApiEvent;
|
||||
import wiiusej.wiiuseapievents.WiiUseApiListener;
|
||||
@@ -265,7 +265,7 @@ public class Wiimote implements WiiUseApiListener {
|
||||
public void onWiiUseApiEvent(WiiUseApiEvent e) {
|
||||
if (e.getWiimoteId() == id) {
|
||||
if (e.getEventType() == WiiUseApiEvent.GENERIC_EVENT) {
|
||||
notifyWiiMoteEventListeners((GenericEvent) e);
|
||||
notifyWiiMoteEventListeners((WiimoteEvent) e);
|
||||
} else if (e.getEventType() == WiiUseApiEvent.STATUS_EVENT
|
||||
|| e.getEventType() == WiiUseApiEvent.WIIUSE_NUNCHUK_INSERTED
|
||||
|| e.getEventType() == WiiUseApiEvent.WIIUSE_NUNCHUK_REMOVED
|
||||
@@ -315,9 +315,9 @@ public class Wiimote implements WiiUseApiListener {
|
||||
* third the listeners for Motion sensing events.
|
||||
*
|
||||
* @param evt
|
||||
* WiimoteEvent occured
|
||||
* GenericEvent occured
|
||||
*/
|
||||
private void notifyWiiMoteEventListeners(GenericEvent evt) {
|
||||
private void notifyWiiMoteEventListeners(WiimoteEvent evt) {
|
||||
for (WiimoteListener listener : getWiiMoteEventListeners()) {
|
||||
listener.onButtonsEvent(evt.getButtonsEvent());
|
||||
if (evt.isThereIrEvent()) {
|
||||
|
||||
@@ -23,12 +23,11 @@ import java.awt.event.InputEvent;
|
||||
import wiiusej.WiiUseApiManager;
|
||||
import wiiusej.Wiimote;
|
||||
import wiiusej.values.IRSource;
|
||||
import wiiusej.wiiuseapievents.ButtonsEvent;
|
||||
import wiiusej.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiuseapievents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiuseapievents.IREvent;
|
||||
import wiiusej.wiiuseapievents.MotionSensingEvent;
|
||||
import wiiusej.wiiuseapievents.StatusEvent;
|
||||
import wiiusej.wiiuseapievents.GenericEvent;
|
||||
import wiiusej.wiiuseapievents.WiimoteListener;
|
||||
|
||||
/**
|
||||
@@ -61,7 +60,7 @@ public class Tests implements WiimoteListener {
|
||||
|
||||
private static int nb = 0;
|
||||
|
||||
public void onButtonsEvent(ButtonsEvent e) {
|
||||
public void onButtonsEvent(WiimoteButtonsEvent e) {
|
||||
if (dump == DISPLAY_EACH_VALUE) {
|
||||
// System.out.println("*********** WIIMOTE ID : "+
|
||||
// e.getWiimoteId() + " **************");
|
||||
|
||||
@@ -21,14 +21,15 @@ import java.awt.Robot;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import wiiusej.utils.IRPanel;
|
||||
|
||||
import wiiusej.Wiimote;
|
||||
import wiiusej.utils.AccelerationPanel;
|
||||
import wiiusej.utils.GForcePanel;
|
||||
import wiiusej.utils.ButtonsEventPanel;
|
||||
import wiiusej.utils.GForcePanel;
|
||||
import wiiusej.utils.IRPanel;
|
||||
import wiiusej.utils.OrientationPanel;
|
||||
import wiiusej.wiiuseapievents.ButtonsEvent;
|
||||
import wiiusej.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiuseapievents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiuseapievents.IREvent;
|
||||
import wiiusej.wiiuseapievents.MotionSensingEvent;
|
||||
import wiiusej.wiiuseapievents.StatusEvent;
|
||||
@@ -63,7 +64,7 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements WiimoteListene
|
||||
this.addWindowListener(new CloseGuiTestCleanly(wiimote));
|
||||
}
|
||||
|
||||
public void onButtonsEvent(ButtonsEvent arg0) {
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
if (robot != null) {
|
||||
if (arg0.isButtonAPressed()) {
|
||||
robot.mousePress(InputEvent.BUTTON1_MASK);
|
||||
|
||||
@@ -24,9 +24,10 @@ import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import wiiusej.values.RawAcceleration;
|
||||
import wiiusej.wiiuseapievents.ButtonsEvent;
|
||||
import wiiusej.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiuseapievents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiuseapievents.IREvent;
|
||||
import wiiusej.wiiuseapievents.MotionSensingEvent;
|
||||
import wiiusej.wiiuseapievents.StatusEvent;
|
||||
@@ -129,7 +130,7 @@ public class AccelerationPanel extends javax.swing.JPanel implements WiimoteList
|
||||
}
|
||||
}
|
||||
|
||||
public void onButtonsEvent(ButtonsEvent arg0) {
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
//nothing
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,10 @@ import java.awt.RenderingHints;
|
||||
import java.awt.Shape;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.geom.AffineTransform;
|
||||
|
||||
import wiiusej.wiiuseapievents.ButtonsEvent;
|
||||
import wiiusej.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiuseapievents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiuseapievents.IREvent;
|
||||
import wiiusej.wiiuseapievents.MotionSensingEvent;
|
||||
import wiiusej.wiiuseapievents.StatusEvent;
|
||||
@@ -41,7 +43,7 @@ public class ButtonsEventPanel extends javax.swing.JPanel implements WiimoteList
|
||||
|
||||
private Image mImage;//image for double buffering
|
||||
private Image wiimoteImage;//image for double buffering
|
||||
private ButtonsEvent buttons;
|
||||
private WiimoteButtonsEvent buttons;
|
||||
private Color pressedColor = Color.RED;
|
||||
private Color heldColor = Color.ORANGE;
|
||||
private Color releasedColor = Color.YELLOW;
|
||||
@@ -250,7 +252,7 @@ public class ButtonsEventPanel extends javax.swing.JPanel implements WiimoteList
|
||||
}
|
||||
}
|
||||
|
||||
public void onButtonsEvent(ButtonsEvent arg0) {
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
setSize(wiimoteImage.getWidth(this), wiimoteImage.getHeight(this));
|
||||
buttons = arg0;
|
||||
repaint();
|
||||
|
||||
@@ -24,9 +24,10 @@ import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import wiiusej.values.GForce;
|
||||
import wiiusej.wiiuseapievents.ButtonsEvent;
|
||||
import wiiusej.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiuseapievents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiuseapievents.IREvent;
|
||||
import wiiusej.wiiuseapievents.MotionSensingEvent;
|
||||
import wiiusej.wiiuseapievents.StatusEvent;
|
||||
@@ -149,7 +150,7 @@ public class GForcePanel extends javax.swing.JPanel implements WiimoteListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void onButtonsEvent(ButtonsEvent arg0) {
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
//nothing
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,9 @@ import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import wiiusej.wiiuseapievents.ButtonsEvent;
|
||||
|
||||
import wiiusej.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiuseapievents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiuseapievents.IREvent;
|
||||
import wiiusej.wiiuseapievents.MotionSensingEvent;
|
||||
import wiiusej.wiiuseapievents.StatusEvent;
|
||||
@@ -129,7 +130,7 @@ public class IRPanel extends javax.swing.JPanel implements WiimoteListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void onButtonsEvent(ButtonsEvent arg0) {
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
//nothing
|
||||
repaint();
|
||||
}
|
||||
|
||||
@@ -24,9 +24,10 @@ import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import wiiusej.values.Orientation;
|
||||
import wiiusej.wiiuseapievents.ButtonsEvent;
|
||||
import wiiusej.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiuseapievents.WiimoteButtonsEvent;
|
||||
import wiiusej.wiiuseapievents.IREvent;
|
||||
import wiiusej.wiiuseapievents.MotionSensingEvent;
|
||||
import wiiusej.wiiuseapievents.StatusEvent;
|
||||
@@ -153,7 +154,7 @@ public class OrientationPanel extends javax.swing.JPanel implements WiimoteListe
|
||||
}
|
||||
}
|
||||
|
||||
public void onButtonsEvent(ButtonsEvent arg0) {
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
//nothing
|
||||
}
|
||||
|
||||
|
||||
@@ -20,27 +20,8 @@ package wiiusej.wiiuseapievents;
|
||||
* Class which represents a buttons event.
|
||||
* @author guiguito
|
||||
*/
|
||||
public class ButtonsEvent extends WiimoteEvent{
|
||||
|
||||
/* Buttons MACRO */
|
||||
private static short WIIMOTE_BUTTON_TWO = 0x0001;
|
||||
private static short WIIMOTE_BUTTON_ONE = 0x0002;
|
||||
private static short WIIMOTE_BUTTON_B = 0x0004;
|
||||
private static short WIIMOTE_BUTTON_A = 0x0008;
|
||||
private static short WIIMOTE_BUTTON_MINUS = 0x0010;
|
||||
private static short WIIMOTE_BUTTON_ZACCEL_BIT6 = 0x0020;
|
||||
private static short WIIMOTE_BUTTON_ZACCEL_BIT7 = 0x0040;
|
||||
private static short WIIMOTE_BUTTON_HOME = 0x0080;
|
||||
private static short WIIMOTE_BUTTON_LEFT = 0x0100;
|
||||
private static short WIIMOTE_BUTTON_RIGHT = 0x0200;
|
||||
private static short WIIMOTE_BUTTON_DOWN = 0x0400;
|
||||
private static short WIIMOTE_BUTTON_UP = 0x0800;
|
||||
private static short WIIMOTE_BUTTON_PLUS = 0x1000;
|
||||
private static short WIIMOTE_BUTTON_ZACCEL_BIT4 = 0x2000;
|
||||
private static short WIIMOTE_BUTTON_ZACCEL_BIT5 = 0x4000;
|
||||
private static int WIIMOTE_BUTTON_UNKNOWN = 0x8000;
|
||||
private static short WIIMOTE_BUTTON_ALL = 0x1F9F;
|
||||
|
||||
public abstract class ButtonsEvent extends GenericEvent{
|
||||
|
||||
/* Buttons */
|
||||
private short buttonsJustPressed = 0;
|
||||
private short buttonsJustReleased = 0;
|
||||
@@ -103,223 +84,26 @@ public class ButtonsEvent extends WiimoteEvent{
|
||||
/** **************** BUTTONS Methods ***************** */
|
||||
/* generic button functions */
|
||||
|
||||
private boolean buttonTest(short buttonBitsDefinition, short buttons) {
|
||||
protected boolean buttonTest(short buttonBitsDefinition, short buttons) {
|
||||
return (buttons & buttonBitsDefinition) == buttonBitsDefinition;
|
||||
}
|
||||
|
||||
private boolean isButtonJustPressed(short buttonBitsDefinition) {
|
||||
protected boolean isButtonJustPressed(short buttonBitsDefinition) {
|
||||
return buttonTest(buttonBitsDefinition, buttonsJustPressed)
|
||||
&& !isButtonHeld(buttonBitsDefinition);
|
||||
}
|
||||
|
||||
private boolean isButtonJustReleased(short buttonBitsDefinition) {
|
||||
protected boolean isButtonJustReleased(short buttonBitsDefinition) {
|
||||
return buttonTest(buttonBitsDefinition, buttonsJustReleased);
|
||||
}
|
||||
|
||||
private boolean isButtonHeld(short buttonBitsDefinition) {
|
||||
protected boolean isButtonHeld(short buttonBitsDefinition) {
|
||||
return buttonTest(buttonBitsDefinition, buttonsHeld);
|
||||
}
|
||||
|
||||
private boolean isButtonPressed(short buttonBitsDefinition) {
|
||||
protected boolean isButtonPressed(short buttonBitsDefinition) {
|
||||
return isButtonHeld(buttonBitsDefinition)||isButtonJustPressed(buttonBitsDefinition);
|
||||
}
|
||||
/* Button ONE */
|
||||
|
||||
public boolean isButtonOneJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_ONE);
|
||||
}
|
||||
|
||||
public boolean isButtonOneJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_ONE);
|
||||
}
|
||||
|
||||
public boolean isButtonOneHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_ONE);
|
||||
}
|
||||
|
||||
public boolean isButtonOnePressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_ONE);
|
||||
}
|
||||
|
||||
/* Button TWO */
|
||||
|
||||
public boolean isButtonTwoJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_TWO);
|
||||
}
|
||||
|
||||
public boolean isButtonTwoJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_TWO);
|
||||
}
|
||||
|
||||
public boolean isButtonTwoHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_TWO);
|
||||
}
|
||||
|
||||
public boolean isButtonTwoPressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_TWO);
|
||||
}
|
||||
|
||||
/* Button A */
|
||||
|
||||
public boolean isButtonAJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_A);
|
||||
}
|
||||
|
||||
public boolean isButtonAJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_A);
|
||||
}
|
||||
|
||||
public boolean isButtonAHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_A);
|
||||
}
|
||||
|
||||
public boolean isButtonAPressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_A);
|
||||
}
|
||||
|
||||
/* Button B */
|
||||
|
||||
public boolean isButtonBJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_B);
|
||||
}
|
||||
|
||||
public boolean isButtonBJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_B);
|
||||
}
|
||||
|
||||
public boolean isButtonBHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_B);
|
||||
}
|
||||
|
||||
public boolean isButtonBPressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_B);
|
||||
}
|
||||
|
||||
/* Button LEFT */
|
||||
|
||||
public boolean isButtonLeftJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_LEFT);
|
||||
}
|
||||
|
||||
public boolean isButtonLeftJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_LEFT);
|
||||
}
|
||||
|
||||
public boolean isButtonLeftHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_LEFT);
|
||||
}
|
||||
|
||||
public boolean isButtonLeftPressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_LEFT);
|
||||
}
|
||||
|
||||
/* Button RIGHT */
|
||||
|
||||
public boolean isButtonRightJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_RIGHT);
|
||||
}
|
||||
|
||||
public boolean isButtonRightJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_RIGHT);
|
||||
}
|
||||
|
||||
public boolean isButtonRightHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_RIGHT);
|
||||
}
|
||||
|
||||
public boolean isButtonRightPressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_RIGHT);
|
||||
}
|
||||
|
||||
/* Button UP */
|
||||
|
||||
public boolean isButtonUpJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_UP);
|
||||
}
|
||||
|
||||
public boolean isButtonUpJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_UP);
|
||||
}
|
||||
|
||||
public boolean isButtonUpHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_UP);
|
||||
}
|
||||
|
||||
public boolean isButtonUpPressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_UP);
|
||||
}
|
||||
|
||||
/* Button DOWN */
|
||||
|
||||
public boolean isButtonDownJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_DOWN);
|
||||
}
|
||||
|
||||
public boolean isButtonDownJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_DOWN);
|
||||
}
|
||||
|
||||
public boolean isButtonDownHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_DOWN);
|
||||
}
|
||||
|
||||
public boolean isButtonDownPressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_DOWN);
|
||||
}
|
||||
|
||||
/* Button - */
|
||||
|
||||
public boolean isButtonMinusJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_MINUS);
|
||||
}
|
||||
|
||||
public boolean isButtonMinusJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_MINUS);
|
||||
}
|
||||
|
||||
public boolean isButtonMinusHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_MINUS);
|
||||
}
|
||||
|
||||
public boolean isButtonMinusPressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_MINUS);
|
||||
}
|
||||
|
||||
/* Button + */
|
||||
|
||||
public boolean isButtonPlusJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_PLUS);
|
||||
}
|
||||
|
||||
public boolean isButtonPlusJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_PLUS);
|
||||
}
|
||||
|
||||
public boolean isButtonPlusHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_PLUS);
|
||||
}
|
||||
|
||||
public boolean isButtonPlusPressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_PLUS);
|
||||
}
|
||||
|
||||
/* Button HOME */
|
||||
|
||||
public boolean isButtonHomeJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_HOME);
|
||||
}
|
||||
|
||||
public boolean isButtonHomeJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_HOME);
|
||||
}
|
||||
|
||||
public boolean isButtonHomeHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_HOME);
|
||||
}
|
||||
|
||||
public boolean isButtonHomePressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_HOME);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -37,7 +37,6 @@ public class DisconnectionEvent extends WiiUseApiEvent {
|
||||
String out = "";
|
||||
/* Status */
|
||||
out += "/*********** DISCONNECTION EVENT : WIIMOTE ID :" + super.getWiimoteId() + " ********/\n";
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public class EventsGatherer {
|
||||
|
||||
private WiiUseApiEvent[] events;
|
||||
private int index = 0;
|
||||
private GenericEvent genericEvent = null;
|
||||
private WiimoteEvent genericEvent = null;
|
||||
|
||||
/**
|
||||
* Create EventsGatherer.
|
||||
@@ -62,7 +62,7 @@ public class EventsGatherer {
|
||||
*/
|
||||
public void prepareWiiMoteEvent(int id, short buttonsJustPressed,
|
||||
short buttonsJustReleased, short buttonsHeld) {
|
||||
genericEvent = new GenericEvent(id, buttonsJustPressed,
|
||||
genericEvent = new WiimoteEvent(id, buttonsJustPressed,
|
||||
buttonsJustReleased, buttonsHeld);
|
||||
}
|
||||
|
||||
@@ -226,6 +226,28 @@ public class EventsGatherer {
|
||||
DisconnectionEvent evt = new DisconnectionEvent(id);
|
||||
addEvent(evt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a NunchukInsertedEvent to the gatherer.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
*/
|
||||
public void addNunchukInsertedEvent(int id) {
|
||||
NunchukInsertedEvent evt = new NunchukInsertedEvent(id);
|
||||
addEvent(evt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a NunchukRemovedEvent to the gatherer.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
*/
|
||||
public void addNunchukRemovedEvent(int id) {
|
||||
NunchukRemovedEvent evt = new NunchukRemovedEvent(id);
|
||||
addEvent(evt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array containing the events.
|
||||
|
||||
@@ -17,219 +17,43 @@
|
||||
package wiiusej.wiiuseapievents;
|
||||
|
||||
/**
|
||||
* Class that is a bean to be filled by the wiiuse API.
|
||||
* Abstract mother class representing an event with a wiimote id.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class GenericEvent extends WiiUseApiEvent {
|
||||
|
||||
ButtonsEvent buttonsEvent = null;
|
||||
IREvent infraredEvent = null;
|
||||
MotionSensingEvent motionSensingEvent = null;
|
||||
|
||||
public abstract class GenericEvent {
|
||||
|
||||
/* ID */
|
||||
private int wiimoteId = -1;
|
||||
|
||||
/**
|
||||
* Construct the Wiimote setting up the id.
|
||||
* Construct the WiiUseApiEvent setting up the id.
|
||||
*
|
||||
* @param id
|
||||
* the Wiimote id
|
||||
* the Wiimote id
|
||||
*/
|
||||
public GenericEvent(int id) {
|
||||
super(id, WiiUseApiEvent.GENERIC_EVENT);
|
||||
wiimoteId = id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct the Wiimote setting up the id and the buttons.
|
||||
* Get Wiimote ID
|
||||
*
|
||||
* @param id
|
||||
* the Wiimote id
|
||||
* @param buttonsJustPressed
|
||||
* buttons just pressed
|
||||
* @param buttonsJustReleased
|
||||
* buttons just released
|
||||
* @param buttonsHeld
|
||||
* buttons held
|
||||
* @return the wiimote id.
|
||||
*/
|
||||
public GenericEvent(int id, short buttonsJustPressed,
|
||||
short buttonsJustReleased, short buttonsHeld) {
|
||||
super(id, WiiUseApiEvent.GENERIC_EVENT);
|
||||
buttonsEvent = new ButtonsEvent(id, buttonsJustPressed,
|
||||
buttonsJustReleased, buttonsHeld);
|
||||
public int getWiimoteId() {
|
||||
return wiimoteId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tell if there is an IR Event.
|
||||
* Set Wiimote ID
|
||||
*
|
||||
* @return TRUE if there is an IR event.
|
||||
* @param wiimoteId
|
||||
* id of the wiimote
|
||||
*/
|
||||
public boolean isThereIrEvent() {
|
||||
return infraredEvent != null;
|
||||
void setWiimoteId(int wiimoteId) {
|
||||
this.wiimoteId = wiimoteId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell if there is a motion sensing Event.
|
||||
*
|
||||
* @return TRUE if there is a motion sensing event.
|
||||
*/
|
||||
public boolean isThereMotionSensingEvent() {
|
||||
return motionSensingEvent != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get buttons event.
|
||||
*
|
||||
* @return the buttons event.
|
||||
*/
|
||||
public ButtonsEvent getButtonsEvent() {
|
||||
return buttonsEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get IR event.
|
||||
*
|
||||
* @return the IR event if there is one or null.
|
||||
*/
|
||||
public IREvent getIREvent() {
|
||||
return infraredEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get motion sensing event.
|
||||
*
|
||||
* @return the motion sensing event if there is one or null.
|
||||
*/
|
||||
public MotionSensingEvent getMotionSensingEvent() {
|
||||
return motionSensingEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare an IR event to populate.
|
||||
*
|
||||
* @param x
|
||||
* calculated X coordinate.
|
||||
* @param y
|
||||
* calculated Y coordinate.
|
||||
* @param z
|
||||
* calculated distance.
|
||||
* @param ax
|
||||
* absolute X coordinate.
|
||||
* @param ay
|
||||
* absolute Y coordinate
|
||||
* @param xVRes
|
||||
* IR virtual screen x resolution.
|
||||
* @param yVRes
|
||||
* IR virtual screen y resolution.
|
||||
* @param xOffset
|
||||
* IR X correction offset.
|
||||
* @param yOffset
|
||||
* IR Y correction offset.
|
||||
* @param sensorBarPostion
|
||||
* aspect ratio of the screen.
|
||||
* @param screenAsPectRatio
|
||||
* IR sensor bar position.
|
||||
* @param irSensitivity
|
||||
* Sensitivity of the infrared camera.
|
||||
* @param distance
|
||||
* Pixel Distance between first two dots
|
||||
*/
|
||||
public void prepareIRevent(int x, int y, int z, int ax, int ay, int xVRes,
|
||||
int yVRes, int xOffset, int yOffset, short sensorBarPostion,
|
||||
short screenAsPectRatio, short irSensitivity, float distance) {
|
||||
if (infraredEvent == null) {
|
||||
infraredEvent = new IREvent(getWiimoteId(), x, y, z, ax, ay, xVRes,
|
||||
yVRes, xOffset, yOffset, sensorBarPostion,
|
||||
screenAsPectRatio, irSensitivity, distance);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an IR point to the generic event. Create an IR Event if it's not
|
||||
* created yet.
|
||||
*
|
||||
* @param x
|
||||
* x coordinates.
|
||||
* @param y
|
||||
* y coordinates
|
||||
* @param rx
|
||||
* raw X coordinate (0-1023).
|
||||
* @param ry
|
||||
* raw Y coordinate (0-1023).
|
||||
* @param size
|
||||
* size of the IR dot (0-15).
|
||||
*/
|
||||
public void addIRpoint(int x, int y, short rx, short ry, short size) {
|
||||
if (infraredEvent != null)
|
||||
infraredEvent.addIRpoint(x, y, rx, ry, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Motion Sensing Event.
|
||||
*
|
||||
* @param orientationThreshold
|
||||
* value of the minimum angle between two events with the
|
||||
* accelerometer
|
||||
* @param accelerationThreshold
|
||||
* value of the value variation between two events with the
|
||||
* accelerometer
|
||||
* @param smoothingState
|
||||
* true if smoothing flag is activated
|
||||
* @param alphaSmooth
|
||||
* value of the alpha smoothing parameter
|
||||
* @param r
|
||||
* roll
|
||||
* @param p
|
||||
* pitch
|
||||
* @param ya
|
||||
* yaw
|
||||
* @param ar
|
||||
* absolute roll
|
||||
* @param ap
|
||||
* absolute pitch
|
||||
* @param x
|
||||
* gravity force on x axis
|
||||
* @param y
|
||||
* gravity force on y axis
|
||||
* @param z
|
||||
* gravity force on z axis
|
||||
* @param xx
|
||||
* raw acceleration on x axis
|
||||
* @param yy
|
||||
* raw acceleration on y axis
|
||||
* @param zz
|
||||
* raw acceleration on z axis
|
||||
*/
|
||||
public void setMotionSensingEvent(float orientationThreshold,
|
||||
int accelerationThreshold, boolean smoothingState,
|
||||
float alphaSmooth, float r, float p, float ya, float ar, float ap,
|
||||
float x, float y, float z, short xx, short yy, short zz) {
|
||||
motionSensingEvent = new MotionSensingEvent(getWiimoteId(),
|
||||
orientationThreshold, accelerationThreshold, smoothingState,
|
||||
alphaSmooth, r, p, ya, ar, ap, x, y, z, xx, yy, zz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "";
|
||||
/* Status */
|
||||
out += "/*********** GENERIC EVENT : WIIMOTE ID :"
|
||||
+ super.getWiimoteId() + " ********/\n";
|
||||
|
||||
out += buttonsEvent;
|
||||
|
||||
if (infraredEvent != null) {
|
||||
out += infraredEvent;
|
||||
} else {
|
||||
out += "/******** IR Tracking ********/\n";
|
||||
out += "--- Active : false\n";
|
||||
}
|
||||
|
||||
if (motionSensingEvent != null) {
|
||||
out += motionSensingEvent;
|
||||
} else {
|
||||
out += "/******** Motion sensing ********/\n";
|
||||
out += "--- Motion sensing : false \n";
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
public abstract String toString();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import wiiusej.values.IRSource;
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class IREvent extends WiimoteEvent {
|
||||
public class IREvent extends GenericEvent {
|
||||
|
||||
/* IR Tracking */
|
||||
private IRSource[] IRPoints;
|
||||
@@ -285,13 +285,15 @@ public class IREvent extends WiimoteEvent {
|
||||
out += "--- Active : true\n";
|
||||
out += "--- calculated X coordinate : " + x + "\n";
|
||||
out += "--- calculated Y coordinate : " + y + "\n";
|
||||
out += "--- calculated distance : " + z + "\n";
|
||||
out += "--- calculated Z coordinate : " + z + "\n";
|
||||
out += "--- calculated distance : " + distance + "\n";
|
||||
out += "--- absolute X coordinate : " + ax + "\n";
|
||||
out += "--- absolute Y coordinate : " + ay + "\n";
|
||||
out += "--- IR virtual screen x resolution : " + xVRes + "\n";
|
||||
out += "--- IR virtual screen y resolution : " + yVRes + "\n";
|
||||
out += "--- IR X correction offset : " + xOffset + "\n";
|
||||
out += "--- IR Y correction offset : " + yOffset + "\n";
|
||||
out += "--- IR Sensitivity (between 1-5) : " + irSensitivity + "\n";
|
||||
if (isScreenAspectRatio43()) {
|
||||
out += "--- aspect ratio of the screen : 4/3\n";
|
||||
} else if (isScreenAspectRatio169()) {
|
||||
@@ -301,7 +303,7 @@ public class IREvent extends WiimoteEvent {
|
||||
out += "--- IR sensor bar position. : Above\n";
|
||||
} else if (isSensorBarBelow()) {
|
||||
out += "--- IR sensor bar position. : Below\n";
|
||||
}
|
||||
}
|
||||
out += "--- Seen points\n";
|
||||
for (int i = 0; i < IRPoints.length; i++) {
|
||||
if (IRPoints[i] != null) {
|
||||
|
||||
@@ -25,7 +25,7 @@ import wiiusej.values.RawAcceleration;
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class MotionSensingEvent extends WiimoteEvent {
|
||||
public class MotionSensingEvent extends GenericEvent {
|
||||
|
||||
/* Motion Sensing */
|
||||
private Orientation orientation;
|
||||
|
||||
86
WiiUseJ/src/wiiusej/wiiuseapievents/NunchukButtonsEvent.java
Normal file
86
WiiUseJ/src/wiiusej/wiiuseapievents/NunchukButtonsEvent.java
Normal file
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.wiiuseapievents;
|
||||
|
||||
/**
|
||||
* Class which represents a buttons event for a generic event. It means buttons
|
||||
* from a wiimote.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class NunchukButtonsEvent extends ButtonsEvent {
|
||||
|
||||
private static short NUNCHUK_BUTTON_Z = 0x01;
|
||||
private static short NUNCHUK_BUTTON_C = 0x02;
|
||||
private static short NUNCHUK_BUTTON_ALL = 0x03;
|
||||
|
||||
/**
|
||||
* Constructor of the nunchuk button Event.
|
||||
* @param id id of the wiimote.
|
||||
* @param buttonsJustPressed buttons just pressed.
|
||||
* @param buttonsJustReleased buttons just released.
|
||||
* @param buttonsHeld buttons just pressed.
|
||||
*/
|
||||
public NunchukButtonsEvent(int id, short buttonsJustPressed,
|
||||
short buttonsJustReleased, short buttonsHeld) {
|
||||
super(id, buttonsJustPressed, buttonsJustReleased, buttonsHeld);
|
||||
}
|
||||
|
||||
/* Button Z */
|
||||
|
||||
public boolean isButtonZJustPressed() {
|
||||
return isButtonJustPressed(NUNCHUK_BUTTON_Z);
|
||||
}
|
||||
|
||||
public boolean isButtonZJustReleased() {
|
||||
return isButtonJustReleased(NUNCHUK_BUTTON_Z);
|
||||
}
|
||||
|
||||
public boolean isButtonZeHeld() {
|
||||
return isButtonHeld(NUNCHUK_BUTTON_Z);
|
||||
}
|
||||
|
||||
public boolean isButtonZPressed() {
|
||||
return isButtonPressed(NUNCHUK_BUTTON_Z);
|
||||
}
|
||||
|
||||
/* Button Z */
|
||||
|
||||
public boolean isButtonCJustPressed() {
|
||||
return isButtonJustPressed(NUNCHUK_BUTTON_C);
|
||||
}
|
||||
|
||||
public boolean isButtonCJustReleased() {
|
||||
return isButtonJustReleased(NUNCHUK_BUTTON_C);
|
||||
}
|
||||
|
||||
public boolean isButtonCHeld() {
|
||||
return isButtonHeld(NUNCHUK_BUTTON_C);
|
||||
}
|
||||
|
||||
public boolean isButtonCPressed() {
|
||||
return isButtonPressed(NUNCHUK_BUTTON_C);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "/******** Buttons for Nunchhuk Event ********/\n"
|
||||
+ super.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.wiiuseapievents;
|
||||
|
||||
/**
|
||||
* Event that represents the connection of a nunchuk to a wiimote.
|
||||
* @author guiguito
|
||||
*
|
||||
*/
|
||||
public class NunchukInsertedEvent extends WiiUseApiEvent {
|
||||
|
||||
/**
|
||||
* Construct the NunchukInsertedEvent setting up the id.
|
||||
* @param id id of the wiimote.
|
||||
*/
|
||||
public NunchukInsertedEvent(int id) {
|
||||
super(id, WIIUSE_NUNCHUK_INSERTED);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see wiiusej.wiiuseapievents.WiiUseApiEvent#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "";
|
||||
/* Status */
|
||||
out += "/*********** NUNCHUK INSERTED EVENT : WIIMOTE ID :" + super.getWiimoteId() + " ********/\n";
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
44
WiiUseJ/src/wiiusej/wiiuseapievents/NunchukRemovedEvent.java
Normal file
44
WiiUseJ/src/wiiusej/wiiuseapievents/NunchukRemovedEvent.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.wiiuseapievents;
|
||||
|
||||
/**
|
||||
* Event that represents the connection of a nunchuk to a wiimote.
|
||||
* @author guiguito
|
||||
*/
|
||||
public class NunchukRemovedEvent extends WiiUseApiEvent {
|
||||
|
||||
/**
|
||||
* Construct the NunchukInsertedEvent setting up the id.
|
||||
* @param id id of the wiimote.
|
||||
*/
|
||||
public NunchukRemovedEvent(int id) {
|
||||
super(id, WIIUSE_NUNCHUK_REMOVED);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see wiiusej.wiiuseapievents.WiiUseApiEvent#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "";
|
||||
/* Status */
|
||||
out += "/*********** NUNCHUK REMOVED EVENT : WIIMOTE ID :" + super.getWiimoteId() + " ********/\n";
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,7 +21,7 @@ package wiiusej.wiiuseapievents;
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public abstract class WiiUseApiEvent extends WiimoteEvent{
|
||||
public abstract class WiiUseApiEvent extends GenericEvent{
|
||||
|
||||
public static int GENERIC_EVENT = 1;
|
||||
public static int STATUS_EVENT = 2;
|
||||
|
||||
@@ -28,7 +28,7 @@ public interface WiiUseApiListener extends java.util.EventListener {
|
||||
/**
|
||||
* Method called when a WiiUseApiEvent occurs.
|
||||
* A WiiUseApiEvent can be :
|
||||
* - GenericEvent (Storing ButtonsEvent and
|
||||
* - WiimoteEvent (Storing ButtonsEvent and
|
||||
* eventually IREvent and MotionSensingEvent)
|
||||
* - StatusEvent
|
||||
* - DisconnectionEvent
|
||||
|
||||
262
WiiUseJ/src/wiiusej/wiiuseapievents/WiimoteButtonsEvent.java
Normal file
262
WiiUseJ/src/wiiusej/wiiuseapievents/WiimoteButtonsEvent.java
Normal file
@@ -0,0 +1,262 @@
|
||||
/**
|
||||
* This file is part of WiiuseJ.
|
||||
*
|
||||
* WiiuseJ is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* WiiuseJ is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package wiiusej.wiiuseapievents;
|
||||
|
||||
/**
|
||||
* Class which represents a buttons event for a generic event. It means buttons
|
||||
* from a wiimote.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class WiimoteButtonsEvent extends ButtonsEvent {
|
||||
|
||||
/* Buttons MACRO */
|
||||
private static short WIIMOTE_BUTTON_TWO = 0x0001;
|
||||
private static short WIIMOTE_BUTTON_ONE = 0x0002;
|
||||
private static short WIIMOTE_BUTTON_B = 0x0004;
|
||||
private static short WIIMOTE_BUTTON_A = 0x0008;
|
||||
private static short WIIMOTE_BUTTON_MINUS = 0x0010;
|
||||
private static short WIIMOTE_BUTTON_ZACCEL_BIT6 = 0x0020;
|
||||
private static short WIIMOTE_BUTTON_ZACCEL_BIT7 = 0x0040;
|
||||
private static short WIIMOTE_BUTTON_HOME = 0x0080;
|
||||
private static short WIIMOTE_BUTTON_LEFT = 0x0100;
|
||||
private static short WIIMOTE_BUTTON_RIGHT = 0x0200;
|
||||
private static short WIIMOTE_BUTTON_DOWN = 0x0400;
|
||||
private static short WIIMOTE_BUTTON_UP = 0x0800;
|
||||
private static short WIIMOTE_BUTTON_PLUS = 0x1000;
|
||||
private static short WIIMOTE_BUTTON_ZACCEL_BIT4 = 0x2000;
|
||||
private static short WIIMOTE_BUTTON_ZACCEL_BIT5 = 0x4000;
|
||||
private static int WIIMOTE_BUTTON_UNKNOWN = 0x8000;
|
||||
private static short WIIMOTE_BUTTON_ALL = 0x1F9F;
|
||||
|
||||
/**
|
||||
* Constructor of the wiimote button Event.
|
||||
* @param id id of the wiimote.
|
||||
* @param buttonsJustPressed buttons just pressed.
|
||||
* @param buttonsJustReleased buttons just released.
|
||||
* @param buttonsHeld buttons held.
|
||||
*/
|
||||
public WiimoteButtonsEvent(int id, short buttonsJustPressed,
|
||||
short buttonsJustReleased, short buttonsHeld) {
|
||||
super(id, buttonsJustPressed, buttonsJustReleased, buttonsHeld);
|
||||
}
|
||||
|
||||
/* Button ONE */
|
||||
|
||||
public boolean isButtonOneJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_ONE);
|
||||
}
|
||||
|
||||
public boolean isButtonOneJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_ONE);
|
||||
}
|
||||
|
||||
public boolean isButtonOneHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_ONE);
|
||||
}
|
||||
|
||||
public boolean isButtonOnePressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_ONE);
|
||||
}
|
||||
|
||||
/* Button TWO */
|
||||
|
||||
public boolean isButtonTwoJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_TWO);
|
||||
}
|
||||
|
||||
public boolean isButtonTwoJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_TWO);
|
||||
}
|
||||
|
||||
public boolean isButtonTwoHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_TWO);
|
||||
}
|
||||
|
||||
public boolean isButtonTwoPressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_TWO);
|
||||
}
|
||||
|
||||
/* Button A */
|
||||
|
||||
public boolean isButtonAJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_A);
|
||||
}
|
||||
|
||||
public boolean isButtonAJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_A);
|
||||
}
|
||||
|
||||
public boolean isButtonAHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_A);
|
||||
}
|
||||
|
||||
public boolean isButtonAPressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_A);
|
||||
}
|
||||
|
||||
/* Button B */
|
||||
|
||||
public boolean isButtonBJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_B);
|
||||
}
|
||||
|
||||
public boolean isButtonBJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_B);
|
||||
}
|
||||
|
||||
public boolean isButtonBHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_B);
|
||||
}
|
||||
|
||||
public boolean isButtonBPressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_B);
|
||||
}
|
||||
|
||||
/* Button LEFT */
|
||||
|
||||
public boolean isButtonLeftJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_LEFT);
|
||||
}
|
||||
|
||||
public boolean isButtonLeftJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_LEFT);
|
||||
}
|
||||
|
||||
public boolean isButtonLeftHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_LEFT);
|
||||
}
|
||||
|
||||
public boolean isButtonLeftPressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_LEFT);
|
||||
}
|
||||
|
||||
/* Button RIGHT */
|
||||
|
||||
public boolean isButtonRightJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_RIGHT);
|
||||
}
|
||||
|
||||
public boolean isButtonRightJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_RIGHT);
|
||||
}
|
||||
|
||||
public boolean isButtonRightHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_RIGHT);
|
||||
}
|
||||
|
||||
public boolean isButtonRightPressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_RIGHT);
|
||||
}
|
||||
|
||||
/* Button UP */
|
||||
|
||||
public boolean isButtonUpJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_UP);
|
||||
}
|
||||
|
||||
public boolean isButtonUpJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_UP);
|
||||
}
|
||||
|
||||
public boolean isButtonUpHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_UP);
|
||||
}
|
||||
|
||||
public boolean isButtonUpPressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_UP);
|
||||
}
|
||||
|
||||
/* Button DOWN */
|
||||
|
||||
public boolean isButtonDownJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_DOWN);
|
||||
}
|
||||
|
||||
public boolean isButtonDownJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_DOWN);
|
||||
}
|
||||
|
||||
public boolean isButtonDownHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_DOWN);
|
||||
}
|
||||
|
||||
public boolean isButtonDownPressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_DOWN);
|
||||
}
|
||||
|
||||
/* Button - */
|
||||
|
||||
public boolean isButtonMinusJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_MINUS);
|
||||
}
|
||||
|
||||
public boolean isButtonMinusJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_MINUS);
|
||||
}
|
||||
|
||||
public boolean isButtonMinusHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_MINUS);
|
||||
}
|
||||
|
||||
public boolean isButtonMinusPressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_MINUS);
|
||||
}
|
||||
|
||||
/* Button + */
|
||||
|
||||
public boolean isButtonPlusJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_PLUS);
|
||||
}
|
||||
|
||||
public boolean isButtonPlusJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_PLUS);
|
||||
}
|
||||
|
||||
public boolean isButtonPlusHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_PLUS);
|
||||
}
|
||||
|
||||
public boolean isButtonPlusPressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_PLUS);
|
||||
}
|
||||
|
||||
/* Button HOME */
|
||||
|
||||
public boolean isButtonHomeJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_HOME);
|
||||
}
|
||||
|
||||
public boolean isButtonHomeJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_HOME);
|
||||
}
|
||||
|
||||
public boolean isButtonHomeHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_HOME);
|
||||
}
|
||||
|
||||
public boolean isButtonHomePressed() {
|
||||
return isButtonPressed(WIIMOTE_BUTTON_HOME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "/******** Buttons for Wiimote generic Event ********/\n"
|
||||
+ super.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,44 +16,224 @@
|
||||
*/
|
||||
package wiiusej.wiiuseapievents;
|
||||
|
||||
import wiiusej.values.Expansion;
|
||||
|
||||
/**
|
||||
* Abstract mother class representing an event with a wiimote id.
|
||||
* Class that is a bean to be filled by the wiiuse API on an event that occurs
|
||||
* on a wiimote.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public abstract class WiimoteEvent {
|
||||
|
||||
/* ID */
|
||||
private int wiimoteId = -1;
|
||||
|
||||
public class WiimoteEvent extends WiiUseApiEvent {
|
||||
|
||||
WiimoteButtonsEvent buttonsEvent = null;
|
||||
IREvent infraredEvent = null;
|
||||
MotionSensingEvent motionSensingEvent = null;
|
||||
Expansion expansion = null;
|
||||
|
||||
/**
|
||||
* Construct the WiiUseApiEvent setting up the id.
|
||||
* Construct the Wiimote setting up the id.
|
||||
*
|
||||
* @param id
|
||||
* the Wiimote id
|
||||
* the Wiimote id
|
||||
*/
|
||||
public WiimoteEvent(int id) {
|
||||
wiimoteId = id;
|
||||
super(id, WiiUseApiEvent.GENERIC_EVENT);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Wiimote ID
|
||||
* Construct the Wiimote setting up the id and the buttons.
|
||||
*
|
||||
* @return the wiimote id.
|
||||
* @param id
|
||||
* the Wiimote id
|
||||
* @param buttonsJustPressed
|
||||
* buttons just pressed
|
||||
* @param buttonsJustReleased
|
||||
* buttons just released
|
||||
* @param buttonsHeld
|
||||
* buttons held
|
||||
*/
|
||||
public int getWiimoteId() {
|
||||
return wiimoteId;
|
||||
public WiimoteEvent(int id, short buttonsJustPressed,
|
||||
short buttonsJustReleased, short buttonsHeld) {
|
||||
super(id, WiiUseApiEvent.GENERIC_EVENT);
|
||||
buttonsEvent = new WiimoteButtonsEvent(id, buttonsJustPressed,
|
||||
buttonsJustReleased, buttonsHeld);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set Wiimote ID
|
||||
* Tell if there is an IR Event.
|
||||
*
|
||||
* @param wiimoteId
|
||||
* id of the wiimote
|
||||
* @return TRUE if there is an IR event.
|
||||
*/
|
||||
void setWiimoteId(int wiimoteId) {
|
||||
this.wiimoteId = wiimoteId;
|
||||
public boolean isThereIrEvent() {
|
||||
return infraredEvent != null;
|
||||
}
|
||||
|
||||
public abstract String toString();
|
||||
|
||||
/**
|
||||
* Tell if there is a motion sensing Event.
|
||||
*
|
||||
* @return TRUE if there is a motion sensing event.
|
||||
*/
|
||||
public boolean isThereMotionSensingEvent() {
|
||||
return motionSensingEvent != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get buttons event.
|
||||
*
|
||||
* @return the buttons event.
|
||||
*/
|
||||
public WiimoteButtonsEvent getButtonsEvent() {
|
||||
return buttonsEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get IR event.
|
||||
*
|
||||
* @return the IR event if there is one or null.
|
||||
*/
|
||||
public IREvent getIREvent() {
|
||||
return infraredEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get motion sensing event.
|
||||
*
|
||||
* @return the motion sensing event if there is one or null.
|
||||
*/
|
||||
public MotionSensingEvent getMotionSensingEvent() {
|
||||
return motionSensingEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare an IR event to populate.
|
||||
*
|
||||
* @param x
|
||||
* calculated X coordinate.
|
||||
* @param y
|
||||
* calculated Y coordinate.
|
||||
* @param z
|
||||
* calculated distance.
|
||||
* @param ax
|
||||
* absolute X coordinate.
|
||||
* @param ay
|
||||
* absolute Y coordinate
|
||||
* @param xVRes
|
||||
* IR virtual screen x resolution.
|
||||
* @param yVRes
|
||||
* IR virtual screen y resolution.
|
||||
* @param xOffset
|
||||
* IR X correction offset.
|
||||
* @param yOffset
|
||||
* IR Y correction offset.
|
||||
* @param sensorBarPostion
|
||||
* aspect ratio of the screen.
|
||||
* @param screenAsPectRatio
|
||||
* IR sensor bar position.
|
||||
* @param irSensitivity
|
||||
* Sensitivity of the infrared camera.
|
||||
* @param distance
|
||||
* Pixel Distance between first two dots
|
||||
*/
|
||||
public void prepareIRevent(int x, int y, int z, int ax, int ay, int xVRes,
|
||||
int yVRes, int xOffset, int yOffset, short sensorBarPostion,
|
||||
short screenAsPectRatio, short irSensitivity, float distance) {
|
||||
if (infraredEvent == null) {
|
||||
infraredEvent = new IREvent(getWiimoteId(), x, y, z, ax, ay, xVRes,
|
||||
yVRes, xOffset, yOffset, sensorBarPostion,
|
||||
screenAsPectRatio, irSensitivity, distance);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an IR point to the generic event. Create an IR Event if it's not
|
||||
* created yet.
|
||||
*
|
||||
* @param x
|
||||
* x coordinates.
|
||||
* @param y
|
||||
* y coordinates
|
||||
* @param rx
|
||||
* raw X coordinate (0-1023).
|
||||
* @param ry
|
||||
* raw Y coordinate (0-1023).
|
||||
* @param size
|
||||
* size of the IR dot (0-15).
|
||||
*/
|
||||
public void addIRpoint(int x, int y, short rx, short ry, short size) {
|
||||
if (infraredEvent != null)
|
||||
infraredEvent.addIRpoint(x, y, rx, ry, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Motion Sensing Event.
|
||||
*
|
||||
* @param orientationThreshold
|
||||
* value of the minimum angle between two events with the
|
||||
* accelerometer
|
||||
* @param accelerationThreshold
|
||||
* value of the value variation between two events with the
|
||||
* accelerometer
|
||||
* @param smoothingState
|
||||
* true if smoothing flag is activated
|
||||
* @param alphaSmooth
|
||||
* value of the alpha smoothing parameter
|
||||
* @param r
|
||||
* roll
|
||||
* @param p
|
||||
* pitch
|
||||
* @param ya
|
||||
* yaw
|
||||
* @param ar
|
||||
* absolute roll
|
||||
* @param ap
|
||||
* absolute pitch
|
||||
* @param x
|
||||
* gravity force on x axis
|
||||
* @param y
|
||||
* gravity force on y axis
|
||||
* @param z
|
||||
* gravity force on z axis
|
||||
* @param xx
|
||||
* raw acceleration on x axis
|
||||
* @param yy
|
||||
* raw acceleration on y axis
|
||||
* @param zz
|
||||
* raw acceleration on z axis
|
||||
*/
|
||||
public void setMotionSensingEvent(float orientationThreshold,
|
||||
int accelerationThreshold, boolean smoothingState,
|
||||
float alphaSmooth, float r, float p, float ya, float ar, float ap,
|
||||
float x, float y, float z, short xx, short yy, short zz) {
|
||||
motionSensingEvent = new MotionSensingEvent(getWiimoteId(),
|
||||
orientationThreshold, accelerationThreshold, smoothingState,
|
||||
alphaSmooth, r, p, ya, ar, ap, x, y, z, xx, yy, zz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "";
|
||||
/* Status */
|
||||
out += "/*********** GENERIC EVENT : WIIMOTE ID :"
|
||||
+ super.getWiimoteId() + " ********/\n";
|
||||
|
||||
out += buttonsEvent;
|
||||
|
||||
if (infraredEvent != null) {
|
||||
out += infraredEvent;
|
||||
} else {
|
||||
out += "/******** IR Tracking ********/\n";
|
||||
out += "--- Active : false\n";
|
||||
}
|
||||
|
||||
if (motionSensingEvent != null) {
|
||||
out += motionSensingEvent;
|
||||
} else {
|
||||
out += "/******** Motion sensing ********/\n";
|
||||
out += "--- Motion sensing : false \n";
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public interface WiimoteListener extends java.util.EventListener {
|
||||
* @param e the buttonEvent with the last informations
|
||||
* about the buttons of the wiimote.
|
||||
*/
|
||||
void onButtonsEvent(ButtonsEvent e);
|
||||
void onButtonsEvent(WiimoteButtonsEvent e);
|
||||
|
||||
/**
|
||||
* Method called when an IR event occurs.
|
||||
|
||||
Reference in New Issue
Block a user