added infos on IR event

motion sensing event (raw acceleration)
and support for more wiiuse functions

git-svn-id: http://wiiusej.googlecode.com/svn/trunk@75 ae48ae66-6a45-0410-b38e-211266189506
This commit is contained in:
guilhem.duche
2008-03-08 01:06:45 +00:00
parent f6b653eab9
commit d55ddcddde
18 changed files with 808 additions and 127 deletions

Binary file not shown.

View File

@@ -159,6 +159,40 @@ public class WiiUseApi {
*/ */
native void deactivateContinuous(int id); native void deactivateContinuous(int id);
/**
* Notify wiiuse that your screen has an aspect ratio of 4/3.
* @param id the id of the wiimote of which we want the status.
*/
native void setScreenRatio43(int id);
/**
* Notify wiiuse that your screen has an aspect ratio of 16/9.
* @param id the id of the wiimote of which we want the status.
*/
native void setScreenRatio169(int id);
/**
* Notify wiiuse that the sensor bar is above your screen.
* @param id the id of the wiimote of which we want the status.
*/
native void setSensorBarAboveScreen(int id);
/**
* Notify wiiuse that the sensor bar is below your screen.
* @param id the id of the wiimote of which we want the status.
*/
native void setSensorBarBelowScreen(int id);
/**
* Set virtual screen resolution. It is used to automatically
* compute the position of a cursor on this virtual screen
* using the sensor bar. These results come in the IREvent.
* @param id the id of the wiimote of which we want the status.
* @param x x resolution.
* @param y y resolution.
*/
native void setVirtualScreenResolution(int id, int x, int y);
/** /**
* Get status and values from the wiimotes and send it through callbacks. * Get status and values from the wiimotes and send it through callbacks.
* *
@@ -173,4 +207,6 @@ public class WiiUseApi {
*/ */
native void specialPoll(EventsGatherer gath); native void specialPoll(EventsGatherer gath);
} }

View File

@@ -27,6 +27,7 @@ import wiiusej.wiiuseapievents.WiiUseApiListener;
import wiiusej.wiiuseapirequest.FloatValueRequest; import wiiusej.wiiuseapirequest.FloatValueRequest;
import wiiusej.wiiuseapirequest.IntValueRequest; import wiiusej.wiiuseapirequest.IntValueRequest;
import wiiusej.wiiuseapirequest.LedsRequest; import wiiusej.wiiuseapirequest.LedsRequest;
import wiiusej.wiiuseapirequest.TwoIntValueRequest;
import wiiusej.wiiuseapirequest.WiiUseApiRequest; import wiiusej.wiiuseapirequest.WiiUseApiRequest;
/** /**
@@ -72,7 +73,7 @@ public class WiiUseApiManager extends Thread {
manager.wiimotes = new Wiimote[nbWiimotes]; manager.wiimotes = new Wiimote[nbWiimotes];
for (int i = 1; i <= nbWiimotes; i++) { for (int i = 1; i <= nbWiimotes; i++) {
Wiimote wim = new Wiimote(i, manager); Wiimote wim = new Wiimote(i, manager);
manager.wiimotes[i-1] = wim; manager.wiimotes[i - 1] = wim;
manager.addWiiUseApiListener(wim); manager.addWiiUseApiListener(wim);
} }
} }
@@ -114,8 +115,8 @@ public class WiiUseApiManager extends Thread {
* id of the wiimote to disconnect. * id of the wiimote to disconnect.
*/ */
public void closeConnection(int id) { public void closeConnection(int id) {
removeWiiUseApiListener(wiimotes[id-1]); removeWiiUseApiListener(wiimotes[id - 1]);
wiimotes[id-1] = null; wiimotes[id - 1] = null;
requests.add(new WiiUseApiRequest(id, requests.add(new WiiUseApiRequest(id,
WiiUseApiRequest.WIIUSE_CLOSE_CONNECTION_REQUEST)); WiiUseApiRequest.WIIUSE_CLOSE_CONNECTION_REQUEST));
System.out.println("Wiimote " + id + " disconnected !"); System.out.println("Wiimote " + id + " disconnected !");
@@ -308,6 +309,7 @@ public class WiiUseApiManager extends Thread {
/** /**
* Try to resync with the wiimote by starting a new handshake. * Try to resync with the wiimote by starting a new handshake.
*
* @TODO not used yet !! * @TODO not used yet !!
* @param id * @param id
* id of the wiimote * id of the wiimote
@@ -316,6 +318,67 @@ public class WiiUseApiManager extends Thread {
requests.add(new WiiUseApiRequest(id, WiiUseApiRequest.WIIUSE_RESYNC)); requests.add(new WiiUseApiRequest(id, WiiUseApiRequest.WIIUSE_RESYNC));
} }
/**
* Set screen aspect ratio to 4/3 for the given id.
*
* @param id
* id of the wiimote
*/
public void setScreenAspectRatio43(int id) {
requests.add(new WiiUseApiRequest(id,
WiiUseApiRequest.WIIUSE_ASPECT_RATIO_4_3));
}
/**
* Set screen aspect ratio to 16/9 for the given id.
*
* @param id
* id of the wiimote
*/
public void setScreenAspectRatio169(int id) {
requests.add(new WiiUseApiRequest(id,
WiiUseApiRequest.WIIUSE_ASPECT_RATIO_16_9));
}
/**
* Set the sensor bar to be above the screen.
*
* @param id
* id of the wiimote
*/
public void setSensorBarAboveScreen(int id) {
requests.add(new WiiUseApiRequest(id,
WiiUseApiRequest.WIIUSE_SENSOR_BAR_ABOVE));
}
/**
* Set the sensor bar to be below the screen.
*
* @param id
* id of the wiimote
*/
public void setSensorBarBelowScreen(int id) {
requests.add(new WiiUseApiRequest(id,
WiiUseApiRequest.WIIUSE_SENSOR_BAR_BELOW));
}
/**
* Set virtual resolution. It is used to automatically compute the position
* of a cursor on this virtual screen using the sensor bar. These results
* come in the IREvent.
*
* @param id
* id of the wiimote
* @param x
* x resolution
* @param y
* y resolution
*/
public void setVirtualResolution(int id, int x, int y) {
requests.add(new TwoIntValueRequest(id,
WiiUseApiRequest.WIIUSE_SET_VIRTUAL_RESOLUTION, x, y));
}
/** /**
* Get Status for the wiimote for the given id. * Get Status for the wiimote for the given id.
* *
@@ -336,7 +399,7 @@ public class WiiUseApiManager extends Thread {
EventsGatherer gather = new EventsGatherer(nbMaxWiimotes); EventsGatherer gather = new EventsGatherer(nbMaxWiimotes);
// Start polling and tell the observers when there Wiimote events // Start polling and tell the observers when there Wiimote events
while (running.get() && connected > 0) { while (running.get() && connected > 0) {
/* Polling */ /* Polling */
wiiuse.specialPoll(gather); wiiuse.specialPoll(gather);
@@ -359,7 +422,7 @@ public class WiiUseApiManager extends Thread {
} }
gather.clearEvents(); gather.clearEvents();
/* deal with request done to wiiuse API*/ /* deal with request done to wiiuse API */
WiiUseApiRequest req = requests.poll(); WiiUseApiRequest req = requests.poll();
if (req != null) {// there is a request for the wiiuse api if (req != null) {// there is a request for the wiiuse api
int id = req.getId(); int id = req.getId();
@@ -427,6 +490,23 @@ public class WiiUseApiManager extends Thread {
} else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_RESYNC) { } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_RESYNC) {
/* set resync request */ /* set resync request */
wiiuse.reSync(req.getId()); wiiuse.reSync(req.getId());
} else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ASPECT_RATIO_4_3) {
/* set screen aspect ratio to 4/3 */
wiiuse.setScreenRatio43(req.getId());
} else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ASPECT_RATIO_16_9) {
/* set screen aspect ratio to 16/9 */
wiiuse.setScreenRatio169(req.getId());
} else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_SENSOR_BAR_ABOVE) {
/* set sensor bar above the screen */
wiiuse.setSensorBarAboveScreen(req.getId());
} else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_SENSOR_BAR_BELOW) {
/* set sensor bar above the screen */
wiiuse.setSensorBarBelowScreen(req.getId());
} else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_SET_VIRTUAL_RESOLUTION) {
/* set virtual resolution */
wiiuse.setVirtualScreenResolution(req.getId(),
((TwoIntValueRequest) req).getIntValue(),
((TwoIntValueRequest) req).getSecondIntValue());
} else { } else {
System.out.println("Bad request to Wiiuse API !!!!!"); System.out.println("Bad request to Wiiuse API !!!!!");
} }

View File

@@ -170,10 +170,49 @@ public class Wiimote implements WiiUseApiListener {
* @param th * @param th
* threshold * threshold
*/ */
public void setAlphaSmoothingValue(int th) { public void setAlphaSmoothingValue(float th) {
manager.setAlphaSmoothing(id,th); manager.setAlphaSmoothing(id,th);
} }
/**
* Set the screen aspect ratio to be considered as 4/3.
*/
public void setScreenAspectRatio43() {
manager.setScreenAspectRatio43(id);
}
/**
* Set the screen aspect ratio to be considered as 16/9.
*/
public void setScreenAspectRatio169() {
manager.setScreenAspectRatio169(id);
}
/**
* Set the sensor bar to be considered above the screen.
*/
public void setSensorBarAboveScreen() {
manager.setSensorBarAboveScreen(id);
}
/**
* Set the sensor bar to be considered below the screen.
*/
public void setSensorBarBelowScreen() {
manager.setSensorBarBelowScreen(id);
}
/**
* Set the screen resolution of the you are pointing at
* with your wiimote.
*
* @param x x resolution.
* @param y y resolution.
*/
public void setVirtualResolution(int x, int y) {
manager.setVirtualResolution(id, x ,y);
}
//TODO resync ? //TODO resync ?
/** /**
@@ -185,12 +224,21 @@ public class Wiimote implements WiiUseApiListener {
manager.getStatus(id); manager.getStatus(id);
} }
/**
* Method called when a WiiUseApiEvent occurs.
* @param e the WiiUseApiEvent.
*/
public void onWiiUseApiEvent(WiiUseApiEvent e) { public void onWiiUseApiEvent(WiiUseApiEvent e) {
if (e.getWiimoteId() == id){ if (e.getWiimoteId() == id){
if (e.getEventType() == WiiUseApiEvent.GENERIC_EVENT){ if (e.getEventType() == WiiUseApiEvent.GENERIC_EVENT){
notifyWiiMoteEventListeners((GenericEvent)e); notifyWiiMoteEventListeners((GenericEvent)e);
}else if (e.getEventType() == WiiUseApiEvent.STATUS_EVENT){ }else if (e.getEventType() == WiiUseApiEvent.STATUS_EVENT
||e.getEventType() == WiiUseApiEvent.WIIUSE_NUNCHUK_INSERTED
||e.getEventType() == WiiUseApiEvent.WIIUSE_NUNCHUK_REMOVED
||e.getEventType() == WiiUseApiEvent.WIIUSE_CLASSIC_CTRL_INSERTED
||e.getEventType() == WiiUseApiEvent.WIIUSE_CLASSIC_CTRL_REMOVED
||e.getEventType() == WiiUseApiEvent.WIIUSE_GUITAR_HERO_3_CTRL_INSERTED
||e.getEventType() == WiiUseApiEvent.WIIUSE_GUITAR_HERO_3_CTRL_REMOVED){
notifyStatusEventListeners((StatusEvent)e); notifyStatusEventListeners((StatusEvent)e);
}else if (e.getEventType() == WiiUseApiEvent.DISCONNECTION_EVENT){ }else if (e.getEventType() == WiiUseApiEvent.DISCONNECTION_EVENT){
notifyDisconnectionEventListeners((DisconnectionEvent)e); notifyDisconnectionEventListeners((DisconnectionEvent)e);

View File

@@ -22,7 +22,7 @@ import java.awt.event.InputEvent;
import wiiusej.WiiUseApiManager; import wiiusej.WiiUseApiManager;
import wiiusej.Wiimote; import wiiusej.Wiimote;
import wiiusej.values.Point2DInteger; import wiiusej.values.IRSource;
import wiiusej.wiiuseapievents.ButtonsEvent; import wiiusej.wiiuseapievents.ButtonsEvent;
import wiiusej.wiiuseapievents.DisconnectionEvent; import wiiusej.wiiuseapievents.DisconnectionEvent;
import wiiusej.wiiuseapievents.IREvent; import wiiusej.wiiuseapievents.IREvent;
@@ -343,17 +343,11 @@ public class Tests implements WiimoteListener {
public void onIrEvent(IREvent e) { public void onIrEvent(IREvent e) {
if (dump == DISPLAY_EACH_VALUE) { if (dump == DISPLAY_EACH_VALUE) {
/* display ir points */ System.out.println(e);
Point2DInteger[] list = e.getIRPoints();
for (int i = 0; i < list.length; i++) {
if (list[i] != null)
System.out.print("Point :(" + list[i].getX() + ","
+ list[i].getY() + ") ");
}
} else if (dump == DUMP) { } else if (dump == DUMP) {
System.out.println(e); System.out.println(e);
} else if (dump == MOVE_MOUSE) { } else if (dump == MOVE_MOUSE) {
Point2DInteger[] list = e.getIRPoints(); IRSource[] list = e.getIRPoints();
if (list.length > 0) { if (list.length > 0) {
int x1 = (int) list[0].getX(); int x1 = (int) list[0].getX();
int y1 = (int) list[0].getY(); int y1 = (int) list[0].getY();

View File

@@ -54,13 +54,6 @@ public class GForce {
return x; return x;
} }
/**
* @param x the x to set
*/
public void setX(float x) {
this.x = x;
}
/** /**
* @return the y * @return the y
*/ */
@@ -68,13 +61,6 @@ public class GForce {
return y; return y;
} }
/**
* @param y the y to set
*/
public void setY(float y) {
this.y = y;
}
/** /**
* @return the z * @return the z
*/ */
@@ -82,13 +68,6 @@ public class GForce {
return z; return z;
} }
/**
* @param z the z to set
*/
public void setZ(float z) {
this.z = z;
}
@Override @Override
public String toString() { public String toString() {
return "Gravity force : ("+x+", "+y+","+z+")"; return "Gravity force : ("+x+", "+y+","+z+")";

View File

@@ -0,0 +1,109 @@
/**
* 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.values;
/**
* Class used for IR sources.
* @author guiguito
*/
public class IRSource{
private int x;
private int y;
private short rx;
private short ry;
private short size;
/**
* Build an IR source with all details.
*
* @param xx
* xx interpolated coordinates.
* @param yy
* yy interpolated coordinates.
* @param rxx
* raw X coordinate (0-1023).
* @param ryy
* raw Y coordinate (0-1023).
* @param si
* size of the IR dot (0-15).
*/
public IRSource(int xx, int yy, short rxx, short ryy, short si) {
x = xx;
y = yy;
rx = rxx;
ry = ryy;
size = si;
}
/**
* Return x interpolated coordinates.
* @return the x
*/
public int getX() {
return x;
}
/**
* Return y interpolated coordinates.
* @return the y
*/
public int getY() {
return y;
}
/**
* Return raw X coordinate (0-1023).
* @return the rx
*/
public short getRx() {
return rx;
}
/**
* Return raw Y coordinate (0-1023).
* @return the ry
*/
public short getRy() {
return ry;
}
/**
* Return size of the IR dot (0-15).
* @return the size
*/
public short getSize() {
return size;
}
@Override
public String toString() {
return "Interpolated coordinates ("+x+","+y+"), Raw coordinates("+rx+","+ry+"), source size : "+size+")";
}
}

View File

@@ -53,36 +53,20 @@ public class Orientation {
public float getRoll() { public float getRoll() {
return roll; return roll;
} }
/**
* @param roll the roll to set
*/
public void setRoll(float roll) {
this.roll = roll;
}
/** /**
* @return the pitch * @return the pitch
*/ */
public float getPitch() { public float getPitch() {
return pitch; return pitch;
} }
/**
* @param pitch the pitch to set
*/
public void setPitch(float pitch) {
this.pitch = pitch;
}
/** /**
* @return the yaw * @return the yaw
*/ */
public float getYaw() { public float getYaw() {
return yaw; return yaw;
} }
/**
* @param yaw the yaw to set
*/
public void setYaw(float yaw) {
this.yaw = yaw;
}
@Override @Override
public String toString() { public String toString() {

View File

@@ -16,40 +16,60 @@
*/ */
package wiiusej.values; package wiiusej.values;
import java.awt.geom.Point2D;
/** /**
* Class used for IR sources. * Represents raw acceleration on each axis.
* @author guiguito * @author guiguito
*/ */
public class Point2DInteger extends Point2D { public class RawAcceleration {
private int x;
private int y;
public Point2DInteger(int xx, int yy) { private short x;
super(); private short y;
setLocation(xx,yy); private short z;
/**
* Default constructor;
*/
public RawAcceleration() {
x = 0;
y = 0;
z = 0;
} }
@Override /**
public double getX() { * Constructor with raw acceleration on each axis.
* @param xx x value
* @param yy x value
* @param zz x value
*/
public RawAcceleration(short xx, short yy, short zz) {
x = xx;
y = yy;
z = zz;
}
/**
* @return the x
*/
public short getX() {
return x; return x;
} }
/**
@Override * @return the y
public double getY() { */
public short getY() {
return y; return y;
} }
@Override /**
public void setLocation(double xx, double yy) { * @return the z
this.x = (int)xx; */
this.y = (int)yy; public short getZ() {
return z;
} }
@Override @Override
public String toString() { public String toString() {
return "("+x+","+y+")"; return "Raw acceleration : ("+x+", "+y+","+z+")";
} }
} }

View File

@@ -120,6 +120,9 @@ public class ButtonsEvent extends WiimoteEvent{
return buttonTest(buttonBitsDefinition, buttonsHeld); return buttonTest(buttonBitsDefinition, buttonsHeld);
} }
private boolean isButtonPressed(short buttonBitsDefinition) {
return isButtonHeld(buttonBitsDefinition)||isButtonJustPressed(buttonBitsDefinition);
}
/* Button ONE */ /* Button ONE */
public boolean isButtonOneJustPressed() { public boolean isButtonOneJustPressed() {
@@ -134,6 +137,10 @@ public class ButtonsEvent extends WiimoteEvent{
return isButtonHeld(WIIMOTE_BUTTON_ONE); return isButtonHeld(WIIMOTE_BUTTON_ONE);
} }
public boolean isButtonOnePressed() {
return isButtonPressed(WIIMOTE_BUTTON_ONE);
}
/* Button TWO */ /* Button TWO */
public boolean isButtonTwoJustPressed() { public boolean isButtonTwoJustPressed() {
@@ -148,6 +155,10 @@ public class ButtonsEvent extends WiimoteEvent{
return isButtonHeld(WIIMOTE_BUTTON_TWO); return isButtonHeld(WIIMOTE_BUTTON_TWO);
} }
public boolean isButtonTwoPressed() {
return isButtonPressed(WIIMOTE_BUTTON_TWO);
}
/* Button A */ /* Button A */
public boolean isButtonAJustPressed() { public boolean isButtonAJustPressed() {
@@ -162,6 +173,10 @@ public class ButtonsEvent extends WiimoteEvent{
return isButtonHeld(WIIMOTE_BUTTON_A); return isButtonHeld(WIIMOTE_BUTTON_A);
} }
public boolean isButtonAPressed() {
return isButtonPressed(WIIMOTE_BUTTON_A);
}
/* Button B */ /* Button B */
public boolean isButtonBJustPressed() { public boolean isButtonBJustPressed() {
@@ -176,6 +191,10 @@ public class ButtonsEvent extends WiimoteEvent{
return isButtonHeld(WIIMOTE_BUTTON_B); return isButtonHeld(WIIMOTE_BUTTON_B);
} }
public boolean isButtonBPressed() {
return isButtonPressed(WIIMOTE_BUTTON_B);
}
/* Button LEFT */ /* Button LEFT */
public boolean isButtonLeftJustPressed() { public boolean isButtonLeftJustPressed() {
@@ -190,6 +209,10 @@ public class ButtonsEvent extends WiimoteEvent{
return isButtonHeld(WIIMOTE_BUTTON_LEFT); return isButtonHeld(WIIMOTE_BUTTON_LEFT);
} }
public boolean isButtonLeftPressed() {
return isButtonPressed(WIIMOTE_BUTTON_LEFT);
}
/* Button RIGHT */ /* Button RIGHT */
public boolean isButtonRightJustPressed() { public boolean isButtonRightJustPressed() {
@@ -204,6 +227,10 @@ public class ButtonsEvent extends WiimoteEvent{
return isButtonHeld(WIIMOTE_BUTTON_RIGHT); return isButtonHeld(WIIMOTE_BUTTON_RIGHT);
} }
public boolean isButtonRightPressed() {
return isButtonPressed(WIIMOTE_BUTTON_RIGHT);
}
/* Button UP */ /* Button UP */
public boolean isButtonUpJustPressed() { public boolean isButtonUpJustPressed() {
@@ -218,6 +245,10 @@ public class ButtonsEvent extends WiimoteEvent{
return isButtonHeld(WIIMOTE_BUTTON_UP); return isButtonHeld(WIIMOTE_BUTTON_UP);
} }
public boolean isButtonUpPressed() {
return isButtonPressed(WIIMOTE_BUTTON_UP);
}
/* Button DOWN */ /* Button DOWN */
public boolean isButtonDownJustPressed() { public boolean isButtonDownJustPressed() {
@@ -232,6 +263,10 @@ public class ButtonsEvent extends WiimoteEvent{
return isButtonHeld(WIIMOTE_BUTTON_DOWN); return isButtonHeld(WIIMOTE_BUTTON_DOWN);
} }
public boolean isButtonDownPressed() {
return isButtonPressed(WIIMOTE_BUTTON_DOWN);
}
/* Button - */ /* Button - */
public boolean isButtonMinusJustPressed() { public boolean isButtonMinusJustPressed() {
@@ -246,6 +281,10 @@ public class ButtonsEvent extends WiimoteEvent{
return isButtonHeld(WIIMOTE_BUTTON_MINUS); return isButtonHeld(WIIMOTE_BUTTON_MINUS);
} }
public boolean isButtonMinusPressed() {
return isButtonPressed(WIIMOTE_BUTTON_MINUS);
}
/* Button + */ /* Button + */
public boolean isButtonPlusJustPressed() { public boolean isButtonPlusJustPressed() {
@@ -260,6 +299,10 @@ public class ButtonsEvent extends WiimoteEvent{
return isButtonHeld(WIIMOTE_BUTTON_PLUS); return isButtonHeld(WIIMOTE_BUTTON_PLUS);
} }
public boolean isButtonPlusPressed() {
return isButtonPressed(WIIMOTE_BUTTON_PLUS);
}
/* Button HOME */ /* Button HOME */
public boolean isButtonHomeJustPressed() { public boolean isButtonHomeJustPressed() {
@@ -274,6 +317,10 @@ public class ButtonsEvent extends WiimoteEvent{
return isButtonHeld(WIIMOTE_BUTTON_HOME); return isButtonHeld(WIIMOTE_BUTTON_HOME);
} }
public boolean isButtonHomePressed() {
return isButtonPressed(WIIMOTE_BUTTON_HOME);
}
@Override @Override
public String toString() { public String toString() {
String out = ""; String out = "";

View File

@@ -16,7 +16,6 @@
*/ */
package wiiusej.wiiuseapievents; package wiiusej.wiiuseapievents;
/** /**
* This class is used to gather events during a call to the Wiiuse API. * This class is used to gather events during a call to the Wiiuse API.
* *
@@ -67,6 +66,39 @@ public class EventsGatherer {
buttonsJustReleased, buttonsHeld); buttonsJustReleased, buttonsHeld);
} }
/**
* 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.
*/
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) {
genericEvent.prepareIRevent(x, y, z, ax, ay, xVRes,
yVRes, xOffset, yOffset, sensorBarPostion, screenAsPectRatio);
}
/** /**
* Add an IR point to the WiiMoteEvent prepared * Add an IR point to the WiiMoteEvent prepared
@@ -75,10 +107,17 @@ public class EventsGatherer {
* x coordinates * x coordinates
* @param y * @param y
* y coordinates * y coordinates
* @param rxx
* raw X coordinate (0-1023).
* @param ryy
* raw Y coordinate (0-1023).
* @param si
* size of the IR dot (0-15).
*/ */
public void addIRPointToPreparedWiiMoteEvent(int x, int y) { public void addIRPointToPreparedWiiMoteEvent(int x, int y, short rx,
short ry, short size) {
if (genericEvent != null) { if (genericEvent != null) {
genericEvent.addIRpoint(x, y); genericEvent.addIRpoint(x, y, rx, ry, size);
} }
} }
@@ -97,11 +136,17 @@ public class EventsGatherer {
* gravity force on y axis * gravity force on y axis
* @param z * @param z
* gravity force on z axis * 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 addMotionSensingValues(float r, float p, float ya, float x, public void addMotionSensingValues(float r, float p, float ya, float x,
float y, float z) { float y, float z, short xx, short yy, short zz) {
if (genericEvent != null) { if (genericEvent != null) {
genericEvent.setMotionSensingEvent(r, p, ya, x, y, z); genericEvent.setMotionSensingEvent(r, p, ya, x, y, z, xx, yy, zz);
} }
} }

View File

@@ -16,7 +16,6 @@
*/ */
package wiiusej.wiiuseapievents; package wiiusej.wiiuseapievents;
/** /**
* Class that is a bean to be filled by the wiiuse API. * Class that is a bean to be filled by the wiiuse API.
* *
@@ -77,6 +76,7 @@ public class GenericEvent extends WiiUseApiEvent {
/** /**
* Get buttons event. * Get buttons event.
*
* @return the buttons event. * @return the buttons event.
*/ */
public ButtonsEvent getButtonsEvent() { public ButtonsEvent getButtonsEvent() {
@@ -85,6 +85,7 @@ public class GenericEvent extends WiiUseApiEvent {
/** /**
* Get IR event. * Get IR event.
*
* @return the IR event if there is one or null. * @return the IR event if there is one or null.
*/ */
public IREvent getIREvent() { public IREvent getIREvent() {
@@ -93,6 +94,7 @@ public class GenericEvent extends WiiUseApiEvent {
/** /**
* Get motion sensing event. * Get motion sensing event.
*
* @return the motion sensing event if there is one or null. * @return the motion sensing event if there is one or null.
*/ */
public MotionSensingEvent getMotionSensingEvent() { public MotionSensingEvent getMotionSensingEvent() {
@@ -100,17 +102,59 @@ public class GenericEvent extends WiiUseApiEvent {
} }
/** /**
* Add an IR point to the generic event. * Prepare an IR event to populate.
* Create an IR Event if it's not created yet. *
* @param x x coordinates. * @param x
* @param y y coordinates * 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.
*/ */
public void addIRpoint(int x,int y){ public void prepareIRevent(int x, int y, int z, int ax, int ay, int xVRes,
//@TODO add points size int yVRes, int xOffset, int yOffset, short sensorBarPostion,
if (infraredEvent == null){ short screenAsPectRatio) {
infraredEvent = new IREvent(getWiimoteId()); if (infraredEvent == null) {
infraredEvent = new IREvent(getWiimoteId(), x, y, z, ax, ay, xVRes,
yVRes, xOffset, yOffset, sensorBarPostion,
screenAsPectRatio);
} }
infraredEvent.addIRpoint(x, y); }
/**
* 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 rxx
* raw X coordinate (0-1023).
* @param ryy
* raw Y coordinate (0-1023).
* @param si
* 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);
} }
/** /**
@@ -128,14 +172,19 @@ public class GenericEvent extends WiiUseApiEvent {
* gravity force on y axis * gravity force on y axis
* @param z * @param z
* gravity force on z axis * 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 r, float p, float ya, float x, float y, public void setMotionSensingEvent(float r, float p, float ya, float x,
float z){ float y, float z, short xx, short yy, short zz) {
motionSensingEvent = new MotionSensingEvent(getWiimoteId(), r, p, ya, x, y, z); motionSensingEvent = new MotionSensingEvent(getWiimoteId(), r, p, ya,
x, y, z, xx, yy, zz);
} }
@Override @Override
public String toString() { public String toString() {
String out = ""; String out = "";
@@ -147,14 +196,14 @@ public class GenericEvent extends WiiUseApiEvent {
if (infraredEvent != null) { if (infraredEvent != null) {
out += infraredEvent; out += infraredEvent;
}else{ } else {
out += "/******** IR Tracking ********/\n"; out += "/******** IR Tracking ********/\n";
out += "--- Active : false\n"; out += "--- Active : false\n";
} }
if (motionSensingEvent != null) { if (motionSensingEvent != null) {
out += motionSensingEvent; out += motionSensingEvent;
}else{ } else {
out += "/******** Motion sensing ********/\n"; out += "/******** Motion sensing ********/\n";
out += "--- Motion sensing : false \n"; out += "--- Motion sensing : false \n";
} }

View File

@@ -16,28 +16,81 @@
*/ */
package wiiusej.wiiuseapievents; package wiiusej.wiiuseapievents;
import wiiusej.values.Point2DInteger; import wiiusej.values.IRSource;
/** /**
* Class which represents an IR event. * Class which represents an IR event.
* *
* @author guiguito * @author guiguito
*/ */
public class IREvent extends WiimoteEvent{ public class IREvent extends WiimoteEvent {
/* IR Tracking */ /* IR Tracking */
private Point2DInteger[] IRPoints; private IRSource[] IRPoints;
private short indexPoints = 0; private short indexPoints = 0;
private int x;
private int y;
private int z;// distance from the sensor bar
private int ax;
private int ay;
private int xVRes;
private int yVRes;
private int xOffset;
private int yOffset;
private short sensorBarPostion;
private short screenAsPectRatio;
static private short WIIUSE_IR_ABOVE = 0;
static private short WIIUSE_IR_BELOW = 1;
static private short WIIUSE_SCREEN_RATIO_4_3 = 0;
static private short WIIUSE_SCREEN_RATIO_16_9 = 1;
private static short NB_POINTS = 4;// number of points IR can track private static short NB_POINTS = 4;// number of points IR can track
/** /**
* Constructor for an infrared event. * Constructor of IREvent with full infos.
* @param id id of the wiimote concerned. *
* @param id
* d of the wiimote concerned.
* @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.
*/ */
public IREvent(int id) { public IREvent(int id, int x, int y, int z, int ax, int ay, int xVRes,
int yVRes, int xOffset, int yOffset, short sensorBarPostion,
short screenAsPectRatio) {
super(id); super(id);
IRPoints = new Point2DInteger[NB_POINTS]; this.x = x;
this.y = y;
this.z = z;
this.ax = ax;
this.ay = ay;
this.xVRes = xVRes;
this.yVRes = yVRes;
this.xOffset = xOffset;
this.yOffset = yOffset;
this.sensorBarPostion = sensorBarPostion;
this.screenAsPectRatio = screenAsPectRatio;
IRPoints = new IRSource[NB_POINTS];
} }
/** /**
@@ -45,7 +98,7 @@ public class IREvent extends WiimoteEvent{
* *
* @return the list of 2D points * @return the list of 2D points
*/ */
public Point2DInteger[] getIRPoints() { public IRSource[] getIRPoints() {
return java.util.Arrays.copyOfRange(IRPoints, 0, indexPoints); return java.util.Arrays.copyOfRange(IRPoints, 0, indexPoints);
} }
@@ -56,19 +109,170 @@ public class IREvent extends WiimoteEvent{
* x value * x value
* @param y * @param y
* y value * y value
* @param rxx
* raw X coordinate (0-1023).
* @param ryy
* raw Y coordinate (0-1023).
* @param si
* size of the IR dot (0-15).
*/ */
public void addIRpoint(int x, int y) { public void addIRpoint(int x, int y, short rx, short ry, short size) {
IRPoints[indexPoints] = new Point2DInteger(x, y); IRPoints[indexPoints] = new IRSource(x, y, rx, ry, size);
indexPoints++; indexPoints++;
return; return;
} }
/**
* Return calculated X coordinate.
*
* @return the x
*/
public int getX() {
return x;
}
/**
* Return calculated Y coordinate.
*
* @return the y
*/
public int getY() {
return y;
}
/**
* Return calculated distance.
*
* @return the z
*/
public int getZ() {
return z;
}
/**
* Return absolute X coordinate.
*
* @return the ax
*/
public int getAx() {
return ax;
}
/**
* Return absolute Y coordinate.
*
* @return the ay
*/
public int getAy() {
return ay;
}
/**
* Return IR virtual screen x resolution.
*
* @return the xVRes
*/
public int getXVRes() {
return xVRes;
}
/**
* Return IR virtual screen y resolution.
*
* @return the yVRes
*/
public int getYVRes() {
return yVRes;
}
/**
* Return IR X correction offset.
*
* @return the xOffset
*/
public int getXOffset() {
return xOffset;
}
/**
* Return IR Y correction offset.
*
* @return the yOffset
*/
public int getYOffset() {
return yOffset;
}
/**
* Return true if the sensor bar is above.
*
* @return true if the sensor bar is above.
*/
public boolean isSensorBarAbove() {
return sensorBarPostion == WIIUSE_IR_ABOVE;
}
/**
* Return true if the sensor bar is below.
*
* @return true if the sensor bar is below.
*/
public boolean isSensorBarBelow() {
return sensorBarPostion == WIIUSE_IR_BELOW;
}
/**
* Return true if screen aspect ratio set is 4/3.
*
* @return true if screen aspect ratio set is 4/3.
*/
public boolean isScreenAspectRatio43() {
return screenAsPectRatio == WIIUSE_SCREEN_RATIO_4_3;
}
/**
* Return true if screen aspect ratio set is 16/9.
*
* @return true if screen aspect ratio set is 16/9.
*/
public boolean isScreenAspectRatio169() {
return screenAsPectRatio == WIIUSE_SCREEN_RATIO_16_9;
}
/**
* Return aspect ratio of the screen.
*
* @return the screenAsPectRatio
*/
public short getScreenAsPectRatio() {
return screenAsPectRatio;
}
@Override @Override
public String toString() { public String toString() {
String out = ""; String out = "";
/* Display IR Tracking */ /* Display IR Tracking */
out += "/******** IR Tracking ********/\n"; out += "/******** IR Tracking ********/\n";
out += "--- Active : true\n"; out += "--- Active : true\n";
out += "--- calculated X coordinate : " + x + "\n";
out += "--- calculated Y coordinate : " + y + "\n";
out += "--- calculated distance : " + z + "\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";
if (isScreenAspectRatio43()) {
out += "--- aspect ratio of the screen : 4/3\n";
} else if (isScreenAspectRatio169()) {
out += "--- aspect ratio of the screen : 16/9\n";
}
if (isSensorBarAbove()) {
out += "--- IR sensor bar position. : Above\n";
} else if (isSensorBarBelow()) {
out += "--- IR sensor bar position. : Below\n";
}
out += "--- Seen points\n"; out += "--- Seen points\n";
for (int i = 0; i < IRPoints.length; i++) { for (int i = 0; i < IRPoints.length; i++) {
if (IRPoints[i] != null) { if (IRPoints[i] != null) {
@@ -77,5 +281,4 @@ public class IREvent extends WiimoteEvent{
} }
return out; return out;
} }
} }

View File

@@ -18,6 +18,7 @@ package wiiusej.wiiuseapievents;
import wiiusej.values.GForce; import wiiusej.values.GForce;
import wiiusej.values.Orientation; import wiiusej.values.Orientation;
import wiiusej.values.RawAcceleration;
/** /**
* Class which represents a motion sensing event. * Class which represents a motion sensing event.
@@ -29,6 +30,7 @@ public class MotionSensingEvent extends WiimoteEvent{
/* Motion Sensing */ /* Motion Sensing */
private Orientation orientation; private Orientation orientation;
private GForce gforce; private GForce gforce;
private RawAcceleration acceleration;
/** /**
* Constructor for a Motion Sensing Event. * Constructor for a Motion Sensing Event.
@@ -47,15 +49,21 @@ public class MotionSensingEvent extends WiimoteEvent{
* gravity force on y axis * gravity force on y axis
* @param z * @param z
* gravity force on z axis * 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 MotionSensingEvent(int id, float r, float p, float ya, float x, float y, public MotionSensingEvent(int id, float r, float p, float ya, float x, float y,
float z) { float z, short xx, short yy, short zz) {
super(id); super(id);
setOrientationAndGforce(r, p, ya, x, y, z); setOrientationAndGforce(r, p, ya, x, y, z, xx, yy, zz);
} }
/** /**
* Set orientation and gravity force. * Set orientation, gravity force and raw acceleration.
* *
* @param r * @param r
* roll * roll
@@ -69,11 +77,18 @@ public class MotionSensingEvent extends WiimoteEvent{
* gravity force on y axis * gravity force on y axis
* @param z * @param z
* gravity force on z axis * 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
*/ */
private void setOrientationAndGforce(float r, float p, float ya, float x, private void setOrientationAndGforce(float r, float p, float ya, float x,
float y, float z) { float y, float z, short xx, short yy, short zz) {
this.orientation = new Orientation(r, p, ya); this.orientation = new Orientation(r, p, ya);
this.gforce = new GForce(x, y, z); this.gforce = new GForce(x, y, z);
this.acceleration = new RawAcceleration(xx, yy, zz);
} }
/** /**
@@ -92,6 +107,15 @@ public class MotionSensingEvent extends WiimoteEvent{
return gforce; return gforce;
} }
/**
* Get the raw acceleration.
*
* @return the raw acceleration
*/
public RawAcceleration getRawAcceleration() {
return acceleration;
}
@Override @Override
public String toString() { public String toString() {
String out = ""; String out = "";
@@ -100,6 +124,7 @@ public class MotionSensingEvent extends WiimoteEvent{
out += "--- Motion sensing : true \n"; out += "--- Motion sensing : true \n";
out += "--- " + orientation + "\n"; out += "--- " + orientation + "\n";
out += "--- " + gforce + "\n"; out += "--- " + gforce + "\n";
out += "--- " + acceleration + "\n";
return out; return out;
} }
} }

View File

@@ -154,6 +154,54 @@ public class StatusEvent extends WiiUseApiEvent {
return leds; return leds;
} }
/**
* Get led1 status.
* @return true if the led is set.
*/
public boolean isLed1Set(){
if ((leds & WIIMOTE_LED_1) > 0){
return true;
}else{
return false;
}
}
/**
* Get led2 status.
* @return true if the led is set.
*/
public boolean isLed2Set(){
if ((leds & WIIMOTE_LED_2) > 0){
return true;
}else{
return false;
}
}
/**
* Get led3 status.
* @return true if the led is set.
*/
public boolean isLed3Set(){
if ((leds & WIIMOTE_LED_3) > 0){
return true;
}else{
return false;
}
}
/**
* Get led4 status.
* @return true if the led is set.
*/
public boolean isLed4Set(){
if ((leds & WIIMOTE_LED_4) > 0){
return true;
}else{
return false;
}
}
/** /**
* Tell if the speaker is enable for this wiimote * Tell if the speaker is enable for this wiimote
* *

View File

@@ -26,6 +26,12 @@ public abstract class WiiUseApiEvent extends WiimoteEvent{
public static int GENERIC_EVENT = 1; public static int GENERIC_EVENT = 1;
public static int STATUS_EVENT = 2; public static int STATUS_EVENT = 2;
public static int DISCONNECTION_EVENT = 3; public static int DISCONNECTION_EVENT = 3;
public static int WIIUSE_NUNCHUK_INSERTED = 4;
public static int WIIUSE_NUNCHUK_REMOVED = 5;
public static int WIIUSE_CLASSIC_CTRL_INSERTED = 6;
public static int WIIUSE_CLASSIC_CTRL_REMOVED = 7;
public static int WIIUSE_GUITAR_HERO_3_CTRL_INSERTED = 8;
public static int WIIUSE_GUITAR_HERO_3_CTRL_REMOVED = 9;
/* Event Type */ /* Event Type */
private int eventType; private int eventType;

View File

@@ -26,7 +26,8 @@ public class IntValueRequest extends WiiUseApiRequest {
private int intValue; private int intValue;
/** /**
* Constructor setting the id of the wiimote concerned. * Constructor setting the id of the wiimote
* concerned and the type of the request.
* *
* @param id * @param id
* the id of the wiimote concerned. * the id of the wiimote concerned.
@@ -36,14 +37,16 @@ public class IntValueRequest extends WiiUseApiRequest {
} }
/** /**
* Constructor setting the id of the wiimote concerned. * Constructor setting the id of the wiimote
* concerned, the type of the request
* and the int value.
* *
* @param id * @param id
* the id of the wiimote concerned. * the id of the wiimote concerned.
* @param type * @param type
* type of the request * type of the request
* @param th * @param th
* threshold in degrees * the int value.
*/ */
public IntValueRequest(int id, int type, int th) { public IntValueRequest(int id, int type, int th) {
super(id, type); super(id, type);

View File

@@ -40,6 +40,11 @@ public class WiiUseApiRequest {
public static int WIIUSE_ACCEL_THRESHOLHD_REQUEST = 10; public static int WIIUSE_ACCEL_THRESHOLHD_REQUEST = 10;
public static int WIIUSE_ALPHA_SMOOTHING_REQUEST = 11; public static int WIIUSE_ALPHA_SMOOTHING_REQUEST = 11;
public static int WIIUSE_RESYNC = 12; public static int WIIUSE_RESYNC = 12;
public static int WIIUSE_ASPECT_RATIO_4_3 = 13;
public static int WIIUSE_ASPECT_RATIO_16_9 = 14;
public static int WIIUSE_SENSOR_BAR_ABOVE = 15;
public static int WIIUSE_SENSOR_BAR_BELOW = 16;
public static int WIIUSE_SET_VIRTUAL_RESOLUTION = 17;
private int wiimoteId = 0; private int wiimoteId = 0;
private int requestType = 0; private int requestType = 0;