diff --git a/WiiUseJ_0.12/.classpath b/WiiUseJ_0.12/.classpath
new file mode 100644
index 0000000..d171cd4
--- /dev/null
+++ b/WiiUseJ_0.12/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/WiiUseJ_0.12/.project b/WiiUseJ_0.12/.project
new file mode 100644
index 0000000..9485f4a
--- /dev/null
+++ b/WiiUseJ_0.12/.project
@@ -0,0 +1,17 @@
+
+
+ WiiUseJava
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/WiiUseJ_0.12/.settings/org.eclipse.jdt.ui.prefs b/WiiUseJ_0.12/.settings/org.eclipse.jdt.ui.prefs
new file mode 100644
index 0000000..81f7b8f
--- /dev/null
+++ b/WiiUseJ_0.12/.settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,3 @@
+#Thu May 08 01:25:43 CEST 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.ui.text.custom_code_templates=/**\r\n * @return the ${bare_field_name}\r\n *//**\r\n * @param ${param} the ${bare_field_name} to set\r\n *//**\r\n * ${tags}\r\n *//**\r\n * This file is part of WiiuseJ.\r\n *\r\n * WiiuseJ is free software\: you can redistribute it and/or modify\r\n * it under the terms of the GNU General Public License as published by\r\n * the Free Software Foundation, either version 3 of the License, or\r\n * (at your option) any later version.\r\n *\r\n * WiiuseJ is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r\n * GNU General Public License for more details.\r\n *\r\n * You should have received a copy of the GNU General Public License\r\n * along with WiiuseJ. If not, see <http\://www.gnu.org/licenses/>.\r\n *//**\r\n *\r\n * @author ${user}\r\n * ${tags}\r\n *//**\r\n * \r\n *//**\r\n * ${tags}\r\n *//* (non-Javadoc)\r\n * ${see_to_overridden}\r\n *//**\r\n * ${tags}\r\n * ${see_to_target}\r\n */${filecomment}\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}\r\n\r\n\r\n\r\n// ${todo} Auto-generated catch block\r\n${exception_var}.printStackTrace();// ${todo} Auto-generated method stub\r\n${body_statement}${body_statement}\r\n// ${todo} Auto-generated constructor stubreturn ${field};${field} \= ${param};
diff --git a/WiiUseJ_0.12/README.TXT b/WiiUseJ_0.12/README.TXT
new file mode 100644
index 0000000..ba8e176
--- /dev/null
+++ b/WiiUseJ_0.12/README.TXT
@@ -0,0 +1,56 @@
+/**
+ * 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 .
+ */
+
+
+WiiuseJ is a java API to use wiimotes on your computer. This API is built on top of an excellent API call Wiiuse using JNI.
+
+WiiuseJ intent to be a very simple, easy to use and lightweight java API for wiimotes.
+
+Some of the great aspects of this API are :
+
+ * The compatibility which is as large as Wiiuse's API compatibility
+
+ * Cross-platform : Windows and linux (like Wiiuse)
+
+ * Easy to use
+
+
+WiiuseJ is made by Guilhem Duché : guiguito1@hotmail.com.
+You can contact me if you need more information.
+
+Go to : http://wiiusej.googlecode.com/ for further documentations.
+
+
+
+CHANGELOG :
+
+wiiusej 0.12 :
+- added nunchuk support.
+- all new stuffs from wiiuse 0.12.
+- added timeout method.
+- added IR sensitivity.
+- updated to be able to reconnect wiimotes.
+- new architecture behind the scene.
+- cleaning of the project.
+
+wiiusej 0.11 :
+- updated with new stuffs from wiiuse 0.11.
+- Linux version.
+- selectionnable rumble on wiimotes connection.
+
+wiiusej 0.1 :
+- first version on wiiuse 0.1.
\ No newline at end of file
diff --git a/WiiUseJ_0.12/WiiUseJ.dll b/WiiUseJ_0.12/WiiUseJ.dll
new file mode 100644
index 0000000..aeebf07
Binary files /dev/null and b/WiiUseJ_0.12/WiiUseJ.dll differ
diff --git a/WiiUseJ_0.12/img/wiimote.png b/WiiUseJ_0.12/img/wiimote.png
new file mode 100644
index 0000000..3f26f52
Binary files /dev/null and b/WiiUseJ_0.12/img/wiimote.png differ
diff --git a/WiiUseJ_0.12/libWiiuseJ.so b/WiiUseJ_0.12/libWiiuseJ.so
new file mode 100644
index 0000000..0caea08
Binary files /dev/null and b/WiiUseJ_0.12/libWiiuseJ.so differ
diff --git a/WiiUseJ_0.12/libwiiuse.so b/WiiUseJ_0.12/libwiiuse.so
new file mode 100644
index 0000000..481e0e2
Binary files /dev/null and b/WiiUseJ_0.12/libwiiuse.so differ
diff --git a/WiiUseJ_0.12/src/img/wiimote.png b/WiiUseJ_0.12/src/img/wiimote.png
new file mode 100644
index 0000000..3f26f52
Binary files /dev/null and b/WiiUseJ_0.12/src/img/wiimote.png differ
diff --git a/WiiUseJ_0.12/src/wiiusej/WiiUseApi.java b/WiiUseJ_0.12/src/wiiusej/WiiUseApi.java
new file mode 100644
index 0000000..428f522
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/WiiUseApi.java
@@ -0,0 +1,351 @@
+/**
+ * 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;
+
+import wiiusej.wiiusejevents.utils.EventsGatherer;
+
+/**
+ * Singleton used to manipulate WiiUse Api.
+ *
+ * @author guiguito
+ */
+public class WiiUseApi {
+
+ static {
+ System.loadLibrary("WiiuseJ");
+ }
+
+ private static WiiUseApi instance = new WiiUseApi();
+
+ /**
+ * Get the only instance of WiiUseApi.
+ *
+ * @return the only instace of WiiUseApi.
+ */
+ protected static WiiUseApi getInstance() {
+ return instance;
+ }
+
+ /**
+ * Connect to a wiimote or wiimotes once an address is known.
+ *
+ * @param nbWiimotes
+ * The number of wiimotes.
+ * @return The number of wiimotes that successfully connected.
+ */
+ synchronized native int connect(int nbWiimotes);
+
+ /**
+ * Find a wiimote or wiimotes.
+ *
+ * @param nbMaxWiimotes
+ * The number of wiimotes.
+ * @param timeout
+ * The number of seconds before the search times out.
+ * @return The number of wiimotes found.
+ */
+ synchronized native int find(int nbMaxWiimotes, int timeout);
+
+ /**
+ * Initialize an array of wiimote structures (for the C side of the
+ * library).
+ *
+ * @param nbPossibleWiimotes
+ * size of the array.
+ */
+ synchronized native void init(int nbPossibleWiimotes);
+
+ /**
+ * Close connection to the wiimote with the given id.
+ *
+ */
+ synchronized native void closeConnection(int id);
+
+ /**
+ * Get unique id of a wiimote in the wiimotes array. Please make sure you
+ * call an existing index with a wiimote initialized at this index, other
+ * wise you'll get a wrong value.
+ *
+ * @param index
+ * index of the wiimote in the wiimotes array.
+ * @return the unid of the wiimote, or a wrong value if the index was false.
+ *
+ */
+ synchronized native int getUnId(int index);
+
+ /**
+ * CleanUp Wiiuse API.
+ */
+ synchronized native void cleanUp();
+
+ /**
+ * Activate rumble on the wiimote with the given id.
+ *
+ * @param id
+ * the id of the wiimote.
+ */
+ synchronized native void activateRumble(int id);
+
+ /**
+ * Deactivate rumble on the wiimote with the given id.
+ *
+ * @param id
+ * the id of the wiimote.
+ */
+ synchronized native void deactivateRumble(int id);
+
+ /**
+ * Activate IR Tracking on the wiimote with the given id.
+ *
+ * @param id
+ * the id of the wiimote.
+ */
+ synchronized native void activateIRTracking(int id);
+
+ /**
+ * Deactivate IR Tracking on the wiimote with the given id.
+ *
+ * @param id
+ * the id of the wiimote.
+ */
+ synchronized native void deactivateIRTracking(int id);
+
+ /**
+ * Activate motion sensing on the wiimote with the given id.
+ *
+ * @param id
+ * the id of the wiimote.
+ */
+ synchronized native void activateMotionSensing(int id);
+
+ /**
+ * Deactivate motion sensing on the wiimote with the given id.
+ *
+ * @param id
+ * the id of the wiimote.
+ */
+ synchronized native void deactivateMotionSensing(int id);
+
+ /**
+ * Set wiimote leds status.
+ *
+ * @param id
+ * the id of the wiimote concerned.
+ * @param led1
+ * status of led1: True=ON, False=OFF.
+ * @param led2
+ * status of led2: True=ON, False=OFF.
+ * @param led3
+ * status of led3: True=ON, False=OFF.
+ * @param led4
+ * status of led4: True=ON, False=OFF.
+ */
+ synchronized native void setLeds(int id, boolean led1, boolean led2,
+ boolean led3, boolean led4);
+
+ /**
+ * Set how many degrees an angle must change to generate an event.
+ *
+ * @param id
+ * id of the wiimote concerned.
+ * @param angle
+ * minimum angle detected by an event.
+ */
+ synchronized native void setOrientThreshold(int id, float angle);
+
+ /**
+ * Set how much acceleration must change to generate an event.
+ *
+ * @param id
+ * id of the wiimote concerned.
+ * @param value
+ * minimum value detected by an event.
+ */
+ synchronized native void setAccelThreshold(int id, int value);
+
+ /**
+ * Set alpha smoothing parameter for the given id.
+ *
+ * @param id
+ * id of the wiimote concerned.
+ * @param value
+ * alpha smoothing value.
+ */
+ synchronized native void setAlphaSmoothing(int id, float value);
+
+ /**
+ * Try to resync with the wiimote by starting a new handshake.
+ *
+ * @param id
+ * id of the wiimote concerned.
+ */
+ synchronized native void reSync(int id);
+
+ /**
+ * Make the the accelerometers give smoother results. This is set by
+ * default.
+ *
+ * @param id
+ * the id of the wiimote concerned.
+ */
+ synchronized native void activateSmoothing(int id);
+
+ /**
+ * Make the the accelerometers give raw results.
+ *
+ * @param id
+ * the id of the wiimote concerned.
+ */
+ synchronized native void deactivateSmoothing(int id);
+
+ /**
+ * Make the wiimote generate an event each time we poll. Not set by default.
+ *
+ * @param id
+ * the id of the wiimote concerned.
+ */
+ synchronized native void activateContinuous(int id);
+
+ /**
+ * Make the wiimote generate an event only when there is one.
+ *
+ * @param id
+ * the id of the wiimote concerned.
+ */
+ synchronized 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.
+ */
+ synchronized 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.
+ */
+ synchronized 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.
+ */
+ synchronized 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.
+ */
+ synchronized 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.
+ */
+ synchronized native void setVirtualScreenResolution(int id, int x, int y);
+
+ /**
+ * Get status and values from the wiimotes and send it through callbacks.
+ *
+ * @param id
+ * the id of the wiimote of which we want the status.
+ */
+ synchronized native void getStatus(int id);
+
+ /**
+ * Set the normal and expansion handshake timeouts.
+ *
+ * @param id
+ * the id of the wiimote concerned.
+ * @param normalTimeout
+ * The timeout in milliseconds for a normal read.
+ * @param expansionTimeout
+ * The timeout in millisecondsd to wait for an expansion
+ * handshake.
+ */
+ synchronized native void setTimeout(int id, short normalTimeout,
+ short expansionTimeout);
+
+ /**
+ * Set the IR sensitivity.
+ *
+ * @param id
+ * the id of the wiimote concerned.
+ * @param level
+ * 1-5, same as Wii system sensitivity setting. If the level is <
+ * 1, then level will be set to 1. If the level is > 5, then
+ * level will be set to 5.
+ */
+ synchronized native void setIrSensitivity(int id, int level);
+
+ /**
+ * Set how many degrees an angle must change to generate an event for the
+ * nunchuk.
+ *
+ * @param id
+ * id of the wiimote concerned.
+ * @param angle
+ * minimum angle detected by an event.
+ */
+ synchronized native void setNunchukOrientationThreshold(int id, float angle);
+
+ /**
+ * Set how much acceleration must change to generate an event for the
+ * nunchuk.
+ *
+ * @param id
+ * id of the wiimote concerned.
+ * @param value
+ * minimum value detected by an event.
+ */
+ synchronized native void setNunchukAccelerationThreshold(int id, int value);
+
+ /**
+ * Force the bluetooth stack type.(useful only for windows)
+ *
+ * @param bluetoothStackType
+ * must be WiiUseApi.WIIUSE_STACK_UNKNOWN or
+ * WiiUseApi.WIIUSE_STACK_MS or
+ * WiiUseApi.WIIUSE_STACK_BLUESOLEIL.
+ */
+ native void windowsSetBluetoothStack(int bluetoothStackType);
+
+ /**
+ * Check for new Events and Get it.
+ *
+ * @param gath
+ * the object where we store all the new events.
+ */
+ native void specialPoll(EventsGatherer gath);
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/WiiUseApiManager.java b/WiiUseJ_0.12/src/wiiusej/WiiUseApiManager.java
new file mode 100644
index 0000000..9378660
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/WiiUseApiManager.java
@@ -0,0 +1,662 @@
+/**
+ * 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;
+
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.swing.event.EventListenerList;
+
+import wiiusej.wiiusejevents.utils.EventsGatherer;
+import wiiusej.wiiusejevents.utils.WiiUseApiListener;
+import wiiusej.wiiusejevents.wiiuseapievents.WiiUseApiEvent;
+
+/**
+ * Class that manages the use of Wiiuse API.
+ *
+ * @author guiguito
+ */
+public class WiiUseApiManager extends Thread {
+
+ private static WiiUseApiManager instance = new WiiUseApiManager();
+
+ private final EventListenerList listeners = new EventListenerList();
+
+ private Semaphore semaphore = new Semaphore(0);
+
+ private Wiimote[] wiimotes;
+
+ private WiiUseApi wiiuse = WiiUseApi.getInstance();
+
+ private int connected = -1;
+
+ private AtomicBoolean running = new AtomicBoolean(false);
+
+ private boolean leave = false;
+
+ public static int WIIUSE_STACK_UNKNOWN = 0;
+ public static int WIIUSE_STACK_MS = 1;
+ public static int WIIUSE_STACK_BLUESOLEIL = 2;
+
+ private static WiiUseApiManager getInstance() {
+ return instance;
+ }
+
+ /**
+ * Get wiimotes. Load library if necessary. Connect to wiimotes if
+ * necessary. Start polling if necessary. Return an array with the connected
+ * wiimotes.
+ *
+ * @param nb
+ * try to connect nb wiimotes.
+ * @param rumble
+ * make the connected wiimotes rumble.
+ *
+ * @return an array with connected wiimotes or NULL.
+ */
+ public static Wiimote[] getWiimotes(int nb, boolean rumble) {
+ return getWiimotesPrivate(nb, rumble, false, WIIUSE_STACK_UNKNOWN);
+ }
+
+ /**
+ * Get wiimotes. Load library if necessary. Connect to wiimotes if
+ * necessary. Start polling if necessary. Return an array with the connected
+ * wiimotes.
+ *
+ * @param nb
+ * try to connect nb wiimotes.
+ * @param rumble
+ * make the connected wiimotes rumble.*
+ * @param stackType
+ * the stack type : WiiUseApiManager.WIIUSE_STACK_UNKNOWN or
+ * WiiUseApiManager.WIIUSE_STACK_MS or
+ * WiiUseApiManager.WIIUSE_STACK_BLUESOLEIL
+ *
+ * @return an array with connected wiimotes or NULL.
+ */
+ public static Wiimote[] getWiimotes(int nb, boolean rumble, int stackType) {
+ return getWiimotesPrivate(nb, rumble, true, stackType);
+ }
+
+ /**
+ * Get wiimotes. Load library if necessary. Connect to wiimotes if
+ * necessary. Start polling if necessary. Return an array with the connected
+ * wiimotes.
+ *
+ * @param nb
+ * try to connect nb wiimotes.
+ * @param rumble
+ * make the connected wiimotes rumble.*
+ * @param forceStackType
+ * true if we want to force the stack type.
+ * @param stackType
+ * the stack type : WiiUseApiManager.WIIUSE_STACK_UNKNOWN or
+ * WiiUseApiManager.WIIUSE_STACK_MS or
+ * WiiUseApiManager.WIIUSE_STACK_BLUESOLEIL
+ *
+ * @return an array with connected wiimotes or NULL.
+ */
+ private synchronized static Wiimote[] getWiimotesPrivate(int nb,
+ boolean rumble, boolean forceStackType, int stackType) {
+ WiiUseApiManager manager = getInstance();
+
+ if (manager.leave)
+ return null;// wiiusej definitively stopped
+
+ if (manager.connected <= 0 && !manager.running.get()) {
+ // connect wiimotes.
+ int nbWiimotes = manager.connectWiimotes(nb, rumble,
+ forceStackType, stackType);
+ manager.wiimotes = new Wiimote[nbWiimotes];
+ for (int i = 0; i < nbWiimotes; i++) {
+ Wiimote wim = new Wiimote(WiiUseApi.getInstance().getUnId(i),
+ manager);
+ manager.wiimotes[i] = wim;
+ manager.addWiiUseApiListener(wim);
+ }
+ // Set leds on wiimote
+ for (Wiimote wiimote : manager.wiimotes) {
+ int id = wiimote.getId();
+ if (id % 4 == 0) {
+ wiimote.setLeds(true, true, true, true);
+ } else if (id % 4 == 1) {
+ wiimote.setLeds(true, false, false, false);
+ } else if (id % 4 == 2) {
+ wiimote.setLeds(true, true, false, false);
+ } else if (id % 4 == 3) {
+ wiimote.setLeds(true, true, true, false);
+ }
+ }
+ // make the connected wiimotes rumble
+ if (rumble) {
+ for (Wiimote wiimote : manager.wiimotes) {
+ wiimote.activateRumble();
+ }
+ try {
+ sleep(500);
+ } catch (InterruptedException e) {
+ }
+ for (Wiimote wiimote : manager.wiimotes) {
+ wiimote.deactivateRumble();
+ }
+ }
+ }
+
+ if (manager.connected == 0) {// no wiimote connected
+ // return empty array
+ return new Wiimote[0];
+ }
+
+ if (!manager.isAlive())// start wiiuseJ polling
+ manager.start();
+
+ manager.semaphore.release(1);
+
+ return manager.wiimotes;
+ }
+
+ /**
+ * Connect wiimote and get the number of wiimotes connected. Supposed to be
+ * used once.
+ *
+ * @param nb
+ * try to connect nb wiimotes
+ * @param rumble
+ * make the connected wiimotes rumble
+ * @param forceStackType
+ * true if we want to force the stack type.
+ * @param stackType
+ * the stack type : WiiUseApiManager.WIIUSE_STACK_UNKNOWN or
+ * WiiUseApiManager.WIIUSE_STACK_MS or
+ * WiiUseApiManager.WIIUSE_STACK_BLUESOLEIL
+ * @return 0 if nothing connected or the number of wiimotes connected.
+ */
+ private int connectWiimotes(int nb, boolean rumble, boolean forceStackType,
+ int stackType) {
+ if (connected <= 0) {
+ int nbWiimotesFound;
+ wiiuse.init(nb);
+ // force bluetooth stack type ?
+ if (forceStackType)
+ setBlueToothstackType(stackType);
+ nbWiimotesFound = wiiuse.find(nb, 3);
+ connected = wiiuse.connect(nbWiimotesFound);
+ return connected;
+ } else {// library not loaded, no wiimotes connected
+ return 0;
+ }
+ }
+
+ /**
+ * Ask the thread to close a connection.
+ *
+ * @param id
+ * id of the wiimote to disconnect.
+ */
+ protected void closeConnection(int id) {
+ int index = 0;
+ boolean found = false;
+ while (index < wiimotes.length && !found) {
+ if (wiimotes[index].getId() == id) {// we have a wiimote with this
+ // id
+ // remove the wiimote
+ removeWiiUseApiListener(wiimotes[index]);
+ wiimotes[index] = null;
+ connected--;
+ if (connected == 0) {// stop this thread if there is
+ // no more wiimotes connected.
+ // stop thread
+ running.set(false);
+ }
+ /* Close connection in wiiuse */
+ wiiuse.closeConnection(index);
+ }
+ index++;
+ }
+
+ }
+
+ /**
+ * Get the number of wiimotes connected.
+ *
+ * @return the number of wiimotes connected.
+ */
+ public static int getNbConnectedWiimotes() {
+ return getInstance().connected;
+ }
+
+ /**
+ * Stop thread and shutdown wiiuse Api.
+ */
+ public static void shutdown() {
+ WiiUseApiManager manager = getInstance();
+ if (manager.connected > 0) {
+ for (Wiimote wim : manager.wiimotes) {
+ if (wim != null)
+ wim.disconnect();
+ }
+ }
+ manager.running.set(false);
+ manager.wiiuse.cleanUp();
+ }
+
+ /**
+ * Stop wiiuseJ definitively for this program. It finishes Wiiusej thread
+ * and shutdown wiiuse API.
+ */
+ public static void definitiveShutdown() {
+ getInstance().leave = true;
+ shutdown();
+ }
+
+ /**
+ * Activate the rumble for the wiimote with the given id.
+ *
+ * @param id
+ * id of the wiimote.
+ */
+ protected void activateRumble(int id) {
+ wiiuse.activateRumble(id);
+ }
+
+ /**
+ * Deactivate the rumble for the wiimote with the given id.
+ *
+ * @param id
+ * id of the wiimote.
+ */
+ protected void deactivateRumble(int id) {
+ wiiuse.deactivateRumble(id);
+ }
+
+ /**
+ * Activate IR Tracking for the wiimote with the given id.
+ *
+ * @param id
+ * id of the wiimote.
+ */
+ protected void activateIRTRacking(int id) {
+ wiiuse.activateIRTracking(id);
+ }
+
+ /**
+ * Deactivate IR Tracking for the wiimote with the given id.
+ *
+ * @param id
+ * id of the wiimote.
+ */
+ protected void deactivateIRTRacking(int id) {
+ wiiuse.deactivateIRTracking(id);
+ }
+
+ /**
+ * Activate motion sensing for the wiimote with the given id.
+ *
+ * @param id
+ * id of the wiimote.
+ */
+ protected void activateMotionSensing(int id) {
+ wiiuse.activateMotionSensing(id);
+ }
+
+ /**
+ * Deactivate motion sensing for the wiimoter with the given id.
+ *
+ * @param id
+ * id of the wiimote.
+ */
+ protected void deactivateMotionSensing(int id) {
+ wiiuse.deactivateMotionSensing(id);
+ }
+
+ /**
+ * Activate smoothing the wiimotes with the given id.
+ *
+ * @param id
+ * id of the wiimote.
+ */
+ protected void activateSmoothing(int id) {
+ wiiuse.activateSmoothing(id);
+ }
+
+ /**
+ * Deactivate smoothing the wiimotes with the given id.
+ *
+ * @param id
+ * id of the wiimote.
+ */
+ protected void deactivateSmoothing(int id) {
+ wiiuse.deactivateSmoothing(id);
+ }
+
+ /**
+ * Activate continuous for the wiimotes with the given id.
+ *
+ * @param id
+ * id of the wiimote.
+ */
+ protected void activateContinuous(int id) {
+ wiiuse.activateContinuous(id);
+ }
+
+ /**
+ * Deactivate continuous for the wiimotes with the given id.
+ *
+ * @param id
+ * id of the wiimote.
+ */
+ protected void deactivateContinuous(int id) {
+ wiiuse.deactivateContinuous(id);
+ }
+
+ /**
+ * Set leds for the wiimotes with the given id.
+ *
+ * @param id
+ * id of the wiimote
+ * @param l1
+ * status of led1. True : ON, False : OFF.
+ * @param l2
+ * status of led2. True : ON, False : OFF.
+ * @param l3
+ * status of led3. True : ON, False : OFF.
+ * @param l4
+ * status of led4. True : ON, False : OFF.
+ */
+ protected void setLeds(int id, boolean l1, boolean l2, boolean l3,
+ boolean l4) {
+ wiiuse.setLeds(id, l1, l2, l3, l4);
+ }
+
+ /**
+ * Set the orientation threshold for the given id. (minimum angle between
+ * two events)
+ *
+ * @param id
+ * id of the wiimote.
+ * @param th
+ * threshold in degrees.
+ */
+ protected void setOrientationThreshold(int id, float th) {
+ wiiuse.setOrientThreshold(id, th);
+ }
+
+ /**
+ * Set the acceleration threshold for the given id. (minimum angle between
+ * two events)
+ *
+ * @param id
+ * id of the wiimote.
+ * @param th
+ * threshold.
+ */
+ protected void setAccelerationThreshold(int id, int th) {
+ wiiuse.setAccelThreshold(id, th);
+ }
+
+ /**
+ * Set alpha smoothing for the given id.
+ *
+ * @param id
+ * id of the wiimote.
+ * @param th
+ * threshold.
+ */
+ protected void setAlphaSmoothing(int id, float th) {
+ wiiuse.setAlphaSmoothing(id, th);
+ }
+
+ /**
+ * Try to resync with the wiimote by starting a new handshake.
+ *
+ * @param id
+ * id of the wiimote.
+ */
+ protected void reSync(int id) {
+ wiiuse.reSync(id);
+ }
+
+ /**
+ * Set screen aspect ratio to 4/3 for the given id.
+ *
+ * @param id
+ * id of the wiimote.
+ */
+ protected void setScreenAspectRatio43(int id) {
+ wiiuse.setScreenRatio43(id);
+ }
+
+ /**
+ * Set screen aspect ratio to 16/9 for the given id.
+ *
+ * @param id
+ * id of the wiimote.
+ */
+ protected void setScreenAspectRatio169(int id) {
+ wiiuse.setScreenRatio169(id);
+ }
+
+ /**
+ * Set the sensor bar to be above the screen.
+ *
+ * @param id
+ * id of the wiimote.
+ */
+ protected void setSensorBarAboveScreen(int id) {
+ wiiuse.setSensorBarAboveScreen(id);
+ }
+
+ /**
+ * Set the sensor bar to be below the screen.
+ *
+ * @param id
+ * id of the wiimote.
+ */
+ protected void setSensorBarBelowScreen(int id) {
+ wiiuse.setSensorBarBelowScreen(id);
+ }
+
+ /**
+ * 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.
+ */
+ protected void setVirtualResolution(int id, int x, int y) {
+ wiiuse.setVirtualScreenResolution(id, x, y);
+ }
+
+ /**
+ * Get Status for the wiimote for the given id.
+ *
+ * @param id
+ * id of the wiimote.
+ */
+ protected void getStatus(int id) {
+ wiiuse.getStatus(id);
+ }
+
+ /**
+ * Set the normal and expansion handshake timeouts.
+ *
+ * @param id
+ * the id of the wiimote concerned.
+ * @param normalTimeout
+ * The timeout in milliseconds for a normal read.
+ * @param expansionTimeout
+ * The timeout in millisecondsd to wait for an expansion
+ * handshake.
+ */
+ protected void setTimeout(int id, short normalTimeout,
+ short expansionTimeout) {
+ wiiuse.setTimeout(id, normalTimeout, expansionTimeout);
+ }
+
+ /**
+ * Set the IR sensitivity.
+ *
+ * @param id
+ * the id of the wiimote concerned.
+ * @param level
+ * 1-5, same as Wii system sensitivity setting. If the level is <
+ * 1, then level will be set to 1. If the level is > 5, then
+ * level will be set to 5.
+ */
+ protected void setIrSensitivity(int id, int level) {
+ wiiuse.setIrSensitivity(id, level);
+ }
+
+ /**
+ * Set the nunchuk orientation threshold for the given id. (minimum angle
+ * between two events)
+ *
+ * @param id
+ * id of the wiimote.
+ * @param th
+ * threshold in degrees.
+ */
+ protected void setNunchukOrientationThreshold(int id, float th) {
+ wiiuse.setNunchukOrientationThreshold(id, th);
+ }
+
+ /**
+ * Set the nunchuk acceleration threshold for the given id. (minimum angle
+ * between two events)
+ *
+ * @param id
+ * id of the wiimote.
+ * @param th
+ * threshold.
+ */
+ protected void setNunchukAccelerationThreshold(int id, int th) {
+ wiiuse.setNunchukAccelerationThreshold(id, th);
+ }
+
+ /**
+ * Force the bluetooth stack type.(useful only for windows)
+ *
+ * @param type
+ * must be WIIUSE_STACK_UNKNOWN or WIIUSE_STACK_MS or
+ * WIIUSE_STACK_BLUESOLEIL.
+ */
+ private void setBlueToothstackType(int type) {
+ wiiuse.windowsSetBluetoothStack(type);
+ }
+
+ @Override
+ public void run() {
+
+ while (!leave) {
+ try {
+ semaphore.acquire();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ if (connected > 0) {
+ running.set(true);
+
+ EventsGatherer gather = new EventsGatherer(connected);
+
+ // Start polling and tell the observers when there are Wiimote
+ // events
+ while (running.get() && connected > 0) {
+
+ /* Polling */
+ wiiuse.specialPoll(gather);
+
+ /* deal with events gathered in Wiiuse API */
+ for (WiiUseApiEvent evt : gather.getEvents()) {
+ if (evt.getWiimoteId() != -1) {// event filled
+ // there is an event notify observers
+ notifyWiiUseApiListener(evt);
+ if (evt.getEventType() == WiiUseApiEvent.DISCONNECTION_EVENT) {
+ // check if it was a disconnection
+ // in this case disconnect the wiimote
+ closeConnection(evt.getWiimoteId());
+ }
+ } else {
+ System.out
+ .println("There is an event with id == -1 ??? there is a problem !!! : "
+ + evt);
+ }
+ }
+ gather.clearEvents();
+ }
+ }/* else {
+ if (connected <= 0) {
+ System.out.println("No wiimotes connected !");
+ }
+ }*/
+ }// end while true
+ }
+
+ /**
+ * Add WiiUseApiListener to the listeners list.
+ *
+ * @param listener
+ * a WiiUseApiListener
+ */
+ protected void addWiiUseApiListener(WiiUseApiListener listener) {
+ listeners.add(WiiUseApiListener.class, listener);
+ }
+
+ /**
+ * Remove WiiUseApiListener from the listeners list.
+ *
+ * @param listener
+ * a WiiUseApiListener
+ */
+ protected void removeWiiUseApiListener(WiiUseApiListener listener) {
+ listeners.remove(WiiUseApiListener.class, listener);
+ }
+
+ /**
+ * Get the list of WiiUseApiListeners.
+ *
+ * @return the list of WiiUseApiListeners.
+ */
+ protected WiiUseApiListener[] getWiiUseApiListeners() {
+ return listeners.getListeners(WiiUseApiListener.class);
+ }
+
+ /**
+ * Notify WiiUseApiListeners that an event occured.
+ *
+ * @param evt
+ * GenericEvent occured
+ */
+ private void notifyWiiUseApiListener(WiiUseApiEvent evt) {
+ for (WiiUseApiListener listener : getWiiUseApiListeners()) {
+ listener.onWiiUseApiEvent(evt);
+ }
+ }
+
+ /**
+ * Called by the garbage collector at the end.
+ */
+ protected void finalize() throws Throwable {
+ shutdown();
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/Wiimote.java b/WiiUseJ_0.12/src/wiiusej/Wiimote.java
new file mode 100644
index 0000000..98a5233
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/Wiimote.java
@@ -0,0 +1,435 @@
+/**
+ * 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;
+
+import javax.swing.event.EventListenerList;
+
+import wiiusej.wiiusejevents.utils.WiiUseApiListener;
+import wiiusej.wiiusejevents.utils.WiimoteListener;
+import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.WiiUseApiEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.WiimoteEvent;
+
+/**
+ * Class that represents a wiimote. You can register as an observer of this
+ * wiimote to listen events from it. You manage it.
+ *
+ * @author guiguito
+ */
+public class Wiimote implements WiiUseApiListener {
+
+ private int id = -1;// wiimote id
+
+ private EventListenerList listeners = new EventListenerList();
+
+ private WiiUseApiManager manager;
+
+ /**
+ * Constructor.
+ *
+ * @param idd
+ * id of the wiimote
+ * @param manager
+ * manager wo built it.
+ */
+ public Wiimote(int idd, WiiUseApiManager manager) {
+ id = idd;
+ this.manager = manager;
+ }
+
+ /**
+ * Get the unique id of the wiimote.
+ *
+ * @return the id
+ */
+ public int getId() {
+ return id;
+ }
+
+ /**
+ * Disconnect this wiimote.
+ */
+ public void disconnect() {
+ deactivateIRTRacking();
+ deactivateMotionSensing();
+ deactivateRumble();
+ manager.closeConnection(id);
+ }
+
+ /**
+ * Activate the rumble.
+ */
+ public void activateRumble() {
+ manager.activateRumble(id);
+ }
+
+ /**
+ * Deactivate the rumble.
+ */
+ public void deactivateRumble() {
+ manager.deactivateRumble(id);
+ }
+
+ /**
+ * Activate IR Tracking.
+ */
+ public void activateIRTRacking() {
+ manager.activateIRTRacking(id);
+ }
+
+ /**
+ * Deactivate IR Tracking.
+ */
+ public void deactivateIRTRacking() {
+ manager.deactivateIRTRacking(id);
+ }
+
+ /**
+ * Activate motion sensing.
+ */
+ public void activateMotionSensing() {
+ manager.activateMotionSensing(id);
+ }
+
+ /**
+ * Deactivate motion sensing.
+ */
+ public void deactivateMotionSensing() {
+ manager.deactivateMotionSensing(id);
+ }
+
+ /**
+ * Activate smoothing.
+ */
+ public void activateSmoothing() {
+ manager.activateSmoothing(id);
+ }
+
+ /**
+ * Deactivate smoothing.
+ */
+ public void deactivateSmoothing() {
+ manager.deactivateSmoothing(id);
+ }
+
+ /**
+ * Activate continuous.
+ */
+ public void activateContinuous() {
+ manager.activateContinuous(id);
+ }
+
+ /**
+ * Deactivate continuous.
+ */
+ public void deactivateContinuous() {
+ manager.deactivateContinuous(id);
+
+ }
+
+ /**
+ * Set leds status.
+ *
+ * @param l1
+ * status of led1. True : ON, False : OFF
+ * @param l2
+ * status of led2. True : ON, False : OFF
+ * @param l3
+ * status of led3. True : ON, False : OFF
+ * @param l4
+ * status of led4. True : ON, False : OFF
+ */
+ public void setLeds(boolean l1, boolean l2, boolean l3, boolean l4) {
+ manager.setLeds(id, l1, l2, l3, l4);
+ }
+
+ /**
+ * Set the orientation threshold (minimum angle between two degrees with
+ * accelerometer).
+ *
+ * @param th
+ * threshold in degrees
+ */
+ public void setOrientationThreshold(float th) {
+ manager.setOrientationThreshold(id, th);
+ }
+
+ /**
+ * Set the acceleration threshold(minimum angle between two degrees with
+ * accelerometer).
+ *
+ * @param th
+ * threshold
+ */
+ public void setAccelerationThreshold(int th) {
+ manager.setAccelerationThreshold(id, th);
+ }
+
+ /**
+ * Set the alpha smoothing value.
+ *
+ * @param th
+ * threshold
+ */
+ 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);
+ }
+
+ /**
+ * Set the nunchuk orientation threshold for the given id. (minimum angle
+ * between two events)
+ *
+ * @param th
+ * threshold in degrees.
+ */
+ public void setNunchukOrientationThreshold(float th) {
+ manager.setNunchukOrientationThreshold(id, th);
+ }
+
+ /**
+ * Set the nunchuk acceleration threshold for the given id. (minimum angle
+ * between two events)
+ *
+ * @param th
+ * threshold.
+ */
+ public void setNunchukAccelerationThreshold(int th) {
+ manager.setNunchukAccelerationThreshold(id, th);
+ }
+
+ /**
+ * Try to resync the wiimote by starting a new handshake.
+ */
+ public void reSync() {
+ manager.reSync(id);
+ }
+
+ /**
+ * Ask for the status of the wiimote. The result will be received in a
+ * status event object. Implements onStatusEvent on wiimote listener to get
+ * it.
+ */
+ public void getStatus() {
+ manager.getStatus(id);
+ }
+
+ /**
+ * Set the normal and expansion handshake timeouts for this wiimote. Normal
+ * time out is for classic polling. The expansion timeout is used when an
+ * expansion is detected until the expansion successfully handshakes.
+ *
+ * @param normalTimeout
+ * The timeout in milliseconds for a normal read.
+ * @param expansionTimeout
+ * The timeout in millisecondsd to wait for an expansion
+ * handshake.
+ */
+ public void setTimeout(short normalTimeout, short expansionTimeout) {
+ manager.setTimeout(id, normalTimeout, expansionTimeout);
+ }
+
+ /**
+ * Set the IR sensitivity.
+ *
+ * @param level
+ * 1-5, same as Wii system sensitivity setting. If the level is <
+ * 1, then level will be set to 1. If the level is > 5, then
+ * level will be set to 5.
+ */
+ public void setIrSensitivity(int level) {
+ manager.setIrSensitivity(id, level);
+ }
+
+ /**
+ * 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((WiimoteEvent) e);
+ } else if (e.getEventType() == WiiUseApiEvent.STATUS_EVENT) {
+ notifyStatusEventListeners((StatusEvent) e);
+ } else if (e.getEventType() == WiiUseApiEvent.DISCONNECTION_EVENT) {
+ notifyDisconnectionEventListeners((DisconnectionEvent) e);
+ } else if (e.getEventType() == WiiUseApiEvent.WIIUSE_NUNCHUK_INSERTED) {
+ notifyNunchukInsertedEventListeners((NunchukInsertedEvent) e);
+ } else if (e.getEventType() == WiiUseApiEvent.WIIUSE_NUNCHUK_REMOVED) {
+ notifyNunchukRemovedEventListeners((NunchukRemovedEvent) e);
+ }
+ /*
+ * events not managed yet || e.getEventType() == WIIUSE_READ_DATA
+ * 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
+ */
+ }
+ }
+
+ /**
+ * Add a WiimoteListener to the listeners list.
+ *
+ * @param listener
+ * a WiimoteListener
+ */
+ public void addWiiMoteEventListeners(WiimoteListener listener) {
+ listeners.add(WiimoteListener.class, listener);
+ }
+
+ /**
+ * Remove a WiimoteListener from the listeners list.
+ *
+ * @param listener
+ * a WiimoteListener
+ */
+ public void removeWiiMoteEventListeners(WiimoteListener listener) {
+ listeners.remove(WiimoteListener.class, listener);
+ }
+
+ /**
+ * Get the list of WiimoteListener.
+ *
+ * @return the list of WiimoteListener.
+ */
+ public WiimoteListener[] getWiiMoteEventListeners() {
+ return listeners.getListeners(WiimoteListener.class);
+ }
+
+ /**
+ * Notify WiimoteListeners that an event occured. Notify in first the
+ * listeners for Buttons Events. In second the listeners for IR Events. In
+ * third the listeners for Motion sensing events.
+ *
+ * @param evt
+ * GenericEvent occured
+ */
+ private void notifyWiiMoteEventListeners(WiimoteEvent evt) {
+ for (WiimoteListener listener : getWiiMoteEventListeners()) {
+ listener.onButtonsEvent(evt.getButtonsEvent());
+ if (evt.isThereIrEvent()) {
+ listener.onIrEvent(evt.getIREvent());
+ }
+ if (evt.isThereMotionSensingEvent()) {
+ listener.onMotionSensingEvent(evt.getMotionSensingEvent());
+ }
+ if (evt.isThereExpansionEvent()) {
+ listener.onExpansionEvent(evt.getExpansionEvent());
+ }
+ }
+ }
+
+ /**
+ * Notify WiimoteListener that a status event occured.
+ *
+ * @param evt
+ * status event occured
+ */
+ private void notifyStatusEventListeners(StatusEvent evt) {
+ for (WiimoteListener listener : getWiiMoteEventListeners()) {
+ listener.onStatusEvent(evt);
+ }
+ }
+
+ /**
+ * Notify WiimoteListener that a disconnection event occured.
+ *
+ * @param evt
+ * disconnection event occured
+ */
+ private void notifyDisconnectionEventListeners(DisconnectionEvent evt) {
+ for (WiimoteListener listener : getWiiMoteEventListeners()) {
+ listener.onDisconnectionEvent(evt);
+ }
+ }
+
+ /**
+ * Notify WiimoteListener that a NunchukInserted Event occured.
+ *
+ * @param evt
+ * NunchukInserted Event occured
+ */
+ private void notifyNunchukInsertedEventListeners(NunchukInsertedEvent evt) {
+ for (WiimoteListener listener : getWiiMoteEventListeners()) {
+ listener.onNunchukInsertedEvent(evt);
+ }
+ }
+
+ /**
+ * Notify WiimoteListener that a NunchukRemoved Event occured.
+ *
+ * @param evt
+ * NunchukRemoved Event occured
+ */
+ private void notifyNunchukRemovedEventListeners(NunchukRemovedEvent evt) {
+ for (WiimoteListener listener : getWiiMoteEventListeners()) {
+ listener.onNunchukRemovedEvent(evt);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "Wiimote with ID : " + id;
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/test/CloseGuiTestCleanly.java b/WiiUseJ_0.12/src/wiiusej/test/CloseGuiTestCleanly.java
new file mode 100644
index 0000000..584f2d9
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/test/CloseGuiTestCleanly.java
@@ -0,0 +1,58 @@
+/**
+ * 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.test;
+
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowListener;
+import wiiusej.WiiUseApiManager;
+
+/**
+ * This class is used to close wiiusej cleanly.
+ *
+ * @author guiguito
+ */
+public class CloseGuiTestCleanly implements WindowListener {
+
+ public void windowOpened(WindowEvent e) {
+ // nothing
+ }
+
+ public void windowClosing(WindowEvent e) {
+ WiiUseApiManager.definitiveShutdown();
+ }
+
+ public void windowClosed(WindowEvent e) {
+ // nothing
+ }
+
+ public void windowIconified(WindowEvent e) {
+ // nothing
+ }
+
+ public void windowDeiconified(WindowEvent e) {
+ // nothing
+ }
+
+ public void windowActivated(WindowEvent e) {
+ // nothing
+ }
+
+ public void windowDeactivated(WindowEvent e) {
+ // nothing
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/test/Main.java b/WiiUseJ_0.12/src/wiiusej/test/Main.java
new file mode 100644
index 0000000..67ef279
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/test/Main.java
@@ -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 .
+ */
+package wiiusej.test;
+
+import wiiusej.WiiUseApiManager;
+import wiiusej.Wiimote;
+
+/**
+ * Main Class to launch WiiuseJ GUI Test.
+ *
+ * @author guiguito
+ */
+public class Main {
+
+ /**
+ * @param args
+ * the command line arguments
+ */
+ public static void main(String[] args) {
+ Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1, true);
+ WiiuseJGuiTest gui = null;
+ if (wiimotes.length > 0) {
+ gui = new WiiuseJGuiTest(wiimotes[0]);
+ } else {
+ gui = new WiiuseJGuiTest();
+ }
+ gui.setDefaultCloseOperation(WiiuseJGuiTest.EXIT_ON_CLOSE);
+ gui.setVisible(true);
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/test/NunchukGuiTest.java b/WiiUseJ_0.12/src/wiiusej/test/NunchukGuiTest.java
new file mode 100644
index 0000000..7054de8
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/test/NunchukGuiTest.java
@@ -0,0 +1,377 @@
+/**
+ * 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.test;
+
+import wiiusej.Wiimote;
+import wiiusej.utils.AccelerationExpansionEventPanel;
+import wiiusej.utils.AccelerationPanel;
+import wiiusej.utils.GForceExpansionEventPanel;
+import wiiusej.utils.GForcePanel;
+import wiiusej.utils.NunchukJoystickEventPanel;
+import wiiusej.utils.OrientationExpansionEventPanel;
+import wiiusej.utils.OrientationPanel;
+import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
+import wiiusej.wiiusejevents.physicalevents.IREvent;
+import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
+import wiiusej.wiiusejevents.physicalevents.NunchukButtonsEvent;
+import wiiusej.wiiusejevents.physicalevents.NunchukEvent;
+import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
+import wiiusej.wiiusejevents.utils.WiimoteListener;
+import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
+
+/**
+ * This frame is used to display events from a nunchuk.
+ *
+ * @author guiguito
+ */
+public class NunchukGuiTest extends javax.swing.JFrame implements
+ WiimoteListener {
+
+ private Wiimote wiimote;
+ private boolean isThresholdsRequested = true;
+
+ /** Creates new form NunchukGuiTest */
+ public NunchukGuiTest(Wiimote wiimote) {
+ initComponents();
+ this.wiimote = wiimote;
+ registerListeners();
+ }
+
+ private void registerListeners() {
+ wiimote.addWiiMoteEventListeners(this);
+ wiimote.addWiiMoteEventListeners((OrientationPanel) orientationPanel);
+ wiimote.addWiiMoteEventListeners((GForcePanel) gForcePanel);
+ wiimote
+ .addWiiMoteEventListeners((AccelerationPanel) rawAccelerationPanel);
+ wiimote
+ .addWiiMoteEventListeners((NunchukJoystickEventPanel) joystickEventsPanel);
+ }
+
+ public void unRegisterListeners() {
+ wiimote
+ .removeWiiMoteEventListeners((OrientationPanel) orientationPanel);
+ wiimote.removeWiiMoteEventListeners((GForcePanel) gForcePanel);
+ wiimote
+ .removeWiiMoteEventListeners((AccelerationPanel) rawAccelerationPanel);
+ wiimote
+ .removeWiiMoteEventListeners((NunchukJoystickEventPanel) joystickEventsPanel);
+ wiimote.removeWiiMoteEventListeners(this);
+ }
+
+ public void requestThresholdsUpdate() {
+ isThresholdsRequested = true;
+ }
+
+ /**
+ * This method is called from within the constructor to initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is always
+ * regenerated by the Form Editor.
+ */
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ topPanels = new javax.swing.JPanel();
+ joystickEventsPanel = joystickEventsPanel = new NunchukJoystickEventPanel();
+ motionSensingEventsPanel = new javax.swing.JPanel();
+ motionSensingEventsTabbedPanels = new javax.swing.JTabbedPane();
+ rawAccelerationPanel = new AccelerationExpansionEventPanel();
+ orientationPanel = new OrientationExpansionEventPanel();
+ gForcePanel = new GForceExpansionEventPanel();
+ setNunchukValuesPanel = new javax.swing.JPanel();
+ nunchukButtonsEventPanel = new javax.swing.JPanel();
+ cButton = new javax.swing.JButton();
+ zButton = new javax.swing.JButton();
+ nunchukOrientationPanel = new javax.swing.JPanel();
+ nunchukOrientationTextField = new javax.swing.JTextField();
+ nunchukOrientationButton = new javax.swing.JButton();
+ nunchukAccelerationPanel = new javax.swing.JPanel();
+ nunchukAccelerationTextField = new javax.swing.JTextField();
+ nunchukAccelerationButton = new javax.swing.JButton();
+ messagePanel = new javax.swing.JPanel();
+ messageText = new javax.swing.JLabel();
+
+ setTitle("WiiuseJ Nunchuk Test GUI");
+ setMinimumSize(new java.awt.Dimension(400, 400));
+ getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.Y_AXIS));
+
+ topPanels.setMinimumSize(new java.awt.Dimension(400, 200));
+ topPanels.setPreferredSize(new java.awt.Dimension(400, 200));
+ topPanels.setLayout(new javax.swing.BoxLayout(topPanels, javax.swing.BoxLayout.LINE_AXIS));
+
+ joystickEventsPanel.setBackground(new java.awt.Color(0, 0, 0));
+ joystickEventsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(51, 153, 0), 2, true), "Joystick View", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(204, 102, 0)));
+ joystickEventsPanel.setToolTipText("JoystickEvent");
+ joystickEventsPanel.setMinimumSize(new java.awt.Dimension(200, 200));
+
+ javax.swing.GroupLayout joystickEventsPanelLayout = new javax.swing.GroupLayout(joystickEventsPanel);
+ joystickEventsPanel.setLayout(joystickEventsPanelLayout);
+ joystickEventsPanelLayout.setHorizontalGroup(
+ joystickEventsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 601, Short.MAX_VALUE)
+ );
+ joystickEventsPanelLayout.setVerticalGroup(
+ joystickEventsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 174, Short.MAX_VALUE)
+ );
+
+ topPanels.add(joystickEventsPanel);
+ joystickEventsPanel.getAccessibleContext().setAccessibleName("Joystick");
+
+ motionSensingEventsPanel.setMinimumSize(new java.awt.Dimension(200, 200));
+
+ rawAccelerationPanel.setToolTipText("Nunchuk MotionSensingEvent");
+
+ javax.swing.GroupLayout rawAccelerationPanelLayout = new javax.swing.GroupLayout(rawAccelerationPanel);
+ rawAccelerationPanel.setLayout(rawAccelerationPanelLayout);
+ rawAccelerationPanelLayout.setHorizontalGroup(
+ rawAccelerationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 597, Short.MAX_VALUE)
+ );
+ rawAccelerationPanelLayout.setVerticalGroup(
+ rawAccelerationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 175, Short.MAX_VALUE)
+ );
+
+ motionSensingEventsTabbedPanels.addTab("RawAcceleration", rawAccelerationPanel);
+
+ javax.swing.GroupLayout orientationPanelLayout = new javax.swing.GroupLayout(orientationPanel);
+ orientationPanel.setLayout(orientationPanelLayout);
+ orientationPanelLayout.setHorizontalGroup(
+ orientationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 597, Short.MAX_VALUE)
+ );
+ orientationPanelLayout.setVerticalGroup(
+ orientationPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 175, Short.MAX_VALUE)
+ );
+
+ motionSensingEventsTabbedPanels.addTab("Orientation", orientationPanel);
+
+ javax.swing.GroupLayout gForcePanelLayout = new javax.swing.GroupLayout(gForcePanel);
+ gForcePanel.setLayout(gForcePanelLayout);
+ gForcePanelLayout.setHorizontalGroup(
+ gForcePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 597, Short.MAX_VALUE)
+ );
+ gForcePanelLayout.setVerticalGroup(
+ gForcePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 175, Short.MAX_VALUE)
+ );
+
+ motionSensingEventsTabbedPanels.addTab("GForce", gForcePanel);
+
+ javax.swing.GroupLayout motionSensingEventsPanelLayout = new javax.swing.GroupLayout(motionSensingEventsPanel);
+ motionSensingEventsPanel.setLayout(motionSensingEventsPanelLayout);
+ motionSensingEventsPanelLayout.setHorizontalGroup(
+ motionSensingEventsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(motionSensingEventsTabbedPanels, javax.swing.GroupLayout.DEFAULT_SIZE, 602, Short.MAX_VALUE)
+ );
+ motionSensingEventsPanelLayout.setVerticalGroup(
+ motionSensingEventsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(motionSensingEventsTabbedPanels, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
+ );
+
+ topPanels.add(motionSensingEventsPanel);
+
+ getContentPane().add(topPanels);
+
+ setNunchukValuesPanel.setMinimumSize(new java.awt.Dimension(400, 200));
+ setNunchukValuesPanel.setPreferredSize(new java.awt.Dimension(400, 200));
+ setNunchukValuesPanel.setLayout(new javax.swing.BoxLayout(setNunchukValuesPanel, javax.swing.BoxLayout.Y_AXIS));
+
+ nunchukButtonsEventPanel.setToolTipText("Nunchuk ButtonsEvent");
+ nunchukButtonsEventPanel.setMinimumSize(new java.awt.Dimension(100, 100));
+ nunchukButtonsEventPanel.setPreferredSize(new java.awt.Dimension(100, 100));
+ nunchukButtonsEventPanel.setLayout(new javax.swing.BoxLayout(nunchukButtonsEventPanel, javax.swing.BoxLayout.LINE_AXIS));
+
+ cButton.setText("C");
+ cButton.setMaximumSize(new java.awt.Dimension(50, 50));
+ cButton.setMinimumSize(new java.awt.Dimension(50, 50));
+ cButton.setPreferredSize(new java.awt.Dimension(50, 50));
+ nunchukButtonsEventPanel.add(cButton);
+
+ zButton.setText("Z");
+ zButton.setMaximumSize(new java.awt.Dimension(50, 50));
+ zButton.setMinimumSize(new java.awt.Dimension(50, 50));
+ zButton.setPreferredSize(new java.awt.Dimension(50, 50));
+ nunchukButtonsEventPanel.add(zButton);
+
+ setNunchukValuesPanel.add(nunchukButtonsEventPanel);
+
+ nunchukOrientationTextField.setPreferredSize(new java.awt.Dimension(60, 20));
+ nunchukOrientationPanel.add(nunchukOrientationTextField);
+
+ nunchukOrientationButton.setText("Set Orientation Threshold");
+ nunchukOrientationButton.addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ nunchukOrientationButtonMousePressed(evt);
+ }
+ });
+ nunchukOrientationPanel.add(nunchukOrientationButton);
+
+ setNunchukValuesPanel.add(nunchukOrientationPanel);
+
+ nunchukAccelerationTextField.setPreferredSize(new java.awt.Dimension(60, 20));
+ nunchukAccelerationPanel.add(nunchukAccelerationTextField);
+
+ nunchukAccelerationButton.setText("Set Acceleration Threshold");
+ nunchukAccelerationButton.addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ nunchukAccelerationButtonMousePressed(evt);
+ }
+ });
+ nunchukAccelerationPanel.add(nunchukAccelerationButton);
+
+ setNunchukValuesPanel.add(nunchukAccelerationPanel);
+
+ messageText.setText("Message:");
+
+ javax.swing.GroupLayout messagePanelLayout = new javax.swing.GroupLayout(messagePanel);
+ messagePanel.setLayout(messagePanelLayout);
+ messagePanelLayout.setHorizontalGroup(
+ messagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 1216, Short.MAX_VALUE)
+ .addGroup(messagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(messagePanelLayout.createSequentialGroup()
+ .addGap(0, 0, Short.MAX_VALUE)
+ .addComponent(messageText)
+ .addGap(0, 0, Short.MAX_VALUE)))
+ );
+ messagePanelLayout.setVerticalGroup(
+ messagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 34, Short.MAX_VALUE)
+ .addGroup(messagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(messagePanelLayout.createSequentialGroup()
+ .addGap(0, 0, Short.MAX_VALUE)
+ .addComponent(messageText)
+ .addGap(0, 0, Short.MAX_VALUE)))
+ );
+
+ setNunchukValuesPanel.add(messagePanel);
+
+ getContentPane().add(setNunchukValuesPanel);
+
+ pack();
+ }// //GEN-END:initComponents
+
+ private void nunchukOrientationButtonMousePressed(
+ java.awt.event.MouseEvent evt) {// GEN-FIRST:event_nunchukOrientationButtonMousePressed
+ try {
+ float nb = Float.parseFloat(nunchukOrientationTextField.getText());
+ wiimote.setNunchukOrientationThreshold(nb);
+ messageText.setText("Nunchuk orientation threshold set to " + nb);
+ } catch (NumberFormatException e) {
+ messageText
+ .setText("Number is not an integer, nunchuk orientation threshold not set !");
+ }
+ }// GEN-LAST:event_nunchukOrientationButtonMousePressed
+
+ private void nunchukAccelerationButtonMousePressed(
+ java.awt.event.MouseEvent evt) {// GEN-FIRST:event_nunchukAccelerationButtonMousePressed
+ try {
+ int nb = Integer.parseInt(nunchukAccelerationTextField.getText());
+ wiimote.setNunchukAccelerationThreshold(nb);
+ messageText.setText("Nunchuk acceleration threshold set to " + nb);
+ } catch (NumberFormatException e) {
+ messageText
+ .setText("Number is not an integer, nunchuk acceleration threshold not set !");
+ }
+ }// GEN-LAST:event_nunchukAccelerationButtonMousePressed
+
+ public void onButtonsEvent(WiimoteButtonsEvent arg0) {
+ // nothing to do
+ }
+
+ public void onIrEvent(IREvent arg0) {
+ // nothing to do
+ }
+
+ public void onMotionSensingEvent(MotionSensingEvent arg0) {
+ // nothing to do
+ }
+
+ public void onExpansionEvent(ExpansionEvent arg0) {
+ if (arg0 instanceof NunchukEvent) {
+ NunchukEvent nunchuk = (NunchukEvent) arg0;
+ NunchukButtonsEvent buttons = nunchuk.getButtonsEvent();
+ if (buttons.isButtonCJustPressed()) {
+ cButton.setEnabled(false);
+ }
+ if (buttons.isButtonCJustReleased()) {
+ cButton.setEnabled(true);
+ }
+ if (buttons.isButtonZJustPressed()) {
+ zButton.setEnabled(false);
+ }
+ if (buttons.isButtonZJustReleased()) {
+ zButton.setEnabled(true);
+ }
+ if (isThresholdsRequested) {
+ MotionSensingEvent evt = nunchuk.getNunchukMotionSensingEvent();
+ nunchukAccelerationTextField.setText(evt
+ .getAccelerationThreshold()
+ + "");
+ nunchukOrientationTextField.setText(evt
+ .getOrientationThreshold()
+ + "");
+ isThresholdsRequested = false;
+ }
+ }
+ }
+
+ public void onStatusEvent(StatusEvent arg0) {
+ // nothing to do
+ }
+
+ public void onDisconnectionEvent(DisconnectionEvent arg0) {
+ // nothing
+ }
+
+ public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
+ // nothing
+ }
+
+ public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
+ // nothing
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton cButton;
+ private javax.swing.JPanel gForcePanel;
+ private javax.swing.JPanel joystickEventsPanel;
+ private javax.swing.JPanel messagePanel;
+ private javax.swing.JLabel messageText;
+ private javax.swing.JPanel motionSensingEventsPanel;
+ private javax.swing.JTabbedPane motionSensingEventsTabbedPanels;
+ private javax.swing.JButton nunchukAccelerationButton;
+ private javax.swing.JPanel nunchukAccelerationPanel;
+ private javax.swing.JTextField nunchukAccelerationTextField;
+ private javax.swing.JPanel nunchukButtonsEventPanel;
+ private javax.swing.JButton nunchukOrientationButton;
+ private javax.swing.JPanel nunchukOrientationPanel;
+ private javax.swing.JTextField nunchukOrientationTextField;
+ private javax.swing.JPanel orientationPanel;
+ private javax.swing.JPanel rawAccelerationPanel;
+ private javax.swing.JPanel setNunchukValuesPanel;
+ private javax.swing.JPanel topPanels;
+ private javax.swing.JButton zButton;
+ // End of variables declaration//GEN-END:variables
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/test/Tests.java b/WiiUseJ_0.12/src/wiiusej/test/Tests.java
new file mode 100644
index 0000000..6a3cdb7
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/test/Tests.java
@@ -0,0 +1,367 @@
+/**
+ * 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.test;
+
+import java.awt.AWTException;
+import java.awt.Robot;
+import java.awt.event.InputEvent;
+
+import wiiusej.WiiUseApiManager;
+import wiiusej.Wiimote;
+import wiiusej.values.IRSource;
+import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
+import wiiusej.wiiusejevents.physicalevents.IREvent;
+import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
+import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
+import wiiusej.wiiusejevents.utils.WiimoteListener;
+import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
+
+/**
+ * This class used to test WiiuseJ in text mode.
+ *
+ * @author guiguito
+ */
+public class Tests implements WiimoteListener {
+
+ Robot robot;
+
+ private static int DISPLAY_EACH_VALUE = 1;
+ private static int DUMP = 2;
+ private static int MOVE_MOUSE = 3;
+ private static int TEST_LEDS = 5;
+
+ private Wiimote wiimote;
+
+ int dump = DISPLAY_EACH_VALUE;
+
+ public Tests(Wiimote wim) {
+ wiimote = wim;
+ wiimote.addWiiMoteEventListeners(this);
+ try {
+ robot = new Robot();
+ } catch (AWTException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void onButtonsEvent(WiimoteButtonsEvent e) {
+ if (dump == DISPLAY_EACH_VALUE) {
+ // System.out.println("*********** WIIMOTE ID : "+
+ // e.getWiimoteId() + " **************");
+ /* button ONE */
+ if (e.isButtonOneJustPressed()) {
+ System.out.println("button one pressed");
+ }
+ if (e.isButtonOneHeld()) {
+ System.out.println("button one held");
+ }
+ if (e.isButtonOneJustReleased()) {
+ System.out.println("button one released");
+ }
+
+ /* button TWO */
+ if (e.isButtonTwoJustPressed()) {
+ System.out.println("button two pressed");
+ }
+ if (e.isButtonTwoHeld()) {
+ System.out.println("button two held");
+ }
+ if (e.isButtonTwoJustReleased()) {
+ System.out.println("button two released");
+ }
+
+ /* button A */
+ if (e.isButtonAJustPressed()) {
+ System.out.println("button A pressed");
+ }
+ if (e.isButtonAHeld()) {
+ System.out.println("button A held");
+ }
+ if (e.isButtonAJustReleased()) {
+ System.out.println("button A released");
+ }
+
+ /* button B */
+ if (e.isButtonBJustPressed()) {
+ System.out.println("button B pressed");
+ }
+ if (e.isButtonBHeld()) {
+ System.out.println("button B held");
+ }
+ if (e.isButtonBJustReleased()) {
+ System.out.println("button B released");
+ }
+
+ /* button LEFT */
+ if (e.isButtonLeftJustPressed()) {
+ System.out.println("button Left pressed");
+ }
+ if (e.isButtonLeftHeld()) {
+ System.out.println("button Left held");
+ }
+ if (e.isButtonLeftJustReleased()) {
+ System.out.println("button Left released");
+ }
+
+ /* button RIGHT */
+ if (e.isButtonRightJustPressed()) {
+ System.out.println("button Right pressed");
+ }
+ if (e.isButtonRightHeld()) {
+ System.out.println("button Right held");
+ }
+ if (e.isButtonRightJustReleased()) {
+ System.out.println("button Right released");
+ }
+
+ /* button UP */
+ if (e.isButtonUpJustPressed()) {
+ System.out.println("button UP pressed");
+ }
+ if (e.isButtonUpHeld()) {
+ System.out.println("button UP held");
+ }
+ if (e.isButtonUpJustReleased()) {
+ System.out.println("button UP released");
+ }
+
+ /* button DOWN */
+ if (e.isButtonDownJustPressed()) {
+ System.out.println("button DOWN pressed");
+ }
+ if (e.isButtonDownHeld()) {
+ System.out.println("button DOWN held");
+ }
+ if (e.isButtonDownJustReleased()) {
+ System.out.println("button DOWN released");
+ }
+
+ /* button MINUS */
+ if (e.isButtonMinusJustPressed()) {
+ System.out.println("button MINUS pressed");
+ }
+ if (e.isButtonMinusHeld()) {
+ System.out.println("button MINUS held");
+ }
+ if (e.isButtonMinusJustReleased()) {
+ System.out.println("button MINUS released");
+ }
+
+ /* button PLUS */
+ if (e.isButtonPlusJustPressed()) {
+ System.out.println("button PLUS pressed");
+ }
+ if (e.isButtonPlusHeld()) {
+ System.out.println("button PLUS held");
+ }
+ if (e.isButtonPlusJustReleased()) {
+ System.out.println("button PLUS released");
+ }
+
+ /* button HOME */
+ if (e.isButtonHomeJustPressed()) {
+ System.out.println("button HOME pressed");
+ }
+ if (e.isButtonHomeHeld()) {
+ System.out.println("button HOME held");
+ }
+ if (e.isButtonHomeJustReleased()) {
+ System.out.println("button HOME released");
+ }
+
+ /* get status */
+ if (e.isButtonUpJustPressed()) {
+ wiimote.getStatus();
+ }
+
+ /* Activate rumble */
+ if (e.isButtonOneJustPressed()) {
+ System.out.println("Rumble Activated");
+ wiimote.activateRumble();
+ }
+ if (e.isButtonTwoJustPressed()) {
+ System.out.println("Rumble Deactivated");
+ wiimote.deactivateRumble();
+ }
+
+ /* Activate IR Tracking */
+ if (e.isButtonAJustPressed()) {
+ System.out.println("IR Activated");
+ wiimote.activateIRTRacking();
+ }
+ if (e.isButtonBJustPressed()) {
+ System.out.println("IR Deactivated");
+ wiimote.deactivateIRTRacking();
+ }
+
+ /* Activate Motion sensing */
+ if (e.isButtonPlusJustPressed()) {
+ System.out.println("Motion sensing Activated");
+ wiimote.activateMotionSensing();
+ }
+ if (e.isButtonMinusJustPressed()) {
+ System.out.println("Motion sensing Deactivated");
+ wiimote.deactivateMotionSensing();
+ }
+
+ /* leave test */
+ if (e.isButtonHomeJustPressed()) {
+ System.out.println("LEAVING TEST");
+ wiimote.disconnect();
+ }
+
+ } else if (dump == DUMP) {
+ System.out.println(e);
+ /* Activate all */
+ if (e.isButtonAJustPressed()) {
+ System.out.println("IR, rumble and motion sensing Activated");
+ wiimote.activateIRTRacking();
+ wiimote.activateMotionSensing();
+ wiimote.activateRumble();
+ }
+ if (e.isButtonBJustPressed()) {
+ System.out.println("IR, rumble and motion sensing Deactivated");
+ wiimote.deactivateIRTRacking();
+ wiimote.deactivateMotionSensing();
+ wiimote.deactivateRumble();
+ }
+
+ /* leave test */
+ if (e.isButtonHomeJustPressed()) {
+ System.out.println("LEAVING TEST");
+ wiimote.disconnect();
+ }
+ } else if (dump == MOVE_MOUSE) {
+ /* Activate IR Tracking */
+ if (e.isButtonOneJustPressed()) {
+ System.out.println("IR Activated");
+ wiimote.activateIRTRacking();
+ }
+ if (e.isButtonTwoJustPressed()) {
+ System.out.println("IR Deactivated");
+ wiimote.deactivateIRTRacking();
+ }
+
+ /* button A */
+ if (e.isButtonAJustPressed()) {
+ robot.mousePress(InputEvent.BUTTON1_MASK);
+ }
+ if (e.isButtonAJustReleased()) {
+ robot.mouseRelease(InputEvent.BUTTON1_MASK);
+ }
+
+ /* button B */
+ if (e.isButtonBJustPressed()) {
+ robot.mousePress(InputEvent.BUTTON2_MASK);
+ }
+ if (e.isButtonBJustReleased()) {
+ robot.mouseRelease(InputEvent.BUTTON2_MASK);
+ }
+
+ /* leave test */
+ if (e.isButtonHomeJustPressed()) {
+ System.out.println("LEAVING TEST");
+ wiimote.disconnect();
+ }
+ } else if (dump == TEST_LEDS) {
+ wiimote.activateMotionSensing();
+ if (e.isButtonUpJustPressed()) {
+ wiimote.setLeds(true, false, false, false);
+ }
+ if (e.isButtonDownJustPressed()) {
+ wiimote.setLeds(false, true, false, false);
+ }
+ if (e.isButtonLeftJustPressed()) {
+ wiimote.setLeds(false, false, true, false);
+ }
+ if (e.isButtonRightJustPressed()) {
+ wiimote.setLeds(false, false, false, true);
+ }
+
+ /* leave test */
+ if (e.isButtonHomeJustPressed()) {
+ System.out.println("LEAVING TEST");
+ wiimote.disconnect();
+ }
+ }
+
+ }
+
+ public void onIrEvent(IREvent e) {
+ if (dump == MOVE_MOUSE) {
+ IRSource[] list = e.getIRPoints();
+ if (list.length > 0) {
+ int x1 = (int) list[0].getX();
+ int y1 = (int) list[0].getY();
+
+ int mousex = (int) Math.round(((double) x1 / 1024.0) * 1280.0);
+ int mousey = (int) Math.round(((double) y1 / 768.0) * 1024.0);
+ robot.mouseMove(mousex, mousey);
+ }
+ } else {
+ System.out.println(e);
+ }
+ }
+
+ public void onMotionSensingEvent(MotionSensingEvent e) {
+ /* display motion sensing */
+ System.out.println(e);
+ }
+
+ public void onExpansionEvent(ExpansionEvent e) {
+ System.out.println(e);
+ }
+
+ public void onStatusEvent(StatusEvent e) {
+ // Display status variables
+ System.out.println(e);
+ }
+
+ public void onDisconnectionEvent(DisconnectionEvent e) {
+ System.out.println(" wiimote " + e.getWiimoteId()
+ + "has been disconnected !!");
+ }
+
+ public void onNunchukInsertedEvent(NunchukInsertedEvent e) {
+ System.out.println(e);
+ }
+
+ public void onNunchukRemovedEvent(NunchukRemovedEvent e) {
+ System.out.println(e);
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1, true);
+ if (wiimotes.length > 0) {
+ System.out.println(wiimotes[0]);
+ new Tests(wiimotes[0]);
+ } else {
+ System.out.println("No wiimotes found !!!");
+ }
+
+ // java.util.Timer timer = new java.util.Timer();
+ // timer.scheduleAtFixedRate(new LedsTask(), 0, 100);
+
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/test/WiiuseJGuiTest.java b/WiiUseJ_0.12/src/wiiusej/test/WiiuseJGuiTest.java
new file mode 100644
index 0000000..2a8f229
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/test/WiiuseJGuiTest.java
@@ -0,0 +1,1329 @@
+/**
+ * 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.test;
+
+import java.awt.AWTException;
+import java.awt.Robot;
+import java.awt.event.InputEvent;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowListener;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.swing.JFrame;
+import wiiusej.WiiUseApiManager;
+import wiiusej.Wiimote;
+import wiiusej.utils.AccelerationPanel;
+import wiiusej.utils.AccelerationWiimoteEventPanel;
+import wiiusej.utils.ButtonsEventPanel;
+import wiiusej.utils.GForcePanel;
+import wiiusej.utils.IRPanel;
+import wiiusej.utils.OrientationPanel;
+import wiiusej.utils.OrientationWiimoteEventPanel;
+import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
+import wiiusej.wiiusejevents.physicalevents.IREvent;
+import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
+import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
+import wiiusej.wiiusejevents.utils.WiimoteListener;
+import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
+
+/**
+ * Gui class to test WiiuseJ.
+ *
+ * @author guiguito
+ */
+public class WiiuseJGuiTest extends javax.swing.JFrame implements
+ WiimoteListener {
+
+ private Wiimote wiimote;
+ private Robot robot = null;
+ private boolean statusMotionRequested = false;
+ private boolean statusIRRequested = false;
+ private JFrame expansionFrame = null;
+ private boolean isFirstStatusGot = false;
+ private WindowListener buttonSetter = new WindowListener() {
+
+ public void windowOpened(WindowEvent e) {
+ // nothing
+ }
+
+ public void windowClosing(WindowEvent e) {
+ // nothing
+ }
+
+ public void windowClosed(WindowEvent e) {
+ // nothing
+ }
+
+ public void windowIconified(WindowEvent e) {
+ // nothing
+ }
+
+ public void windowDeiconified(WindowEvent e) {
+ // nothing
+ }
+
+ public void windowActivated(WindowEvent e) {
+ showExpansionWiimoteButton.setEnabled(false);
+ showExpansionWiimoteButton.setText("Hide Nunchuk");
+ }
+
+ public void windowDeactivated(WindowEvent e) {
+ showExpansionWiimoteButton.setEnabled(true);
+ showExpansionWiimoteButton.setText("Show Nunchuk");
+ }
+ };
+
+ /**
+ * default constructor
+ */
+ public WiiuseJGuiTest() {
+ initComponents();
+ this.addWindowListener(new CloseGuiTestCleanly());
+ }
+
+ /**
+ * Creates new form WiiuseJGuiTest
+ */
+ public WiiuseJGuiTest(Wiimote wiimote) {
+ initComponents();
+ this.addWindowListener(new CloseGuiTestCleanly());
+ if (wiimote != null) {
+ this.wiimote = wiimote;
+ registerListeners();
+ initWiimote();
+ isFirstStatusGot = false;
+ getStatusButtonMousePressed(null);
+ }
+ }
+
+ /**
+ * Clear all views
+ */
+ private void clearViews() {
+ ((IRPanel) irViewPanel).clearView();
+ ((ButtonsEventPanel) buttonsPanel).clearView();
+ ((OrientationPanel) motionSensingPanel).clearView();
+ ((GForcePanel) gForcePanel).clearView();
+ ((AccelerationPanel) accelerationPanel).clearView();
+ }
+
+ /**
+ * Unregister all listeners.
+ */
+ private void unregisterListeners() {
+ wiimote.removeWiiMoteEventListeners((IRPanel) irViewPanel);
+ wiimote.removeWiiMoteEventListeners((ButtonsEventPanel) buttonsPanel);
+ wiimote
+ .removeWiiMoteEventListeners((OrientationPanel) motionSensingPanel);
+ wiimote.removeWiiMoteEventListeners((GForcePanel) gForcePanel);
+ wiimote
+ .removeWiiMoteEventListeners((AccelerationPanel) accelerationPanel);
+ wiimote.removeWiiMoteEventListeners(this);
+ }
+
+ private void initWiimote() {
+ wiimote.deactivateContinuous();
+ wiimote.deactivateSmoothing();
+ wiimote.setScreenAspectRatio169();
+ wiimote.setSensorBarBelowScreen();
+ }
+
+ /**
+ * Register all listeners
+ */
+ private void registerListeners() {
+ wiimote.addWiiMoteEventListeners((IRPanel) irViewPanel);
+ wiimote.addWiiMoteEventListeners((ButtonsEventPanel) buttonsPanel);
+ wiimote.addWiiMoteEventListeners((OrientationPanel) motionSensingPanel);
+ wiimote.addWiiMoteEventListeners((GForcePanel) gForcePanel);
+ wiimote.addWiiMoteEventListeners((AccelerationPanel) accelerationPanel);
+ wiimote.addWiiMoteEventListeners(this);
+
+ }
+
+ public void onButtonsEvent(WiimoteButtonsEvent arg0) {
+ if (robot != null) {
+ if (arg0.isButtonAPressed()) {
+ robot.mousePress(InputEvent.BUTTON1_MASK);
+
+ }
+ if (arg0.isButtonBPressed()) {
+ robot.mousePress(InputEvent.BUTTON2_MASK);
+
+ }
+ if (arg0.isButtonOnePressed()) {
+ robot.mousePress(InputEvent.BUTTON3_MASK);
+
+ }
+ if (arg0.isButtonAJustReleased()) {
+ robot.mouseRelease(InputEvent.BUTTON1_MASK);
+
+ }
+ if (arg0.isButtonBJustReleased()) {
+ robot.mouseRelease(InputEvent.BUTTON2_MASK);
+
+ }
+ if (arg0.isButtonOneJustReleased()) {
+ robot.mouseRelease(InputEvent.BUTTON3_MASK);
+
+ }
+ if (arg0.isButtonUpPressed()) {// mouse wheel up
+ robot.mouseWheel(-1);
+ }
+ if (arg0.isButtonDownPressed()) {// mouse wheel down
+ robot.mouseWheel(1);
+ }
+
+ if (arg0.isButtonTwoPressed()) {// stop mouse control
+ mouseIRControlButtonMousePressed(null);
+ }
+ }
+ }
+
+ public void onIrEvent(IREvent arg0) {
+ if (robot != null) {// if mouse control activated
+ robot.mouseMove(arg0.getX(), arg0.getY());
+ }
+ if (statusIRRequested) {
+ xResolutionTextField.setText("" + arg0.getXVRes());
+ yResolutionTextField.setText("" + arg0.getYVRes());
+ statusIRRequested = false;
+ }
+ }
+
+ public void onMotionSensingEvent(MotionSensingEvent arg0) {
+ if (statusMotionRequested) {// Status requested
+ accelerationThresholdTextField.setText(""
+ + arg0.getAccelerationThreshold());
+ orientationThresholdTextField.setText(""
+ + arg0.getOrientationThreshold());
+ alphaSmoothingTextField.setText("" + arg0.getAlphaSmoothing());
+ statusMotionRequested = false;
+ }
+ }
+
+ public void onExpansionEvent(ExpansionEvent e) {
+ // nothing yet
+ }
+
+ public void onStatusEvent(StatusEvent arg0) {
+ if (!isFirstStatusGot) {
+ if (arg0.isNunchukConnected()) {
+ showExpansionWiimoteButton.setEnabled(true);
+ showExpansionWiimoteButton.setText("Show Nunchuk");
+ expansionFrame = new NunchukGuiTest(wiimote);
+ expansionFrame
+ .setDefaultCloseOperation(NunchukGuiTest.HIDE_ON_CLOSE);
+ expansionFrame.addWindowListener(buttonSetter);
+ isFirstStatusGot = true;
+ }
+ }
+ messageText.setText("Status received !");
+ batteryLevelText.setText(arg0.getBatteryLevel() + " %");
+ led1Button.setEnabled(arg0.isLed1Set());
+ led2Button.setEnabled(arg0.isLed2Set());
+ led3Button.setEnabled(arg0.isLed3Set());
+ led4Button.setEnabled(arg0.isLed4Set());
+ if (arg0.isNunchukConnected()) {
+ ((NunchukGuiTest) expansionFrame).requestThresholdsUpdate();
+ }
+ // attachments
+ int eventType = arg0.getEventType();
+ if (eventType == StatusEvent.WIIUSE_CLASSIC_CTRL_INSERTED) {
+ expansionText.setText("Classic control connected.");
+ } else if (eventType == StatusEvent.WIIUSE_CLASSIC_CTRL_REMOVED) {
+ expansionText.setText("Classic control removed.");
+ } else if (eventType == StatusEvent.WIIUSE_NUNCHUK_INSERTED) {
+ expansionText.setText("Nunchuk connected.");
+ } else if (eventType == StatusEvent.WIIUSE_NUNCHUK_REMOVED) {
+ expansionText.setText("Nunchuk removed.");
+ } else if (eventType == StatusEvent.WIIUSE_GUITAR_HERO_3_CTRL_INSERTED) {
+ expansionText.setText("Guitar Hero 3 control connected.");
+ } else if (eventType == StatusEvent.WIIUSE_GUITAR_HERO_3_CTRL_REMOVED) {
+ expansionText.setText("Guitar Hero 3 control removed.");
+ }
+ }
+
+ public void onDisconnectionEvent(DisconnectionEvent arg0) {
+ messageText.setText("Wiimote Disconnected !");
+ unregisterListeners();
+ clearViews();
+ isFirstStatusGot = false;
+ }
+
+ public void onNunchukInsertedEvent(NunchukInsertedEvent e) {
+ messageText.setText("Nunchuk connected !");
+ expansionText.setText("Expansion connected : Nunchuk.");
+ showExpansionWiimoteButton.setEnabled(true);
+ showExpansionWiimoteButton.setText("Show nunchuk");
+ expansionFrame = new NunchukGuiTest(wiimote);
+ expansionFrame.setDefaultCloseOperation(NunchukGuiTest.HIDE_ON_CLOSE);
+ expansionFrame.addWindowListener(buttonSetter);
+ }
+
+ public void onNunchukRemovedEvent(NunchukRemovedEvent e) {
+ messageText.setText("Nunchuk disconnected !");
+ expansionText.setText("No expansion connected.");
+ showExpansionWiimoteButton.setEnabled(false);
+ showExpansionWiimoteButton.setText("No expansion");
+ if (expansionFrame != null) {
+ if (expansionFrame instanceof NunchukGuiTest) {
+ ((NunchukGuiTest) expansionFrame).unRegisterListeners();
+ }
+ expansionFrame.setEnabled(false);
+ expansionFrame.dispose();
+ expansionFrame = null;
+ }
+ }
+
+ /**
+ * This method is called from within the constructor to initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is always
+ * regenerated by the Form Editor.
+ */
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ leftPanel = new javax.swing.JPanel();
+ irViewPanel = new IRPanel();
+ jTabbedPane1 = new javax.swing.JTabbedPane();
+ accelerationPanel = new AccelerationWiimoteEventPanel();
+ motionSensingPanel = new OrientationWiimoteEventPanel();
+ gForcePanel = new wiiusej.utils.GForceWiimoteEventPanel();
+ rightPanel = new javax.swing.JPanel();
+ fixedWiimotePanel = new javax.swing.JPanel();
+ buttonsPanel = new ButtonsEventPanel();
+ controlsPanel = new javax.swing.JPanel();
+ activateRumbleIRPanel = new javax.swing.JPanel();
+ toggleRumbleButton = new javax.swing.JButton();
+ toggleIRTrackingButton = new javax.swing.JButton();
+ activateMotionSensingPanel = new javax.swing.JPanel();
+ toggleMotionSensingTrackingButton = new javax.swing.JButton();
+ activateSmoothingContinuousPanel = new javax.swing.JPanel();
+ toggleSmoothingButton = new javax.swing.JButton();
+ toggleContinuousButton = new javax.swing.JButton();
+ setLedsPanel = new javax.swing.JPanel();
+ led1Button = new javax.swing.JButton();
+ led2Button = new javax.swing.JButton();
+ led3Button = new javax.swing.JButton();
+ led4Button = new javax.swing.JButton();
+ setLedsButton = new javax.swing.JButton();
+ setAlphaSmoothingPanel = new javax.swing.JPanel();
+ alphaSmoothingTextField = new javax.swing.JTextField();
+ alphaSmoothingButton = new javax.swing.JButton();
+ setOrientationThresholdPanel = new javax.swing.JPanel();
+ orientationThresholdTextField = new javax.swing.JTextField();
+ orientationThresholdButton = new javax.swing.JButton();
+ setAccelerationThresholdPanel = new javax.swing.JPanel();
+ accelerationThresholdTextField = new javax.swing.JTextField();
+ accelerationThresholdButton = new javax.swing.JButton();
+ getStatusPanel = new javax.swing.JPanel();
+ getStatusButton = new javax.swing.JButton();
+ batteryText = new javax.swing.JLabel();
+ batteryLevelText = new javax.swing.JLabel();
+ setIrSensitivyPanel = new javax.swing.JPanel();
+ setIrSensitivySpinner = new javax.swing.JSpinner();
+ setIrSensitivyButton = new javax.swing.JButton();
+ setTimeoutButton = new javax.swing.JButton();
+ setTimeoutPanel = new javax.swing.JPanel();
+ normalTimeoutSpinner = new javax.swing.JSpinner();
+ normalTimeoutText = new javax.swing.JLabel();
+ expansionHandshakeTimeoutSpinner = new javax.swing.JSpinner();
+ expansionHandshakeTimeoutText = new javax.swing.JLabel();
+ setIRConfPanel = new javax.swing.JPanel();
+ toggleSensorBarPositionButton = new javax.swing.JButton();
+ toggleScreenAspectRatioButton = new javax.swing.JButton();
+ setVirtualResolutionPanel = new javax.swing.JPanel();
+ xLabel = new javax.swing.JLabel();
+ xResolutionTextField = new javax.swing.JTextField();
+ yLabel = new javax.swing.JLabel();
+ yResolutionTextField = new javax.swing.JTextField();
+ setVirtualResolutionButton = new javax.swing.JButton();
+ startMouseControlPanel = new javax.swing.JPanel();
+ mouseIRControlButton = new javax.swing.JButton();
+ exPansionPanel = new javax.swing.JPanel();
+ expansionText = new javax.swing.JLabel();
+ showExpansionWiimoteButton = new javax.swing.JButton();
+ showExpansionWiimoteButton.setEnabled(false);
+ messagesPanel = new javax.swing.JPanel();
+ reconnectWiimotesButton = new javax.swing.JButton();
+ messageLabelText = new javax.swing.JLabel();
+ messageText = new javax.swing.JLabel();
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ setTitle("WiiuseJ Test GUI");
+ setName("WiiuseJ Test GUI"); // NOI18N
+
+ leftPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
+
+ irViewPanel.setBackground(new java.awt.Color(0, 0, 0));
+ irViewPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
+ new javax.swing.border.LineBorder(new java.awt.Color(0, 153,
+ 153), 2, true), "IR View",
+ javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
+ javax.swing.border.TitledBorder.DEFAULT_POSITION,
+ new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(255, 0,
+ 51)));
+ irViewPanel.setToolTipText("IREvent");
+
+ javax.swing.GroupLayout irViewPanelLayout = new javax.swing.GroupLayout(
+ irViewPanel);
+ irViewPanel.setLayout(irViewPanelLayout);
+ irViewPanelLayout.setHorizontalGroup(irViewPanelLayout
+ .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 272, Short.MAX_VALUE));
+ irViewPanelLayout.setVerticalGroup(irViewPanelLayout
+ .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 299, Short.MAX_VALUE));
+
+ accelerationPanel.setToolTipText("MotionSensingEvent");
+
+ javax.swing.GroupLayout accelerationPanelLayout = new javax.swing.GroupLayout(
+ accelerationPanel);
+ accelerationPanel.setLayout(accelerationPanelLayout);
+ accelerationPanelLayout.setHorizontalGroup(accelerationPanelLayout
+ .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 279, Short.MAX_VALUE));
+ accelerationPanelLayout.setVerticalGroup(accelerationPanelLayout
+ .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 213, Short.MAX_VALUE));
+
+ jTabbedPane1.addTab("Acceleration", accelerationPanel);
+
+ javax.swing.GroupLayout motionSensingPanelLayout = new javax.swing.GroupLayout(
+ motionSensingPanel);
+ motionSensingPanel.setLayout(motionSensingPanelLayout);
+ motionSensingPanelLayout.setHorizontalGroup(motionSensingPanelLayout
+ .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 279, Short.MAX_VALUE));
+ motionSensingPanelLayout.setVerticalGroup(motionSensingPanelLayout
+ .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 213, Short.MAX_VALUE));
+
+ jTabbedPane1.addTab("Orientation", motionSensingPanel);
+
+ javax.swing.GroupLayout gForcePanelLayout = new javax.swing.GroupLayout(
+ gForcePanel);
+ gForcePanel.setLayout(gForcePanelLayout);
+ gForcePanelLayout.setHorizontalGroup(gForcePanelLayout
+ .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 279, Short.MAX_VALUE));
+ gForcePanelLayout.setVerticalGroup(gForcePanelLayout
+ .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 213, Short.MAX_VALUE));
+
+ jTabbedPane1.addTab("GForce", gForcePanel);
+
+ javax.swing.GroupLayout leftPanelLayout = new javax.swing.GroupLayout(
+ leftPanel);
+ leftPanel.setLayout(leftPanelLayout);
+ leftPanelLayout.setHorizontalGroup(leftPanelLayout.createParallelGroup(
+ javax.swing.GroupLayout.Alignment.LEADING).addComponent(
+ irViewPanel, javax.swing.GroupLayout.Alignment.TRAILING,
+ javax.swing.GroupLayout.DEFAULT_SIZE,
+ javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(jTabbedPane1,
+ javax.swing.GroupLayout.DEFAULT_SIZE, 284,
+ Short.MAX_VALUE));
+ leftPanelLayout
+ .setVerticalGroup(leftPanelLayout
+ .createParallelGroup(
+ javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(
+ javax.swing.GroupLayout.Alignment.TRAILING,
+ leftPanelLayout
+ .createSequentialGroup()
+ .addComponent(
+ jTabbedPane1,
+ javax.swing.GroupLayout.PREFERRED_SIZE,
+ 238,
+ javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(
+ javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(
+ irViewPanel,
+ javax.swing.GroupLayout.DEFAULT_SIZE,
+ javax.swing.GroupLayout.DEFAULT_SIZE,
+ Short.MAX_VALUE)));
+
+ jTabbedPane1.getAccessibleContext().setAccessibleName("Orientation");
+
+ rightPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
+ rightPanel.setLayout(new javax.swing.BoxLayout(rightPanel,
+ javax.swing.BoxLayout.LINE_AXIS));
+
+ fixedWiimotePanel.setMaximumSize(new java.awt.Dimension(120, 32767));
+ fixedWiimotePanel.setMinimumSize(new java.awt.Dimension(120, 100));
+ fixedWiimotePanel.setPreferredSize(new java.awt.Dimension(120, 100));
+ fixedWiimotePanel.setRequestFocusEnabled(false);
+ fixedWiimotePanel.setLayout(null);
+
+ buttonsPanel.setMaximumSize(new java.awt.Dimension(120, 484));
+ buttonsPanel.setMinimumSize(new java.awt.Dimension(120, 484));
+ buttonsPanel.setOpaque(false);
+ buttonsPanel.setPreferredSize(new java.awt.Dimension(120, 484));
+
+ javax.swing.GroupLayout buttonsPanelLayout = new javax.swing.GroupLayout(
+ buttonsPanel);
+ buttonsPanel.setLayout(buttonsPanelLayout);
+ buttonsPanelLayout.setHorizontalGroup(buttonsPanelLayout
+ .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 120, Short.MAX_VALUE));
+ buttonsPanelLayout.setVerticalGroup(buttonsPanelLayout
+ .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGap(0, 484, Short.MAX_VALUE));
+
+ fixedWiimotePanel.add(buttonsPanel);
+ buttonsPanel.setBounds(0, 0, 120, 484);
+
+ rightPanel.add(fixedWiimotePanel);
+
+ controlsPanel.setMinimumSize(new java.awt.Dimension(100, 264));
+ controlsPanel.setPreferredSize(new java.awt.Dimension(190, 264));
+ controlsPanel.setLayout(new java.awt.GridLayout(16, 1));
+
+ toggleRumbleButton.setText("Activate Rumble");
+ toggleRumbleButton.addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ toggleRumbleButtonMousePressed(evt);
+ }
+ });
+ activateRumbleIRPanel.add(toggleRumbleButton);
+
+ toggleIRTrackingButton.setText("Activate IR Tracking");
+ toggleIRTrackingButton
+ .addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ toggleIRTrackingButtonMousePressed(evt);
+ }
+ });
+ activateRumbleIRPanel.add(toggleIRTrackingButton);
+
+ controlsPanel.add(activateRumbleIRPanel);
+
+ toggleMotionSensingTrackingButton
+ .setText("Activate motion sensing Tracking");
+ toggleMotionSensingTrackingButton
+ .addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ toggleMotionSensingTrackingButtonMousePressed(evt);
+ }
+ });
+ activateMotionSensingPanel.add(toggleMotionSensingTrackingButton);
+
+ controlsPanel.add(activateMotionSensingPanel);
+
+ toggleSmoothingButton.setText("Activate Smoothing");
+ toggleSmoothingButton
+ .addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ toggleSmoothingButtonMousePressed(evt);
+ }
+ });
+ activateSmoothingContinuousPanel.add(toggleSmoothingButton);
+
+ toggleContinuousButton.setText("Activate Continuous");
+ toggleContinuousButton
+ .addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ toggleContinuousButtonMousePressed(evt);
+ }
+ });
+ activateSmoothingContinuousPanel.add(toggleContinuousButton);
+
+ controlsPanel.add(activateSmoothingContinuousPanel);
+
+ led1Button.setText("Led1");
+ led1Button.addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ led1ButtonMousePressed(evt);
+ }
+ });
+ setLedsPanel.add(led1Button);
+
+ led2Button.setText("Led2");
+ led2Button.addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ led2ButtonMousePressed(evt);
+ }
+ });
+ setLedsPanel.add(led2Button);
+
+ led3Button.setText("Led3");
+ led3Button.addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ led3ButtonMousePressed(evt);
+ }
+ });
+ setLedsPanel.add(led3Button);
+
+ led4Button.setText("Led4");
+ led4Button.addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ led4ButtonMousePressed(evt);
+ }
+ });
+ setLedsPanel.add(led4Button);
+
+ setLedsButton.setText("Set leds");
+ setLedsButton.addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ setLedsButtonMousePressed(evt);
+ }
+ });
+ setLedsPanel.add(setLedsButton);
+
+ controlsPanel.add(setLedsPanel);
+
+ alphaSmoothingTextField.setMinimumSize(new java.awt.Dimension(100, 20));
+ alphaSmoothingTextField
+ .setPreferredSize(new java.awt.Dimension(100, 20));
+ setAlphaSmoothingPanel.add(alphaSmoothingTextField);
+
+ alphaSmoothingButton.setText("Set alpha smoothing");
+ alphaSmoothingButton
+ .addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ alphaSmoothingButtonMousePressed(evt);
+ }
+ });
+ setAlphaSmoothingPanel.add(alphaSmoothingButton);
+
+ controlsPanel.add(setAlphaSmoothingPanel);
+
+ orientationThresholdTextField.setMinimumSize(new java.awt.Dimension(
+ 100, 20));
+ orientationThresholdTextField.setPreferredSize(new java.awt.Dimension(
+ 100, 20));
+ setOrientationThresholdPanel.add(orientationThresholdTextField);
+
+ orientationThresholdButton.setText("Set orientation threshold");
+ orientationThresholdButton
+ .addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ orientationThresholdButtonMousePressed(evt);
+ }
+ });
+ setOrientationThresholdPanel.add(orientationThresholdButton);
+
+ controlsPanel.add(setOrientationThresholdPanel);
+
+ accelerationThresholdTextField.setPreferredSize(new java.awt.Dimension(
+ 100, 20));
+ setAccelerationThresholdPanel.add(accelerationThresholdTextField);
+
+ accelerationThresholdButton.setText("Set acceleration threshold");
+ accelerationThresholdButton
+ .addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ accelerationThresholdButtonMousePressed(evt);
+ }
+ });
+ setAccelerationThresholdPanel.add(accelerationThresholdButton);
+
+ controlsPanel.add(setAccelerationThresholdPanel);
+
+ getStatusButton.setText("Get status");
+ getStatusButton.addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ getStatusButtonMousePressed(evt);
+ }
+ });
+ getStatusPanel.add(getStatusButton);
+
+ batteryText.setFont(new java.awt.Font("Tahoma", 0, 14));
+ batteryText.setText("Battery level :");
+ getStatusPanel.add(batteryText);
+
+ batteryLevelText.setFont(new java.awt.Font("Arial", 0, 14));
+ batteryLevelText.setText(" %");
+ getStatusPanel.add(batteryLevelText);
+
+ controlsPanel.add(getStatusPanel);
+
+ setIrSensitivySpinner.setPreferredSize(new java.awt.Dimension(50, 18));
+ setIrSensitivySpinner
+ .addChangeListener(new javax.swing.event.ChangeListener() {
+ public void stateChanged(javax.swing.event.ChangeEvent evt) {
+ setIrSensitivySpinnerStateChanged(evt);
+ }
+ });
+ setIrSensitivyPanel.add(setIrSensitivySpinner);
+
+ setIrSensitivyButton.setText("SetIrSensivity");
+ setIrSensitivyButton
+ .addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ setIrSensitivyButtonMousePressed(evt);
+ }
+ });
+ setIrSensitivyPanel.add(setIrSensitivyButton);
+
+ setTimeoutButton.setText("Set timeouts in ms");
+ setTimeoutButton.addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ setTimeoutButtonMousePressed(evt);
+ }
+ });
+ setIrSensitivyPanel.add(setTimeoutButton);
+
+ controlsPanel.add(setIrSensitivyPanel);
+
+ normalTimeoutSpinner.setPreferredSize(new java.awt.Dimension(40, 18));
+ normalTimeoutSpinner
+ .addChangeListener(new javax.swing.event.ChangeListener() {
+ public void stateChanged(javax.swing.event.ChangeEvent evt) {
+ normalTimeoutSpinnerStateChanged(evt);
+ }
+ });
+ setTimeoutPanel.add(normalTimeoutSpinner);
+
+ normalTimeoutText.setText("Normal timeout");
+ setTimeoutPanel.add(normalTimeoutText);
+
+ expansionHandshakeTimeoutSpinner
+ .setPreferredSize(new java.awt.Dimension(40, 18));
+ expansionHandshakeTimeoutSpinner
+ .addChangeListener(new javax.swing.event.ChangeListener() {
+ public void stateChanged(javax.swing.event.ChangeEvent evt) {
+ expansionHandshakeTimeoutSpinnerStateChanged(evt);
+ }
+ });
+ setTimeoutPanel.add(expansionHandshakeTimeoutSpinner);
+
+ expansionHandshakeTimeoutText.setText("Expansion handshake timeout");
+ setTimeoutPanel.add(expansionHandshakeTimeoutText);
+
+ controlsPanel.add(setTimeoutPanel);
+
+ toggleSensorBarPositionButton.setText("Set sensor bar above");
+ toggleSensorBarPositionButton
+ .addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ toggleSensorBarPositionButtonMousePressed(evt);
+ }
+ });
+ setIRConfPanel.add(toggleSensorBarPositionButton);
+
+ toggleScreenAspectRatioButton.setText("Set screen aspect ratio 4/3");
+ toggleScreenAspectRatioButton
+ .addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ toggleScreenAspectRatioButtonMousePressed(evt);
+ }
+ });
+ setIRConfPanel.add(toggleScreenAspectRatioButton);
+
+ controlsPanel.add(setIRConfPanel);
+
+ xLabel.setText("X");
+ setVirtualResolutionPanel.add(xLabel);
+
+ xResolutionTextField.setMinimumSize(new java.awt.Dimension(40, 20));
+ xResolutionTextField.setPreferredSize(new java.awt.Dimension(40, 20));
+ setVirtualResolutionPanel.add(xResolutionTextField);
+
+ yLabel.setText("Y");
+ setVirtualResolutionPanel.add(yLabel);
+
+ yResolutionTextField.setFocusTraversalPolicyProvider(true);
+ yResolutionTextField.setMinimumSize(new java.awt.Dimension(40, 20));
+ yResolutionTextField.setPreferredSize(new java.awt.Dimension(40, 20));
+ setVirtualResolutionPanel.add(yResolutionTextField);
+
+ setVirtualResolutionButton.setText("Set virtual resolution");
+ setVirtualResolutionButton
+ .addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ setVirtualResolutionButtonMousePressed(evt);
+ }
+ });
+ setVirtualResolutionPanel.add(setVirtualResolutionButton);
+
+ controlsPanel.add(setVirtualResolutionPanel);
+
+ mouseIRControlButton.setText("Start infrared mouse control");
+ mouseIRControlButton
+ .addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ mouseIRControlButtonMousePressed(evt);
+ }
+ });
+ startMouseControlPanel.add(mouseIRControlButton);
+
+ controlsPanel.add(startMouseControlPanel);
+
+ expansionText.setText("No expansion connected.");
+ exPansionPanel.add(expansionText);
+
+ showExpansionWiimoteButton.setText("No expansion connected");
+ showExpansionWiimoteButton
+ .addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ showExpansionWiimoteButtonMousePressed(evt);
+ }
+ });
+ exPansionPanel.add(showExpansionWiimoteButton);
+
+ controlsPanel.add(exPansionPanel);
+
+ reconnectWiimotesButton.setText("Reconnect wiimote");
+ reconnectWiimotesButton
+ .addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mousePressed(java.awt.event.MouseEvent evt) {
+ reconnectWiimotesButtonMousePressed(evt);
+ }
+ });
+ messagesPanel.add(reconnectWiimotesButton);
+
+ messageLabelText.setFont(new java.awt.Font("Tahoma", 0, 14));
+ messageLabelText.setText("Message : ");
+ messagesPanel.add(messageLabelText);
+
+ messageText.setFont(new java.awt.Font("Arial", 0, 14));
+ messageText.setText("None");
+ messagesPanel.add(messageText);
+
+ controlsPanel.add(messagesPanel);
+
+ rightPanel.add(controlsPanel);
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
+ getContentPane());
+ getContentPane().setLayout(layout);
+ layout
+ .setHorizontalGroup(layout
+ .createParallelGroup(
+ javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(
+ layout
+ .createSequentialGroup()
+ .addComponent(
+ leftPanel,
+ javax.swing.GroupLayout.DEFAULT_SIZE,
+ javax.swing.GroupLayout.DEFAULT_SIZE,
+ Short.MAX_VALUE)
+ .addPreferredGap(
+ javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(
+ rightPanel,
+ javax.swing.GroupLayout.DEFAULT_SIZE,
+ 498, Short.MAX_VALUE)));
+ layout.setVerticalGroup(layout.createParallelGroup(
+ javax.swing.GroupLayout.Alignment.LEADING).addComponent(
+ leftPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
+ javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(rightPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
+ 573, Short.MAX_VALUE));
+
+ java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit()
+ .getScreenSize();
+ setBounds((screenSize.width - 800) / 2, (screenSize.height - 600) / 2,
+ 800, 600);
+ }// //GEN-END:initComponents
+
+ private void toggleRumbleButtonMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_toggleRumbleButtonMousePressed
+ if (toggleRumbleButton.isEnabled()) {
+ wiimote.activateRumble();
+ toggleRumbleButton.setEnabled(false);
+ toggleRumbleButton.setText("Deactivate Rumble");
+ messageText.setText("Rumble activated");
+ } else {
+ wiimote.deactivateRumble();
+ toggleRumbleButton.setEnabled(true);
+ toggleRumbleButton.setText("Activate Rumble");
+ messageText.setText("Rumble deactivated");
+ }
+ }// GEN-LAST:event_toggleRumbleButtonMousePressed
+
+ private void toggleIRTrackingButtonMousePressed(
+ java.awt.event.MouseEvent evt) {// GEN-FIRST:event_toggleIRTrackingButtonMousePressed
+ if (toggleIRTrackingButton.isEnabled()) {
+ wiimote.activateIRTRacking();
+ toggleIRTrackingButton.setEnabled(false);
+ toggleIRTrackingButton.setText("Deactivate IR Tracking");
+ messageText.setText("IR Tracking activated");
+ } else {
+ wiimote.deactivateIRTRacking();
+ toggleIRTrackingButton.setEnabled(true);
+ toggleIRTrackingButton.setText("Activate IR Tracking");
+ ((IRPanel) irViewPanel).onDisconnectionEvent(null);
+ messageText.setText("IR Tracking deactivated");
+ }
+ }// GEN-LAST:event_toggleIRTrackingButtonMousePressed
+
+ private void toggleMotionSensingTrackingButtonMousePressed(
+ java.awt.event.MouseEvent evt) {// GEN-FIRST:event_toggleMotionSensingTrackingButtonMousePressed
+ if (toggleMotionSensingTrackingButton.isEnabled()) {
+ wiimote.activateMotionSensing();
+ toggleMotionSensingTrackingButton.setEnabled(false);
+ toggleMotionSensingTrackingButton
+ .setText("Deactivate Motion Sensing");
+ messageText.setText("Motion Sensing activated");
+ } else {
+ wiimote.deactivateMotionSensing();
+ toggleMotionSensingTrackingButton.setEnabled(true);
+ toggleMotionSensingTrackingButton
+ .setText("Activate Motion Sensing");
+ ((OrientationPanel) motionSensingPanel).onDisconnectionEvent(null);
+ ((GForcePanel) gForcePanel).onDisconnectionEvent(null);
+ messageText.setText("Motion Sensing deactivated");
+ }
+ }// GEN-LAST:event_toggleMotionSensingTrackingButtonMousePressed
+
+ private void toggleSmoothingButtonMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_toggleSmoothingButtonMousePressed
+ if (toggleSmoothingButton.isEnabled()) {
+ wiimote.activateSmoothing();
+ toggleSmoothingButton.setEnabled(false);
+ toggleSmoothingButton.setText("Deactivate Alpha Smoothing");
+ messageText.setText("Alpha Smoothing activated");
+ } else {
+ wiimote.deactivateSmoothing();
+ toggleSmoothingButton.setEnabled(true);
+ toggleSmoothingButton.setText("Activate Alpha Smoothing");
+ messageText.setText("Alpha Smoothing deactivated");
+ }
+ }// GEN-LAST:event_toggleSmoothingButtonMousePressed
+
+ private void toggleContinuousButtonMousePressed(
+ java.awt.event.MouseEvent evt) {// GEN-FIRST:event_toggleContinuousButtonMousePressed
+ if (toggleContinuousButton.isEnabled()) {
+ wiimote.activateContinuous();
+ toggleContinuousButton.setEnabled(false);
+ toggleContinuousButton.setText("Deactivate Continuous");
+ messageText.setText("Continuous activated");
+ } else {
+ wiimote.deactivateContinuous();
+ toggleContinuousButton.setEnabled(true);
+ toggleContinuousButton.setText("Activate Continuous");
+ messageText.setText("Continuous deactivated");
+ }
+ }// GEN-LAST:event_toggleContinuousButtonMousePressed
+
+ private void led1ButtonMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_led1ButtonMousePressed
+ if (led1Button.isEnabled()) {
+ led1Button.setEnabled(false);
+ } else {
+ led1Button.setEnabled(true);
+ }
+ }// GEN-LAST:event_led1ButtonMousePressed
+
+ private void led2ButtonMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_led2ButtonMousePressed
+ if (led2Button.isEnabled()) {
+ led2Button.setEnabled(false);
+ } else {
+ led2Button.setEnabled(true);
+ }
+ }// GEN-LAST:event_led2ButtonMousePressed
+
+ private void led3ButtonMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_led3ButtonMousePressed
+ if (led3Button.isEnabled()) {
+ led3Button.setEnabled(false);
+ } else {
+ led3Button.setEnabled(true);
+ }
+ }// GEN-LAST:event_led3ButtonMousePressed
+
+ private void led4ButtonMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_led4ButtonMousePressed
+ if (led4Button.isEnabled()) {
+ led4Button.setEnabled(false);
+ } else {
+ led4Button.setEnabled(true);
+ }
+ }// GEN-LAST:event_led4ButtonMousePressed
+
+ private void setLedsButtonMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_setLedsButtonMousePressed
+ wiimote.setLeds(led1Button.isEnabled(), led2Button.isEnabled(),
+ led3Button.isEnabled(), led4Button.isEnabled());
+ messageText.setText("Leds set");
+ }// GEN-LAST:event_setLedsButtonMousePressed
+
+ private void alphaSmoothingButtonMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_alphaSmoothingButtonMousePressed
+ try {
+ float nb = Float.parseFloat(alphaSmoothingTextField.getText());
+ wiimote.setAlphaSmoothingValue(nb);
+ messageText.setText("Alpha smoothing set to " + nb);
+ } catch (NumberFormatException e) {
+ messageText
+ .setText("Number is not a float, alpha smoothing not set !");
+ }
+ }// GEN-LAST:event_alphaSmoothingButtonMousePressed
+
+ private void orientationThresholdButtonMousePressed(
+ java.awt.event.MouseEvent evt) {// GEN-FIRST:event_orientationThresholdButtonMousePressed
+ try {
+ float nb = Float
+ .parseFloat(orientationThresholdTextField.getText());
+ wiimote.setOrientationThreshold(nb);
+ messageText.setText("Orientation threshold set to " + nb);
+ } catch (NumberFormatException e) {
+ messageText
+ .setText("Number is not a float, orientation threshold not set !");
+ }
+ }// GEN-LAST:event_orientationThresholdButtonMousePressed
+
+ private void accelerationThresholdButtonMousePressed(
+ java.awt.event.MouseEvent evt) {// GEN-FIRST:event_accelerationThresholdButtonMousePressed
+ try {
+ int nb = Integer.parseInt(accelerationThresholdTextField.getText());
+ wiimote.setAccelerationThreshold(nb);
+ messageText.setText("Acceleration threshold set to " + nb);
+ } catch (NumberFormatException e) {
+ messageText
+ .setText("Number is not an integer, acceleration threshold not set !");
+ }
+ }// GEN-LAST:event_accelerationThresholdButtonMousePressed
+
+ private void getStatusButtonMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_getStatusButtonMousePressed
+ wiimote.getStatus();
+ statusMotionRequested = true;
+ statusIRRequested = true;
+ if (expansionFrame instanceof NunchukGuiTest) {
+ ((NunchukGuiTest) expansionFrame).requestThresholdsUpdate();
+ }
+ }// GEN-LAST:event_getStatusButtonMousePressed
+
+ private void toggleSensorBarPositionButtonMousePressed(
+ java.awt.event.MouseEvent evt) {// GEN-FIRST:event_toggleSensorBarPositionButtonMousePressed
+ if (toggleSensorBarPositionButton.isEnabled()) {
+ wiimote.setSensorBarBelowScreen();
+ toggleSensorBarPositionButton.setEnabled(false);
+ toggleSensorBarPositionButton.setText("Set sensor bar below");
+ messageText.setText("Sensor bar set above");
+ } else {
+ wiimote.setSensorBarAboveScreen();
+ toggleSensorBarPositionButton.setEnabled(true);
+ toggleSensorBarPositionButton.setText("Set sensor bar above");
+ messageText.setText("Sensor bar set below");
+ }
+ }// GEN-LAST:event_toggleSensorBarPositionButtonMousePressed
+
+ private void toggleScreenAspectRatioButtonMousePressed(
+ java.awt.event.MouseEvent evt) {// GEN-FIRST:event_toggleScreenAspectRatioButtonMousePressed
+ if (toggleScreenAspectRatioButton.isEnabled()) {
+ wiimote.setScreenAspectRatio43();
+ toggleScreenAspectRatioButton.setEnabled(false);
+ toggleScreenAspectRatioButton
+ .setText("Set screen aspect ratio 16/9");
+ messageText.setText("creen aspect ratio to 4/3");
+ } else {
+ wiimote.setScreenAspectRatio169();
+ toggleScreenAspectRatioButton.setEnabled(true);
+ toggleScreenAspectRatioButton
+ .setText("Set screen aspect ratio 4/3");
+ messageText.setText("Screen aspect ratio to 16/9");
+ }
+ }// GEN-LAST:event_toggleScreenAspectRatioButtonMousePressed
+
+ private void setVirtualResolutionButtonMousePressed(
+ java.awt.event.MouseEvent evt) {// GEN-FIRST:event_setVirtualResolutionButtonMousePressed
+ try {
+ int xres = Integer.parseInt(xResolutionTextField.getText());
+ int yres = Integer.parseInt(yResolutionTextField.getText());
+ wiimote.setVirtualResolution(xres, yres);
+ messageText.setText("Virtual resolution set to " + xres + "X"
+ + yres);
+ } catch (NumberFormatException e) {
+ messageText
+ .setText("A number in the virtual resolution is not an integer. Virtual resolution not set!");
+ }
+ }// GEN-LAST:event_setVirtualResolutionButtonMousePressed
+
+ private void mouseIRControlButtonMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_mouseIRControlButtonMousePressed
+ if (mouseIRControlButton.isEnabled()) {
+ try {
+ mouseIRControlButton.setEnabled(false);
+ mouseIRControlButton.setText("Stop infrared mouse control");
+ robot = new Robot();
+ messageText.setText("Infrared mouse control started");
+ } catch (AWTException ex) {
+ Logger.getLogger(WiiuseJGuiTest.class.getName()).log(
+ Level.SEVERE, null, ex);
+ }
+ } else {
+ mouseIRControlButton.setEnabled(true);
+ mouseIRControlButton.setText("Start infrared mouse control");
+ robot = null;
+ messageText.setText("Infrared mouse control stopped");
+ }
+ }// GEN-LAST:event_mouseIRControlButtonMousePressed
+
+ private void normalTimeoutSpinnerStateChanged(
+ javax.swing.event.ChangeEvent evt) {// GEN-FIRST:event_normalTimeoutSpinnerStateChanged
+ String value = normalTimeoutSpinner.getValue().toString();
+ boolean isInt = true;
+ int valueInt = 0;
+ try {
+ valueInt = Integer.parseInt(value);
+ } catch (NumberFormatException e) {
+ isInt = false;
+ messageText.setText("Wrong value for normal timeout.");
+ }
+ if (isInt) {
+ if (valueInt > 1000) {
+ normalTimeoutSpinner.setValue("1000");
+ } else if (valueInt < 0) {
+ normalTimeoutSpinner.setValue("0");
+ }
+ }
+ }// GEN-LAST:event_normalTimeoutSpinnerStateChanged
+
+ private void expansionHandshakeTimeoutSpinnerStateChanged(
+ javax.swing.event.ChangeEvent evt) {// GEN-FIRST:event_expansionHandshakeTimeoutSpinnerStateChanged
+ String value = expansionHandshakeTimeoutSpinner.getValue().toString();
+ boolean isInt = true;
+ int valueInt = 0;
+ try {
+ valueInt = Integer.parseInt(value);
+ } catch (NumberFormatException e) {
+ isInt = false;
+ messageText.setText("Wrong value for expansion handshake timeout.");
+ }
+ if (isInt) {
+ if (valueInt > 1000) {
+ expansionHandshakeTimeoutSpinner.setValue("1000");
+ } else if (valueInt < 0) {
+ expansionHandshakeTimeoutSpinner.setValue("0");
+ }
+ }
+ }// GEN-LAST:event_expansionHandshakeTimeoutSpinnerStateChanged
+
+ private void setIrSensitivySpinnerStateChanged(
+ javax.swing.event.ChangeEvent evt) {// GEN-FIRST:event_setIrSensitivySpinnerStateChanged
+ String value = setIrSensitivySpinner.getValue().toString();
+ boolean isInt = true;
+ int valueInt = 0;
+ try {
+ valueInt = Integer.parseInt(value);
+ } catch (NumberFormatException e) {
+ isInt = false;
+ messageText.setText("Wrong value for IR senstivity.");
+ }
+ if (isInt) {
+ if (valueInt > 5) {
+ setIrSensitivySpinner.setValue("1000");
+ } else if (valueInt < 0) {
+ setIrSensitivySpinner.setValue("0");
+ }
+ }
+ }// GEN-LAST:event_setIrSensitivySpinnerStateChanged
+
+ private void setIrSensitivyButtonMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_setIrSensitivyButtonMousePressed
+ String value = setIrSensitivySpinner.getValue().toString();
+ boolean isInt = true;
+ int valueInt = 0;
+ try {
+ valueInt = Integer.parseInt(value);
+ } catch (NumberFormatException e) {
+ isInt = false;
+ messageText
+ .setText("Wrong value for IR sensitivity. It must be an int !");
+ }
+ if (isInt) {
+ if (valueInt >= 1 && valueInt <= 5) {
+ wiimote.setIrSensitivity(valueInt);
+ messageText.setText("IR senstivity set to: " + valueInt + ".");
+ } else {
+ messageText
+ .setText("Wrong value for IR senstivity. It muset be between 1 and 5 !");
+ }
+ }
+ }// GEN-LAST:event_setIrSensitivyButtonMousePressed
+
+ private void setTimeoutButtonMousePressed(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_setTimeoutButtonMousePressed
+ // get normal timeout
+ String value = normalTimeoutSpinner.getValue().toString();
+ boolean isInt = true;
+ short valueInt = 0;
+ try {
+ valueInt = Short.parseShort(value);
+ } catch (NumberFormatException e) {
+ isInt = false;
+ messageText
+ .setText("Wrong value for normal timeout. It must be an int !");
+ }
+ // get expansion handshake timeout
+ String value2 = expansionHandshakeTimeoutSpinner.getValue().toString();
+ boolean isInt2 = true;
+ short valueInt2 = 0;
+ try {
+ valueInt2 = Short.parseShort(value2);
+ } catch (NumberFormatException e) {
+ isInt2 = false;
+ messageText
+ .setText("Wrong value for expansion handshake timeout. It must be an int !");
+ }
+ if (isInt && isInt2) {
+ if (valueInt > 0 && valueInt2 > 0) {
+ wiimote.setTimeout(valueInt, valueInt2);
+ messageText.setText("Normal timeout set to: " + valueInt
+ + " and expansion handshake timeout set to: "
+ + valueInt2 + "!");
+ } else {
+ messageText
+ .setText("Wrong value for one of the timeout value. It must be an integer > 0 !");
+ }
+ }
+ }// GEN-LAST:event_setTimeoutButtonMousePressed
+
+ private void reconnectWiimotesButtonMousePressed(
+ java.awt.event.MouseEvent evt) {// GEN-FIRST:event_reconnectWiimotesButtonMousePressed
+ // stop manager
+ WiiUseApiManager.shutdown();
+
+ // unregister previous wiimote
+ if (wiimote != null) {
+ onDisconnectionEvent(null);
+ }
+
+ // Reset Gui
+ // remove frame for expansion
+ if (expansionFrame != null) {
+ if (expansionFrame instanceof NunchukGuiTest) {
+ ((NunchukGuiTest) expansionFrame).unRegisterListeners();
+ }
+ expansionFrame.setEnabled(false);
+ expansionFrame.dispose();
+ expansionFrame = null;
+ }
+
+ // setup buttons In first state
+ toggleRumbleButton.setText("Activate Rumble");
+ toggleRumbleButton.setEnabled(true);
+ toggleMotionSensingTrackingButton
+ .setText("Activate motion sensing Tracking");
+ toggleMotionSensingTrackingButton.setEnabled(true);
+ toggleIRTrackingButton.setText("Activate IR Tracking");
+ toggleIRTrackingButton.setEnabled(true);
+ toggleContinuousButton.setText("Activate Continuous");
+ toggleContinuousButton.setEnabled(true);
+ toggleScreenAspectRatioButton.setText("Set screen aspect ratio 4/3");
+ toggleScreenAspectRatioButton.setEnabled(true);
+ toggleSensorBarPositionButton.setText("Set sensor bar above");
+ toggleSensorBarPositionButton.setEnabled(true);
+ toggleSmoothingButton.setText("Activate Smoothing");
+ toggleSmoothingButton.setEnabled(true);
+ mouseIRControlButton.setText("Start infrared mouse control");
+ mouseIRControlButton.setEnabled(true);
+
+ // get wiimote
+ Wiimote[] listWiimote = WiiUseApiManager.getWiimotes(1, true);
+ if (listWiimote != null && listWiimote.length > 0) {
+ wiimote = listWiimote[0];
+
+ // registers listeners
+ registerListeners();
+ initWiimote();
+
+ isFirstStatusGot = false;
+ getStatusButtonMousePressed(null);
+ }
+ }// GEN-LAST:event_reconnectWiimotesButtonMousePressed
+
+ private void showExpansionWiimoteButtonMousePressed(
+ java.awt.event.MouseEvent evt) {// GEN-FIRST:event_showExpansionWiimoteButtonMousePressed
+ if (expansionFrame != null) {
+ if (showExpansionWiimoteButton.isEnabled()) {// expansion frame
+ // not shown
+ // show it
+ expansionFrame.setEnabled(true);
+ expansionFrame.setVisible(true);
+ showExpansionWiimoteButton.setEnabled(false);
+ showExpansionWiimoteButton.setText("Hide Nunchuk");
+ messageText.setText("Nunchuk displayed !");
+ } else {// already being shown
+ expansionFrame.setEnabled(false);
+ expansionFrame.setVisible(false);
+ showExpansionWiimoteButton.setEnabled(true);
+ showExpansionWiimoteButton.setText("Show Nunchuk");
+ messageText.setText("Nunchuk hidden !");
+ }
+ }
+ }// GEN-LAST:event_showExpansionWiimoteButtonMousePressed
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JPanel accelerationPanel;
+ private javax.swing.JButton accelerationThresholdButton;
+ private javax.swing.JTextField accelerationThresholdTextField;
+ private javax.swing.JPanel activateMotionSensingPanel;
+ private javax.swing.JPanel activateRumbleIRPanel;
+ private javax.swing.JPanel activateSmoothingContinuousPanel;
+ private javax.swing.JButton alphaSmoothingButton;
+ private javax.swing.JTextField alphaSmoothingTextField;
+ private javax.swing.JLabel batteryLevelText;
+ private javax.swing.JLabel batteryText;
+ private javax.swing.JPanel buttonsPanel;
+ private javax.swing.JPanel controlsPanel;
+ private javax.swing.JPanel exPansionPanel;
+ private javax.swing.JSpinner expansionHandshakeTimeoutSpinner;
+ private javax.swing.JLabel expansionHandshakeTimeoutText;
+ private javax.swing.JLabel expansionText;
+ private javax.swing.JPanel fixedWiimotePanel;
+ private javax.swing.JPanel gForcePanel;
+ private javax.swing.JButton getStatusButton;
+ private javax.swing.JPanel getStatusPanel;
+ private javax.swing.JPanel irViewPanel;
+ private javax.swing.JTabbedPane jTabbedPane1;
+ private javax.swing.JButton led1Button;
+ private javax.swing.JButton led2Button;
+ private javax.swing.JButton led3Button;
+ private javax.swing.JButton led4Button;
+ private javax.swing.JPanel leftPanel;
+ private javax.swing.JLabel messageLabelText;
+ private javax.swing.JLabel messageText;
+ private javax.swing.JPanel messagesPanel;
+ private javax.swing.JPanel motionSensingPanel;
+ private javax.swing.JButton mouseIRControlButton;
+ private javax.swing.JSpinner normalTimeoutSpinner;
+ private javax.swing.JLabel normalTimeoutText;
+ private javax.swing.JButton orientationThresholdButton;
+ private javax.swing.JTextField orientationThresholdTextField;
+ private javax.swing.JButton reconnectWiimotesButton;
+ private javax.swing.JPanel rightPanel;
+ private javax.swing.JPanel setAccelerationThresholdPanel;
+ private javax.swing.JPanel setAlphaSmoothingPanel;
+ private javax.swing.JPanel setIRConfPanel;
+ private javax.swing.JButton setIrSensitivyButton;
+ private javax.swing.JPanel setIrSensitivyPanel;
+ private javax.swing.JSpinner setIrSensitivySpinner;
+ private javax.swing.JButton setLedsButton;
+ private javax.swing.JPanel setLedsPanel;
+ private javax.swing.JPanel setOrientationThresholdPanel;
+ private javax.swing.JButton setTimeoutButton;
+ private javax.swing.JPanel setTimeoutPanel;
+ private javax.swing.JButton setVirtualResolutionButton;
+ private javax.swing.JPanel setVirtualResolutionPanel;
+ private javax.swing.JButton showExpansionWiimoteButton;
+ private javax.swing.JPanel startMouseControlPanel;
+ private javax.swing.JButton toggleContinuousButton;
+ private javax.swing.JButton toggleIRTrackingButton;
+ private javax.swing.JButton toggleMotionSensingTrackingButton;
+ private javax.swing.JButton toggleRumbleButton;
+ private javax.swing.JButton toggleScreenAspectRatioButton;
+ private javax.swing.JButton toggleSensorBarPositionButton;
+ private javax.swing.JButton toggleSmoothingButton;
+ private javax.swing.JLabel xLabel;
+ private javax.swing.JTextField xResolutionTextField;
+ private javax.swing.JLabel yLabel;
+ private javax.swing.JTextField yResolutionTextField;
+ // End of variables declaration//GEN-END:variables
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/utils/AccelerationExpansionEventPanel.java b/WiiUseJ_0.12/src/wiiusej/utils/AccelerationExpansionEventPanel.java
new file mode 100644
index 0000000..cb3021f
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/utils/AccelerationExpansionEventPanel.java
@@ -0,0 +1,39 @@
+/**
+ * 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.utils;
+
+import wiiusej.values.RawAcceleration;
+import wiiusej.wiiusejevents.GenericEvent;
+import wiiusej.wiiusejevents.physicalevents.NunchukEvent;
+
+/**
+ * Panel to display Acceleration in a MotionSensingEvent from an expansion.
+ *
+ * @author guiguito
+ */
+public class AccelerationExpansionEventPanel extends AccelerationPanel {
+
+ @Override
+ public RawAcceleration getRawAccelerationValue(GenericEvent e) {
+ if (e instanceof NunchukEvent) {
+ return ((NunchukEvent) e).getNunchukMotionSensingEvent()
+ .getRawAcceleration();
+ }
+ return null;
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/utils/AccelerationPanel.java b/WiiUseJ_0.12/src/wiiusej/utils/AccelerationPanel.java
new file mode 100644
index 0000000..6caa3b6
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/utils/AccelerationPanel.java
@@ -0,0 +1,281 @@
+/**
+ * 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.utils;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.RenderingHints;
+import java.awt.geom.AffineTransform;
+import java.util.ArrayList;
+
+import wiiusej.values.RawAcceleration;
+import wiiusej.wiiusejevents.GenericEvent;
+import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
+import wiiusej.wiiusejevents.physicalevents.IREvent;
+import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
+import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
+import wiiusej.wiiusejevents.utils.WiimoteListener;
+import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
+
+/**
+ * This panel is used to watch raw acceleration values from a
+ * MotionSensingEvent.
+ *
+ * @author guiguito
+ */
+public abstract class AccelerationPanel extends javax.swing.JPanel implements
+ WiimoteListener {
+
+ private Image mImage;// image for double buffering
+ private Color xColor = Color.RED;
+ private Color yColor = Color.GREEN;
+ private Color zColor = Color.BLUE;
+ private Color backgroundColor = Color.WHITE;
+ private Color lineColor = Color.BLACK;
+ private ArrayList values = new ArrayList();
+
+ /** Creates new form AccelerationPanel */
+ public AccelerationPanel() {
+ initComponents();
+ }
+
+ /**
+ * Constructor used to choose the colors used by the AccelerationPanel.
+ *
+ * @param bgColor
+ * background color.
+ * @param xColor
+ * x color.
+ * @param yColor
+ * y color.
+ * @param zColor
+ * z color.
+ * @param lColor
+ * line color.
+ */
+ public AccelerationPanel(Color bgColor, Color xColor, Color yColor,
+ Color zColor, Color lColor) {
+ backgroundColor = bgColor;
+ this.xColor = xColor;
+ this.yColor = yColor;
+ this.zColor = zColor;
+ lineColor = lColor;
+ initComponents();
+ }
+
+ @Override
+ public void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ Dimension d = getSize();
+ checkOffScreenImage();
+ Graphics offG = mImage.getGraphics();
+ offG.setColor(backgroundColor);
+ offG.fillRect(0, 0, d.width, d.height);
+ Graphics2D g2 = (Graphics2D) mImage.getGraphics();
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+
+ // draw medium line
+ int yLine = getHeight() - 25;
+
+ g2.setPaint(lineColor);
+ g2.drawLine(0, yLine, getWidth(), yLine);
+
+ RawAcceleration[] valuesArray = values.toArray(new RawAcceleration[0]);
+
+ double unit = yLine / 255.0;
+ int previousX = 0;
+ int previousY = 0;
+ int previousZ = 0;
+ // draw curves
+ for (int i = 0; i < valuesArray.length && i < getWidth(); i++) {
+ RawAcceleration acceleration = valuesArray[i];
+ // draw X
+ g2.setPaint(xColor);
+ int yDelta = (int) Math.round(unit * acceleration.getX());
+ int y = -1 * yDelta + yLine;
+ g2.drawLine(i - 1, previousX, i, y);
+ g2.setTransform(new AffineTransform());
+ previousX = y;
+ // draw Y
+ g2.setPaint(yColor);
+ yDelta = (int) Math.round(unit * acceleration.getY());
+ y = -1 * yDelta + yLine;
+ g2.drawLine(i - 1, previousY, i, y);
+ g2.setTransform(new AffineTransform());
+ previousY = y;
+ // draw Z
+ g2.setPaint(zColor);
+ yDelta = (int) Math.round(unit * acceleration.getZ());
+ y = -1 * yDelta + yLine;
+ g2.drawLine(i - 1, previousZ, i, y);
+ g2.setTransform(new AffineTransform());
+ previousZ = y;
+ }
+
+ // draw legend
+ g2.setPaint(xColor);
+ g2.drawLine(5, getHeight() - 10, 25, getHeight() - 10);
+ g2.setPaint(yColor);
+ g2.drawLine(60, getHeight() - 10, 80, getHeight() - 10);
+ g2.setPaint(zColor);
+ g2.drawLine(120, getHeight() - 10, 140, getHeight() - 10);
+
+ g2.setPaint(lineColor);
+ g2.drawString("X", 30, getHeight() - 5);
+ g2.drawString("Y", 85, getHeight() - 5);
+ g2.drawString("Z", 145, getHeight() - 5);
+ g2.drawString("0", 2, yLine - 5);
+ g2.drawString("255", 2, 15);
+ // put offscreen image on the screen
+ g.drawImage(mImage, 0, 0, null);
+ }
+
+ /**
+ * check if the mImage variable has been initialized. If it's not the case
+ * it initializes it with the dimensions of the panel. mImage is for double
+ * buffering.
+ */
+ private void checkOffScreenImage() {
+ Dimension d = getSize();
+ if (mImage == null || mImage.getWidth(null) != d.width
+ || mImage.getHeight(null) != d.height) {
+ mImage = createImage(d.width, d.height);
+ }
+ }
+
+ public void onButtonsEvent(WiimoteButtonsEvent arg0) {
+ // nothing
+ }
+
+ public void onIrEvent(IREvent arg0) {
+ // nothing
+ }
+
+ public void onMotionSensingEvent(MotionSensingEvent arg0) {
+ draw(arg0);
+ }
+
+ public void onExpansionEvent(ExpansionEvent arg0) {
+ draw(arg0);
+ }
+
+ public void onStatusEvent(StatusEvent arg0) {
+ // nothing
+ }
+
+ public void onDisconnectionEvent(DisconnectionEvent arg0) {
+ // Clear points.
+ values.clear();
+ repaint();
+ }
+
+ public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
+ // nothing
+ }
+
+ public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
+ // nothing
+ }
+
+ private void draw(GenericEvent arg0) {
+ if (values.size() >= getWidth()) {
+ // if there are as many values as pixels in the width
+ // clear points
+ values.clear();
+ }
+ RawAcceleration rawAcceleration = getRawAccelerationValue(arg0);
+ if (rawAcceleration != null)
+ values.add(rawAcceleration);
+ repaint();
+ }
+
+ public abstract RawAcceleration getRawAccelerationValue(GenericEvent e);
+
+ public Color getBackgroundColor() {
+ return backgroundColor;
+ }
+
+ public Color getLineColor() {
+ return lineColor;
+ }
+
+ public Color getXColor() {
+ return xColor;
+ }
+
+ public Color getYColor() {
+ return yColor;
+ }
+
+ public Color getZColor() {
+ return zColor;
+ }
+
+ public void setBackgroundColor(Color backgroundColor) {
+ this.backgroundColor = backgroundColor;
+ }
+
+ public void setLineColor(Color lineColor) {
+ this.lineColor = lineColor;
+ }
+
+ public void setXColor(Color xColor) {
+ this.xColor = xColor;
+ }
+
+ public void setYColor(Color yColor) {
+ this.yColor = yColor;
+ }
+
+ public void setZColor(Color zColor) {
+ this.zColor = zColor;
+ }
+
+ public void clearView() {
+ values.clear();
+ repaint();
+ }
+
+ /**
+ * This method is called from within the constructor to initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is always
+ * regenerated by the Form Editor.
+ */
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+ this.setLayout(layout);
+ layout.setHorizontalGroup(layout.createParallelGroup(
+ javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
+ Short.MAX_VALUE));
+ layout.setVerticalGroup(layout.createParallelGroup(
+ javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
+ Short.MAX_VALUE));
+ }// //GEN-END:initComponents
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ // End of variables declaration//GEN-END:variables
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/utils/AccelerationWiimoteEventPanel.java b/WiiUseJ_0.12/src/wiiusej/utils/AccelerationWiimoteEventPanel.java
new file mode 100644
index 0000000..4e716de
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/utils/AccelerationWiimoteEventPanel.java
@@ -0,0 +1,37 @@
+/**
+ * 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.utils;
+
+import wiiusej.values.RawAcceleration;
+import wiiusej.wiiusejevents.GenericEvent;
+import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
+
+/**
+ * Panel to display Acceleration in a MotionSensingEvent from a wiimote.
+ * @author guiguito
+ */
+public class AccelerationWiimoteEventPanel extends AccelerationPanel {
+
+ @Override
+ public RawAcceleration getRawAccelerationValue(GenericEvent e) {
+ if (e instanceof MotionSensingEvent) {
+ return ((MotionSensingEvent) e).getRawAcceleration();
+ }
+ return null;
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/utils/ButtonsEventPanel.java b/WiiUseJ_0.12/src/wiiusej/utils/ButtonsEventPanel.java
new file mode 100644
index 0000000..ba01ef4
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/utils/ButtonsEventPanel.java
@@ -0,0 +1,363 @@
+/**
+ * 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.utils;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.RenderingHints;
+import java.awt.Shape;
+import java.awt.Toolkit;
+import java.awt.geom.AffineTransform;
+
+import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
+import wiiusej.wiiusejevents.physicalevents.IREvent;
+import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
+import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
+import wiiusej.wiiusejevents.utils.WiimoteListener;
+import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
+
+/**
+ * This panel is used to see what buttons are pressed on the wiimote. It
+ * displays the result of last ButtonsEvent.
+ *
+ * @author guiguito
+ */
+public class ButtonsEventPanel extends javax.swing.JPanel implements
+ WiimoteListener {
+
+ private Image mImage;// image for double buffering
+ private Image wiimoteImage;// image for double buffering
+ private WiimoteButtonsEvent buttons;
+ private Color pressedColor = Color.RED;
+ private Color heldColor = Color.ORANGE;
+ private Color releasedColor = Color.YELLOW;
+ private Shape shape;
+
+ /**
+ * Default constructor. Red : button just pressed. Orange : button held.
+ * Yellow : button just released.
+ */
+ public ButtonsEventPanel() {
+ Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
+ java.net.URL url = ButtonsEventPanel.class
+ .getResource("/img/wiimote.png");
+ wiimoteImage = toolkit.createImage(url);
+ shape = new java.awt.geom.Ellipse2D.Double(0, 0, 13, 13);
+ initComponents();
+ }
+
+ /**
+ * Constructor used to set colors and shape used.
+ *
+ * @param pressColor
+ * color of a button just pressed.
+ * @param hColor
+ * color of a button held.
+ * @param relColor
+ * color of a button just released.
+ * @param sh
+ * shape draw on the buttons.
+ */
+ public ButtonsEventPanel(Color pressColor, Color hColor, Color relColor,
+ Shape sh) {
+ pressedColor = pressColor;
+ heldColor = hColor;
+ releasedColor = relColor;
+ shape = sh;
+ Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
+ wiimoteImage = toolkit.createImage("img\\wiimote.png");
+ shape = new java.awt.geom.Ellipse2D.Double(0, 0, 13, 13);
+ initComponents();
+ }
+
+ @Override
+ public void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ Dimension d = getSize();
+ checkOffScreenImage();
+ Graphics offG = mImage.getGraphics();
+ // offG.setColor(backgroundColor);
+ offG.fillRect(0, 0, d.width, d.height);
+ Graphics2D g2 = (Graphics2D) mImage.getGraphics();
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+
+ // draw buttons pushed
+ g2.drawImage(wiimoteImage, 0, 0, this);
+ g2.setTransform(new AffineTransform());
+
+ if (buttons != null) {
+ /* button ONE */
+ if (buttons.isButtonOneJustPressed()) {
+ drawFunction(g2, pressedColor, 53, 353);
+ }
+ if (buttons.isButtonOneHeld()) {
+ drawFunction(g2, heldColor, 53, 353);
+ }
+ if (buttons.isButtonOneJustReleased()) {
+ drawFunction(g2, releasedColor, 53, 353);
+ }
+
+ /* button TWO */
+ if (buttons.isButtonTwoJustPressed()) {
+ drawFunction(g2, pressedColor, 53, 395);
+ }
+ if (buttons.isButtonTwoHeld()) {
+ drawFunction(g2, heldColor, 53, 395);
+ }
+ if (buttons.isButtonTwoJustReleased()) {
+ drawFunction(g2, releasedColor, 53, 395);
+ }
+
+ /* button A */
+ if (buttons.isButtonAJustPressed()) {
+ drawFunction(g2, pressedColor, 53, 150);
+ }
+ if (buttons.isButtonAHeld()) {
+ drawFunction(g2, heldColor, 53, 150);
+ }
+ if (buttons.isButtonAJustReleased()) {
+ drawFunction(g2, releasedColor, 53, 150);
+ }
+
+ /* button B */
+ if (buttons.isButtonBJustPressed()) {
+ drawFunction(g2, pressedColor, 16, 149);
+ }
+ if (buttons.isButtonBHeld()) {
+ drawFunction(g2, heldColor, 16, 149);
+ }
+ if (buttons.isButtonBJustReleased()) {
+ drawFunction(g2, releasedColor, 16, 149);
+ }
+
+ /* button LEFT */
+ if (buttons.isButtonLeftJustPressed()) {
+ drawFunction(g2, pressedColor, 33, 77);
+ }
+ if (buttons.isButtonLeftHeld()) {
+ drawFunction(g2, heldColor, 33, 77);
+ }
+ if (buttons.isButtonLeftJustReleased()) {
+ drawFunction(g2, releasedColor, 33, 77);
+ }
+
+ /* button RIGHT */
+ if (buttons.isButtonRightJustPressed()) {
+ drawFunction(g2, pressedColor, 73, 77);
+ }
+ if (buttons.isButtonRightHeld()) {
+ drawFunction(g2, heldColor, 73, 77);
+ }
+ if (buttons.isButtonRightJustReleased()) {
+ drawFunction(g2, releasedColor, 73, 77);
+ }
+
+ /* button UP */
+ if (buttons.isButtonUpJustPressed()) {
+ drawFunction(g2, pressedColor, 54, 60);
+ }
+ if (buttons.isButtonUpHeld()) {
+ drawFunction(g2, heldColor, 54, 60);
+ }
+ if (buttons.isButtonUpJustReleased()) {
+ drawFunction(g2, releasedColor, 54, 60);
+ }
+
+ /* button DOWN */
+ if (buttons.isButtonDownJustPressed()) {
+ drawFunction(g2, pressedColor, 54, 97);
+ }
+ if (buttons.isButtonDownHeld()) {
+ drawFunction(g2, heldColor, 54, 97);
+ }
+ if (buttons.isButtonDownJustReleased()) {
+ drawFunction(g2, releasedColor, 54, 97);
+ }
+
+ /* button MINUS */
+ if (buttons.isButtonMinusJustPressed()) {
+ drawFunction(g2, pressedColor, 20, 230);
+ }
+ if (buttons.isButtonMinusHeld()) {
+ drawFunction(g2, heldColor, 20, 230);
+ }
+ if (buttons.isButtonMinusJustReleased()) {
+ drawFunction(g2, releasedColor, 20, 230);
+ }
+
+ /* button PLUS */
+ if (buttons.isButtonPlusJustPressed()) {
+ drawFunction(g2, pressedColor, 86, 230);
+ }
+ if (buttons.isButtonPlusHeld()) {
+ drawFunction(g2, heldColor, 86, 230);
+ }
+ if (buttons.isButtonPlusJustReleased()) {
+ drawFunction(g2, releasedColor, 86, 230);
+ }
+
+ /* button HOME */
+ if (buttons.isButtonHomeJustPressed()) {
+ drawFunction(g2, pressedColor, 53, 230);
+ }
+ if (buttons.isButtonHomeHeld()) {
+ drawFunction(g2, heldColor, 53, 230);
+ }
+ if (buttons.isButtonHomeJustReleased()) {
+ drawFunction(g2, releasedColor, 53, 230);
+ }
+
+ buttons = null;
+ }
+
+ // put offscreen image on the screen
+ g.drawImage(mImage, 0, 0, null);
+ }
+
+ /**
+ * Function used to factorize code.
+ *
+ * @param g2
+ * where to draw a shape.
+ * @param col
+ * color to use.
+ * @param x
+ * x coordinates.
+ * @param y
+ * y coordinates.
+ */
+ private void drawFunction(Graphics2D g2, Color col, int x, int y) {
+ g2.setPaint(col);
+ g2.translate(x, y);
+ g2.draw(shape);
+ g2.fill(shape);
+ g2.setTransform(new AffineTransform());
+ }
+
+ /**
+ * check if the mImage variable has been initialized. If it's not the case
+ * it initializes it with the dimensions of the panel. mImage is for double
+ * buffering.
+ */
+ private void checkOffScreenImage() {
+ Dimension d = getSize();
+ if (mImage == null || mImage.getWidth(null) != d.width
+ || mImage.getHeight(null) != d.height) {
+ mImage = createImage(d.width, d.height);
+ }
+ }
+
+ public void onButtonsEvent(WiimoteButtonsEvent arg0) {
+ setSize(wiimoteImage.getWidth(this), wiimoteImage.getHeight(this));
+ buttons = arg0;
+ repaint();
+ }
+
+ public void onIrEvent(IREvent arg0) {
+ // nothing
+ }
+
+ public void onMotionSensingEvent(MotionSensingEvent arg0) {
+ // nothing
+ }
+
+ public void onExpansionEvent(ExpansionEvent e) {
+ // nothing
+ }
+
+ public void onStatusEvent(StatusEvent arg0) {
+ // nothing
+ }
+
+ public void onDisconnectionEvent(DisconnectionEvent arg0) {
+ buttons = null;
+ repaint();
+ }
+
+ public void onNunchukInsertedEvent(NunchukInsertedEvent e) {
+ // nothing
+ }
+
+ public void onNunchukRemovedEvent(NunchukRemovedEvent e) {
+ // nothing
+ }
+
+ public Color getHeldColor() {
+ return heldColor;
+ }
+
+ public Color getPressedColor() {
+ return pressedColor;
+ }
+
+ public Color getReleasedColor() {
+ return releasedColor;
+ }
+
+ public Shape getShape() {
+ return shape;
+ }
+
+ public void setHeldColor(Color heldColor) {
+ this.heldColor = heldColor;
+ }
+
+ public void setPressedColor(Color pressedColor) {
+ this.pressedColor = pressedColor;
+ }
+
+ public void setReleasedColor(Color releasedColor) {
+ this.releasedColor = releasedColor;
+ }
+
+ public void setShape(Shape shape) {
+ this.shape = shape;
+ }
+
+ public void clearView() {
+ buttons = null;
+ repaint();
+ }
+
+ /**
+ * This method is called from within the constructor to initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is always
+ * regenerated by the Form Editor.
+ */
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+ this.setLayout(layout);
+ layout.setHorizontalGroup(layout.createParallelGroup(
+ javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
+ Short.MAX_VALUE));
+ layout.setVerticalGroup(layout.createParallelGroup(
+ javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
+ Short.MAX_VALUE));
+ }// //GEN-END:initComponents
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ // End of variables declaration//GEN-END:variables
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/utils/GForceExpansionEventPanel.java b/WiiUseJ_0.12/src/wiiusej/utils/GForceExpansionEventPanel.java
new file mode 100644
index 0000000..d5852b0
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/utils/GForceExpansionEventPanel.java
@@ -0,0 +1,38 @@
+/**
+ * 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.utils;
+
+import wiiusej.values.GForce;
+import wiiusej.wiiusejevents.GenericEvent;
+import wiiusej.wiiusejevents.physicalevents.NunchukEvent;
+
+/**
+ * Panel to display GForce in a MotionSensingEvent from an expansion.
+ *
+ * @author guiguito
+ */
+public class GForceExpansionEventPanel extends GForcePanel{
+
+ @Override
+ public GForce getGForceValue(GenericEvent e) {
+ if (e instanceof NunchukEvent){
+ return ((NunchukEvent)e).getNunchukMotionSensingEvent().getGforce();
+ }
+ return null;
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/utils/GForcePanel.java b/WiiUseJ_0.12/src/wiiusej/utils/GForcePanel.java
new file mode 100644
index 0000000..14de5f2
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/utils/GForcePanel.java
@@ -0,0 +1,282 @@
+/**
+ * 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.utils;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.RenderingHints;
+import java.awt.geom.AffineTransform;
+import java.util.ArrayList;
+
+import wiiusej.values.GForce;
+import wiiusej.wiiusejevents.GenericEvent;
+import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
+import wiiusej.wiiusejevents.physicalevents.IREvent;
+import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
+import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
+import wiiusej.wiiusejevents.utils.WiimoteListener;
+import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
+
+/**
+ * This panel is used to watch gravity force values from a MotionSensingEvent.
+ *
+ * @author guiguito
+ */
+public abstract class GForcePanel extends javax.swing.JPanel implements
+ WiimoteListener {
+
+ private Image mImage;// image for double buffering
+ private Color xColor = Color.RED;
+ private Color yColor = Color.GREEN;
+ private Color zColor = Color.BLUE;
+ private Color backgroundColor = Color.WHITE;
+ private Color lineColor = Color.BLACK;
+ private ArrayList values = new ArrayList();
+
+ /**
+ * Default constructor of the AccelerationPanel.
+ */
+ public GForcePanel() {
+ initComponents();
+ }
+
+ /**
+ * Constructor used to choose the colors used by the AccelerationPanel.
+ *
+ * @param bgColor
+ * background color.
+ * @param xxColor
+ * color of the acceleration on X axis.
+ * @param yyColor
+ * color of the acceleration on Y axis.
+ * @param zzColor
+ * color of the acceleration on Z axis.
+ * @param lColor
+ * line color.
+ */
+ public GForcePanel(Color bgColor, Color xxColor, Color yyColor,
+ Color zzColor, Color lColor) {
+ backgroundColor = bgColor;
+ xColor = xxColor;
+ yColor = yyColor;
+ zColor = zzColor;
+ lineColor = lColor;
+ initComponents();
+ }
+
+ @Override
+ public void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ Dimension d = getSize();
+ checkOffScreenImage();
+ Graphics offG = mImage.getGraphics();
+ offG.setColor(backgroundColor);
+ offG.fillRect(0, 0, d.width, d.height);
+ Graphics2D g2 = (Graphics2D) mImage.getGraphics();
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+
+ // draw medium line
+ double yMiddleFloat = getHeight() / 2.0;
+ int yMiddle = (int) Math.round(yMiddleFloat);
+
+ g2.setPaint(lineColor);
+ g2.drawLine(0, yMiddle, getWidth(), yMiddle);
+
+ GForce[] valuesArray = values.toArray(new GForce[0]);
+ double unit = yMiddleFloat / 5.0;
+ int previousX = 0;
+ int previousY = 0;
+ int previousZ = 0;
+ // draw curves
+ for (int i = 0; i < valuesArray.length && i < getWidth(); i++) {
+ GForce gforce = valuesArray[i];
+ // draw X
+ g2.setPaint(xColor);
+ int yDelta = (int) Math.round(unit * gforce.getX());
+ int y = -1 * yDelta + yMiddle;
+ g2.drawLine(i - 1, previousX, i, y);
+ g2.setTransform(new AffineTransform());
+ previousX = y;
+ // draw Y
+ g2.setPaint(yColor);
+ yDelta = (int) Math.round(unit * gforce.getY());
+ y = -1 * yDelta + yMiddle;
+ g2.drawLine(i - 1, previousY, i, y);
+ g2.setTransform(new AffineTransform());
+ previousY = y;
+ // draw Z
+ g2.setPaint(zColor);
+ yDelta = (int) Math.round(unit * gforce.getZ());
+ y = -1 * yDelta + yMiddle;
+ g2.drawLine(i - 1, previousZ, i, y);
+ g2.setTransform(new AffineTransform());
+ previousZ = y;
+ }
+
+ // draw legend
+ g2.setPaint(xColor);
+ g2.drawLine(5, getHeight() - 10, 25, getHeight() - 10);
+ g2.setPaint(yColor);
+ g2.drawLine(60, getHeight() - 10, 80, getHeight() - 10);
+ g2.setPaint(zColor);
+ g2.drawLine(120, getHeight() - 10, 140, getHeight() - 10);
+
+ g2.setPaint(lineColor);
+ g2.drawString("X", 30, getHeight() - 5);
+ g2.drawString("Y", 85, getHeight() - 5);
+ g2.drawString("Z", 145, getHeight() - 5);
+ g2.drawString("0", 2, yMiddle - 5);
+ g2.drawString("5", 2, 10);
+ g2.drawString("-5", 2, getHeight() - 15);
+ // put offscreen image on the screen
+ g.drawImage(mImage, 0, 0, null);
+ }
+
+ /**
+ * check if the mImage variable has been initialized. If it's not the case
+ * it initializes it with the dimensions of the panel. mImage is for double
+ * buffering.
+ */
+ private void checkOffScreenImage() {
+ Dimension d = getSize();
+ if (mImage == null || mImage.getWidth(null) != d.width
+ || mImage.getHeight(null) != d.height) {
+ mImage = createImage(d.width, d.height);
+ }
+ }
+
+ public void onButtonsEvent(WiimoteButtonsEvent arg0) {
+ // nothing
+ }
+
+ public void onIrEvent(IREvent arg0) {
+ // nothing
+ }
+
+ public void onMotionSensingEvent(MotionSensingEvent arg0) {
+ draw(arg0);
+ }
+
+ public void onExpansionEvent(ExpansionEvent arg0) {
+ draw(arg0);
+ }
+
+ public void onStatusEvent(StatusEvent arg0) {
+ // nothing
+ }
+
+ public void onDisconnectionEvent(DisconnectionEvent arg0) {
+ // Clear points.
+ values.clear();
+ repaint();
+ }
+
+ public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
+ // nothing
+ }
+
+ public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
+ // nothing
+ }
+
+ private void draw(GenericEvent arg0) {
+ if (values.size() >= getWidth()) {
+ // if there are as many values as pixels in the width
+ // clear points
+ values.clear();
+ }
+ GForce gforce = getGForceValue(arg0);
+ if (gforce != null)
+ values.add(gforce);
+ repaint();
+ }
+
+ public abstract GForce getGForceValue(GenericEvent e);
+
+ public Color getBackgroundColor() {
+ return backgroundColor;
+ }
+
+ public Color getLineColor() {
+ return lineColor;
+ }
+
+ public Color getXColor() {
+ return xColor;
+ }
+
+ public Color getYColor() {
+ return yColor;
+ }
+
+ public Color getZColor() {
+ return zColor;
+ }
+
+ public void setBackgroundColor(Color backgroundColor) {
+ this.backgroundColor = backgroundColor;
+ }
+
+ public void setLineColor(Color lineColor) {
+ this.lineColor = lineColor;
+ }
+
+ public void setXColor(Color xColor) {
+ this.xColor = xColor;
+ }
+
+ public void setYColor(Color yColor) {
+ this.yColor = yColor;
+ }
+
+ public void setZColor(Color zColor) {
+ this.zColor = zColor;
+ }
+
+ public void clearView() {
+ values.clear();
+ repaint();
+ }
+
+ /**
+ * This method is called from within the constructor to initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is always
+ * regenerated by the Form Editor.
+ */
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+ this.setLayout(layout);
+ layout.setHorizontalGroup(layout.createParallelGroup(
+ javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
+ Short.MAX_VALUE));
+ layout.setVerticalGroup(layout.createParallelGroup(
+ javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
+ Short.MAX_VALUE));
+ }// //GEN-END:initComponents
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ // End of variables declaration//GEN-END:variables
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/utils/GForceWiimoteEventPanel.java b/WiiUseJ_0.12/src/wiiusej/utils/GForceWiimoteEventPanel.java
new file mode 100644
index 0000000..1ae710e
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/utils/GForceWiimoteEventPanel.java
@@ -0,0 +1,37 @@
+/**
+ * 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.utils;
+
+import wiiusej.values.GForce;
+import wiiusej.wiiusejevents.GenericEvent;
+import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
+
+/**
+ * Panel to display GForce in a MotionSensingEvent from a wiimote.
+ *
+ * @author guiguito
+ */
+public class GForceWiimoteEventPanel extends GForcePanel {
+
+ @Override
+ public GForce getGForceValue(GenericEvent e) {
+ if (e instanceof MotionSensingEvent) {
+ return ((MotionSensingEvent) e).getGforce();
+ }
+ return null;
+ }
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/utils/IRPanel.java b/WiiUseJ_0.12/src/wiiusej/utils/IRPanel.java
new file mode 100644
index 0000000..c826fee
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/utils/IRPanel.java
@@ -0,0 +1,253 @@
+/**
+ * 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.utils;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.RenderingHints;
+import java.awt.Shape;
+import java.awt.geom.AffineTransform;
+
+import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
+import wiiusej.wiiusejevents.physicalevents.IREvent;
+import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
+import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
+import wiiusej.wiiusejevents.utils.WiimoteListener;
+import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
+
+/**
+ * This panel is used to see what the IR camera of the wiimote sees.
+ *
+ * @author guiguito
+ */
+public class IRPanel extends javax.swing.JPanel implements WiimoteListener {
+
+ private static int MAX_NB_POINTS = 4;
+ private Color color = Color.YELLOW;
+ private Color backgroundColor = Color.BLACK;
+ private Color borderColor = Color.BLUE;
+ private Shape shape;
+ private Image mImage;// image for double buffering
+ private int[] xCoordinates;
+ private int[] yCoordinates;
+ private int nbPoints = -1;
+
+ /**
+ * Default constructor for IR Panel. Background color : black. IR sources
+ * color : yellow. Border color of IR sources : blue. Shape of the IR
+ * sources : circle with a diameter of 10.
+ */
+ public IRPanel() {
+ shape = new java.awt.geom.Ellipse2D.Double(0, 0, 10, 10);
+ initArrays();
+ initComponents();
+ }
+
+ /**
+ * Constructor used to parameterize the IR panel.
+ *
+ * @param bgColor
+ * color.
+ * @param ptColor
+ * IR sources color.
+ * @param bdColor
+ * border color of IR sources.
+ * @param sh
+ * Shape of the IR sources.
+ */
+ public IRPanel(Color bgColor, Color ptColor, Color bdColor, Shape sh) {
+ backgroundColor = bgColor;
+ color = ptColor;
+ borderColor = bdColor;
+ shape = sh;
+ initArrays();
+ initComponents();
+ }
+
+ private void initArrays() {
+ xCoordinates = new int[MAX_NB_POINTS];
+ yCoordinates = new int[MAX_NB_POINTS];
+ for (int i = 0; i < MAX_NB_POINTS; i++) {
+ xCoordinates[i] = -1;
+ yCoordinates[i] = -1;
+ }
+ }
+
+ @Override
+ public void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ Dimension d = getSize();
+ checkOffScreenImage();
+ Graphics offG = mImage.getGraphics();
+ offG.setColor(backgroundColor);
+ offG.fillRect(0, 0, d.width, d.height);
+ Graphics2D g2 = (Graphics2D) mImage.getGraphics();
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+
+ // draw points
+ int i = 0;
+ while (i < nbPoints) {
+ double x = xCoordinates[i];
+ double y = yCoordinates[i];
+
+ long xx = getWidth() - Math.round((double) getWidth() * x / 1024.0);
+ long yy = getHeight()
+ - Math.round((double) getHeight() * y / 768.0);
+ g2.translate(xx, yy);
+
+ g2.setPaint(borderColor);
+ g2.draw(shape);
+ g2.setPaint(color);
+ g2.fill(shape);
+
+ g2.setTransform(new AffineTransform());
+ i++;
+ }
+ // put offscreen image on the screen
+ g.drawImage(mImage, 0, 0, null);
+ }
+
+ /**
+ * check if the mImage variable has been initialized. If it's not the case
+ * it initializes it with the dimensions of the panel. mImage is for double
+ * buffering.
+ */
+ private void checkOffScreenImage() {
+ Dimension d = getSize();
+ if (mImage == null || mImage.getWidth(null) != d.width
+ || mImage.getHeight(null) != d.height) {
+ mImage = createImage(d.width, d.height);
+ }
+ }
+
+ public void onButtonsEvent(WiimoteButtonsEvent arg0) {
+ // nothing
+ repaint();
+ }
+
+ public void onIrEvent(IREvent arg0) {
+ // transfer points
+ wiiusej.values.IRSource[] points = arg0.getIRPoints();
+ nbPoints = points.length;
+ for (int i = 0; i < points.length; i++) {
+ xCoordinates[i] = (int) points[i].getRx();
+ yCoordinates[i] = (int) points[i].getRy();
+ }
+ for (int i = points.length; i < MAX_NB_POINTS; i++) {
+ xCoordinates[i] = -1;
+ yCoordinates[i] = -1;
+ }
+
+ // redraw panel
+ repaint();
+ }
+
+ public void onMotionSensingEvent(MotionSensingEvent arg0) {
+ // nothing
+ }
+
+ public void onExpansionEvent(ExpansionEvent e) {
+ // nothing
+ }
+
+ public void onStatusEvent(StatusEvent arg0) {
+ // nothing
+ }
+
+ public void onDisconnectionEvent(DisconnectionEvent arg0) {
+ // clear previous points
+ for (int i = 0; i < MAX_NB_POINTS; i++) {
+ xCoordinates[i] = -1;
+ yCoordinates[i] = -1;
+ }
+ // redraw panel
+ repaint();
+ }
+
+ public void onNunchukInsertedEvent(NunchukInsertedEvent e) {
+ // nothing
+ }
+
+ public void onNunchukRemovedEvent(NunchukRemovedEvent e) {
+ // nothing
+ }
+
+ public Color getBackgroundColor() {
+ return backgroundColor;
+ }
+
+ public Color getBorderColor() {
+ return borderColor;
+ }
+
+ public Color getColor() {
+ return color;
+ }
+
+ public Shape getShape() {
+ return shape;
+ }
+
+ public void setBackgroundColor(Color backgroundColor) {
+ this.backgroundColor = backgroundColor;
+ }
+
+ public void setBorderColor(Color borderColor) {
+ this.borderColor = borderColor;
+ }
+
+ public void setColor(Color color) {
+ this.color = color;
+ }
+
+ public void setShape(Shape shape) {
+ this.shape = shape;
+ }
+
+ public void clearView() {
+ initArrays();
+ repaint();
+ }
+
+ /**
+ * This method is called from within the constructor to initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is always
+ * regenerated by the Form Editor.
+ */
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+ this.setLayout(layout);
+ layout.setHorizontalGroup(layout.createParallelGroup(
+ javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
+ Short.MAX_VALUE));
+ layout.setVerticalGroup(layout.createParallelGroup(
+ javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
+ Short.MAX_VALUE));
+ }// //GEN-END:initComponents
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ // End of variables declaration//GEN-END:variables
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/utils/JoystickEventPanel.java b/WiiUseJ_0.12/src/wiiusej/utils/JoystickEventPanel.java
new file mode 100644
index 0000000..6f04ce6
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/utils/JoystickEventPanel.java
@@ -0,0 +1,231 @@
+/**
+ * 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.utils;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.RenderingHints;
+import java.awt.Shape;
+import java.awt.geom.AffineTransform;
+import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
+import wiiusej.wiiusejevents.physicalevents.IREvent;
+import wiiusej.wiiusejevents.physicalevents.JoystickEvent;
+import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
+import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
+import wiiusej.wiiusejevents.utils.WiimoteListener;
+import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
+
+/**
+ * Panel to display joystick events.
+ *
+ * @author guiguito
+ */
+public abstract class JoystickEventPanel extends javax.swing.JPanel implements
+ WiimoteListener {
+
+ private Image mImage;// image for double buffering
+ private Color backgroundColor = Color.BLACK;
+ private Color borderColor = Color.RED;
+ private Color pointColor = Color.RED;
+ private Shape shape = new java.awt.geom.Ellipse2D.Double(0, 0, 30, 30);
+ private JoystickEvent lastJoystickEvent = null;
+
+ /** Creates new form JoystickPanel */
+ public JoystickEventPanel() {
+ initComponents();
+ }
+
+ /**
+ * Constructor used to choose the colors used by the JoystickPanel.
+ *
+ * @param bgColor
+ * background color.
+ * @param pColor
+ * point color.
+ * @param bdColor
+ * border color for the shape.
+ * @param sh
+ * shape of what is drawn.
+ */
+ public JoystickEventPanel(Color bgColor, Color pColor, Color bdColor,
+ Shape sh) {
+ backgroundColor = bgColor;
+ pointColor = pColor;
+ shape = sh;
+ borderColor = bdColor;
+ initComponents();
+ }
+
+ @Override
+ public void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ Dimension d = getSize();
+ checkOffScreenImage();
+ Graphics offG = mImage.getGraphics();
+ offG.setColor(backgroundColor);
+ offG.fillRect(0, 0, d.width, d.height);
+ Graphics2D g2 = (Graphics2D) mImage.getGraphics();
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+ g2.setTransform(new AffineTransform());
+
+ // compute center
+ int xCenter = (int) Math.round(d.getWidth() / 2.0);
+ int yCenter = (int) Math.round(d.getHeight() / 2.0);
+
+ // compute coordinates
+ if (lastJoystickEvent != null) {
+ double xAng = Math.sin(lastJoystickEvent.getAngle() * Math.PI
+ / 180.0)
+ * lastJoystickEvent.getMagnitude();
+ double yAng = Math.cos(lastJoystickEvent.getAngle() * Math.PI
+ / 180.0)
+ * lastJoystickEvent.getMagnitude();
+ int dx = (int) Math.round(shape.getBounds().getWidth() / 2);
+ int dy = (int) Math.round(shape.getBounds().getHeight() / 2);
+ double xTemp = xAng * (xCenter - dx * 2);
+ double yTemp = yAng * (yCenter - dy * 2);
+ int x = xCenter - dx + (int) xTemp;
+ int y = yCenter - dy - (int) yTemp;
+ // System.out.println("--------------------------------------------------------------------");
+ // System.out.println(lastJoystickEvent);
+ // System.out.println("xCenter ,yCenter : "+xCenter+" , "+yCenter);
+ // System.out.println("xAng, yAng : "+xAng+" , "+yAng);
+ // System.out.println("dx, dy : "+dx+" , "+dy);
+ // System.out.println("xTemp, yTemp : "+xTemp+" , "+yTemp);
+ // System.out.println("x, y : "+x+" , "+y);
+ // shape
+ g2.translate(x, y);
+ g2.setPaint(borderColor);
+ g2.draw(shape);
+ g2.setPaint(pointColor);
+ g2.fill(shape);
+ }
+ // put offscreen image on the screen
+ g.drawImage(mImage, 0, 0, null);
+ }
+
+ /**
+ * check if the mImage variable has been initialized. If it's not the case
+ * it initializes it with the dimensions of the panel. mImage is for double
+ * buffering.
+ */
+ private void checkOffScreenImage() {
+ Dimension d = getSize();
+ if (mImage == null || mImage.getWidth(null) != d.width
+ || mImage.getHeight(null) != d.height) {
+ mImage = createImage(d.width, d.height);
+ }
+ }
+
+ public void onButtonsEvent(WiimoteButtonsEvent arg0) {
+ // nothing
+ }
+
+ public void onIrEvent(IREvent arg0) {
+ // nothing
+ }
+
+ public void onMotionSensingEvent(MotionSensingEvent arg0) {
+ // nothing
+ }
+
+ public void onExpansionEvent(ExpansionEvent arg0) {
+ JoystickEvent joy = getJoystikEvent(arg0);
+ if (joy != null) {
+ lastJoystickEvent = joy;
+ }
+ repaint();
+ }
+
+ public void onStatusEvent(StatusEvent arg0) {
+ // nothing
+ }
+
+ public void onDisconnectionEvent(DisconnectionEvent arg0) {
+ // nothing
+ }
+
+ public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
+ // nothing
+ }
+
+ public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
+ // nothing
+ }
+
+ public Color getBackgroundColor() {
+ return backgroundColor;
+ }
+
+ public Color getPointColor() {
+ return pointColor;
+ }
+
+ public Color getBorderColor() {
+ return borderColor;
+ }
+
+ public Shape getShape() {
+ return shape;
+ }
+
+ public void setBackgroundColor(Color backgroundColor) {
+ this.backgroundColor = backgroundColor;
+ }
+
+ public void setPointColor(Color pointColor) {
+ this.pointColor = pointColor;
+ }
+
+ public void setBorderColor(Color borderColor) {
+ this.borderColor = borderColor;
+ }
+
+ public void setShape(Shape shape) {
+ this.shape = shape;
+ }
+
+ public abstract JoystickEvent getJoystikEvent(ExpansionEvent e);
+
+ /**
+ * This method is called from within the constructor to initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is always
+ * regenerated by the Form Editor.
+ */
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+ this.setLayout(layout);
+ layout.setHorizontalGroup(layout.createParallelGroup(
+ javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
+ Short.MAX_VALUE));
+ layout.setVerticalGroup(layout.createParallelGroup(
+ javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
+ Short.MAX_VALUE));
+ }// //GEN-END:initComponents
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ // End of variables declaration//GEN-END:variables
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/utils/NunchukJoystickEventPanel.java b/WiiUseJ_0.12/src/wiiusej/utils/NunchukJoystickEventPanel.java
new file mode 100644
index 0000000..a534751
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/utils/NunchukJoystickEventPanel.java
@@ -0,0 +1,37 @@
+/**
+ * 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.utils;
+
+import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
+import wiiusej.wiiusejevents.physicalevents.JoystickEvent;
+import wiiusej.wiiusejevents.physicalevents.NunchukEvent;
+
+/**
+ * Panel to display nunchuk joystick events.
+ *
+ * @author guiguito
+ */
+public class NunchukJoystickEventPanel extends JoystickEventPanel {
+
+ @Override
+ public JoystickEvent getJoystikEvent(ExpansionEvent e) {
+ if (e instanceof NunchukEvent) {
+ return ((NunchukEvent) e).getNunchukJoystickEvent();
+ }
+ return null;
+ }
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/utils/OrientationExpansionEventPanel.java b/WiiUseJ_0.12/src/wiiusej/utils/OrientationExpansionEventPanel.java
new file mode 100644
index 0000000..f5e3856
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/utils/OrientationExpansionEventPanel.java
@@ -0,0 +1,38 @@
+/**
+ * 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.utils;
+
+import wiiusej.values.Orientation;
+import wiiusej.wiiusejevents.GenericEvent;
+import wiiusej.wiiusejevents.physicalevents.NunchukEvent;
+
+/**
+ * Panel to display Orientation in a MotionSensingEvent from an expansion.
+ *
+ * @author guiguito
+ */
+public class OrientationExpansionEventPanel extends OrientationPanel {
+
+ @Override
+ public Orientation getOrientationValue(GenericEvent e) {
+ if (e instanceof NunchukEvent) {
+ return ((NunchukEvent) e).getNunchukMotionSensingEvent()
+ .getOrientation();
+ }
+ return null;
+ }
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/utils/OrientationPanel.java b/WiiUseJ_0.12/src/wiiusej/utils/OrientationPanel.java
new file mode 100644
index 0000000..b298911
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/utils/OrientationPanel.java
@@ -0,0 +1,283 @@
+/**
+ * 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.utils;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.RenderingHints;
+import java.awt.geom.AffineTransform;
+import java.util.ArrayList;
+
+import wiiusej.values.Orientation;
+import wiiusej.wiiusejevents.GenericEvent;
+import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
+import wiiusej.wiiusejevents.physicalevents.IREvent;
+import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
+import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
+import wiiusej.wiiusejevents.utils.WiimoteListener;
+import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
+
+/**
+ * This panel is used to watch orientation values from a MotionSensingEvent.
+ *
+ * @author guiguito
+ */
+public abstract class OrientationPanel extends javax.swing.JPanel implements
+ WiimoteListener {
+
+ private Image mImage;// image for double buffering
+ private Color rollColor = Color.RED;
+ private Color pitchColor = Color.GREEN;
+ private Color yawColor = Color.BLUE;
+ private Color backgroundColor = Color.WHITE;
+ private Color lineColor = Color.BLACK;
+ private ArrayList values = new ArrayList();
+
+ /**
+ * Default constructor. Background color : White. Roll color : Red. Pitch
+ * color : Green. Yaw color : Blue.
+ */
+ public OrientationPanel() {
+ initComponents();
+ }
+
+ /**
+ * Constructor used to choose the colors used by the OrientationPanel.
+ *
+ * @param bgColor
+ * background color.
+ * @param rColor
+ * roll color.
+ * @param pColor
+ * pitch color.
+ * @param yColor
+ * yaw color.
+ * @param lColor
+ * line color.
+ */
+ public OrientationPanel(Color bgColor, Color rColor, Color pColor,
+ Color yColor, Color lColor) {
+ backgroundColor = bgColor;
+ rollColor = rColor;
+ pitchColor = pColor;
+ yawColor = yColor;
+ lineColor = lColor;
+ initComponents();
+ }
+
+ @Override
+ public void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ Dimension d = getSize();
+ checkOffScreenImage();
+ Graphics offG = mImage.getGraphics();
+ offG.setColor(backgroundColor);
+ offG.fillRect(0, 0, d.width, d.height);
+ Graphics2D g2 = (Graphics2D) mImage.getGraphics();
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+
+ // draw medium line
+ double yMiddleFloat = getHeight() / 2.0;
+ int yMiddle = (int) Math.round(yMiddleFloat);
+
+ g2.setPaint(lineColor);
+ g2.drawLine(0, yMiddle, getWidth(), yMiddle);
+
+ Orientation[] valuesArray = values.toArray(new Orientation[0]);
+ double unit = yMiddleFloat / 180.0;
+ int previousRoll = 0;
+ int previousPitch = 0;
+ int previousYaw = 0;
+ // draw curves
+ for (int i = 0; i < valuesArray.length && i < getWidth(); i++) {
+ Orientation orientation = valuesArray[i];
+ // draw roll
+ g2.setPaint(rollColor);
+ int yDelta = (int) Math.round(unit * orientation.getRoll());
+ int y = -1 * yDelta + yMiddle;
+ g2.drawLine(i - 1, previousRoll, i, y);
+ g2.setTransform(new AffineTransform());
+ previousRoll = y;
+ // draw pitch
+ g2.setPaint(pitchColor);
+ yDelta = (int) Math.round(unit * orientation.getPitch());
+ y = -1 * yDelta + yMiddle;
+ g2.drawLine(i - 1, previousPitch, i, y);
+ g2.setTransform(new AffineTransform());
+ previousPitch = y;
+ // draw yaw
+ g2.setPaint(yawColor);
+ yDelta = (int) Math.round(unit * orientation.getYaw());
+ y = -1 * yDelta + yMiddle;
+ g2.drawLine(i - 1, previousYaw, i, y);
+ g2.setTransform(new AffineTransform());
+ previousYaw = y;
+ }
+
+ // draw legend
+ g2.setPaint(rollColor);
+ g2.drawLine(5, getHeight() - 10, 25, getHeight() - 10);
+ g2.setPaint(pitchColor);
+ g2.drawLine(60, getHeight() - 10, 80, getHeight() - 10);
+ g2.setPaint(yawColor);
+ g2.drawLine(120, getHeight() - 10, 140, getHeight() - 10);
+
+ g2.setPaint(lineColor);
+ g2.drawString("Roll", 30, getHeight() - 5);
+ g2.drawString("Pitch", 85, getHeight() - 5);
+ g2.drawString("Yaw", 145, getHeight() - 5);
+ g2.drawString("0", 2, yMiddle - 5);
+ g2.drawString("180", 2, 10);
+ g2.drawString("-180", 2, getHeight() - 15);
+ // put offscreen image on the screen
+ g.drawImage(mImage, 0, 0, null);
+ }
+
+ /**
+ * check if the mImage variable has been initialized. If it's not the case
+ * it initializes it with the dimensions of the panel. mImage is for double
+ * buffering.
+ */
+ private void checkOffScreenImage() {
+ Dimension d = getSize();
+ if (mImage == null || mImage.getWidth(null) != d.width
+ || mImage.getHeight(null) != d.height) {
+ mImage = createImage(d.width, d.height);
+ }
+ }
+
+ public void onButtonsEvent(WiimoteButtonsEvent arg0) {
+ // nothing
+ }
+
+ public void onIrEvent(IREvent arg0) {
+ // nothing
+ }
+
+ public void onMotionSensingEvent(MotionSensingEvent arg0) {
+ draw(arg0);
+ }
+
+ public void onExpansionEvent(ExpansionEvent arg0) {
+ draw(arg0);
+ }
+
+ public void onStatusEvent(StatusEvent arg0) {
+ // nothing
+ }
+
+ public void onDisconnectionEvent(DisconnectionEvent arg0) {
+ // Clear points.
+ values.clear();
+ repaint();
+ }
+
+ public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
+ // nothing
+ }
+
+ public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
+ // nothing
+ }
+
+ private void draw(GenericEvent arg0) {
+ if (values.size() >= getWidth()) {
+ // if there are as many values as pixels in the width
+ // clear points
+ values.clear();
+ }
+ Orientation orientation = getOrientationValue(arg0);
+ if (orientation != null)
+ values.add(orientation);
+ repaint();
+ }
+
+ public abstract Orientation getOrientationValue(GenericEvent e);
+
+ public Color getBackgroundColor() {
+ return backgroundColor;
+ }
+
+ public Color getLineColor() {
+ return lineColor;
+ }
+
+ public Color getPitchColor() {
+ return pitchColor;
+ }
+
+ public Color getRollColor() {
+ return rollColor;
+ }
+
+ public Color getYawColor() {
+ return yawColor;
+ }
+
+ public void setBackgroundColor(Color backgroundColor) {
+ this.backgroundColor = backgroundColor;
+ }
+
+ public void setLineColor(Color lineColor) {
+ this.lineColor = lineColor;
+ }
+
+ public void setPitchColor(Color pitchColor) {
+ this.pitchColor = pitchColor;
+ }
+
+ public void setRollColor(Color rollColor) {
+ this.rollColor = rollColor;
+ }
+
+ public void setYawColor(Color yawColor) {
+ this.yawColor = yawColor;
+ }
+
+ public void clearView() {
+ values.clear();
+ repaint();
+ }
+
+ /**
+ * This method is called from within the constructor to initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is always
+ * regenerated by the Form Editor.
+ */
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+ this.setLayout(layout);
+ layout.setHorizontalGroup(layout.createParallelGroup(
+ javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
+ Short.MAX_VALUE));
+ layout.setVerticalGroup(layout.createParallelGroup(
+ javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
+ Short.MAX_VALUE));
+ }// //GEN-END:initComponents
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ // End of variables declaration//GEN-END:variables
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/utils/OrientationWiimoteEventPanel.java b/WiiUseJ_0.12/src/wiiusej/utils/OrientationWiimoteEventPanel.java
new file mode 100644
index 0000000..e38f3c9
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/utils/OrientationWiimoteEventPanel.java
@@ -0,0 +1,38 @@
+/**
+ * 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.utils;
+
+import wiiusej.values.Orientation;
+import wiiusej.wiiusejevents.GenericEvent;
+import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
+
+/**
+ * Panel to display Orientation in a MotionSensingEvent from a wiimote.
+ *
+ * @author guiguito
+ */
+public class OrientationWiimoteEventPanel extends OrientationPanel {
+
+ @Override
+ public Orientation getOrientationValue(GenericEvent e) {
+ if (e instanceof MotionSensingEvent) {
+ return ((MotionSensingEvent) e).getOrientation();
+ }
+ return null;
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/values/GForce.java b/WiiUseJ_0.12/src/wiiusej/values/GForce.java
new file mode 100644
index 0000000..da79ed2
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/values/GForce.java
@@ -0,0 +1,80 @@
+/**
+ * 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;
+
+/**
+ * Represents gravity force on each axis.
+ *
+ * @author guiguito
+ */
+public class GForce {
+
+ private float x;
+ private float y;
+ private float z;
+
+ /**
+ * Default constructor;
+ */
+ public GForce() {
+ x = 0;
+ y = 0;
+ z = 0;
+ }
+
+ /**
+ * Constructor with gravity force on each axis.
+ *
+ * @param xx
+ * x value
+ * @param yy
+ * x value
+ * @param zz
+ * x value
+ */
+ public GForce(float xx, float yy, float zz) {
+ x = xx;
+ y = yy;
+ z = zz;
+ }
+
+ /**
+ * @return the x
+ */
+ public float getX() {
+ return x;
+ }
+
+ /**
+ * @return the y
+ */
+ public float getY() {
+ return y;
+ }
+
+ /**
+ * @return the z
+ */
+ public float getZ() {
+ return z;
+ }
+
+ @Override
+ public String toString() {
+ return "Gravity force : (" + x + ", " + y + "," + z + ")";
+ }
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/values/IRSource.java b/WiiUseJ_0.12/src/wiiusej/values/IRSource.java
new file mode 100644
index 0000000..a738c05
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/values/IRSource.java
@@ -0,0 +1,106 @@
+/**
+ * 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_0.12/src/wiiusej/values/Orientation.java b/WiiUseJ_0.12/src/wiiusej/values/Orientation.java
new file mode 100644
index 0000000..124d890
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/values/Orientation.java
@@ -0,0 +1,117 @@
+/**
+ * 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 that represents the orientation of the wiimote.
+ *
+ * @author guiguito
+ */
+public class Orientation {
+
+ private float roll;
+ private float pitch;
+ private float yaw;
+ private float a_roll;
+ private float a_pitch;
+
+ /**
+ * Default constructor.
+ */
+ public Orientation() {
+ roll = 0;
+ pitch = 0;
+ yaw = 0;
+ a_roll = 0;
+ a_pitch = 0;
+ }
+
+ /**
+ * Contructor with raw, pitch , yaw.
+ *
+ * @param r
+ * roll (can be smoothed)
+ * @param p
+ * pitch (can be smoothed)
+ * @param y
+ * yaw
+ * @param ar
+ * absolute roll
+ * @param ap
+ * absolute pitch
+ */
+ public Orientation(float r, float p, float y, float ar, float ap) {
+ roll = r;
+ pitch = p;
+ yaw = y;
+ a_roll = ar;
+ a_pitch = ap;
+ }
+
+ /**
+ * Get the roll (can be smoothed).
+ *
+ * @return the roll
+ */
+ public float getRoll() {
+ return roll;
+ }
+
+ /**
+ * Get the pitch (can be smoothed).
+ *
+ * @return the pitch
+ */
+ public float getPitch() {
+ return pitch;
+ }
+
+ /**
+ * Get the yaw.
+ *
+ * @return the yaw
+ */
+ public float getYaw() {
+ return yaw;
+ }
+
+ /**
+ * Get absolute roll (can not be smoothed).
+ *
+ * @return the a_roll
+ */
+ public float getARoll() {
+ return a_roll;
+ }
+
+ /**
+ * Get absolute pitch (can not be smoothed).
+ *
+ * @return the a_pitch
+ */
+ public float getAPitch() {
+ return a_pitch;
+ }
+
+ @Override
+ public String toString() {
+ return "Orientation : (roll: " + roll + ", pitch: " + pitch + ", yaw: "
+ + yaw + ", absolute roll: " + a_roll + ", absolute pitch: "
+ + a_pitch + ")";
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/values/RawAcceleration.java b/WiiUseJ_0.12/src/wiiusej/values/RawAcceleration.java
new file mode 100644
index 0000000..83f9578
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/values/RawAcceleration.java
@@ -0,0 +1,81 @@
+/**
+ * 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;
+
+/**
+ * Represents raw acceleration on each axis.
+ *
+ * @author guiguito
+ */
+public class RawAcceleration {
+
+ 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;
+ }
+
+ /**
+ * @return the x
+ */
+ public short getX() {
+ return x;
+ }
+
+ /**
+ * @return the y
+ */
+ public short getY() {
+ return y;
+ }
+
+ /**
+ * @return the z
+ */
+ public short getZ() {
+ return z;
+ }
+
+ @Override
+ public String toString() {
+ return "Raw acceleration : (" + x + ", " + y + "," + z + ")";
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/wiiusejevents/GenericEvent.java b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/GenericEvent.java
new file mode 100644
index 0000000..18d8429
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/GenericEvent.java
@@ -0,0 +1,59 @@
+/**
+ * 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.wiiusejevents;
+
+/**
+ * Abstract mother class representing an event with a wiimote id.
+ *
+ * @author guiguito
+ */
+public abstract class GenericEvent {
+
+ /* ID */
+ private int wiimoteId = -1;
+
+ /**
+ * Construct the WiiUseApiEvent setting up the id.
+ *
+ * @param id
+ * the Wiimote id
+ */
+ public GenericEvent(int id) {
+ wiimoteId = id;
+ }
+
+ /**
+ * Get Wiimote ID
+ *
+ * @return the wiimote id.
+ */
+ public int getWiimoteId() {
+ return wiimoteId;
+ }
+
+ /**
+ * Set Wiimote ID
+ *
+ * @param wiimoteId
+ * id of the wiimote
+ */
+ void setWiimoteId(int wiimoteId) {
+ this.wiimoteId = wiimoteId;
+ }
+
+ public abstract String toString();
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/ButtonsEvent.java b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/ButtonsEvent.java
new file mode 100644
index 0000000..d9705fa
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/ButtonsEvent.java
@@ -0,0 +1,128 @@
+/**
+ * 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.wiiusejevents.physicalevents;
+
+import wiiusej.wiiusejevents.GenericEvent;
+
+/**
+ * Class which represents a buttons event.
+ *
+ * @author guiguito
+ */
+public abstract class ButtonsEvent extends GenericEvent {
+
+ /* Buttons */
+ private short buttonsJustPressed = 0;
+ private short buttonsJustReleased = 0;
+ private short buttonsHeld = 0;
+
+ /**
+ * Constructor of the button Event.
+ *
+ * @param id
+ * id of the wiimote concerned.
+ * @param buttonsJustPressed
+ * buttons just pressed.
+ * @param buttonsJustReleased
+ * buttons just released.
+ * @param buttonsHeld
+ * buttons just held.
+ */
+ public ButtonsEvent(int id, short buttonsJustPressed,
+ short buttonsJustReleased, short buttonsHeld) {
+ super(id);
+ setAllButtons(buttonsJustPressed, buttonsJustReleased, buttonsHeld);
+ }
+
+ /**
+ * Set all buttons in one method.
+ *
+ * @param buttonsJustPressed
+ * @param buttonsJustReleased
+ * @param buttonsHeld
+ */
+ private void setAllButtons(short buttonsJustPressed,
+ short buttonsJustReleased, short buttonsHeld) {
+ this.buttonsJustPressed = buttonsJustPressed;
+ this.buttonsJustReleased = buttonsJustReleased;
+ this.buttonsHeld = buttonsHeld;
+ }
+
+ /**
+ * Get the short storing the buttons just pressed
+ *
+ * @return the short storing the buttons just pressed
+ */
+ public short getButtonsJustPressed() {
+ return buttonsJustPressed;
+ }
+
+ /**
+ * Get the short storing the buttons just released
+ *
+ * @return the short storing the buttons just released
+ */
+ public short getButtonsJustReleased() {
+ return buttonsJustReleased;
+ }
+
+ /**
+ * get the short storing the buttons held
+ *
+ * @return the short storing the buttons held
+ */
+ public short getButtonsHeld() {
+ return buttonsHeld;
+ }
+
+ /** **************** BUTTONS Methods ***************** */
+ /* generic button functions */
+
+ protected boolean buttonTest(short buttonBitsDefinition, short buttons) {
+ return (buttons & buttonBitsDefinition) == buttonBitsDefinition;
+ }
+
+ protected boolean isButtonJustPressed(short buttonBitsDefinition) {
+ return buttonTest(buttonBitsDefinition, buttonsJustPressed)
+ && !isButtonHeld(buttonBitsDefinition);
+ }
+
+ protected boolean isButtonJustReleased(short buttonBitsDefinition) {
+ return buttonTest(buttonBitsDefinition, buttonsJustReleased);
+ }
+
+ protected boolean isButtonHeld(short buttonBitsDefinition) {
+ return buttonTest(buttonBitsDefinition, buttonsHeld);
+ }
+
+ protected boolean isButtonPressed(short buttonBitsDefinition) {
+ return isButtonHeld(buttonBitsDefinition)
+ || isButtonJustPressed(buttonBitsDefinition);
+ }
+
+ @Override
+ public String toString() {
+ String out = "";
+ /* Display buttons */
+ out += "/******** Buttons ********/\n";
+ out += "--- Buttons just pressed : " + buttonsJustPressed + "\n";
+ out += "--- Buttons just released : " + buttonsJustReleased + "\n";
+ out += "--- Buttons held : " + buttonsHeld + "\n";
+ return out;
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/ExpansionEvent.java b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/ExpansionEvent.java
new file mode 100644
index 0000000..868f33c
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/ExpansionEvent.java
@@ -0,0 +1,40 @@
+/**
+ * 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.wiiusejevents.physicalevents;
+
+import wiiusej.wiiusejevents.GenericEvent;
+
+/**
+ * Mother Class of all expansions event.
+ *
+ * @author guiguito
+ */
+public abstract class ExpansionEvent extends GenericEvent {
+
+ /**
+ * Constructor of an ExpansionEvent.
+ *
+ * @param id
+ * id of the wiimote to which the expansion is connected.
+ */
+ public ExpansionEvent(int id) {
+ super(id);
+ }
+
+ public abstract String toString();
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/IREvent.java b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/IREvent.java
new file mode 100644
index 0000000..1873a8c
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/IREvent.java
@@ -0,0 +1,317 @@
+/**
+ * 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.wiiusejevents.physicalevents;
+
+import wiiusej.values.IRSource;
+import wiiusej.wiiusejevents.GenericEvent;
+
+/**
+ * Class which represents an IR event.
+ *
+ * @author guiguito
+ */
+public class IREvent extends GenericEvent {
+
+ /* IR Tracking */
+ private IRSource[] IRPoints;
+ private short indexPoints = 0;
+ private int x;
+ private int y;
+ private float 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;
+ private short irSensitivity;
+ private float distance;
+
+ 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 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.
+ * @param irSensitivity
+ * Sensitivity of the infrared camera.
+ * @param distance
+ * Pixel Distance between first two dots
+ */
+ public IREvent(int id, int x, int y, float z, int ax, int ay, int xVRes,
+ int yVRes, int xOffset, int yOffset, short sensorBarPostion,
+ short screenAsPectRatio, short irSensitivity, float distance) {
+ super(id);
+ 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;
+ this.irSensitivity = irSensitivity;
+ this.distance = distance;
+ IRPoints = new IRSource[NB_POINTS];
+ }
+
+ /**
+ * Get list of IR points.
+ *
+ * @return the list of 2D points
+ */
+ public IRSource[] getIRPoints() {
+ return java.util.Arrays.copyOfRange(IRPoints, 0, indexPoints);
+ }
+
+ /**
+ * Add IR Point in the list (Max 4 points)
+ *
+ * @param x
+ * x value
+ * @param y
+ * y value
+ * @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) {
+ 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 float 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;
+ }
+
+ /**
+ * The sensitivity of the IR camera can be turned up or down depending on
+ * your needs. Like the Wii, wiiusej and wiiuse can set the camera
+ * sensitivity to a degree between 1 (lowest) and 5 (highest). The default
+ * is 3.
+ *
+ * @return the irSensitivity
+ */
+ public short getIrSensitivity() {
+ return irSensitivity;
+ }
+
+ /**
+ * Pixel distance between first 2 dots.
+ *
+ * @return the distance between first 2 dots.
+ */
+ public float getDistance() {
+ return distance;
+ }
+
+ @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 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()) {
+ 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) {
+ out += IRPoints[i].toString();
+ }
+ }
+ out += "\n";
+ return out;
+ }
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/JoystickEvent.java b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/JoystickEvent.java
new file mode 100644
index 0000000..5dc7f2f
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/JoystickEvent.java
@@ -0,0 +1,135 @@
+/**
+ * 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.wiiusejevents.physicalevents;
+
+import wiiusej.wiiusejevents.GenericEvent;
+
+/**
+ * Class that stores values on a joystick Event.
+ *
+ * @author guiguito
+ */
+public class JoystickEvent extends GenericEvent {
+
+ private float angle;
+ private float magnitude;
+ private short[] max;
+ private short[] min;
+ private short[] center;
+
+ /**
+ * Constructor of a JoystickEvent.
+ *
+ * @param id
+ * id of the wiimote connected.
+ * @param angle
+ * angle the joystick is being held.
+ * @param magnitude
+ * magnitude of the joystick (range 0-1).
+ * @param max1
+ * maximum joystick value 1.
+ * @param max2
+ * maximum joystick value 2.
+ * @param min1
+ * minimum joystick value 1.
+ * @param min2
+ * minimum joystick value 2.
+ * @param center1
+ * center joystick value 1.
+ * @param center2
+ * center joystick value 2.
+ */
+ public JoystickEvent(int id, float angle, float magnitude, short max1,
+ short max2, short min1, short min2, short center1, short center2) {
+ super(id);
+ this.angle = angle;
+ this.magnitude = magnitude;
+ max = new short[2];
+ max[0] = max1;
+ max[1] = max2;
+ min = new short[2];
+ min[0] = min1;
+ min[1] = min2;
+ center = new short[2];
+ center[0] = center1;
+ center[1] = center2;
+ }
+
+ /**
+ * Get angle the joystick is being held.
+ *
+ * @return the angle angle the joystick.
+ */
+ public float getAngle() {
+ return angle;
+ }
+
+ /**
+ * Get magnitude of the joystick (range 0-1).
+ *
+ * @return the magnitude magnitude of the joystick.
+ */
+ public float getMagnitude() {
+ return magnitude;
+ }
+
+ /**
+ * Maximum joystick values.
+ *
+ * @return the max
+ */
+ public short[] getMax() {
+ return max;
+ }
+
+ /**
+ * Minimum joystick values.
+ *
+ * @return the min
+ */
+ public short[] getMin() {
+ return min;
+ }
+
+ /**
+ * Center joystick values.
+ *
+ * @return the center
+ */
+ public short[] getCenter() {
+ return center;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see wiiusej.wiiusejevents.GenericEvent#toString()
+ */
+ @Override
+ public String toString() {
+ String out = "";
+ /* Display IR Tracking */
+ out += "/******** Joystick ********/\n";
+ out += "--- angle : " + angle + "\n";
+ out += "--- magnitude : " + magnitude + "\n";
+ out += "--- maximum values : " + max[0] + "," + max[1] + "\n";
+ out += "--- minimum values : " + min[0] + "," + min[1] + "\n";
+ out += "--- center values : " + center[0] + "," + center[1] + "\n";
+ return out;
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/MotionSensingEvent.java b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/MotionSensingEvent.java
new file mode 100644
index 0000000..0945a48
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/MotionSensingEvent.java
@@ -0,0 +1,203 @@
+/**
+ * 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.wiiusejevents.physicalevents;
+
+import wiiusej.values.GForce;
+import wiiusej.values.Orientation;
+import wiiusej.values.RawAcceleration;
+import wiiusej.wiiusejevents.GenericEvent;
+
+/**
+ * Class which represents a motion sensing event.
+ *
+ * @author guiguito
+ */
+public class MotionSensingEvent extends GenericEvent {
+
+ /* Motion Sensing */
+ private Orientation orientation;
+ private GForce gforce;
+ private RawAcceleration acceleration;
+
+ private float orientationThreshold = 0;
+ private int accelerationThreshold = 0;
+ private float alphaSmoothing = 0;
+ private boolean isSmoothingActive = false;
+
+ /**
+ * Constructor for a Motion Sensing Event.
+ *
+ * @param id
+ * id of the wiimote concerned.
+ * @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 MotionSensingEvent(int id, 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) {
+ super(id);
+ this.orientationThreshold = orientationThreshold;
+ this.accelerationThreshold = accelerationThreshold;
+ this.isSmoothingActive = smoothingState;
+ this.alphaSmoothing = alphaSmooth;
+ setOrientationAndGforce(r, p, ya, ar, ap, x, y, z, xx, yy, zz);
+ }
+
+ /**
+ * Set orientation, gravity force and raw acceleration.
+ *
+ * @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
+ */
+ private void setOrientationAndGforce(float r, float p, float ya, float ar,
+ float ap, float x, float y, float z, short xx, short yy, short zz) {
+ this.orientation = new Orientation(r, p, ya, ar, ap);
+ this.gforce = new GForce(x, y, z);
+ this.acceleration = new RawAcceleration(xx, yy, zz);
+ }
+
+ /**
+ * @return the orientation
+ */
+ public Orientation getOrientation() {
+ return orientation;
+ }
+
+ /**
+ * Get the gravity force.
+ *
+ * @return the gforce
+ */
+ public GForce getGforce() {
+ return gforce;
+ }
+
+ /**
+ * Get the raw acceleration.
+ *
+ * @return the raw acceleration
+ */
+ public RawAcceleration getRawAcceleration() {
+ return acceleration;
+ }
+
+ /**
+ * Get orientation threshold.
+ *
+ * @return the orientationThreshold
+ */
+ public float getOrientationThreshold() {
+ return orientationThreshold;
+ }
+
+ /**
+ * Get acceleration threshold.
+ *
+ * @return the accelerationThreshold
+ */
+ public int getAccelerationThreshold() {
+ return accelerationThreshold;
+ }
+
+ /**
+ * Get alpha smoothing.
+ *
+ * @return the alphaSmoothing
+ */
+ public float getAlphaSmoothing() {
+ return alphaSmoothing;
+ }
+
+ /**
+ * Tell if the option SMOOTHING is activated.
+ *
+ * @return the isSmoothingActive
+ */
+ public boolean isSmoothingActive() {
+ return isSmoothingActive;
+ }
+
+ @Override
+ public String toString() {
+ String out = "";
+ /* Motion sensing */
+ out += "/******** Motion sensing ********/\n";
+ out += "--- Motion sensing : true \n";
+ out += "--- Orientation threshold value ? : " + orientationThreshold
+ + "\n";
+ out += "--- Acceleration threshold value ? : " + accelerationThreshold
+ + "\n";
+ out += "--- Alpha smoothing threshold value ? : " + alphaSmoothing
+ + "\n";
+ out += "--- Smoothing ? : " + isSmoothingActive + "\n";
+ out += "--- " + orientation + "\n";
+ out += "--- " + gforce + "\n";
+ out += "--- " + acceleration + "\n";
+ return out;
+ }
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/NunchukButtonsEvent.java b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/NunchukButtonsEvent.java
new file mode 100644
index 0000000..b6584d6
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/NunchukButtonsEvent.java
@@ -0,0 +1,90 @@
+/**
+ * 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.wiiusejevents.physicalevents;
+
+/**
+ * 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 Nunchuk Event ********/\n"
+ + super.toString();
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/NunchukEvent.java b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/NunchukEvent.java
new file mode 100644
index 0000000..eec7b97
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/NunchukEvent.java
@@ -0,0 +1,169 @@
+/**
+ * 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.wiiusejevents.physicalevents;
+
+/**
+ * This class represents the values from the joystick and its events.
+ *
+ * @author guiguito
+ */
+public class NunchukEvent extends ExpansionEvent {
+
+ NunchukButtonsEvent buttonsEvent;
+ MotionSensingEvent nunchukMotionSensingEvent;
+ JoystickEvent nunchukJoystickEvent;
+
+ /**
+ * Constructor of NunchukEvent.
+ *
+ * @param id
+ * id of the wiimote.
+ * @param buttonsJustPressed
+ * buttons just pressed.
+ * @param buttonsJustReleased
+ * buttons just released.
+ * @param buttonsHeld
+ * buttons just pressed.
+ * @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.
+ * @param angle
+ * angle the joystick is being held.
+ * @param magnitude
+ * magnitude of the joystick (range 0-1).
+ * @param max1
+ * maximum joystick value 1.
+ * @param max2
+ * maximum joystick value 2.
+ * @param min1
+ * minimum joystick value 1.
+ * @param min2
+ * minimum joystick value 2.
+ * @param center1
+ * center joystick value 1.
+ * @param center2
+ * center joystick value 2.
+ */
+ public NunchukEvent(int id, short buttonsJustPressed,
+ short buttonsJustReleased, short buttonsHeld,
+ 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, float angle, float magnitude, short max1,
+ short max2, short min1, short min2, short center1, short center2) {
+ super(id);
+ buttonsEvent = new NunchukButtonsEvent(id, buttonsJustPressed,
+ buttonsJustReleased, buttonsHeld);
+ nunchukMotionSensingEvent = new MotionSensingEvent(id,
+ orientationThreshold, accelerationThreshold, smoothingState,
+ alphaSmooth, r, p, ya, ar, ap, x, y, z, xx, yy, zz);
+ nunchukJoystickEvent = new JoystickEvent(id, angle, magnitude, max1,
+ max2, min1, min2, center1, center2);
+ }
+
+ /**
+ * Tell if there is a nunchuk motion sensing Event.
+ *
+ * @return TRUE if there is a nunchuk motion sensing event, false otherwise.
+ */
+ public boolean isThereMotionSensingEvent() {
+ return nunchukMotionSensingEvent != null;
+ }
+
+ /**
+ * Tell if there is a nunchuk joystick event.
+ *
+ * @return TRUE if there is a nunchuk joystick event, false otherwise.
+ */
+ public boolean isThereNunchukJoystickEvent() {
+ return nunchukJoystickEvent != null;
+ }
+
+ /**
+ * Get joystick buttons event.
+ *
+ * @return the joystick buttons event if there is one or null.
+ */
+ public NunchukButtonsEvent getButtonsEvent() {
+ return buttonsEvent;
+ }
+
+ /**
+ * Get the nunchuk motion sensing event.
+ *
+ * @return the nunchuk motion sensing event if there is one or null.
+ */
+ public MotionSensingEvent getNunchukMotionSensingEvent() {
+ return nunchukMotionSensingEvent;
+ }
+
+ /**
+ * Get the nunchuk joystick event.
+ *
+ * @return the nunchuk Joystick Event if there is one or null.
+ */
+ public JoystickEvent getNunchukJoystickEvent() {
+ return nunchukJoystickEvent;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see wiiusej.wiiusejevents.GenericEvent#toString()
+ */
+ @Override
+ public String toString() {
+ String out = "";
+ /* Status */
+ out += "/*********** Nunchuk EVENT : WIIMOTE ID :" + getWiimoteId()
+ + " ********/\n";
+ out += buttonsEvent;
+ out += nunchukJoystickEvent;
+ out += nunchukMotionSensingEvent;
+ return out;
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/WiimoteButtonsEvent.java b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/WiimoteButtonsEvent.java
new file mode 100644
index 0000000..106fc1c
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/physicalevents/WiimoteButtonsEvent.java
@@ -0,0 +1,267 @@
+/**
+ * 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.wiiusejevents.physicalevents;
+
+/**
+ * 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();
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/wiiusejevents/utils/EventsGatherer.java b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/utils/EventsGatherer.java
new file mode 100644
index 0000000..31ed13a
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/utils/EventsGatherer.java
@@ -0,0 +1,355 @@
+/**
+ * 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.wiiusejevents.utils;
+
+import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.WiiUseApiEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.WiimoteEvent;
+
+/**
+ * This class is used to gather events during a call to the Wiiuse API.
+ *
+ * @author guiguito
+ */
+public class EventsGatherer {
+
+ private WiiUseApiEvent[] events;
+ private int index = 0;
+ private WiimoteEvent genericEvent = null;
+
+ /**
+ * Create EventsGatherer.
+ *
+ * @param nbWiimotes
+ * nb wiimotes (nb a of events possible in a call to Wiiuse API).
+ */
+ public EventsGatherer(int nbWiimotes) {
+ events = new WiiUseApiEvent[nbWiimotes];
+ }
+
+ /**
+ * Add an event to the array.
+ *
+ * @param e
+ * the event to add.
+ */
+ private void addEvent(WiiUseApiEvent e) {
+ events[index] = e;
+ index++;
+ }
+
+ /**
+ * Prepare a wiimote event to add.
+ *
+ * @param id
+ * id of the wiimote.
+ * @param buttonsJustPressed
+ * buttons just pressed.
+ * @param buttonsJustReleased
+ * buttons just released.
+ * @param buttonsHeld
+ * buttons held.
+ */
+ public void prepareWiiMoteEvent(int id, short buttonsJustPressed,
+ short buttonsJustReleased, short buttonsHeld) {
+ genericEvent = new WiimoteEvent(id, buttonsJustPressed,
+ 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.
+ * @param irSensitivity
+ * Sensitivity of the infrared camera.
+ * @param distance
+ * Pixel Distance between first two dots.
+ */
+ public void prepareIRevent(int x, int y, float z, int ax, int ay,
+ int xVRes, int yVRes, int xOffset, int yOffset,
+ short sensorBarPostion, short screenAsPectRatio,
+ short irSensitivity, float distance) {
+ genericEvent.prepareIRevent(x, y, z, ax, ay, xVRes, yVRes, xOffset,
+ yOffset, sensorBarPostion, screenAsPectRatio, irSensitivity,
+ distance);
+
+ }
+
+ /**
+ * Add an IR point to the WiiMoteEvent prepared.
+ *
+ * @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 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.
+ *
+ * @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 addMotionSensingValues(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) {
+ if (genericEvent != null) {
+ genericEvent.setMotionSensingEvent(orientationThreshold,
+ accelerationThreshold, smoothingState, alphaSmooth, r, p,
+ ya, ar, ap, x, y, z, xx, yy, zz);
+ }
+ }
+
+ /**
+ * Set a NunchukEvent to the prepared .
+ *
+ * @param buttonsJustPressed
+ * buttons just pressed.
+ * @param buttonsJustReleased
+ * buttons just released.
+ * @param buttonsHeld
+ * buttons just pressed.
+ * @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.
+ * @param angle
+ * angle the joystick is being held.
+ * @param magnitude
+ * magnitude of the joystick (range 0-1).
+ * @param max1
+ * maximum joystick value 1.
+ * @param max2
+ * maximum joystick value 2.
+ * @param min1
+ * minimum joystick value 1.
+ * @param min2
+ * minimum joystick value 2.
+ * @param center1
+ * center joystick value 1.
+ * @param center2
+ * center joystick value 2.
+ */
+ public void addNunchunkEventToPreparedWiimoteEvent(
+ short buttonsJustPressed, short buttonsJustReleased,
+ short buttonsHeld, 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,
+ float angle, float magnitude, short max1, short max2, short min1,
+ short min2, short center1, short center2) {
+ if (genericEvent != null) {
+ genericEvent.setNunchukEvent(buttonsJustPressed,
+ buttonsJustReleased, buttonsHeld, orientationThreshold,
+ accelerationThreshold, smoothingState, alphaSmooth, r, p,
+ ya, ar, ap, x, y, z, xx, yy, zz, angle, magnitude, max1,
+ max2, min1, min2, center1, center2);
+ }
+ }
+
+ /**
+ * Add the prepared WiimoteEvent to the gatherer.
+ */
+ public void addWiimoteEvent() {
+ if (genericEvent != null) {
+ addEvent(genericEvent);
+ genericEvent = null;
+ }
+ }
+
+ /**
+ * Add a StatusEvent to the gatherer.
+ *
+ * @param id
+ * id of the wiimote.
+ * @param connect
+ * true if the wiimote is connected.
+ * @param batt
+ * battery level.
+ * @param led
+ * status of leds.
+ * @param speak
+ * speakers status.
+ * @param attach
+ * attachment status.
+ * @param rumbleState
+ * true if rumble is active.
+ * @param continuousState
+ * true if continuous flag is activated.
+ * @param irState
+ * true if ir is active.
+ * @param motionSensingState
+ * true if accelerometer is active.
+ */
+ public void addStatusEvent(int id, boolean connect, float batt, short led,
+ boolean speak, int attach, boolean rumbleState,
+ boolean continuousState, boolean irState, boolean motionSensingState) {
+ StatusEvent evt = new StatusEvent(id, connect, batt, led, speak,
+ attach, rumbleState, continuousState, irState,
+ motionSensingState);
+ addEvent(evt);
+ }
+
+ /**
+ * Add a DisconnectionEvent to the gatherer.
+ *
+ * @param id
+ * id of the wiimote.
+ */
+ public void addDisconnectionEvent(int id) {
+ 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.
+ *
+ * @return events received.
+ */
+ public WiiUseApiEvent[] getEvents() {
+ return java.util.Arrays.copyOfRange(events, 0, index);
+ }
+
+ /**
+ * Clear the gatherer and remove objects.
+ */
+ public void clearEvents() {
+ for (int i = 0; i < events.length; i++) {
+ events[i] = null;
+ }
+ genericEvent = null;
+ index = 0;
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/wiiusejevents/utils/WiiUseApiListener.java b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/utils/WiiUseApiListener.java
new file mode 100644
index 0000000..ee1ce80
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/utils/WiiUseApiListener.java
@@ -0,0 +1,37 @@
+/**
+ * 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.wiiusejevents.utils;
+
+import wiiusej.wiiusejevents.wiiuseapievents.WiiUseApiEvent;
+
+/**
+ * This is the interface to implement to listen to events from the wiiuse API.
+ *
+ * @author guiguito
+ */
+public interface WiiUseApiListener extends java.util.EventListener {
+
+ /**
+ * Method called when a WiiUseApiEvent occurs. A WiiUseApiEvent can be : -
+ * WiimoteEvent (Storing ButtonsEvent and eventually IREvent and
+ * MotionSensingEvent) - StatusEvent - DisconnectionEvent
+ *
+ * @param e
+ */
+ void onWiiUseApiEvent(WiiUseApiEvent e);
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/wiiusejevents/utils/WiimoteListener.java b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/utils/WiimoteListener.java
new file mode 100644
index 0000000..d066516
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/utils/WiimoteListener.java
@@ -0,0 +1,107 @@
+/**
+ * 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.wiiusejevents.utils;
+
+import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
+import wiiusej.wiiusejevents.physicalevents.IREvent;
+import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
+import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
+import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
+
+/**
+ * This is the interface to implement to listen to events from wiimotes. The
+ * differents methods are called in this order : onButtonsEvent, onIrEvent,
+ * onMotionSensingEvent, onExpansionEvent, onStatusEvent, onDisconnectionEvent
+ * onNunchukInsertedEvent, onNunchukRemovedEvent.
+ *
+ * @author guiguito
+ */
+public interface WiimoteListener extends java.util.EventListener {
+
+ /**
+ * Method called on a button Event.
+ *
+ * @param e
+ * the buttonEvent with the last informations about the buttons
+ * of the wiimote.
+ */
+ void onButtonsEvent(WiimoteButtonsEvent e);
+
+ /**
+ * Method called when an IR event occurs.
+ *
+ * @param e
+ * the IREvent with the IR points seen.
+ */
+ void onIrEvent(IREvent e);
+
+ /**
+ * Method called when a motion sensing event occurs.
+ *
+ * @param e
+ * the motion sensing event with orientation and acceleration.
+ */
+ void onMotionSensingEvent(MotionSensingEvent e);
+
+ /**
+ * Method called when an expansion event occurs.
+ *
+ * @param e
+ * the expansion event occured.
+ */
+ void onExpansionEvent(ExpansionEvent e);
+
+ /**
+ * Method called on a status event. A status event occurs when : - we ask it -
+ * an expansion controller has been plugged - an expansion controller has
+ * been unplugged This is where you can get the different values of the
+ * parameters setup on your wiimote.
+ *
+ * @param e
+ * the status event.
+ */
+ void onStatusEvent(StatusEvent e);
+
+ /**
+ * This is the method called when a disconnection event occurs. A
+ * disconnection event happens when : - there are no battery left - the
+ * wiimote has just been turned off - the connection is dropped
+ *
+ * @param e
+ * the disconnection event.
+ */
+ void onDisconnectionEvent(DisconnectionEvent e);
+
+ /**
+ * This is the method called when a NunchukInsertedEvent occurs.
+ *
+ * @param e
+ * the NunchukInsertedEvent.
+ */
+ void onNunchukInsertedEvent(NunchukInsertedEvent e);
+
+ /**
+ * This is the method called when a NunchukRemovedEvent occurs.
+ *
+ * @param e
+ * the NunchukRemovedEvent.
+ */
+ void onNunchukRemovedEvent(NunchukRemovedEvent e);
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/wiiusejevents/wiiuseapievents/DisconnectionEvent.java b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/wiiuseapievents/DisconnectionEvent.java
new file mode 100644
index 0000000..1c844c7
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/wiiuseapievents/DisconnectionEvent.java
@@ -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 .
+ */
+package wiiusej.wiiusejevents.wiiuseapievents;
+
+/**
+ * Class representing a disconnection event.
+ *
+ * @author guiguito
+ */
+public class DisconnectionEvent extends WiiUseApiEvent {
+
+ /**
+ * Construct the DisconnectionEvent setting up the id.
+ *
+ * @param id
+ * the Wiimote id
+ */
+ public DisconnectionEvent(int id) {
+ super(id, WiiUseApiEvent.DISCONNECTION_EVENT);
+ }
+
+ @Override
+ public String toString() {
+ String out = "";
+ /* Status */
+ out += "/*********** DISCONNECTION EVENT : WIIMOTE ID :"
+ + super.getWiimoteId() + " ********/\n";
+ return out;
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukInsertedEvent.java b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukInsertedEvent.java
new file mode 100644
index 0000000..6aff636
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukInsertedEvent.java
@@ -0,0 +1,51 @@
+/**
+ * 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.wiiusejevents.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.wiiusejevents.WiiUseApiEvent#toString()
+ */
+ @Override
+ public String toString() {
+ String out = "";
+ /* Status */
+ out += "/*********** NUNCHUK INSERTED EVENT : WIIMOTE ID :"
+ + super.getWiimoteId() + " ********/\n";
+ return out;
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukRemovedEvent.java b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukRemovedEvent.java
new file mode 100644
index 0000000..c9c585d
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/wiiuseapievents/NunchukRemovedEvent.java
@@ -0,0 +1,50 @@
+/**
+ * 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.wiiusejevents.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.wiiusejevents.WiiUseApiEvent#toString()
+ */
+ @Override
+ public String toString() {
+ String out = "";
+ /* Status */
+ out += "/*********** NUNCHUK REMOVED EVENT : WIIMOTE ID :"
+ + super.getWiimoteId() + " ********/\n";
+ return out;
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/wiiusejevents/wiiuseapievents/StatusEvent.java b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/wiiuseapievents/StatusEvent.java
new file mode 100644
index 0000000..d200bb7
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/wiiuseapievents/StatusEvent.java
@@ -0,0 +1,293 @@
+/**
+ * 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.wiiusejevents.wiiuseapievents;
+
+/**
+ * Class used to represent a status event. This class is used to know what are
+ * the settings of the wiimote.
+ *
+ * @author guiguito
+ */
+public class StatusEvent extends WiiUseApiEvent {
+
+ protected static short WIIMOTE_LED_1 = 1;
+ protected static short WIIMOTE_LED_2 = 2;
+ protected static short WIIMOTE_LED_3 = 4;
+ protected static short WIIMOTE_LED_4 = 8;
+
+ /* ATTACHMENT CONSTANTS */
+
+ private static short EXP_NONE = 0;
+ private static short EXP_NUNCHUK = 1;
+ private static short EXP_CLASSIC = 2;
+ private static short EXP_GUITAR_HERO_3 = 3;
+
+ /* Status variables */
+ private boolean connected = false;
+
+ private float batteryLevel = -1;
+
+ private short leds = 0;
+
+ private boolean isSpeakerEnabled = false;
+
+ private int attachment = 0;
+
+ private boolean isRumbleActive = false;
+
+ private boolean isContinuousActive = false;
+
+ private boolean isIrActive = false;
+
+ private boolean isMotionSensingActive = false;
+
+ /**
+ * Construct the StatusEvent setting up the id.
+ *
+ * @param id
+ * the Wiimote id
+ */
+ public StatusEvent(int id) {
+ super(id, WiiUseApiEvent.STATUS_EVENT);
+ }
+
+ /**
+ * Build a StatusEvent with all fields set.
+ *
+ * @param id
+ * id of the wiimote
+ * @param connect
+ * true if the wiimote is connected
+ * @param batt
+ * battery level
+ * @param led
+ * status of leds
+ * @param speak
+ * speakers status
+ * @param attach
+ * attachment status
+ * @param rumbleState
+ * true if rumble is active
+ * @param continuousState
+ * true if continuous flag is activated
+ * @param irState
+ * true if ir is active
+ * @param motionSensingState
+ * true if accelerometer is active
+ */
+ public StatusEvent(int id, boolean connect, float batt, short led,
+ boolean speak, int attach, boolean rumbleState,
+ boolean continuousState, boolean irState, boolean motionSensingState) {
+ super(id, WiiUseApiEvent.STATUS_EVENT);
+ connected = connect;
+ this.batteryLevel = batt;
+ this.leds = led;
+ this.isSpeakerEnabled = speak;
+ this.attachment = attach;
+ isRumbleActive = rumbleState;
+ isContinuousActive = continuousState;
+ isIrActive = irState;
+ isMotionSensingActive = motionSensingState;
+ }
+
+ /**
+ * True if the wiimote is connected false otherwise.
+ *
+ * @return return the connected status.
+ */
+ public boolean isConnected() {
+ return connected;
+ }
+
+ /**
+ * Get battery level.
+ *
+ * @return battery level. 1 = 100%
+ */
+ public float getBatteryLevel() {
+ return batteryLevel;
+ }
+
+ /**
+ * Get status of the leds .
+ *
+ * @return a short representing LEDS turned on.
+ */
+ public short getLeds() {
+ return leds;
+ }
+
+ /**
+ * Tells if the given led is turned on according to the leds status int.
+ *
+ * @param led
+ * the int encoding a led.
+ * @return true if the led is turned on false otherwise.
+ */
+ private boolean ledStatusCheck(short led) {
+ if ((leds & led) > 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Get led1 status.
+ *
+ * @return true if the led is set.
+ */
+ public boolean isLed1Set() {
+ return ledStatusCheck(WIIMOTE_LED_1);
+ }
+
+ /**
+ * Get led2 status.
+ *
+ * @return true if the led is set.
+ */
+ public boolean isLed2Set() {
+ return ledStatusCheck(WIIMOTE_LED_2);
+ }
+
+ /**
+ * Get led3 status.
+ *
+ * @return true if the led is set.
+ */
+ public boolean isLed3Set() {
+ return ledStatusCheck(WIIMOTE_LED_3);
+ }
+
+ /**
+ * Get led4 status.
+ *
+ * @return true if the led is set.
+ */
+ public boolean isLed4Set() {
+ return ledStatusCheck(WIIMOTE_LED_4);
+ }
+
+ /**
+ * Tell if the speaker is enable for this wiimote
+ *
+ * @return TRUE if it enabled false otherwise
+ */
+ public boolean isSpeakerEnabled() {
+ return isSpeakerEnabled;
+ }
+
+ /**
+ * Get the int representing the attachment type.
+ *
+ * @return value of the Attachment Type
+ */
+ public int getAttachment() {
+ return attachment;
+ }
+
+ /**
+ * Get the status of rumble.
+ *
+ * @return true if the rumble is active false otherwise
+ */
+ public boolean isRumbleActive() {
+ return isRumbleActive;
+ }
+
+ /**
+ * Tell if the CONTINUOUS option is activated.
+ *
+ * @return the isContinuousActive
+ */
+ public boolean isContinuousActive() {
+ return isContinuousActive;
+ }
+
+ /**
+ * Tell if the IR Tracking is active.
+ *
+ * @return TRUE if it is active or false otherwise.
+ */
+ public boolean isIrActive() {
+ return isIrActive;
+ }
+
+ /**
+ * Get the flag indicating if the motion sensing is active.
+ *
+ * @return true if the motion sensing is active false otherwise
+ */
+ public boolean isMotionSensingActive() {
+ return isMotionSensingActive;
+ }
+
+ /**
+ * Tells if an attachment is connected.
+ *
+ * @return true if anything is connected to the wiimote false otherwise.
+ */
+ public boolean isAttachmentConnected() {
+ return attachment == EXP_NONE;
+ }
+
+ /**
+ * Tells if a nunchuk is connected.
+ *
+ * @return true if a nunchuk is connected to the wiimote false otherwise.
+ */
+ public boolean isNunchukConnected() {
+ return attachment == EXP_NUNCHUK;
+ }
+
+ /**
+ * Tells if a classic controller is connected.
+ *
+ * @return true if a classic controller is connected to the wiimote false otherwise.
+ */
+ public boolean isClassicControllerConnected() {
+ return attachment == EXP_CLASSIC;
+ }
+
+ /**
+ * Tells if a guitar hero controller is connected.
+ *
+ * @return true if a guitar hero controllerr is connected to the wiimote false otherwise.
+ */
+ public boolean isGuitarHeroConnected() {
+ return attachment == EXP_GUITAR_HERO_3;
+ }
+
+ @Override
+ public String toString() {
+ String out = "";
+ /* Status */
+ out += "/*********** STATUS EVENT : WIIMOTE ID :"
+ + super.getWiimoteId() + " ********/\n";
+ out += "--- connected : " + connected + "\n";
+ out += "--- Battery level : " + batteryLevel + "\n";
+ out += "--- Leds : " + leds + "\n";
+ out += "--- Speaker enabled : " + isSpeakerEnabled + "\n";
+ out += "--- Attachment ? : " + attachment + "\n";
+ out += "--- Rumble ? : " + isRumbleActive + "\n";
+ out += "--- Continuous ? : " + isContinuousActive + "\n";
+ out += "--- IR active ? : " + isIrActive + "\n";
+ out += "--- Motion sensing active ? : " + isMotionSensingActive + "\n";
+ return out;
+ }
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/wiiusejevents/wiiuseapievents/WiiUseApiEvent.java b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/wiiuseapievents/WiiUseApiEvent.java
new file mode 100644
index 0000000..0527b13
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/wiiuseapievents/WiiUseApiEvent.java
@@ -0,0 +1,66 @@
+/**
+ * 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.wiiusejevents.wiiuseapievents;
+
+import wiiusej.wiiusejevents.GenericEvent;
+
+/**
+ * This class describes the structure of an event from the WiiUse API event.
+ *
+ * @author guiguito
+ */
+public abstract class WiiUseApiEvent extends GenericEvent{
+
+ public static int NONE_EVENT = 0;
+ public static int GENERIC_EVENT = 1;
+ public static int STATUS_EVENT = 2;
+ public static int DISCONNECTION_EVENT = 3;
+ public static int WIIUSE_READ_DATA = 4;
+ public static int WIIUSE_NUNCHUK_INSERTED = 5;
+ public static int WIIUSE_NUNCHUK_REMOVED = 6;
+ public static int WIIUSE_CLASSIC_CTRL_INSERTED = 7;
+ public static int WIIUSE_CLASSIC_CTRL_REMOVED = 8;
+ public static int WIIUSE_GUITAR_HERO_3_CTRL_INSERTED = 9;
+ public static int WIIUSE_GUITAR_HERO_3_CTRL_REMOVED = 10;
+
+ /* Event Type */
+ private int eventType;
+
+ /**
+ * Construct the WiiUseApiEvent setting up the id.
+ *
+ * @param id
+ * the Wiimote id
+ * @param type
+ * type of the event
+ */
+ public WiiUseApiEvent(int id, int type) {
+ super(id);
+ eventType = type;
+ }
+
+ /**
+ * Get the event type.
+ * @return the eventType
+ */
+ public int getEventType() {
+ return eventType;
+ }
+
+ public abstract String toString();
+
+}
diff --git a/WiiUseJ_0.12/src/wiiusej/wiiusejevents/wiiuseapievents/WiimoteEvent.java b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/wiiuseapievents/WiimoteEvent.java
new file mode 100644
index 0000000..04c1840
--- /dev/null
+++ b/WiiUseJ_0.12/src/wiiusej/wiiusejevents/wiiuseapievents/WiimoteEvent.java
@@ -0,0 +1,345 @@
+/**
+ * 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.wiiusejevents.wiiuseapievents;
+
+import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
+import wiiusej.wiiusejevents.physicalevents.IREvent;
+import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
+import wiiusej.wiiusejevents.physicalevents.NunchukEvent;
+import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
+
+/**
+ * Class that is a bean to be filled by the wiiuse API on an event that occurs
+ * on a wiimote.
+ *
+ * @author guiguito
+ */
+public class WiimoteEvent extends WiiUseApiEvent {
+
+ WiimoteButtonsEvent buttonsEvent = null;
+ IREvent infraredEvent = null;
+ MotionSensingEvent motionSensingEvent = null;
+ ExpansionEvent expansionEvent = null;
+
+ /**
+ * Construct the Wiimote setting up the id.
+ *
+ * @param id
+ * the Wiimote id
+ */
+ public WiimoteEvent(int id) {
+ super(id, WiiUseApiEvent.GENERIC_EVENT);
+ }
+
+ /**
+ * Construct the Wiimote setting up the id and the buttons.
+ *
+ * @param id
+ * the Wiimote id
+ * @param buttonsJustPressed
+ * buttons just pressed
+ * @param buttonsJustReleased
+ * buttons just released
+ * @param buttonsHeld
+ * buttons held
+ */
+ public WiimoteEvent(int id, short buttonsJustPressed,
+ short buttonsJustReleased, short buttonsHeld) {
+ super(id, WiiUseApiEvent.GENERIC_EVENT);
+ buttonsEvent = new WiimoteButtonsEvent(id, buttonsJustPressed,
+ buttonsJustReleased, buttonsHeld);
+ }
+
+ /**
+ * Tell if there is an IR Event.
+ *
+ * @return TRUE if there is an IR event.
+ */
+ public boolean isThereIrEvent() {
+ return infraredEvent != null;
+ }
+
+ /**
+ * Tell if there is a motion sensing Event.
+ *
+ * @return TRUE if there is a motion sensing event.
+ */
+ public boolean isThereMotionSensingEvent() {
+ return motionSensingEvent != null;
+ }
+
+ /**
+ * Tell if there is an expansion Event.
+ *
+ * @return TRUE if there is an expansion event.
+ */
+ public boolean isThereExpansionEvent() {
+ return expansionEvent != null;
+ }
+
+ /**
+ * Get buttons event.
+ *
+ * @return the buttons event.
+ */
+ public WiimoteButtonsEvent getButtonsEvent() {
+ return buttonsEvent;
+ }
+
+ /**
+ * Get the IR event.
+ *
+ * @return the IR event if there is one or null.
+ */
+ public IREvent getIREvent() {
+ return infraredEvent;
+ }
+
+ /**
+ * Get the motion sensing event.
+ *
+ * @return the motion sensing event if there is one or null.
+ */
+ public MotionSensingEvent getMotionSensingEvent() {
+ return motionSensingEvent;
+ }
+
+ /**
+ * Get the expansion event.
+ *
+ * @return the expansion event if there is one or null.
+ */
+ public ExpansionEvent getExpansionEvent() {
+ return expansionEvent;
+ }
+
+ /**
+ * 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, float 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);
+ }
+
+ /**
+ * Set a NunchukEvent for the expansion event.
+ *
+ * @param buttonsJustPressed
+ * buttons just pressed.
+ * @param buttonsJustReleased
+ * buttons just released.
+ * @param buttonsHeld
+ * buttons just pressed.
+ * @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.
+ * @param angle
+ * angle the joystick is being held.
+ * @param magnitude
+ * magnitude of the joystick (range 0-1).
+ * @param max1
+ * maximum joystick value 1.
+ * @param max2
+ * maximum joystick value 2.
+ * @param min1
+ * minimum joystick value 1.
+ * @param min2
+ * minimum joystick value 2.
+ * @param center1
+ * center joystick value 1.
+ * @param center2
+ * center joystick value 2.
+ */
+ public void setNunchukEvent(short buttonsJustPressed,
+ short buttonsJustReleased, short buttonsHeld,
+ 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, float angle, float magnitude, short max1,
+ short max2, short min1, short min2, short center1, short center2) {
+ expansionEvent = new NunchukEvent(getWiimoteId(), buttonsJustPressed,
+ buttonsJustReleased, buttonsHeld, orientationThreshold,
+ accelerationThreshold, smoothingState, alphaSmooth, r, p, ya,
+ ar, ap, x, y, z, xx, yy, zz, angle, magnitude, max1, max2,
+ min1, min2, center1, center2);
+ }
+
+ public void setClassicControllerEvent() {
+ // @TODO
+ }
+
+ @Override
+ public String toString() {
+ String out = "";
+ /* Status */
+ out += "/*********** GENERIC EVENT : WIIMOTE ID :" + 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";
+ }
+
+ if (expansionEvent != null) {
+ out += expansionEvent;
+ } else {
+ out += "/******** Expansion ********/\n";
+ out += "--- No expansion connected \n";
+ }
+
+ return out;
+ }
+
+}
diff --git a/WiiUseJ_0.12/wiiuse.dll b/WiiUseJ_0.12/wiiuse.dll
new file mode 100644
index 0000000..a7e228c
Binary files /dev/null and b/WiiUseJ_0.12/wiiuse.dll differ