0.12 going well. Added everything for the nunchuk. Need more testing.

git-svn-id: http://wiiusej.googlecode.com/svn/trunk@141 ae48ae66-6a45-0410-b38e-211266189506
This commit is contained in:
guilhem.duche
2008-05-09 22:22:13 +00:00
parent 732154a82f
commit be56f33b33
16 changed files with 1205 additions and 807 deletions

View File

@@ -144,15 +144,15 @@ public class WiiUseApi {
* Set wiimote leds status. * Set wiimote leds status.
* *
* @param id * @param id
* the id of the wiimote concerned * the id of the wiimote concerned.
* @param led1 * @param led1
* status of led1: True=ON, False=OFF * status of led1: True=ON, False=OFF.
* @param led2 * @param led2
* status of led2: True=ON, False=OFF * status of led2: True=ON, False=OFF.
* @param led3 * @param led3
* status of led3: True=ON, False=OFF * status of led3: True=ON, False=OFF.
* @param led4 * @param led4
* status of led4: True=ON, False=OFF * status of led4: True=ON, False=OFF.
*/ */
synchronized native void setLeds(int id, boolean led1, boolean led2, synchronized native void setLeds(int id, boolean led1, boolean led2,
boolean led3, boolean led4); boolean led3, boolean led4);
@@ -161,9 +161,9 @@ public class WiiUseApi {
* Set how many degrees an angle must change to generate an event. * Set how many degrees an angle must change to generate an event.
* *
* @param id * @param id
* id of the wiimote concerned * id of the wiimote concerned.
* @param angle * @param angle
* minimum angle detected by an event * minimum angle detected by an event.
*/ */
synchronized native void setOrientThreshold(int id, float angle); synchronized native void setOrientThreshold(int id, float angle);
@@ -171,9 +171,9 @@ public class WiiUseApi {
* Set how much acceleration must change to generate an event. * Set how much acceleration must change to generate an event.
* *
* @param id * @param id
* id of the wiimote concerned * id of the wiimote concerned.
* @param value * @param value
* minimum value detected by an event * minimum value detected by an event.
*/ */
synchronized native void setAccelThreshold(int id, int value); synchronized native void setAccelThreshold(int id, int value);
@@ -181,9 +181,9 @@ public class WiiUseApi {
* Set alpha smoothing parameter for the given id. * Set alpha smoothing parameter for the given id.
* *
* @param id * @param id
* id of the wiimote concerned * id of the wiimote concerned.
* @param value * @param value
* alpha smoothing value * alpha smoothing value.
*/ */
synchronized native void setAlphaSmoothing(int id, float value); synchronized native void setAlphaSmoothing(int id, float value);
@@ -191,7 +191,7 @@ public class WiiUseApi {
* Try to resync with the wiimote by starting a new handshake. * Try to resync with the wiimote by starting a new handshake.
* *
* @param id * @param id
* id of the wiimote concerned * id of the wiimote concerned.
*/ */
synchronized native void reSync(int id); synchronized native void reSync(int id);
@@ -200,7 +200,7 @@ public class WiiUseApi {
* default. * default.
* *
* @param id * @param id
* the id of the wiimote concerned * the id of the wiimote concerned.
*/ */
synchronized native void activateSmoothing(int id); synchronized native void activateSmoothing(int id);
@@ -208,7 +208,7 @@ public class WiiUseApi {
* Make the the accelerometers give raw results. * Make the the accelerometers give raw results.
* *
* @param id * @param id
* the id of the wiimote concerned * the id of the wiimote concerned.
*/ */
synchronized native void deactivateSmoothing(int id); synchronized native void deactivateSmoothing(int id);
@@ -216,7 +216,7 @@ public class WiiUseApi {
* Make the wiimote generate an event each time we poll. Not set by default. * Make the wiimote generate an event each time we poll. Not set by default.
* *
* @param id * @param id
* the id of the wiimote concerned * the id of the wiimote concerned.
*/ */
synchronized native void activateContinuous(int id); synchronized native void activateContinuous(int id);
@@ -224,7 +224,7 @@ public class WiiUseApi {
* Make the wiimote generate an event only when there is one. * Make the wiimote generate an event only when there is one.
* *
* @param id * @param id
* the id of the wiimote concerned * the id of the wiimote concerned.
*/ */
synchronized native void deactivateContinuous(int id); synchronized native void deactivateContinuous(int id);
@@ -308,6 +308,27 @@ public class WiiUseApi {
*/ */
synchronized native void setIrSensitivity(int id, int level); 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);
/** /**
* Check for new Events and Get it. * Check for new Events and Get it.
* *

View File

@@ -54,9 +54,9 @@ public class WiiUseApiManager extends Thread {
* wiimotes. * wiimotes.
* *
* @param nb * @param nb
* try to connect nb wiimotes * try to connect nb wiimotes.
* @param rumble * @param rumble
* make the connected wiimotes rumble * make the connected wiimotes rumble.
* @return an array with connected wiimotes or NULL. * @return an array with connected wiimotes or NULL.
*/ */
public synchronized static Wiimote[] getWiimotes(int nb, boolean rumble) { public synchronized static Wiimote[] getWiimotes(int nb, boolean rumble) {
@@ -277,7 +277,7 @@ public class WiiUseApiManager extends Thread {
* Deactivate continuous for the wiimotes with the given id. * Deactivate continuous for the wiimotes with the given id.
* *
* @param id * @param id
* id of the wiimote * id of the wiimote.
*/ */
public void deactivateContinuous(int id) { public void deactivateContinuous(int id) {
wiiuse.deactivateContinuous(id); wiiuse.deactivateContinuous(id);
@@ -289,13 +289,13 @@ public class WiiUseApiManager extends Thread {
* @param id * @param id
* id of the wiimote * id of the wiimote
* @param l1 * @param l1
* status of led1. True : ON, False : OFF * status of led1. True : ON, False : OFF.
* @param l2 * @param l2
* status of led2. True : ON, False : OFF * status of led2. True : ON, False : OFF.
* @param l3 * @param l3
* status of led3. True : ON, False : OFF * status of led3. True : ON, False : OFF.
* @param l4 * @param l4
* status of led4. True : ON, False : OFF * status of led4. True : ON, False : OFF.
*/ */
public void setLeds(int id, boolean l1, boolean l2, boolean l3, boolean l4) { public void setLeds(int id, boolean l1, boolean l2, boolean l3, boolean l4) {
wiiuse.setLeds(id, l1, l2, l3, l4); wiiuse.setLeds(id, l1, l2, l3, l4);
@@ -303,11 +303,12 @@ public class WiiUseApiManager extends Thread {
/** /**
* Set the orientation threshold for the given id. * Set the orientation threshold for the given id.
* (minimum angle between two events)
* *
* @param id * @param id
* id of the wiimote * id of the wiimote.
* @param th * @param th
* threshold in degrees * threshold in degrees.
*/ */
public void setOrientationThreshold(int id, float th) { public void setOrientationThreshold(int id, float th) {
wiiuse.setOrientThreshold(id, th); wiiuse.setOrientThreshold(id, th);
@@ -315,11 +316,12 @@ public class WiiUseApiManager extends Thread {
/** /**
* Set the acceleration threshold for the given id. * Set the acceleration threshold for the given id.
* (minimum angle between two events)
* *
* @param id * @param id
* id of the wiimote * id of the wiimote.
* @param th * @param th
* threshold * threshold.
*/ */
public void setAccelerationThreshold(int id, int th) { public void setAccelerationThreshold(int id, int th) {
wiiuse.setAccelThreshold(id, th); wiiuse.setAccelThreshold(id, th);
@@ -329,9 +331,9 @@ public class WiiUseApiManager extends Thread {
* Set alpha smoothing for the given id. * Set alpha smoothing for the given id.
* *
* @param id * @param id
* id of the wiimote * id of the wiimote.
* @param th * @param th
* threshold * threshold.
*/ */
public void setAlphaSmoothing(int id, float th) { public void setAlphaSmoothing(int id, float th) {
wiiuse.setAlphaSmoothing(id, th); wiiuse.setAlphaSmoothing(id, th);
@@ -341,7 +343,7 @@ public class WiiUseApiManager extends Thread {
* Try to resync with the wiimote by starting a new handshake. * Try to resync with the wiimote by starting a new handshake.
* *
* @param id * @param id
* id of the wiimote * id of the wiimote.
*/ */
public void reSync(int id) { public void reSync(int id) {
wiiuse.reSync(id); wiiuse.reSync(id);
@@ -351,7 +353,7 @@ public class WiiUseApiManager extends Thread {
* Set screen aspect ratio to 4/3 for the given id. * Set screen aspect ratio to 4/3 for the given id.
* *
* @param id * @param id
* id of the wiimote * id of the wiimote.
*/ */
public void setScreenAspectRatio43(int id) { public void setScreenAspectRatio43(int id) {
wiiuse.setScreenRatio43(id); wiiuse.setScreenRatio43(id);
@@ -361,7 +363,7 @@ public class WiiUseApiManager extends Thread {
* Set screen aspect ratio to 16/9 for the given id. * Set screen aspect ratio to 16/9 for the given id.
* *
* @param id * @param id
* id of the wiimote * id of the wiimote.
*/ */
public void setScreenAspectRatio169(int id) { public void setScreenAspectRatio169(int id) {
wiiuse.setScreenRatio169(id); wiiuse.setScreenRatio169(id);
@@ -371,7 +373,7 @@ public class WiiUseApiManager extends Thread {
* Set the sensor bar to be above the screen. * Set the sensor bar to be above the screen.
* *
* @param id * @param id
* id of the wiimote * id of the wiimote.
*/ */
public void setSensorBarAboveScreen(int id) { public void setSensorBarAboveScreen(int id) {
wiiuse.setSensorBarAboveScreen(id); wiiuse.setSensorBarAboveScreen(id);
@@ -381,7 +383,7 @@ public class WiiUseApiManager extends Thread {
* Set the sensor bar to be below the screen. * Set the sensor bar to be below the screen.
* *
* @param id * @param id
* id of the wiimote * id of the wiimote.
*/ */
public void setSensorBarBelowScreen(int id) { public void setSensorBarBelowScreen(int id) {
wiiuse.setSensorBarBelowScreen(id); wiiuse.setSensorBarBelowScreen(id);
@@ -393,11 +395,11 @@ public class WiiUseApiManager extends Thread {
* come in the IREvent. * come in the IREvent.
* *
* @param id * @param id
* id of the wiimote * id of the wiimote.
* @param x * @param x
* x resolution * x resolution.
* @param y * @param y
* y resolution * y resolution.
*/ */
public void setVirtualResolution(int id, int x, int y) { public void setVirtualResolution(int id, int x, int y) {
wiiuse.setVirtualScreenResolution(id, x, y); wiiuse.setVirtualScreenResolution(id, x, y);
@@ -407,7 +409,7 @@ public class WiiUseApiManager extends Thread {
* Get Status for the wiimote for the given id. * Get Status for the wiimote for the given id.
* *
* @param id * @param id
* id of the wiimote * id of the wiimote.
*/ */
public void getStatus(int id) { public void getStatus(int id) {
wiiuse.getStatus(id); wiiuse.getStatus(id);
@@ -441,6 +443,32 @@ public class WiiUseApiManager extends Thread {
public void setIrSensitivity(int id, int level) { public void setIrSensitivity(int id, int level) {
wiiuse.setIrSensitivity(id, 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.
*/
public 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.
*/
public void setNunchukAccelerationThreshold(int id, int th){
wiiuse.setNunchukAccelerationThreshold(id, th);
}
@Override @Override
public void run() { public void run() {

View File

@@ -172,7 +172,8 @@ public class Wiimote implements WiiUseApiListener {
} }
/** /**
* Set the acceleration threshold . * Set the acceleration threshold(minimum angle between two degrees with
* accelerometer).
* *
* @param th * @param th
* threshold * threshold
@@ -230,6 +231,28 @@ public class Wiimote implements WiiUseApiListener {
public void setVirtualResolution(int x, int y) { public void setVirtualResolution(int x, int y) {
manager.setVirtualResolution(id, x, 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. * Try to resync the wiimote by starting a new handshake.
@@ -336,6 +359,9 @@ public class Wiimote implements WiiUseApiListener {
if (evt.isThereMotionSensingEvent()) { if (evt.isThereMotionSensingEvent()) {
listener.onMotionSensingEvent(evt.getMotionSensingEvent()); listener.onMotionSensingEvent(evt.getMotionSensingEvent());
} }
if (evt.isThereExpansionEvent()){
listener.onExpansionEvent(evt.getExpansionEvent());
}
} }
} }

View File

@@ -23,6 +23,7 @@ import java.awt.event.InputEvent;
import wiiusej.WiiUseApiManager; import wiiusej.WiiUseApiManager;
import wiiusej.Wiimote; import wiiusej.Wiimote;
import wiiusej.values.IRSource; import wiiusej.values.IRSource;
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
import wiiusej.wiiusejevents.physicalevents.IREvent; import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent; import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
@@ -325,6 +326,10 @@ public class Tests implements WiimoteListener {
/* display motion sensing */ /* display motion sensing */
System.out.println(e); System.out.println(e);
} }
public void onExpansionEvent(ExpansionEvent e) {
System.out.println(e);
}
public void onStatusEvent(StatusEvent e) { public void onStatusEvent(StatusEvent e) {
// Display status variables // Display status variables

View File

@@ -28,6 +28,7 @@ import wiiusej.utils.ButtonsEventPanel;
import wiiusej.utils.GForcePanel; import wiiusej.utils.GForcePanel;
import wiiusej.utils.IRPanel; import wiiusej.utils.IRPanel;
import wiiusej.utils.OrientationPanel; import wiiusej.utils.OrientationPanel;
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
import wiiusej.wiiusejevents.physicalevents.IREvent; import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent; import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
@@ -124,6 +125,10 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements WiimoteListene
statusMotionRequested = false; statusMotionRequested = false;
} }
} }
public void onExpansionEvent(ExpansionEvent e) {
//nothing yet
}
public void onStatusEvent(StatusEvent arg0) { public void onStatusEvent(StatusEvent arg0) {
messageText.setText("Status received !"); messageText.setText("Status received !");

View File

@@ -26,6 +26,7 @@ import java.awt.geom.AffineTransform;
import java.util.ArrayList; import java.util.ArrayList;
import wiiusej.values.RawAcceleration; import wiiusej.values.RawAcceleration;
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
import wiiusej.wiiusejevents.physicalevents.IREvent; import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent; import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
@@ -36,160 +37,167 @@ import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
/** /**
* This panel is used to watch raw acceleration values from a MotionSensingEvent. * This panel is used to watch raw acceleration values from a
* @author guiguito * MotionSensingEvent.
*
* @author guiguito
*/ */
public class AccelerationPanel extends javax.swing.JPanel implements WiimoteListener { public class AccelerationPanel extends javax.swing.JPanel implements
WiimoteListener {
private Image mImage;//image for double buffering private Image mImage;// image for double buffering
private Color xColor = Color.RED; private Color xColor = Color.RED;
private Color yColor = Color.GREEN; private Color yColor = Color.GREEN;
private Color zColor = Color.BLUE; private Color zColor = Color.BLUE;
private Color backgroundColor = Color.WHITE; private Color backgroundColor = Color.WHITE;
private Color lineColor = Color.BLACK; private Color lineColor = Color.BLACK;
private ArrayList<RawAcceleration> values = new ArrayList<RawAcceleration>(); private ArrayList<RawAcceleration> values = new ArrayList<RawAcceleration>();
/** Creates new form AccelerationPanel */ /** Creates new form AccelerationPanel */
public AccelerationPanel() { public AccelerationPanel() {
initComponents(); initComponents();
} }
@Override @Override
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
super.paintComponent(g); super.paintComponent(g);
Dimension d = getSize(); Dimension d = getSize();
checkOffScreenImage(); checkOffScreenImage();
Graphics offG = mImage.getGraphics(); Graphics offG = mImage.getGraphics();
offG.setColor(backgroundColor); offG.setColor(backgroundColor);
offG.fillRect(0, 0, d.width, d.height); offG.fillRect(0, 0, d.width, d.height);
Graphics2D g2 = (Graphics2D) mImage.getGraphics(); Graphics2D g2 = (Graphics2D) mImage.getGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
//draw medium line // draw medium line
int yLine = getHeight() - 25; int yLine = getHeight() - 25;
g2.setPaint(lineColor); g2.setPaint(lineColor);
g2.drawLine(0, yLine, getWidth(), yLine); g2.drawLine(0, yLine, getWidth(), yLine);
RawAcceleration[] valuesArray = values.toArray(new RawAcceleration[0]); 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 double unit = yLine / 255.0;
g2.setPaint(xColor); int previousX = 0;
g2.drawLine(5, getHeight() - 10, 25, getHeight() - 10); int previousY = 0;
g2.setPaint(yColor); int previousZ = 0;
g2.drawLine(60, getHeight() - 10, 80, getHeight() - 10); // draw curves
g2.setPaint(zColor); for (int i = 0; i < valuesArray.length && i < getWidth(); i++) {
g2.drawLine(120, getHeight() - 10, 140, getHeight() - 10); 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;
}
g2.setPaint(lineColor); // draw legend
g2.drawString("X", 30, getHeight() - 5); g2.setPaint(xColor);
g2.drawString("Y", 85, getHeight() - 5); g2.drawLine(5, getHeight() - 10, 25, getHeight() - 10);
g2.drawString("Z", 145, getHeight() - 5); g2.setPaint(yColor);
g2.drawString("0", 2, yLine - 5); g2.drawLine(60, getHeight() - 10, 80, getHeight() - 10);
g2.drawString("255", 2, 15); g2.setPaint(zColor);
//put offscreen image on the screen g2.drawLine(120, getHeight() - 10, 140, getHeight() - 10);
g.drawImage(mImage, 0, 0, null);
}
/** g2.setPaint(lineColor);
* check if the mImage variable has been initialized. If it's not the case it initializes it g2.drawString("X", 30, getHeight() - 5);
* with the dimensions of the panel. mImage is for double buffering. g2.drawString("Y", 85, getHeight() - 5);
*/ g2.drawString("Z", 145, getHeight() - 5);
private void checkOffScreenImage() { g2.drawString("0", 2, yLine - 5);
Dimension d = getSize(); g2.drawString("255", 2, 15);
if (mImage == null || mImage.getWidth(null) != d.width || mImage.getHeight(null) != d.height) { // put offscreen image on the screen
mImage = createImage(d.width, d.height); g.drawImage(mImage, 0, 0, null);
} }
}
public void onButtonsEvent(WiimoteButtonsEvent arg0) { /**
//nothing * 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 onIrEvent(IREvent arg0) { public void onButtonsEvent(WiimoteButtonsEvent arg0) {
//nothing // nothing
} }
public void onMotionSensingEvent(MotionSensingEvent arg0) { public void onIrEvent(IREvent arg0) {
if (values.size() >= getWidth()) { // nothing
//if there are as many values as pixels in the width }
//clear points
values.clear();
}
values.add(arg0.getRawAcceleration());
repaint();
}
public void onStatusEvent(StatusEvent arg0) { public void onMotionSensingEvent(MotionSensingEvent arg0) {
//nothing if (values.size() >= getWidth()) {
} // if there are as many values as pixels in the width
// clear points
values.clear();
}
values.add(arg0.getRawAcceleration());
repaint();
}
public void onExpansionEvent(ExpansionEvent e) {
// nothing
}
public void onStatusEvent(StatusEvent arg0) {
// nothing
}
public void onDisconnectionEvent(DisconnectionEvent arg0) {
// Clear points.
values.clear();
repaint();
}
public void onDisconnectionEvent(DisconnectionEvent arg0) {
//Clear points.
values.clear();
repaint();
}
public void onNunchukInsertedEvent(NunchukInsertedEvent e) { public void onNunchukInsertedEvent(NunchukInsertedEvent e) {
// TODO Auto-generated method stub // nothing
} }
public void onNunchukRemovedEvent(NunchukRemovedEvent e) { public void onNunchukRemovedEvent(NunchukRemovedEvent e) {
// TODO Auto-generated method stub // nothing
} }
/** This method is called from within the constructor to /**
* initialize the form. * This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is * WARNING: Do NOT modify this code. The content of this method is always
* always regenerated by the Form Editor. * regenerated by the Form Editor.
*/ */
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated
private void initComponents() { // Code">//GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout); this.setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(layout.createParallelGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
.addGap(0, 400, Short.MAX_VALUE) Short.MAX_VALUE));
); layout.setVerticalGroup(layout.createParallelGroup(
layout.setVerticalGroup( javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) Short.MAX_VALUE));
.addGap(0, 300, Short.MAX_VALUE) }// </editor-fold>//GEN-END:initComponents
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
} }

View File

@@ -27,6 +27,7 @@ import java.awt.Toolkit;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import wiiusej.wiiusejevents.physicalevents.ButtonsEvent; import wiiusej.wiiusejevents.physicalevents.ButtonsEvent;
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
import wiiusej.wiiusejevents.physicalevents.IREvent; import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent; import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
@@ -37,275 +38,290 @@ import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
/** /**
* This panel is used to see what buttons are pressed. * This panel is used to see what buttons are pressed. It displays the result of
* It displays the result of last ButtonsEvent. * last ButtonsEvent.
* @author guiguito *
* @author guiguito
*/ */
public class ButtonsEventPanel extends javax.swing.JPanel implements WiimoteListener { public class ButtonsEventPanel extends javax.swing.JPanel implements
WiimoteListener {
private Image mImage;//image for double buffering private Image mImage;// image for double buffering
private Image wiimoteImage;//image for double buffering private Image wiimoteImage;// image for double buffering
private WiimoteButtonsEvent buttons; private WiimoteButtonsEvent buttons;
private Color pressedColor = Color.RED; private Color pressedColor = Color.RED;
private Color heldColor = Color.ORANGE; private Color heldColor = Color.ORANGE;
private Color releasedColor = Color.YELLOW; private Color releasedColor = Color.YELLOW;
private Shape shape; private Shape shape;
/** /**
* Default constructor. * Default constructor. Red : button just pressed. Orange : button held.
* Red : button just pressed. * Yellow : button just released.
* Orange : button held. */
* Yellow : button just released. public ButtonsEventPanel() {
*/ Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
public ButtonsEventPanel() { java.net.URL url = ButtonsEventPanel.class
Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit(); .getResource("/img/wiimote.png");
java.net.URL url = ButtonsEventPanel.class.getResource("/img/wiimote.png"); wiimoteImage = toolkit.createImage(url);
wiimoteImage = toolkit.createImage(url); shape = new java.awt.geom.Ellipse2D.Double(0, 0, 13, 13);
shape = new java.awt.geom.Ellipse2D.Double(0, 0, 13, 13); initComponents();
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) { * Constructor used to set colors and shape used.
super.paintComponent(g); *
Dimension d = getSize(); * @param pressColor
checkOffScreenImage(); * color of a button just pressed.
Graphics offG = mImage.getGraphics(); * @param hColor
//offG.setColor(backgroundColor); * color of a button held.
offG.fillRect(0, 0, d.width, d.height); * @param relColor
Graphics2D g2 = (Graphics2D) mImage.getGraphics(); * color of a button just released.
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); * @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();
}
//draw buttons pushed @Override
g2.drawImage(wiimoteImage, 0, 0, this); public void paintComponent(Graphics g) {
g2.setTransform(new AffineTransform()); 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);
if (buttons != null) { // draw buttons pushed
/* button ONE */ g2.drawImage(wiimoteImage, 0, 0, this);
if (buttons.isButtonOneJustPressed()) { g2.setTransform(new AffineTransform());
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 != null) {
if (buttons.isButtonAJustPressed()) { /* button ONE */
drawFunction(g2,pressedColor,53,150); if (buttons.isButtonOneJustPressed()) {
} drawFunction(g2, pressedColor, 53, 353);
if (buttons.isButtonAHeld()) { }
drawFunction(g2,heldColor,53,150); if (buttons.isButtonOneHeld()) {
} drawFunction(g2, heldColor, 53, 353);
if (buttons.isButtonAJustReleased()) { }
drawFunction(g2,releasedColor,53,150); if (buttons.isButtonOneJustReleased()) {
} drawFunction(g2, releasedColor, 53, 353);
}
/* button B */ /* button TWO */
if (buttons.isButtonBJustPressed()) { if (buttons.isButtonTwoJustPressed()) {
drawFunction(g2,pressedColor,16,149); drawFunction(g2, pressedColor, 53, 395);
} }
if (buttons.isButtonBHeld()) { if (buttons.isButtonTwoHeld()) {
drawFunction(g2,heldColor,16,149); drawFunction(g2, heldColor, 53, 395);
} }
if (buttons.isButtonBJustReleased()) { if (buttons.isButtonTwoJustReleased()) {
drawFunction(g2,releasedColor,16,149); drawFunction(g2, releasedColor, 53, 395);
} }
/* button LEFT */ /* button A */
if (buttons.isButtonLeftJustPressed()) { if (buttons.isButtonAJustPressed()) {
drawFunction(g2,pressedColor,33,77); drawFunction(g2, pressedColor, 53, 150);
} }
if (buttons.isButtonLeftHeld()) { if (buttons.isButtonAHeld()) {
drawFunction(g2,heldColor,33,77); drawFunction(g2, heldColor, 53, 150);
} }
if (buttons.isButtonLeftJustReleased()) { if (buttons.isButtonAJustReleased()) {
drawFunction(g2,releasedColor,33,77); drawFunction(g2, releasedColor, 53, 150);
} }
/* button RIGHT */ /* button B */
if (buttons.isButtonRightJustPressed()) { if (buttons.isButtonBJustPressed()) {
drawFunction(g2,pressedColor,73,77); drawFunction(g2, pressedColor, 16, 149);
} }
if (buttons.isButtonRightHeld()) { if (buttons.isButtonBHeld()) {
drawFunction(g2,heldColor,73,77); drawFunction(g2, heldColor, 16, 149);
} }
if (buttons.isButtonRightJustReleased()) { if (buttons.isButtonBJustReleased()) {
drawFunction(g2,releasedColor,73,77); drawFunction(g2, releasedColor, 16, 149);
} }
/* 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 */ /* button LEFT */
if (buttons.isButtonDownJustPressed()) { if (buttons.isButtonLeftJustPressed()) {
drawFunction(g2,pressedColor,54,97); drawFunction(g2, pressedColor, 33, 77);
} }
if (buttons.isButtonDownHeld()) { if (buttons.isButtonLeftHeld()) {
drawFunction(g2,heldColor,54,97); drawFunction(g2, heldColor, 33, 77);
} }
if (buttons.isButtonDownJustReleased()) { if (buttons.isButtonLeftJustReleased()) {
drawFunction(g2,releasedColor,54,97); drawFunction(g2, releasedColor, 33, 77);
} }
/* button MINUS */ /* button RIGHT */
if (buttons.isButtonMinusJustPressed()) { if (buttons.isButtonRightJustPressed()) {
drawFunction(g2,pressedColor,20,230); drawFunction(g2, pressedColor, 73, 77);
} }
if (buttons.isButtonMinusHeld()) { if (buttons.isButtonRightHeld()) {
drawFunction(g2,heldColor,20,230); drawFunction(g2, heldColor, 73, 77);
} }
if (buttons.isButtonMinusJustReleased()) { if (buttons.isButtonRightJustReleased()) {
drawFunction(g2,releasedColor,20,230); drawFunction(g2, releasedColor, 73, 77);
} }
/* button PLUS */ /* button UP */
if (buttons.isButtonPlusJustPressed()) { if (buttons.isButtonUpJustPressed()) {
drawFunction(g2,pressedColor,86,230); drawFunction(g2, pressedColor, 54, 60);
} }
if (buttons.isButtonPlusHeld()) { if (buttons.isButtonUpHeld()) {
drawFunction(g2,heldColor,86,230); drawFunction(g2, heldColor, 54, 60);
} }
if (buttons.isButtonPlusJustReleased()) { if (buttons.isButtonUpJustReleased()) {
drawFunction(g2,releasedColor,86,230); drawFunction(g2, releasedColor, 54, 60);
} }
/* button HOME */ /* button DOWN */
if (buttons.isButtonHomeJustPressed()) { if (buttons.isButtonDownJustPressed()) {
drawFunction(g2,pressedColor,53,230); drawFunction(g2, pressedColor, 54, 97);
} }
if (buttons.isButtonHomeHeld()) { if (buttons.isButtonDownHeld()) {
drawFunction(g2,heldColor,53,230); drawFunction(g2, heldColor, 54, 97);
} }
if (buttons.isButtonHomeJustReleased()) { if (buttons.isButtonDownJustReleased()) {
drawFunction(g2,releasedColor,53,230); drawFunction(g2, releasedColor, 54, 97);
} }
buttons = null; /* 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);
}
//put offscreen image on the screen /* button HOME */
g.drawImage(mImage, 0, 0, null); 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;
* 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());
}
/** // put offscreen image on the screen
* check if the mImage variable has been initialized. If it's not the case it initializes it g.drawImage(mImage, 0, 0, null);
* 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)); * Function used to factorize code.
buttons = arg0; *
repaint(); * @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());
}
public void onIrEvent(IREvent arg0) { /**
//nothing * 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 onMotionSensingEvent(MotionSensingEvent arg0) { public void onButtonsEvent(WiimoteButtonsEvent arg0) {
//nothing setSize(wiimoteImage.getWidth(this), wiimoteImage.getHeight(this));
} buttons = arg0;
repaint();
}
public void onStatusEvent(StatusEvent arg0) { public void onIrEvent(IREvent arg0) {
//nothing // nothing
} }
public void onDisconnectionEvent(DisconnectionEvent arg0) { public void onMotionSensingEvent(MotionSensingEvent arg0) {
buttons = null; // nothing
repaint(); }
}
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) { public void onNunchukInsertedEvent(NunchukInsertedEvent e) {
// TODO Auto-generated method stub // nothing
} }
public void onNunchukRemovedEvent(NunchukRemovedEvent e) { public void onNunchukRemovedEvent(NunchukRemovedEvent e) {
// TODO Auto-generated method stub // nothing
} }
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); /**
this.setLayout(layout); * This method is called from within the constructor to initialize the form.
layout.setHorizontalGroup( * WARNING: Do NOT modify this code. The content of this method is always
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) * regenerated by the Form Editor.
.addGap(0, 400, Short.MAX_VALUE) */
); // <editor-fold defaultstate="collapsed" desc="Generated
layout.setVerticalGroup( // Code">//GEN-BEGIN:initComponents
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) private void initComponents() {
.addGap(0, 300, Short.MAX_VALUE)
); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
}// </editor-fold>//GEN-END:initComponents this.setLayout(layout);
// Variables declaration - do not modify//GEN-BEGIN:variables layout.setHorizontalGroup(layout.createParallelGroup(
// End of variables declaration//GEN-END:variables 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));
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
} }

View File

@@ -26,6 +26,7 @@ import java.awt.geom.AffineTransform;
import java.util.ArrayList; import java.util.ArrayList;
import wiiusej.values.GForce; import wiiusej.values.GForce;
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
import wiiusej.wiiusejevents.physicalevents.IREvent; import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent; import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
@@ -37,178 +38,190 @@ import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
/** /**
* This panel is used to watch gravity force values from a MotionSensingEvent. * This panel is used to watch gravity force values from a MotionSensingEvent.
* @author guiguito *
* @author guiguito
*/ */
public class GForcePanel extends javax.swing.JPanel implements WiimoteListener { public class GForcePanel extends javax.swing.JPanel implements WiimoteListener {
private Image mImage;//image for double buffering private Image mImage;// image for double buffering
private Color xColor = Color.RED; private Color xColor = Color.RED;
private Color yColor = Color.GREEN; private Color yColor = Color.GREEN;
private Color zColor = Color.BLUE; private Color zColor = Color.BLUE;
private Color backgroundColor = Color.WHITE; private Color backgroundColor = Color.WHITE;
private Color lineColor = Color.BLACK; private Color lineColor = Color.BLACK;
private ArrayList<GForce> values = new ArrayList<GForce>(); private ArrayList<GForce> values = new ArrayList<GForce>();
/** /**
* Default constructor of the AccelerationPanel. * Default constructor of the AccelerationPanel.
*/ */
public GForcePanel() { public GForcePanel() {
initComponents(); 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) { * Constructor used to choose the colors used by the AccelerationPanel.
super.paintComponent(g); *
Dimension d = getSize(); * @param bgColor
checkOffScreenImage(); * background color.
Graphics offG = mImage.getGraphics(); * @param xxColor
offG.setColor(backgroundColor); * color of the acceleration on X axis.
offG.fillRect(0, 0, d.width, d.height); * @param yyColor
Graphics2D g2 = (Graphics2D) mImage.getGraphics(); * color of the acceleration on Y axis.
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); * @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();
}
//draw medium line @Override
double yMiddleFloat = getHeight() / 2.0; public void paintComponent(Graphics g) {
int yMiddle = (int) Math.round(yMiddleFloat); 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.setPaint(lineColor); // draw medium line
g2.drawLine(0, yMiddle, getWidth(), yMiddle); double yMiddleFloat = getHeight() / 2.0;
int yMiddle = (int) Math.round(yMiddleFloat);
GForce[] valuesArray = values.toArray(new GForce[0]); g2.setPaint(lineColor);
double unit = yMiddleFloat / 5.0; g2.drawLine(0, yMiddle, getWidth(), yMiddle);
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 GForce[] valuesArray = values.toArray(new GForce[0]);
g2.setPaint(xColor); double unit = yMiddleFloat / 5.0;
g2.drawLine(5, getHeight() - 10, 25, getHeight() - 10); int previousX = 0;
g2.setPaint(yColor); int previousY = 0;
g2.drawLine(60, getHeight() - 10, 80, getHeight() - 10); int previousZ = 0;
g2.setPaint(zColor); // draw curves
g2.drawLine(120, getHeight() - 10, 140, getHeight() - 10); 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;
}
g2.setPaint(lineColor); // draw legend
g2.drawString("X", 30, getHeight() - 5); g2.setPaint(xColor);
g2.drawString("Y", 85, getHeight() - 5); g2.drawLine(5, getHeight() - 10, 25, getHeight() - 10);
g2.drawString("Z", 145, getHeight() - 5); g2.setPaint(yColor);
g2.drawString("0", 2, yMiddle-5); g2.drawLine(60, getHeight() - 10, 80, getHeight() - 10);
g2.drawString("5", 2, 10); g2.setPaint(zColor);
g2.drawString("-5", 2, getHeight()-15); g2.drawLine(120, getHeight() - 10, 140, getHeight() - 10);
//put offscreen image on the screen
g.drawImage(mImage, 0, 0, null);
}
/** g2.setPaint(lineColor);
* check if the mImage variable has been initialized. If it's not the case it initializes it g2.drawString("X", 30, getHeight() - 5);
* with the dimensions of the panel. mImage is for double buffering. g2.drawString("Y", 85, getHeight() - 5);
*/ g2.drawString("Z", 145, getHeight() - 5);
private void checkOffScreenImage() { g2.drawString("0", 2, yMiddle - 5);
Dimension d = getSize(); g2.drawString("5", 2, 10);
if (mImage == null || mImage.getWidth(null) != d.width || mImage.getHeight(null) != d.height) { g2.drawString("-5", 2, getHeight() - 15);
mImage = createImage(d.width, d.height); // put offscreen image on the screen
} g.drawImage(mImage, 0, 0, null);
} }
public void onButtonsEvent(WiimoteButtonsEvent arg0) { /**
//nothing * 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 onIrEvent(IREvent arg0) { public void onButtonsEvent(WiimoteButtonsEvent arg0) {
//nothing // nothing
} }
public void onMotionSensingEvent(MotionSensingEvent arg0) { public void onIrEvent(IREvent arg0) {
if (values.size() >= getWidth()) { // nothing
//if there are as many values as pixels in the width }
//clear points
values.clear();
}
values.add(arg0.getGforce());
repaint();
}
public void onStatusEvent(StatusEvent arg0) { public void onMotionSensingEvent(MotionSensingEvent arg0) {
//nothing if (values.size() >= getWidth()) {
} // if there are as many values as pixels in the width
// clear points
values.clear();
}
values.add(arg0.getGforce());
repaint();
}
public void onDisconnectionEvent(DisconnectionEvent arg0) { public void onExpansionEvent(ExpansionEvent e) {
//Clear points. // nothing
values.clear(); }
repaint();
} public void onStatusEvent(StatusEvent arg0) {
// nothing
}
public void onDisconnectionEvent(DisconnectionEvent arg0) {
// Clear points.
values.clear();
repaint();
}
public void onNunchukInsertedEvent(NunchukInsertedEvent e) { public void onNunchukInsertedEvent(NunchukInsertedEvent e) {
// TODO Auto-generated method stub // nothing
} }
public void onNunchukRemovedEvent(NunchukRemovedEvent e) { public void onNunchukRemovedEvent(NunchukRemovedEvent e) {
// TODO Auto-generated method stub // nothing
} }
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); /**
this.setLayout(layout); * This method is called from within the constructor to initialize the form.
layout.setHorizontalGroup( * WARNING: Do NOT modify this code. The content of this method is always
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) * regenerated by the Form Editor.
.addGap(0, 400, Short.MAX_VALUE) */
); // <editor-fold defaultstate="collapsed" desc="Generated
layout.setVerticalGroup( // Code">//GEN-BEGIN:initComponents
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) private void initComponents() {
.addGap(0, 300, Short.MAX_VALUE)
); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
}// </editor-fold>//GEN-END:initComponents this.setLayout(layout);
// Variables declaration - do not modify//GEN-BEGIN:variables layout.setHorizontalGroup(layout.createParallelGroup(
// End of variables declaration//GEN-END:variables 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));
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
} }

View File

@@ -25,6 +25,7 @@ import java.awt.RenderingHints;
import java.awt.Shape; import java.awt.Shape;
import java.awt.geom.AffineTransform; import java.awt.geom.AffineTransform;
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
import wiiusej.wiiusejevents.physicalevents.IREvent; import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent; import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
@@ -157,6 +158,10 @@ public class IRPanel extends javax.swing.JPanel implements WiimoteListener {
public void onMotionSensingEvent(MotionSensingEvent arg0) { public void onMotionSensingEvent(MotionSensingEvent arg0) {
//nothing //nothing
} }
public void onExpansionEvent(ExpansionEvent e) {
// nothing
}
public void onStatusEvent(StatusEvent arg0) { public void onStatusEvent(StatusEvent arg0) {
//nothing //nothing
@@ -173,13 +178,11 @@ public class IRPanel extends javax.swing.JPanel implements WiimoteListener {
} }
public void onNunchukInsertedEvent(NunchukInsertedEvent e) { public void onNunchukInsertedEvent(NunchukInsertedEvent e) {
// TODO Auto-generated method stub // nothing
} }
public void onNunchukRemovedEvent(NunchukRemovedEvent e) { public void onNunchukRemovedEvent(NunchukRemovedEvent e) {
// TODO Auto-generated method stub // nothing
} }
/** This method is called from within the constructor to /** This method is called from within the constructor to

View File

@@ -26,6 +26,7 @@ import java.awt.geom.AffineTransform;
import java.util.ArrayList; import java.util.ArrayList;
import wiiusej.values.Orientation; import wiiusej.values.Orientation;
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
import wiiusej.wiiusejevents.physicalevents.IREvent; import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent; import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
@@ -37,182 +38,192 @@ import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
/** /**
* This panel is used to watch orientation values from a MotionSensingEvent. * This panel is used to watch orientation values from a MotionSensingEvent.
* @author guiguito *
* @author guiguito
*/ */
public class OrientationPanel extends javax.swing.JPanel implements WiimoteListener { public class OrientationPanel extends javax.swing.JPanel implements
WiimoteListener {
private Image mImage;//image for double buffering private Image mImage;// image for double buffering
private Color rollColor = Color.RED; private Color rollColor = Color.RED;
private Color pitchColor = Color.GREEN; private Color pitchColor = Color.GREEN;
private Color yawColor = Color.BLUE; private Color yawColor = Color.BLUE;
private Color backgroundColor = Color.WHITE; private Color backgroundColor = Color.WHITE;
private Color lineColor = Color.BLACK; private Color lineColor = Color.BLACK;
private ArrayList<Orientation> values = new ArrayList<Orientation>(); private ArrayList<Orientation> values = new ArrayList<Orientation>();
/** /**
* Default constructor. * Default constructor. Background color : White. Roll color : Red. Pitch
* Background color : White. * color : Green. Yaw color : Blue.
* Roll color : Red. */
* Pitch color : Green. public OrientationPanel() {
* Yaw color : Blue. initComponents();
*/ }
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) { * Constructor used to choose the colors used by the OrientationPanel.
super.paintComponent(g); *
Dimension d = getSize(); * @param bgColor
checkOffScreenImage(); * background color.
Graphics offG = mImage.getGraphics(); * @param rColor
offG.setColor(backgroundColor); * roll color.
offG.fillRect(0, 0, d.width, d.height); * @param pColor
Graphics2D g2 = (Graphics2D) mImage.getGraphics(); * pitch color.
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); * @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();
}
//draw medium line @Override
double yMiddleFloat = getHeight() / 2.0; public void paintComponent(Graphics g) {
int yMiddle = (int) Math.round(yMiddleFloat); 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.setPaint(lineColor); // draw medium line
g2.drawLine(0, yMiddle, getWidth(), yMiddle); double yMiddleFloat = getHeight() / 2.0;
int yMiddle = (int) Math.round(yMiddleFloat);
Orientation[] valuesArray = values.toArray(new Orientation[0]); g2.setPaint(lineColor);
double unit = yMiddleFloat / 180.0; g2.drawLine(0, yMiddle, getWidth(), yMiddle);
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);
}
/** Orientation[] valuesArray = values.toArray(new Orientation[0]);
* check if the mImage variable has been initialized. If it's not the case it initializes it double unit = yMiddleFloat / 180.0;
* with the dimensions of the panel. mImage is for double buffering. int previousRoll = 0;
*/ int previousPitch = 0;
private void checkOffScreenImage() { int previousYaw = 0;
Dimension d = getSize(); // draw curves
if (mImage == null || mImage.getWidth(null) != d.width || mImage.getHeight(null) != d.height) { for (int i = 0; i < valuesArray.length && i < getWidth(); i++) {
mImage = createImage(d.width, d.height); 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;
}
public void onButtonsEvent(WiimoteButtonsEvent arg0) { // draw legend
//nothing 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);
public void onIrEvent(IREvent arg0) { g2.setPaint(lineColor);
//nothing 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);
}
public void onMotionSensingEvent(MotionSensingEvent arg0) { /**
if (values.size() >= getWidth()) { * check if the mImage variable has been initialized. If it's not the case
//if there are as many values as pixels in the width * it initializes it with the dimensions of the panel. mImage is for double
//clear points * buffering.
values.clear(); */
} private void checkOffScreenImage() {
values.add(arg0.getOrientation()); Dimension d = getSize();
repaint(); if (mImage == null || mImage.getWidth(null) != d.width
} || mImage.getHeight(null) != d.height) {
mImage = createImage(d.width, d.height);
}
}
public void onStatusEvent(StatusEvent arg0) { public void onButtonsEvent(WiimoteButtonsEvent arg0) {
//nothing // nothing
} }
public void onIrEvent(IREvent arg0) {
// nothing
}
public void onMotionSensingEvent(MotionSensingEvent arg0) {
if (values.size() >= getWidth()) {
// if there are as many values as pixels in the width
// clear points
values.clear();
}
values.add(arg0.getOrientation());
repaint();
}
public void onExpansionEvent(ExpansionEvent e) {
// nothing
}
public void onStatusEvent(StatusEvent arg0) {
// nothing
}
public void onDisconnectionEvent(DisconnectionEvent arg0) {
// Clear points.
values.clear();
repaint();
}
public void onDisconnectionEvent(DisconnectionEvent arg0) {
//Clear points.
values.clear();
repaint();
}
public void onNunchukInsertedEvent(NunchukInsertedEvent e) { public void onNunchukInsertedEvent(NunchukInsertedEvent e) {
// TODO Auto-generated method stub // nothing
} }
public void onNunchukRemovedEvent(NunchukRemovedEvent e) { public void onNunchukRemovedEvent(NunchukRemovedEvent e) {
// TODO Auto-generated method stub // nothing
} }
/** This method is called from within the constructor to /**
* initialize the form. * This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is * WARNING: Do NOT modify this code. The content of this method is always
* always regenerated by the Form Editor. * regenerated by the Form Editor.
*/ */
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated
private void initComponents() { // Code">//GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout); this.setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(layout.createParallelGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
.addGap(0, 400, Short.MAX_VALUE) Short.MAX_VALUE));
); layout.setVerticalGroup(layout.createParallelGroup(
layout.setVerticalGroup( javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 300,
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) Short.MAX_VALUE));
.addGap(0, 300, Short.MAX_VALUE) }// </editor-fold>//GEN-END:initComponents
); // Variables declaration - do not modify//GEN-BEGIN:variables
}// </editor-fold>//GEN-END:initComponents // End of variables declaration//GEN-END:variables
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
} }

View File

@@ -124,7 +124,6 @@ public class JoystickEvent extends GenericEvent {
String out = ""; String out = "";
/* Display IR Tracking */ /* Display IR Tracking */
out += "/******** Joystick ********/\n"; out += "/******** Joystick ********/\n";
out += "--- Active : true\n";
out += "--- angle : " + angle + "\n"; out += "--- angle : " + angle + "\n";
out += "--- magnitude : " + magnitude + "\n"; out += "--- magnitude : " + magnitude + "\n";
out += "--- maximum values : " + max[0] + "," + max[1] + "\n"; out += "--- maximum values : " + max[0] + "," + max[1] + "\n";

View File

@@ -45,36 +45,36 @@ public class MotionSensingEvent extends GenericEvent {
* id of the wiimote concerned. * id of the wiimote concerned.
* @param orientationThreshold * @param orientationThreshold
* value of the minimum angle between two events with the * value of the minimum angle between two events with the
* accelerometer * accelerometer.
* @param accelerationThreshold * @param accelerationThreshold
* value of the value variation between two events with the * value of the value variation between two events with the
* accelerometer * accelerometer.
* @param smoothingState * @param smoothingState
* true if smoothing flag is activated * true if smoothing flag is activated.
* @param alphaSmooth * @param alphaSmooth
* value of the alpha smoothing parameter * value of the alpha smoothing parameter.
* @param r * @param r
* roll * roll.
* @param p * @param p
* pitch * pitch.
* @param ya * @param ya
* yaw * yaw.
* @param ar * @param ar
* absolute roll * absolute roll.
* @param ap * @param ap
* absolute pitch * absolute pitch.
* @param x * @param x
* gravity force on x axis * gravity force on x axis.
* @param y * @param y
* gravity force on y axis * gravity force on y axis.
* @param z * @param z
* gravity force on z axis * gravity force on z axis.
* @param xx * @param xx
* raw acceleration on x axis * raw acceleration on x axis.
* @param yy * @param yy
* raw acceleration on y axis * raw acceleration on y axis.
* @param zz * @param zz
* raw acceleration on z axis * raw acceleration on z axis.
*/ */
public MotionSensingEvent(int id, float orientationThreshold, public MotionSensingEvent(int id, float orientationThreshold,
int accelerationThreshold, boolean smoothingState, int accelerationThreshold, boolean smoothingState,

View File

@@ -28,16 +28,129 @@ public class NunchukEvent extends ExpansionEvent {
JoystickEvent nunchukJoystickEvent; JoystickEvent nunchukJoystickEvent;
/** /**
* Constructor of NunchukEvent.
*
* @param id * @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) { 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, int angle, int magnitude, short max1,
short max2, short min1, short min2, short center1, short center2) {
super(id); super(id);
// TODO Auto-generated constructor stub 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) * (non-Javadoc)
* *

View File

@@ -38,7 +38,7 @@ public class EventsGatherer {
* Create EventsGatherer. * Create EventsGatherer.
* *
* @param nbWiimotes * @param nbWiimotes
* nb wiimotes (nb a of events possible in a call to Wiiuse API) * nb wiimotes (nb a of events possible in a call to Wiiuse API).
*/ */
public EventsGatherer(int nbWiimotes) { public EventsGatherer(int nbWiimotes) {
events = new WiiUseApiEvent[nbWiimotes]; events = new WiiUseApiEvent[nbWiimotes];
@@ -61,11 +61,11 @@ public class EventsGatherer {
* @param id * @param id
* id of the wiimote. * id of the wiimote.
* @param buttonsJustPressed * @param buttonsJustPressed
* buttons just pressed * buttons just pressed.
* @param buttonsJustReleased * @param buttonsJustReleased
* buttons just released * buttons just released.
* @param buttonsHeld * @param buttonsHeld
* buttons held * buttons held.
*/ */
public void prepareWiiMoteEvent(int id, short buttonsJustPressed, public void prepareWiiMoteEvent(int id, short buttonsJustPressed,
short buttonsJustReleased, short buttonsHeld) { short buttonsJustReleased, short buttonsHeld) {
@@ -85,7 +85,7 @@ public class EventsGatherer {
* @param ax * @param ax
* absolute X coordinate. * absolute X coordinate.
* @param ay * @param ay
* absolute Y coordinate * absolute Y coordinate.
* @param xVRes * @param xVRes
* IR virtual screen x resolution. * IR virtual screen x resolution.
* @param yVRes * @param yVRes
@@ -101,7 +101,7 @@ public class EventsGatherer {
* @param irSensitivity * @param irSensitivity
* Sensitivity of the infrared camera. * Sensitivity of the infrared camera.
* @param distance * @param distance
* Pixel Distance between first two dots * Pixel Distance between first two dots.
*/ */
public void prepareIRevent(int x, int y, int z, int ax, int ay, int xVRes, public void prepareIRevent(int x, int y, int z, int ax, int ay, int xVRes,
int yVRes, int xOffset, int yOffset, short sensorBarPostion, int yVRes, int xOffset, int yOffset, short sensorBarPostion,
@@ -113,12 +113,12 @@ public class EventsGatherer {
} }
/** /**
* Add an IR point to the WiiMoteEvent prepared * Add an IR point to the WiiMoteEvent prepared.
* *
* @param x * @param x
* x coordinates * x coordinates.
* @param y * @param y
* y coordinates * y coordinates.
* @param rx * @param rx
* raw X coordinate (0-1023). * raw X coordinate (0-1023).
* @param ry * @param ry
@@ -138,36 +138,36 @@ public class EventsGatherer {
* *
* @param orientationThreshold * @param orientationThreshold
* value of the minimum angle between two events with the * value of the minimum angle between two events with the
* accelerometer * accelerometer.
* @param accelerationThreshold * @param accelerationThreshold
* value of the value variation between two events with the * value of the value variation between two events with the
* accelerometer * accelerometer.
* @param smoothingState * @param smoothingState
* true if smoothing flag is activated * true if smoothing flag is activated.
* @param alphaSmooth * @param alphaSmooth
* value of the alpha smoothing parameter * value of the alpha smoothing parameter.
* @param r * @param r
* roll * roll.
* @param p * @param p
* pitch * pitch.
* @param ya * @param ya
* yaw * yaw.
* @param ar * @param ar
* absolute roll * absolute roll.
* @param ap * @param ap
* absolute pitch * absolute pitch.
* @param x * @param x
* gravity force on x axis * gravity force on x axis.
* @param y * @param y
* gravity force on y axis * gravity force on y axis.
* @param z * @param z
* gravity force on z axis * gravity force on z axis.
* @param xx * @param xx
* raw acceleration on x axis * raw acceleration on x axis.
* @param yy * @param yy
* raw acceleration on y axis * raw acceleration on y axis.
* @param zz * @param zz
* raw acceleration on z axis * raw acceleration on z axis.
*/ */
public void addMotionSensingValues(float orientationThreshold, public void addMotionSensingValues(float orientationThreshold,
int accelerationThreshold, boolean smoothingState, int accelerationThreshold, boolean smoothingState,
@@ -179,6 +179,80 @@ public class EventsGatherer {
ya, ar, ap, x, y, z, xx, yy, zz); 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, int angle, int 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. * Add the prepared WiimoteEvent to the gatherer.
@@ -194,25 +268,25 @@ public class EventsGatherer {
* Add a StatusEvent to the gatherer. * Add a StatusEvent to the gatherer.
* *
* @param id * @param id
* id of the wiimote * id of the wiimote.
* @param connect * @param connect
* true if the wiimote is connected * true if the wiimote is connected.
* @param batt * @param batt
* battery level * battery level.
* @param led * @param led
* status of leds * status of leds.
* @param speak * @param speak
* speakers status * speakers status.
* @param attach * @param attach
* attachment status * attachment status.
* @param rumbleState * @param rumbleState
* true if rumble is active * true if rumble is active.
* @param continuousState * @param continuousState
* true if continuous flag is activated * true if continuous flag is activated.
* @param irState * @param irState
* true if ir is active * true if ir is active.
* @param motionSensingState * @param motionSensingState
* true if accelerometer is active * true if accelerometer is active.
*/ */
public void addStatusEvent(int id, boolean connect, float batt, short led, public void addStatusEvent(int id, boolean connect, float batt, short led,
boolean speak, int attach, boolean rumbleState, boolean speak, int attach, boolean rumbleState,
@@ -227,7 +301,7 @@ public class EventsGatherer {
* Add a DisconnectionEvent to the gatherer. * Add a DisconnectionEvent to the gatherer.
* *
* @param id * @param id
* id of the wiimote * id of the wiimote.
*/ */
public void addDisconnectionEvent(int id) { public void addDisconnectionEvent(int id) {
DisconnectionEvent evt = new DisconnectionEvent(id); DisconnectionEvent evt = new DisconnectionEvent(id);
@@ -238,7 +312,7 @@ public class EventsGatherer {
* Add a NunchukInsertedEvent to the gatherer. * Add a NunchukInsertedEvent to the gatherer.
* *
* @param id * @param id
* id of the wiimote * id of the wiimote.
*/ */
public void addNunchukInsertedEvent(int id) { public void addNunchukInsertedEvent(int id) {
NunchukInsertedEvent evt = new NunchukInsertedEvent(id); NunchukInsertedEvent evt = new NunchukInsertedEvent(id);
@@ -249,7 +323,7 @@ public class EventsGatherer {
* Add a NunchukRemovedEvent to the gatherer. * Add a NunchukRemovedEvent to the gatherer.
* *
* @param id * @param id
* id of the wiimote * id of the wiimote.
*/ */
public void addNunchukRemovedEvent(int id) { public void addNunchukRemovedEvent(int id) {
NunchukRemovedEvent evt = new NunchukRemovedEvent(id); NunchukRemovedEvent evt = new NunchukRemovedEvent(id);
@@ -259,7 +333,7 @@ public class EventsGatherer {
/** /**
* Return an array containing the events. * Return an array containing the events.
* *
* @return events received * @return events received.
*/ */
public WiiUseApiEvent[] getEvents() { public WiiUseApiEvent[] getEvents() {
return java.util.Arrays.copyOfRange(events, 0, index); return java.util.Arrays.copyOfRange(events, 0, index);

View File

@@ -16,6 +16,7 @@
*/ */
package wiiusej.wiiusejevents.utils; package wiiusej.wiiusejevents.utils;
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
import wiiusej.wiiusejevents.physicalevents.IREvent; import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent; import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
@@ -52,6 +53,12 @@ public interface WiimoteListener extends java.util.EventListener {
*/ */
void onMotionSensingEvent(MotionSensingEvent e); 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. * Method called on a status event.
* A status event occurs when : * A status event occurs when :

View File

@@ -19,6 +19,7 @@ package wiiusej.wiiusejevents.wiiuseapievents;
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent; import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
import wiiusej.wiiusejevents.physicalevents.IREvent; import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.NunchukEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent; import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
/** /**
@@ -33,7 +34,7 @@ public class WiimoteEvent extends WiiUseApiEvent {
IREvent infraredEvent = null; IREvent infraredEvent = null;
MotionSensingEvent motionSensingEvent = null; MotionSensingEvent motionSensingEvent = null;
ExpansionEvent expansionEvent = null; ExpansionEvent expansionEvent = null;
/** /**
* Construct the Wiimote setting up the id. * Construct the Wiimote setting up the id.
* *
@@ -80,7 +81,7 @@ public class WiimoteEvent extends WiiUseApiEvent {
public boolean isThereMotionSensingEvent() { public boolean isThereMotionSensingEvent() {
return motionSensingEvent != null; return motionSensingEvent != null;
} }
/** /**
* Tell if there is an expansion Event. * Tell if there is an expansion Event.
* *
@@ -116,7 +117,7 @@ public class WiimoteEvent extends WiiUseApiEvent {
public MotionSensingEvent getMotionSensingEvent() { public MotionSensingEvent getMotionSensingEvent() {
return motionSensingEvent; return motionSensingEvent;
} }
/** /**
* Get the expansion event. * Get the expansion event.
* *
@@ -191,36 +192,36 @@ public class WiimoteEvent extends WiiUseApiEvent {
* *
* @param orientationThreshold * @param orientationThreshold
* value of the minimum angle between two events with the * value of the minimum angle between two events with the
* accelerometer * accelerometer.
* @param accelerationThreshold * @param accelerationThreshold
* value of the value variation between two events with the * value of the value variation between two events with the
* accelerometer * accelerometer.
* @param smoothingState * @param smoothingState
* true if smoothing flag is activated * true if smoothing flag is activated.
* @param alphaSmooth * @param alphaSmooth
* value of the alpha smoothing parameter * value of the alpha smoothing parameter.
* @param r * @param r
* roll * roll.
* @param p * @param p
* pitch * pitch.
* @param ya * @param ya
* yaw * yaw.
* @param ar * @param ar
* absolute roll * absolute roll.
* @param ap * @param ap
* absolute pitch * absolute pitch.
* @param x * @param x
* gravity force on x axis * gravity force on x axis.
* @param y * @param y
* gravity force on y axis * gravity force on y axis.
* @param z * @param z
* gravity force on z axis * gravity force on z axis.
* @param xx * @param xx
* raw acceleration on x axis * raw acceleration on x axis.
* @param yy * @param yy
* raw acceleration on y axis * raw acceleration on y axis.
* @param zz * @param zz
* raw acceleration on z axis * raw acceleration on z axis.
*/ */
public void setMotionSensingEvent(float orientationThreshold, public void setMotionSensingEvent(float orientationThreshold,
int accelerationThreshold, boolean smoothingState, int accelerationThreshold, boolean smoothingState,
@@ -229,14 +230,82 @@ public class WiimoteEvent extends WiiUseApiEvent {
motionSensingEvent = new MotionSensingEvent(getWiimoteId(), motionSensingEvent = new MotionSensingEvent(getWiimoteId(),
orientationThreshold, accelerationThreshold, smoothingState, orientationThreshold, accelerationThreshold, smoothingState,
alphaSmooth, r, p, ya, ar, ap, x, y, z, xx, yy, zz); alphaSmooth, r, p, ya, ar, ap, x, y, z, xx, yy, zz);
}
public void setNunchukEvent(){
} }
public void setClassicControllerEvent(){ /**
//@TODO * 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, int angle, int 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 @Override
@@ -261,7 +330,7 @@ public class WiimoteEvent extends WiiUseApiEvent {
out += "/******** Motion sensing ********/\n"; out += "/******** Motion sensing ********/\n";
out += "--- Motion sensing : false \n"; out += "--- Motion sensing : false \n";
} }
if (expansionEvent != null) { if (expansionEvent != null) {
out += expansionEvent; out += expansionEvent;
} else { } else {