diff --git a/WiiUseJ/libWiiuseJ.dll b/WiiUseJ/libWiiuseJ.dll index 604fa63..d1c51cc 100644 Binary files a/WiiUseJ/libWiiuseJ.dll and b/WiiUseJ/libWiiuseJ.dll differ diff --git a/WiiUseJ/src/wiiusej/WiiUseApi.java b/WiiUseJ/src/wiiusej/WiiUseApi.java index 4c580e1..cb91767 100644 --- a/WiiUseJ/src/wiiusej/WiiUseApi.java +++ b/WiiUseJ/src/wiiusej/WiiUseApi.java @@ -158,6 +158,40 @@ public class WiiUseApi { * @param id the id of the wiimote concerned */ 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. @@ -171,6 +205,8 @@ public class WiiUseApi { * * @param gath the object where we store all the new events. */ - native void specialPoll(EventsGatherer gath); + native void specialPoll(EventsGatherer gath); + + } diff --git a/WiiUseJ/src/wiiusej/WiiUseApiManager.java b/WiiUseJ/src/wiiusej/WiiUseApiManager.java index 1f5bb4c..35549cb 100644 --- a/WiiUseJ/src/wiiusej/WiiUseApiManager.java +++ b/WiiUseJ/src/wiiusej/WiiUseApiManager.java @@ -27,6 +27,7 @@ import wiiusej.wiiuseapievents.WiiUseApiListener; import wiiusej.wiiuseapirequest.FloatValueRequest; import wiiusej.wiiuseapirequest.IntValueRequest; import wiiusej.wiiuseapirequest.LedsRequest; +import wiiusej.wiiuseapirequest.TwoIntValueRequest; import wiiusej.wiiuseapirequest.WiiUseApiRequest; /** @@ -72,7 +73,7 @@ public class WiiUseApiManager extends Thread { manager.wiimotes = new Wiimote[nbWiimotes]; for (int i = 1; i <= nbWiimotes; i++) { Wiimote wim = new Wiimote(i, manager); - manager.wiimotes[i-1] = wim; + manager.wiimotes[i - 1] = wim; manager.addWiiUseApiListener(wim); } } @@ -113,9 +114,9 @@ public class WiiUseApiManager extends Thread { * @param id * id of the wiimote to disconnect. */ - public void closeConnection(int id) { - removeWiiUseApiListener(wiimotes[id-1]); - wiimotes[id-1] = null; + public void closeConnection(int id) { + removeWiiUseApiListener(wiimotes[id - 1]); + wiimotes[id - 1] = null; requests.add(new WiiUseApiRequest(id, WiiUseApiRequest.WIIUSE_CLOSE_CONNECTION_REQUEST)); 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. + * * @TODO not used yet !! * @param id * id of the wiimote @@ -316,6 +318,67 @@ public class WiiUseApiManager extends Thread { 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. * @@ -336,8 +399,8 @@ public class WiiUseApiManager extends Thread { EventsGatherer gather = new EventsGatherer(nbMaxWiimotes); // Start polling and tell the observers when there Wiimote events - while (running.get() && connected > 0) { - + while (running.get() && connected > 0) { + /* Polling */ wiiuse.specialPoll(gather); @@ -358,8 +421,8 @@ public class WiiUseApiManager extends Thread { } } gather.clearEvents(); - - /* deal with request done to wiiuse API*/ + + /* deal with request done to wiiuse API */ WiiUseApiRequest req = requests.poll(); if (req != null) {// there is a request for the wiiuse api int id = req.getId(); @@ -427,6 +490,23 @@ public class WiiUseApiManager extends Thread { } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_RESYNC) { /* set resync request */ 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 { System.out.println("Bad request to Wiiuse API !!!!!"); } diff --git a/WiiUseJ/src/wiiusej/Wiimote.java b/WiiUseJ/src/wiiusej/Wiimote.java index 0179f60..4108c70 100644 --- a/WiiUseJ/src/wiiusej/Wiimote.java +++ b/WiiUseJ/src/wiiusej/Wiimote.java @@ -170,9 +170,48 @@ public class Wiimote implements WiiUseApiListener { * @param th * threshold */ - public void setAlphaSmoothingValue(int th) { + public void setAlphaSmoothingValue(float 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 ? @@ -185,12 +224,21 @@ public class Wiimote implements WiiUseApiListener { manager.getStatus(id); } - + /** + * Method called when a WiiUseApiEvent occurs. + * @param e the WiiUseApiEvent. + */ public void onWiiUseApiEvent(WiiUseApiEvent e) { if (e.getWiimoteId() == id){ if (e.getEventType() == WiiUseApiEvent.GENERIC_EVENT){ 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); }else if (e.getEventType() == WiiUseApiEvent.DISCONNECTION_EVENT){ notifyDisconnectionEventListeners((DisconnectionEvent)e); diff --git a/WiiUseJ/src/wiiusej/test/Tests.java b/WiiUseJ/src/wiiusej/test/Tests.java index ded66b8..6926be0 100644 --- a/WiiUseJ/src/wiiusej/test/Tests.java +++ b/WiiUseJ/src/wiiusej/test/Tests.java @@ -22,7 +22,7 @@ import java.awt.event.InputEvent; import wiiusej.WiiUseApiManager; import wiiusej.Wiimote; -import wiiusej.values.Point2DInteger; +import wiiusej.values.IRSource; import wiiusej.wiiuseapievents.ButtonsEvent; import wiiusej.wiiuseapievents.DisconnectionEvent; import wiiusej.wiiuseapievents.IREvent; @@ -343,17 +343,11 @@ public class Tests implements WiimoteListener { public void onIrEvent(IREvent e) { if (dump == DISPLAY_EACH_VALUE) { - /* display ir points */ - 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() + ") "); - } + System.out.println(e); } else if (dump == DUMP) { System.out.println(e); } else if (dump == MOVE_MOUSE) { - Point2DInteger[] list = e.getIRPoints(); + IRSource[] list = e.getIRPoints(); if (list.length > 0) { int x1 = (int) list[0].getX(); int y1 = (int) list[0].getY(); diff --git a/WiiUseJ/src/wiiusej/values/GForce.java b/WiiUseJ/src/wiiusej/values/GForce.java index 144024e..9732121 100644 --- a/WiiUseJ/src/wiiusej/values/GForce.java +++ b/WiiUseJ/src/wiiusej/values/GForce.java @@ -54,13 +54,6 @@ public class GForce { return x; } - /** - * @param x the x to set - */ - public void setX(float x) { - this.x = x; - } - /** * @return the y */ @@ -68,26 +61,12 @@ public class GForce { return y; } - /** - * @param y the y to set - */ - public void setY(float y) { - this.y = y; - } - /** * @return the z */ public float getZ() { return z; } - - /** - * @param z the z to set - */ - public void setZ(float z) { - this.z = z; - } @Override public String toString() { diff --git a/WiiUseJ/src/wiiusej/values/IRSource.java b/WiiUseJ/src/wiiusej/values/IRSource.java new file mode 100644 index 0000000..7caef55 --- /dev/null +++ b/WiiUseJ/src/wiiusej/values/IRSource.java @@ -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 . + */ +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+")"; + } + +} diff --git a/WiiUseJ/src/wiiusej/values/Orientation.java b/WiiUseJ/src/wiiusej/values/Orientation.java index 7afe928..4c4f741 100644 --- a/WiiUseJ/src/wiiusej/values/Orientation.java +++ b/WiiUseJ/src/wiiusej/values/Orientation.java @@ -53,36 +53,20 @@ public class Orientation { public float getRoll() { return roll; } - /** - * @param roll the roll to set - */ - public void setRoll(float roll) { - this.roll = roll; - } + /** * @return the pitch */ public float getPitch() { return pitch; } - /** - * @param pitch the pitch to set - */ - public void setPitch(float pitch) { - this.pitch = pitch; - } + /** * @return the yaw */ public float getYaw() { return yaw; } - /** - * @param yaw the yaw to set - */ - public void setYaw(float yaw) { - this.yaw = yaw; - } @Override public String toString() { diff --git a/WiiUseJ/src/wiiusej/values/Point2DInteger.java b/WiiUseJ/src/wiiusej/values/RawAcceleration.java similarity index 53% rename from WiiUseJ/src/wiiusej/values/Point2DInteger.java rename to WiiUseJ/src/wiiusej/values/RawAcceleration.java index a717882..903a51c 100644 --- a/WiiUseJ/src/wiiusej/values/Point2DInteger.java +++ b/WiiUseJ/src/wiiusej/values/RawAcceleration.java @@ -16,40 +16,60 @@ */ package wiiusej.values; -import java.awt.geom.Point2D; - /** - * Class used for IR sources. + * Represents raw acceleration on each axis. * @author guiguito */ -public class Point2DInteger extends Point2D { - private int x; - private int y; +public class RawAcceleration { - public Point2DInteger(int xx, int yy) { - super(); - setLocation(xx,yy); + private short x; + private short y; + private short z; + + /** + * Default constructor; + */ + public RawAcceleration() { + x = 0; + y = 0; + z = 0; + } + + /** + * 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; } - @Override - public double getX() { + /** + * @return the x + */ + public short getX() { return x; } - - @Override - public double getY() { + /** + * @return the y + */ + public short getY() { return y; } - @Override - public void setLocation(double xx, double yy) { - this.x = (int)xx; - this.y = (int)yy; + /** + * @return the z + */ + public short getZ() { + return z; } @Override public String toString() { - return "("+x+","+y+")"; + return "Raw acceleration : ("+x+", "+y+","+z+")"; } } diff --git a/WiiUseJ/src/wiiusej/wiiuseapievents/ButtonsEvent.java b/WiiUseJ/src/wiiusej/wiiuseapievents/ButtonsEvent.java index b79818e..ce78551 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapievents/ButtonsEvent.java +++ b/WiiUseJ/src/wiiusej/wiiuseapievents/ButtonsEvent.java @@ -119,7 +119,10 @@ public class ButtonsEvent extends WiimoteEvent{ private boolean isButtonHeld(short buttonBitsDefinition) { return buttonTest(buttonBitsDefinition, buttonsHeld); } - + + private boolean isButtonPressed(short buttonBitsDefinition) { + return isButtonHeld(buttonBitsDefinition)||isButtonJustPressed(buttonBitsDefinition); + } /* Button ONE */ public boolean isButtonOneJustPressed() { @@ -133,6 +136,10 @@ public class ButtonsEvent extends WiimoteEvent{ public boolean isButtonOneHeld() { return isButtonHeld(WIIMOTE_BUTTON_ONE); } + + public boolean isButtonOnePressed() { + return isButtonPressed(WIIMOTE_BUTTON_ONE); + } /* Button TWO */ @@ -147,6 +154,10 @@ public class ButtonsEvent extends WiimoteEvent{ public boolean isButtonTwoHeld() { return isButtonHeld(WIIMOTE_BUTTON_TWO); } + + public boolean isButtonTwoPressed() { + return isButtonPressed(WIIMOTE_BUTTON_TWO); + } /* Button A */ @@ -161,6 +172,10 @@ public class ButtonsEvent extends WiimoteEvent{ public boolean isButtonAHeld() { return isButtonHeld(WIIMOTE_BUTTON_A); } + + public boolean isButtonAPressed() { + return isButtonPressed(WIIMOTE_BUTTON_A); + } /* Button B */ @@ -175,6 +190,10 @@ public class ButtonsEvent extends WiimoteEvent{ public boolean isButtonBHeld() { return isButtonHeld(WIIMOTE_BUTTON_B); } + + public boolean isButtonBPressed() { + return isButtonPressed(WIIMOTE_BUTTON_B); + } /* Button LEFT */ @@ -189,6 +208,10 @@ public class ButtonsEvent extends WiimoteEvent{ public boolean isButtonLeftHeld() { return isButtonHeld(WIIMOTE_BUTTON_LEFT); } + + public boolean isButtonLeftPressed() { + return isButtonPressed(WIIMOTE_BUTTON_LEFT); + } /* Button RIGHT */ @@ -203,6 +226,10 @@ public class ButtonsEvent extends WiimoteEvent{ public boolean isButtonRightHeld() { return isButtonHeld(WIIMOTE_BUTTON_RIGHT); } + + public boolean isButtonRightPressed() { + return isButtonPressed(WIIMOTE_BUTTON_RIGHT); + } /* Button UP */ @@ -217,6 +244,10 @@ public class ButtonsEvent extends WiimoteEvent{ public boolean isButtonUpHeld() { return isButtonHeld(WIIMOTE_BUTTON_UP); } + + public boolean isButtonUpPressed() { + return isButtonPressed(WIIMOTE_BUTTON_UP); + } /* Button DOWN */ @@ -231,6 +262,10 @@ public class ButtonsEvent extends WiimoteEvent{ public boolean isButtonDownHeld() { return isButtonHeld(WIIMOTE_BUTTON_DOWN); } + + public boolean isButtonDownPressed() { + return isButtonPressed(WIIMOTE_BUTTON_DOWN); + } /* Button - */ @@ -245,6 +280,10 @@ public class ButtonsEvent extends WiimoteEvent{ public boolean isButtonMinusHeld() { return isButtonHeld(WIIMOTE_BUTTON_MINUS); } + + public boolean isButtonMinusPressed() { + return isButtonPressed(WIIMOTE_BUTTON_MINUS); + } /* Button + */ @@ -259,6 +298,10 @@ public class ButtonsEvent extends WiimoteEvent{ public boolean isButtonPlusHeld() { return isButtonHeld(WIIMOTE_BUTTON_PLUS); } + + public boolean isButtonPlusPressed() { + return isButtonPressed(WIIMOTE_BUTTON_PLUS); + } /* Button HOME */ @@ -274,6 +317,10 @@ public class ButtonsEvent extends WiimoteEvent{ return isButtonHeld(WIIMOTE_BUTTON_HOME); } + public boolean isButtonHomePressed() { + return isButtonPressed(WIIMOTE_BUTTON_HOME); + } + @Override public String toString() { String out = ""; diff --git a/WiiUseJ/src/wiiusej/wiiuseapievents/EventsGatherer.java b/WiiUseJ/src/wiiusej/wiiuseapievents/EventsGatherer.java index 5014901..7fcb57c 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapievents/EventsGatherer.java +++ b/WiiUseJ/src/wiiusej/wiiuseapievents/EventsGatherer.java @@ -16,7 +16,6 @@ */ package wiiusej.wiiuseapievents; - /** * This class is used to gather events during a call to the Wiiuse API. * @@ -44,7 +43,7 @@ public class EventsGatherer { * @param e * the event to add. */ - private void addEvent(WiiUseApiEvent e) { + private void addEvent(WiiUseApiEvent e) { events[index] = e; index++; } @@ -67,6 +66,39 @@ public class EventsGatherer { 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 @@ -75,13 +107,20 @@ public class EventsGatherer { * 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 addIRPointToPreparedWiiMoteEvent(int x, int y) { - if (genericEvent != null) { - genericEvent.addIRpoint(x, y); + public void addIRPointToPreparedWiiMoteEvent(int x, int y, short rx, + short ry, short size) { + if (genericEvent != null) { + genericEvent.addIRpoint(x, y, rx, ry, size); } } - + /** * Set orientation and gravity force of the prepared event. * @@ -97,11 +136,17 @@ public class EventsGatherer { * 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 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) { - genericEvent.setMotionSensingEvent(r, p, ya, x, y, z); + genericEvent.setMotionSensingEvent(r, p, ya, x, y, z, xx, yy, zz); } } diff --git a/WiiUseJ/src/wiiusej/wiiuseapievents/GenericEvent.java b/WiiUseJ/src/wiiusej/wiiuseapievents/GenericEvent.java index f534ff0..0671ff8 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapievents/GenericEvent.java +++ b/WiiUseJ/src/wiiusej/wiiuseapievents/GenericEvent.java @@ -16,7 +16,6 @@ */ package wiiusej.wiiuseapievents; - /** * Class that is a bean to be filled by the wiiuse API. * @@ -77,6 +76,7 @@ public class GenericEvent extends WiiUseApiEvent { /** * Get buttons event. + * * @return the buttons event. */ public ButtonsEvent getButtonsEvent() { @@ -85,6 +85,7 @@ public class GenericEvent extends WiiUseApiEvent { /** * Get IR event. + * * @return the IR event if there is one or null. */ public IREvent getIREvent() { @@ -93,6 +94,7 @@ public class GenericEvent extends WiiUseApiEvent { /** * Get motion sensing event. + * * @return the motion sensing event if there is one or null. */ public MotionSensingEvent getMotionSensingEvent() { @@ -100,19 +102,61 @@ public class GenericEvent extends WiiUseApiEvent { } /** - * 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 + * 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 addIRpoint(int x,int y){ - //@TODO add points size - if (infraredEvent == null){ - infraredEvent = new IREvent(getWiimoteId()); + 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) { + 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); + } + /** * Set the Motion Sensing Event. * @@ -128,13 +172,18 @@ public class GenericEvent extends WiiUseApiEvent { * 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 r, float p, float ya, float x, float y, - float z){ - motionSensingEvent = new MotionSensingEvent(getWiimoteId(), r, p, ya, x, y, z); + public void setMotionSensingEvent(float r, float p, float ya, float x, + float y, float z, short xx, short yy, short zz) { + motionSensingEvent = new MotionSensingEvent(getWiimoteId(), r, p, ya, + x, y, z, xx, yy, zz); } - - @Override public String toString() { @@ -147,19 +196,19 @@ public class GenericEvent extends WiiUseApiEvent { if (infraredEvent != null) { out += infraredEvent; - }else{ + } else { out += "/******** IR Tracking ********/\n"; out += "--- Active : false\n"; } if (motionSensingEvent != null) { out += motionSensingEvent; - }else{ + } else { out += "/******** Motion sensing ********/\n"; out += "--- Motion sensing : false \n"; } return out; } - + } diff --git a/WiiUseJ/src/wiiusej/wiiuseapievents/IREvent.java b/WiiUseJ/src/wiiusej/wiiuseapievents/IREvent.java index 568fb4e..9950327 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapievents/IREvent.java +++ b/WiiUseJ/src/wiiusej/wiiuseapievents/IREvent.java @@ -16,28 +16,81 @@ */ package wiiusej.wiiuseapievents; -import wiiusej.values.Point2DInteger; +import wiiusej.values.IRSource; /** * Class which represents an IR event. * * @author guiguito */ -public class IREvent extends WiimoteEvent{ +public class IREvent extends WiimoteEvent { /* IR Tracking */ - private Point2DInteger[] IRPoints; + private IRSource[] IRPoints; 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 - + /** - * Constructor for an infrared event. - * @param id id of the wiimote concerned. + * Constructor of IREvent with full infos. + * + * @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); - 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 */ - public Point2DInteger[] getIRPoints() { + public IRSource[] getIRPoints() { return java.util.Arrays.copyOfRange(IRPoints, 0, indexPoints); } @@ -56,19 +109,170 @@ public class IREvent extends WiimoteEvent{ * x value * @param y * 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) { - IRPoints[indexPoints] = new Point2DInteger(x, y); + public void addIRpoint(int x, int y, short rx, short ry, short size) { + IRPoints[indexPoints] = new IRSource(x, y, rx, ry, size); indexPoints++; 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 public String toString() { String out = ""; /* Display IR Tracking */ out += "/******** IR Tracking ********/\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"; for (int i = 0; i < IRPoints.length; i++) { if (IRPoints[i] != null) { @@ -77,5 +281,4 @@ public class IREvent extends WiimoteEvent{ } return out; } - } diff --git a/WiiUseJ/src/wiiusej/wiiuseapievents/MotionSensingEvent.java b/WiiUseJ/src/wiiusej/wiiuseapievents/MotionSensingEvent.java index 305c346..c15127d 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapievents/MotionSensingEvent.java +++ b/WiiUseJ/src/wiiusej/wiiuseapievents/MotionSensingEvent.java @@ -18,6 +18,7 @@ package wiiusej.wiiuseapievents; import wiiusej.values.GForce; import wiiusej.values.Orientation; +import wiiusej.values.RawAcceleration; /** * Class which represents a motion sensing event. @@ -29,6 +30,7 @@ public class MotionSensingEvent extends WiimoteEvent{ /* Motion Sensing */ private Orientation orientation; private GForce gforce; + private RawAcceleration acceleration; /** * Constructor for a Motion Sensing Event. @@ -47,15 +49,21 @@ public class MotionSensingEvent extends WiimoteEvent{ * 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 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); - 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 * roll @@ -69,11 +77,18 @@ public class MotionSensingEvent extends WiimoteEvent{ * 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 */ 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.gforce = new GForce(x, y, z); + this.acceleration = new RawAcceleration(xx, yy, zz); } /** @@ -91,6 +106,15 @@ public class MotionSensingEvent extends WiimoteEvent{ public GForce getGforce() { return gforce; } + + /** + * Get the raw acceleration. + * + * @return the raw acceleration + */ + public RawAcceleration getRawAcceleration() { + return acceleration; + } @Override public String toString() { @@ -100,6 +124,7 @@ public class MotionSensingEvent extends WiimoteEvent{ out += "--- Motion sensing : true \n"; out += "--- " + orientation + "\n"; out += "--- " + gforce + "\n"; + out += "--- " + acceleration + "\n"; return out; } } diff --git a/WiiUseJ/src/wiiusej/wiiuseapievents/StatusEvent.java b/WiiUseJ/src/wiiusej/wiiuseapievents/StatusEvent.java index e45410c..7367ced 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapievents/StatusEvent.java +++ b/WiiUseJ/src/wiiusej/wiiuseapievents/StatusEvent.java @@ -153,6 +153,54 @@ public class StatusEvent extends WiiUseApiEvent { public short getLeds() { 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 diff --git a/WiiUseJ/src/wiiusej/wiiuseapievents/WiiUseApiEvent.java b/WiiUseJ/src/wiiusej/wiiuseapievents/WiiUseApiEvent.java index 4c5b032..880c632 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapievents/WiiUseApiEvent.java +++ b/WiiUseJ/src/wiiusej/wiiuseapievents/WiiUseApiEvent.java @@ -25,7 +25,13 @@ public abstract class WiiUseApiEvent extends WiimoteEvent{ public static int GENERIC_EVENT = 1; 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 */ private int eventType; diff --git a/WiiUseJ/src/wiiusej/wiiuseapirequest/IntValueRequest.java b/WiiUseJ/src/wiiusej/wiiuseapirequest/IntValueRequest.java index b2a9a14..801093d 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapirequest/IntValueRequest.java +++ b/WiiUseJ/src/wiiusej/wiiuseapirequest/IntValueRequest.java @@ -26,7 +26,8 @@ public class IntValueRequest extends WiiUseApiRequest { 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 * 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 * the id of the wiimote concerned. * @param type * type of the request * @param th - * threshold in degrees + * the int value. */ public IntValueRequest(int id, int type, int th) { super(id, type); diff --git a/WiiUseJ/src/wiiusej/wiiuseapirequest/WiiUseApiRequest.java b/WiiUseJ/src/wiiusej/wiiuseapirequest/WiiUseApiRequest.java index 679213f..1f4525b 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapirequest/WiiUseApiRequest.java +++ b/WiiUseJ/src/wiiusej/wiiuseapirequest/WiiUseApiRequest.java @@ -40,6 +40,11 @@ public class WiiUseApiRequest { public static int WIIUSE_ACCEL_THRESHOLHD_REQUEST = 10; public static int WIIUSE_ALPHA_SMOOTHING_REQUEST = 11; 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 requestType = 0;