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:
@@ -144,15 +144,15 @@ public class WiiUseApi {
|
||||
* Set wiimote leds status.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote concerned
|
||||
* the id of the wiimote concerned.
|
||||
* @param led1
|
||||
* status of led1: True=ON, False=OFF
|
||||
* status of led1: True=ON, False=OFF.
|
||||
* @param led2
|
||||
* status of led2: True=ON, False=OFF
|
||||
* status of led2: True=ON, False=OFF.
|
||||
* @param led3
|
||||
* status of led3: True=ON, False=OFF
|
||||
* status of led3: True=ON, False=OFF.
|
||||
* @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,
|
||||
boolean led3, boolean led4);
|
||||
@@ -161,9 +161,9 @@ public class WiiUseApi {
|
||||
* Set how many degrees an angle must change to generate an event.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote concerned
|
||||
* id of the wiimote concerned.
|
||||
* @param angle
|
||||
* minimum angle detected by an event
|
||||
* minimum angle detected by an event.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote concerned
|
||||
* id of the wiimote concerned.
|
||||
* @param value
|
||||
* minimum value detected by an event
|
||||
* minimum value detected by an event.
|
||||
*/
|
||||
synchronized native void setAccelThreshold(int id, int value);
|
||||
|
||||
@@ -181,9 +181,9 @@ public class WiiUseApi {
|
||||
* Set alpha smoothing parameter for the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote concerned
|
||||
* id of the wiimote concerned.
|
||||
* @param value
|
||||
* alpha smoothing value
|
||||
* alpha smoothing 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.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote concerned
|
||||
* id of the wiimote concerned.
|
||||
*/
|
||||
synchronized native void reSync(int id);
|
||||
|
||||
@@ -200,7 +200,7 @@ public class WiiUseApi {
|
||||
* default.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote concerned
|
||||
* the id of the wiimote concerned.
|
||||
*/
|
||||
synchronized native void activateSmoothing(int id);
|
||||
|
||||
@@ -208,7 +208,7 @@ public class WiiUseApi {
|
||||
* Make the the accelerometers give raw results.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote concerned
|
||||
* the id of the wiimote concerned.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote concerned
|
||||
* the id of the wiimote concerned.
|
||||
*/
|
||||
synchronized native void activateContinuous(int id);
|
||||
|
||||
@@ -224,7 +224,7 @@ public class WiiUseApi {
|
||||
* Make the wiimote generate an event only when there is one.
|
||||
*
|
||||
* @param id
|
||||
* the id of the wiimote concerned
|
||||
* the id of the wiimote concerned.
|
||||
*/
|
||||
synchronized native void deactivateContinuous(int id);
|
||||
|
||||
@@ -308,6 +308,27 @@ public class WiiUseApi {
|
||||
*/
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -54,9 +54,9 @@ public class WiiUseApiManager extends Thread {
|
||||
* wiimotes.
|
||||
*
|
||||
* @param nb
|
||||
* try to connect nb wiimotes
|
||||
* try to connect nb wiimotes.
|
||||
* @param rumble
|
||||
* make the connected wiimotes rumble
|
||||
* make the connected wiimotes rumble.
|
||||
* @return an array with connected wiimotes or NULL.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
* id of the wiimote.
|
||||
*/
|
||||
public void deactivateContinuous(int id) {
|
||||
wiiuse.deactivateContinuous(id);
|
||||
@@ -289,13 +289,13 @@ public class WiiUseApiManager extends Thread {
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
* @param l1
|
||||
* status of led1. True : ON, False : OFF
|
||||
* status of led1. True : ON, False : OFF.
|
||||
* @param l2
|
||||
* status of led2. True : ON, False : OFF
|
||||
* status of led2. True : ON, False : OFF.
|
||||
* @param l3
|
||||
* status of led3. True : ON, False : OFF
|
||||
* status of led3. True : ON, False : OFF.
|
||||
* @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) {
|
||||
wiiuse.setLeds(id, l1, l2, l3, l4);
|
||||
@@ -303,11 +303,12 @@ public class WiiUseApiManager extends Thread {
|
||||
|
||||
/**
|
||||
* Set the orientation threshold for the given id.
|
||||
* (minimum angle between two events)
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
* id of the wiimote.
|
||||
* @param th
|
||||
* threshold in degrees
|
||||
* threshold in degrees.
|
||||
*/
|
||||
public void setOrientationThreshold(int id, float th) {
|
||||
wiiuse.setOrientThreshold(id, th);
|
||||
@@ -315,11 +316,12 @@ public class WiiUseApiManager extends Thread {
|
||||
|
||||
/**
|
||||
* Set the acceleration threshold for the given id.
|
||||
* (minimum angle between two events)
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
* id of the wiimote.
|
||||
* @param th
|
||||
* threshold
|
||||
* threshold.
|
||||
*/
|
||||
public void setAccelerationThreshold(int id, int th) {
|
||||
wiiuse.setAccelThreshold(id, th);
|
||||
@@ -329,9 +331,9 @@ public class WiiUseApiManager extends Thread {
|
||||
* Set alpha smoothing for the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
* id of the wiimote.
|
||||
* @param th
|
||||
* threshold
|
||||
* threshold.
|
||||
*/
|
||||
public void setAlphaSmoothing(int id, float 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.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
* id of the wiimote.
|
||||
*/
|
||||
public void reSync(int id) {
|
||||
wiiuse.reSync(id);
|
||||
@@ -351,7 +353,7 @@ public class WiiUseApiManager extends Thread {
|
||||
* Set screen aspect ratio to 4/3 for the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
* id of the wiimote.
|
||||
*/
|
||||
public void setScreenAspectRatio43(int id) {
|
||||
wiiuse.setScreenRatio43(id);
|
||||
@@ -361,7 +363,7 @@ public class WiiUseApiManager extends Thread {
|
||||
* Set screen aspect ratio to 16/9 for the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
* id of the wiimote.
|
||||
*/
|
||||
public void setScreenAspectRatio169(int id) {
|
||||
wiiuse.setScreenRatio169(id);
|
||||
@@ -371,7 +373,7 @@ public class WiiUseApiManager extends Thread {
|
||||
* Set the sensor bar to be above the screen.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
* id of the wiimote.
|
||||
*/
|
||||
public void setSensorBarAboveScreen(int id) {
|
||||
wiiuse.setSensorBarAboveScreen(id);
|
||||
@@ -381,7 +383,7 @@ public class WiiUseApiManager extends Thread {
|
||||
* Set the sensor bar to be below the screen.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
* id of the wiimote.
|
||||
*/
|
||||
public void setSensorBarBelowScreen(int id) {
|
||||
wiiuse.setSensorBarBelowScreen(id);
|
||||
@@ -393,11 +395,11 @@ public class WiiUseApiManager extends Thread {
|
||||
* come in the IREvent.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
* id of the wiimote.
|
||||
* @param x
|
||||
* x resolution
|
||||
* x resolution.
|
||||
* @param y
|
||||
* y resolution
|
||||
* y resolution.
|
||||
*/
|
||||
public void setVirtualResolution(int id, int x, int y) {
|
||||
wiiuse.setVirtualScreenResolution(id, x, y);
|
||||
@@ -407,7 +409,7 @@ public class WiiUseApiManager extends Thread {
|
||||
* Get Status for the wiimote for the given id.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
* id of the wiimote.
|
||||
*/
|
||||
public void getStatus(int id) {
|
||||
wiiuse.getStatus(id);
|
||||
@@ -441,6 +443,32 @@ public class WiiUseApiManager extends Thread {
|
||||
public 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.
|
||||
*/
|
||||
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
|
||||
public void run() {
|
||||
|
||||
@@ -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
|
||||
* threshold
|
||||
@@ -230,6 +231,28 @@ public class Wiimote implements WiiUseApiListener {
|
||||
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.
|
||||
@@ -336,6 +359,9 @@ public class Wiimote implements WiiUseApiListener {
|
||||
if (evt.isThereMotionSensingEvent()) {
|
||||
listener.onMotionSensingEvent(evt.getMotionSensingEvent());
|
||||
}
|
||||
if (evt.isThereExpansionEvent()){
|
||||
listener.onExpansionEvent(evt.getExpansionEvent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ 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;
|
||||
@@ -325,6 +326,10 @@ public class Tests implements WiimoteListener {
|
||||
/* display motion sensing */
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
public void onExpansionEvent(ExpansionEvent e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent e) {
|
||||
// Display status variables
|
||||
|
||||
@@ -28,6 +28,7 @@ import wiiusej.utils.ButtonsEventPanel;
|
||||
import wiiusej.utils.GForcePanel;
|
||||
import wiiusej.utils.IRPanel;
|
||||
import wiiusej.utils.OrientationPanel;
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
@@ -124,6 +125,10 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements WiimoteListene
|
||||
statusMotionRequested = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void onExpansionEvent(ExpansionEvent e) {
|
||||
//nothing yet
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent arg0) {
|
||||
messageText.setText("Status received !");
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.awt.geom.AffineTransform;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import wiiusej.values.RawAcceleration;
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
@@ -36,160 +37,167 @@ import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||
|
||||
/**
|
||||
* This panel is used to watch raw acceleration values from a MotionSensingEvent.
|
||||
* @author guiguito
|
||||
* This panel is used to watch raw acceleration values from a
|
||||
* 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 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<RawAcceleration> values = new ArrayList<RawAcceleration>();
|
||||
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<RawAcceleration> values = new ArrayList<RawAcceleration>();
|
||||
|
||||
/** Creates new form AccelerationPanel */
|
||||
public AccelerationPanel() {
|
||||
initComponents();
|
||||
}
|
||||
/** Creates new form AccelerationPanel */
|
||||
public AccelerationPanel() {
|
||||
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);
|
||||
@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;
|
||||
// draw medium line
|
||||
int yLine = getHeight() - 25;
|
||||
|
||||
g2.setPaint(lineColor);
|
||||
g2.drawLine(0, yLine, getWidth(), yLine);
|
||||
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;
|
||||
}
|
||||
RawAcceleration[] valuesArray = values.toArray(new RawAcceleration[0]);
|
||||
|
||||
//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);
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
// 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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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) {
|
||||
//nothing
|
||||
}
|
||||
public void onButtonsEvent(WiimoteButtonsEvent 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.getRawAcceleration());
|
||||
repaint();
|
||||
}
|
||||
public void onIrEvent(IREvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent 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.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) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
// nothing
|
||||
}
|
||||
|
||||
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() {
|
||||
/**
|
||||
* 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);
|
||||
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)
|
||||
);
|
||||
}// </editor-fold>//GEN-END: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));
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.awt.Toolkit;
|
||||
import java.awt.geom.AffineTransform;
|
||||
|
||||
import wiiusej.wiiusejevents.physicalevents.ButtonsEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
@@ -37,275 +38,290 @@ import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
|
||||
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||
|
||||
/**
|
||||
* This panel is used to see what buttons are pressed.
|
||||
* It displays the result of last ButtonsEvent.
|
||||
* @author guiguito
|
||||
* This panel is used to see what buttons are pressed. It displays the result of
|
||||
* last ButtonsEvent.
|
||||
*
|
||||
* @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 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;
|
||||
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();
|
||||
}
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
@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);
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
//draw buttons pushed
|
||||
g2.drawImage(wiimoteImage, 0, 0, this);
|
||||
g2.setTransform(new AffineTransform());
|
||||
@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);
|
||||
|
||||
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);
|
||||
}
|
||||
// draw buttons pushed
|
||||
g2.drawImage(wiimoteImage, 0, 0, this);
|
||||
g2.setTransform(new AffineTransform());
|
||||
|
||||
/* 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);
|
||||
}
|
||||
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 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 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 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 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 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 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 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 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 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 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 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 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 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);
|
||||
}
|
||||
/* 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);
|
||||
}
|
||||
|
||||
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
|
||||
g.drawImage(mImage, 0, 0, null);
|
||||
}
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
buttons = 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);
|
||||
}
|
||||
}
|
||||
// put offscreen image on the screen
|
||||
g.drawImage(mImage, 0, 0, null);
|
||||
}
|
||||
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
setSize(wiimoteImage.getWidth(this), wiimoteImage.getHeight(this));
|
||||
buttons = arg0;
|
||||
repaint();
|
||||
}
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
|
||||
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) {
|
||||
//nothing
|
||||
}
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
setSize(wiimoteImage.getWidth(this), wiimoteImage.getHeight(this));
|
||||
buttons = arg0;
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent arg0) {
|
||||
//nothing
|
||||
}
|
||||
public void onIrEvent(IREvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onDisconnectionEvent(DisconnectionEvent arg0) {
|
||||
buttons = null;
|
||||
repaint();
|
||||
}
|
||||
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) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
// nothing
|
||||
}
|
||||
|
||||
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);
|
||||
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)
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
/**
|
||||
* 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);
|
||||
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));
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.awt.geom.AffineTransform;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import wiiusej.values.GForce;
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
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.
|
||||
* @author guiguito
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public 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<GForce> values = new ArrayList<GForce>();
|
||||
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<GForce> values = new ArrayList<GForce>();
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
/**
|
||||
* Default constructor of the AccelerationPanel.
|
||||
*/
|
||||
public GForcePanel() {
|
||||
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);
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
//draw medium line
|
||||
double yMiddleFloat = getHeight() / 2.0;
|
||||
int yMiddle = (int) Math.round(yMiddleFloat);
|
||||
@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.setPaint(lineColor);
|
||||
g2.drawLine(0, yMiddle, getWidth(), yMiddle);
|
||||
// draw medium line
|
||||
double yMiddleFloat = getHeight() / 2.0;
|
||||
int yMiddle = (int) Math.round(yMiddleFloat);
|
||||
|
||||
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;
|
||||
}
|
||||
g2.setPaint(lineColor);
|
||||
g2.drawLine(0, yMiddle, getWidth(), yMiddle);
|
||||
|
||||
//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);
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
// 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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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) {
|
||||
//nothing
|
||||
}
|
||||
public void onButtonsEvent(WiimoteButtonsEvent 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.getGforce());
|
||||
repaint();
|
||||
}
|
||||
public void onIrEvent(IREvent arg0) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent 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.getGforce());
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void onDisconnectionEvent(DisconnectionEvent arg0) {
|
||||
//Clear points.
|
||||
values.clear();
|
||||
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 onNunchukInsertedEvent(NunchukInsertedEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
// nothing
|
||||
}
|
||||
|
||||
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);
|
||||
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)
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
/**
|
||||
* 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);
|
||||
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));
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ 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;
|
||||
@@ -157,6 +158,10 @@ public class IRPanel extends javax.swing.JPanel implements WiimoteListener {
|
||||
public void onMotionSensingEvent(MotionSensingEvent arg0) {
|
||||
//nothing
|
||||
}
|
||||
|
||||
public void onExpansionEvent(ExpansionEvent e) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent arg0) {
|
||||
//nothing
|
||||
@@ -173,13 +178,11 @@ public class IRPanel extends javax.swing.JPanel implements WiimoteListener {
|
||||
}
|
||||
|
||||
public void onNunchukInsertedEvent(NunchukInsertedEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
// nothing
|
||||
}
|
||||
|
||||
public void onNunchukRemovedEvent(NunchukRemovedEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
// nothing
|
||||
}
|
||||
|
||||
/** This method is called from within the constructor to
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.awt.geom.AffineTransform;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import wiiusej.values.Orientation;
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
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.
|
||||
* @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 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<Orientation> values = new ArrayList<Orientation>();
|
||||
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<Orientation> values = new ArrayList<Orientation>();
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
/**
|
||||
* Default constructor. Background color : White. Roll color : Red. Pitch
|
||||
* color : Green. Yaw color : Blue.
|
||||
*/
|
||||
public OrientationPanel() {
|
||||
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);
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
//draw medium line
|
||||
double yMiddleFloat = getHeight() / 2.0;
|
||||
int yMiddle = (int) Math.round(yMiddleFloat);
|
||||
@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.setPaint(lineColor);
|
||||
g2.drawLine(0, yMiddle, getWidth(), yMiddle);
|
||||
// draw medium line
|
||||
double yMiddleFloat = getHeight() / 2.0;
|
||||
int yMiddle = (int) Math.round(yMiddleFloat);
|
||||
|
||||
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);
|
||||
}
|
||||
g2.setPaint(lineColor);
|
||||
g2.drawLine(0, yMiddle, getWidth(), yMiddle);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
//nothing
|
||||
}
|
||||
// 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);
|
||||
|
||||
public void onIrEvent(IREvent arg0) {
|
||||
//nothing
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
/**
|
||||
* 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 onStatusEvent(StatusEvent arg0) {
|
||||
//nothing
|
||||
}
|
||||
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
|
||||
// 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) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
// nothing
|
||||
}
|
||||
|
||||
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() {
|
||||
/**
|
||||
* 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);
|
||||
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)
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
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));
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
|
||||
@@ -124,7 +124,6 @@ public class JoystickEvent extends GenericEvent {
|
||||
String out = "";
|
||||
/* Display IR Tracking */
|
||||
out += "/******** Joystick ********/\n";
|
||||
out += "--- Active : true\n";
|
||||
out += "--- angle : " + angle + "\n";
|
||||
out += "--- magnitude : " + magnitude + "\n";
|
||||
out += "--- maximum values : " + max[0] + "," + max[1] + "\n";
|
||||
|
||||
@@ -45,36 +45,36 @@ public class MotionSensingEvent extends GenericEvent {
|
||||
* id of the wiimote concerned.
|
||||
* @param orientationThreshold
|
||||
* value of the minimum angle between two events with the
|
||||
* accelerometer
|
||||
* accelerometer.
|
||||
* @param accelerationThreshold
|
||||
* value of the value variation between two events with the
|
||||
* accelerometer
|
||||
* accelerometer.
|
||||
* @param smoothingState
|
||||
* true if smoothing flag is activated
|
||||
* true if smoothing flag is activated.
|
||||
* @param alphaSmooth
|
||||
* value of the alpha smoothing parameter
|
||||
* value of the alpha smoothing parameter.
|
||||
* @param r
|
||||
* roll
|
||||
* roll.
|
||||
* @param p
|
||||
* pitch
|
||||
* pitch.
|
||||
* @param ya
|
||||
* yaw
|
||||
* yaw.
|
||||
* @param ar
|
||||
* absolute roll
|
||||
* absolute roll.
|
||||
* @param ap
|
||||
* absolute pitch
|
||||
* absolute pitch.
|
||||
* @param x
|
||||
* gravity force on x axis
|
||||
* gravity force on x axis.
|
||||
* @param y
|
||||
* gravity force on y axis
|
||||
* gravity force on y axis.
|
||||
* @param z
|
||||
* gravity force on z axis
|
||||
* gravity force on z axis.
|
||||
* @param xx
|
||||
* raw acceleration on x axis
|
||||
* raw acceleration on x axis.
|
||||
* @param yy
|
||||
* raw acceleration on y axis
|
||||
* raw acceleration on y axis.
|
||||
* @param zz
|
||||
* raw acceleration on z axis
|
||||
* raw acceleration on z axis.
|
||||
*/
|
||||
public MotionSensingEvent(int id, float orientationThreshold,
|
||||
int accelerationThreshold, boolean smoothingState,
|
||||
|
||||
@@ -28,16 +28,129 @@ public class NunchukEvent extends ExpansionEvent {
|
||||
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) {
|
||||
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);
|
||||
// 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)
|
||||
*
|
||||
|
||||
@@ -38,7 +38,7 @@ public class EventsGatherer {
|
||||
* Create EventsGatherer.
|
||||
*
|
||||
* @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) {
|
||||
events = new WiiUseApiEvent[nbWiimotes];
|
||||
@@ -61,11 +61,11 @@ public class EventsGatherer {
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
* @param buttonsJustPressed
|
||||
* buttons just pressed
|
||||
* buttons just pressed.
|
||||
* @param buttonsJustReleased
|
||||
* buttons just released
|
||||
* buttons just released.
|
||||
* @param buttonsHeld
|
||||
* buttons held
|
||||
* buttons held.
|
||||
*/
|
||||
public void prepareWiiMoteEvent(int id, short buttonsJustPressed,
|
||||
short buttonsJustReleased, short buttonsHeld) {
|
||||
@@ -85,7 +85,7 @@ public class EventsGatherer {
|
||||
* @param ax
|
||||
* absolute X coordinate.
|
||||
* @param ay
|
||||
* absolute Y coordinate
|
||||
* absolute Y coordinate.
|
||||
* @param xVRes
|
||||
* IR virtual screen x resolution.
|
||||
* @param yVRes
|
||||
@@ -101,7 +101,7 @@ public class EventsGatherer {
|
||||
* @param irSensitivity
|
||||
* Sensitivity of the infrared camera.
|
||||
* @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,
|
||||
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
|
||||
* x coordinates
|
||||
* x coordinates.
|
||||
* @param y
|
||||
* y coordinates
|
||||
* y coordinates.
|
||||
* @param rx
|
||||
* raw X coordinate (0-1023).
|
||||
* @param ry
|
||||
@@ -138,36 +138,36 @@ public class EventsGatherer {
|
||||
*
|
||||
* @param orientationThreshold
|
||||
* value of the minimum angle between two events with the
|
||||
* accelerometer
|
||||
* accelerometer.
|
||||
* @param accelerationThreshold
|
||||
* value of the value variation between two events with the
|
||||
* accelerometer
|
||||
* accelerometer.
|
||||
* @param smoothingState
|
||||
* true if smoothing flag is activated
|
||||
* true if smoothing flag is activated.
|
||||
* @param alphaSmooth
|
||||
* value of the alpha smoothing parameter
|
||||
* value of the alpha smoothing parameter.
|
||||
* @param r
|
||||
* roll
|
||||
* roll.
|
||||
* @param p
|
||||
* pitch
|
||||
* pitch.
|
||||
* @param ya
|
||||
* yaw
|
||||
* yaw.
|
||||
* @param ar
|
||||
* absolute roll
|
||||
* absolute roll.
|
||||
* @param ap
|
||||
* absolute pitch
|
||||
* absolute pitch.
|
||||
* @param x
|
||||
* gravity force on x axis
|
||||
* gravity force on x axis.
|
||||
* @param y
|
||||
* gravity force on y axis
|
||||
* gravity force on y axis.
|
||||
* @param z
|
||||
* gravity force on z axis
|
||||
* gravity force on z axis.
|
||||
* @param xx
|
||||
* raw acceleration on x axis
|
||||
* raw acceleration on x axis.
|
||||
* @param yy
|
||||
* raw acceleration on y axis
|
||||
* raw acceleration on y axis.
|
||||
* @param zz
|
||||
* raw acceleration on z axis
|
||||
* raw acceleration on z axis.
|
||||
*/
|
||||
public void addMotionSensingValues(float orientationThreshold,
|
||||
int accelerationThreshold, boolean smoothingState,
|
||||
@@ -179,6 +179,80 @@ public class EventsGatherer {
|
||||
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.
|
||||
@@ -194,25 +268,25 @@ public class EventsGatherer {
|
||||
* Add a StatusEvent to the gatherer.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
* id of the wiimote.
|
||||
* @param connect
|
||||
* true if the wiimote is connected
|
||||
* true if the wiimote is connected.
|
||||
* @param batt
|
||||
* battery level
|
||||
* battery level.
|
||||
* @param led
|
||||
* status of leds
|
||||
* status of leds.
|
||||
* @param speak
|
||||
* speakers status
|
||||
* speakers status.
|
||||
* @param attach
|
||||
* attachment status
|
||||
* attachment status.
|
||||
* @param rumbleState
|
||||
* true if rumble is active
|
||||
* true if rumble is active.
|
||||
* @param continuousState
|
||||
* true if continuous flag is activated
|
||||
* true if continuous flag is activated.
|
||||
* @param irState
|
||||
* true if ir is active
|
||||
* true if ir is active.
|
||||
* @param motionSensingState
|
||||
* true if accelerometer is active
|
||||
* true if accelerometer is active.
|
||||
*/
|
||||
public void addStatusEvent(int id, boolean connect, float batt, short led,
|
||||
boolean speak, int attach, boolean rumbleState,
|
||||
@@ -227,7 +301,7 @@ public class EventsGatherer {
|
||||
* Add a DisconnectionEvent to the gatherer.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
* id of the wiimote.
|
||||
*/
|
||||
public void addDisconnectionEvent(int id) {
|
||||
DisconnectionEvent evt = new DisconnectionEvent(id);
|
||||
@@ -238,7 +312,7 @@ public class EventsGatherer {
|
||||
* Add a NunchukInsertedEvent to the gatherer.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
* id of the wiimote.
|
||||
*/
|
||||
public void addNunchukInsertedEvent(int id) {
|
||||
NunchukInsertedEvent evt = new NunchukInsertedEvent(id);
|
||||
@@ -249,7 +323,7 @@ public class EventsGatherer {
|
||||
* Add a NunchukRemovedEvent to the gatherer.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
* id of the wiimote.
|
||||
*/
|
||||
public void addNunchukRemovedEvent(int id) {
|
||||
NunchukRemovedEvent evt = new NunchukRemovedEvent(id);
|
||||
@@ -259,7 +333,7 @@ public class EventsGatherer {
|
||||
/**
|
||||
* Return an array containing the events.
|
||||
*
|
||||
* @return events received
|
||||
* @return events received.
|
||||
*/
|
||||
public WiiUseApiEvent[] getEvents() {
|
||||
return java.util.Arrays.copyOfRange(events, 0, index);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package wiiusej.wiiusejevents.utils;
|
||||
|
||||
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
@@ -52,6 +53,12 @@ public interface WiimoteListener extends java.util.EventListener {
|
||||
*/
|
||||
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 :
|
||||
|
||||
@@ -19,6 +19,7 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -33,7 +34,7 @@ public class WiimoteEvent extends WiiUseApiEvent {
|
||||
IREvent infraredEvent = null;
|
||||
MotionSensingEvent motionSensingEvent = null;
|
||||
ExpansionEvent expansionEvent = null;
|
||||
|
||||
|
||||
/**
|
||||
* Construct the Wiimote setting up the id.
|
||||
*
|
||||
@@ -80,7 +81,7 @@ public class WiimoteEvent extends WiiUseApiEvent {
|
||||
public boolean isThereMotionSensingEvent() {
|
||||
return motionSensingEvent != null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tell if there is an expansion Event.
|
||||
*
|
||||
@@ -116,7 +117,7 @@ public class WiimoteEvent extends WiiUseApiEvent {
|
||||
public MotionSensingEvent getMotionSensingEvent() {
|
||||
return motionSensingEvent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the expansion event.
|
||||
*
|
||||
@@ -191,36 +192,36 @@ public class WiimoteEvent extends WiiUseApiEvent {
|
||||
*
|
||||
* @param orientationThreshold
|
||||
* value of the minimum angle between two events with the
|
||||
* accelerometer
|
||||
* accelerometer.
|
||||
* @param accelerationThreshold
|
||||
* value of the value variation between two events with the
|
||||
* accelerometer
|
||||
* accelerometer.
|
||||
* @param smoothingState
|
||||
* true if smoothing flag is activated
|
||||
* true if smoothing flag is activated.
|
||||
* @param alphaSmooth
|
||||
* value of the alpha smoothing parameter
|
||||
* value of the alpha smoothing parameter.
|
||||
* @param r
|
||||
* roll
|
||||
* roll.
|
||||
* @param p
|
||||
* pitch
|
||||
* pitch.
|
||||
* @param ya
|
||||
* yaw
|
||||
* yaw.
|
||||
* @param ar
|
||||
* absolute roll
|
||||
* absolute roll.
|
||||
* @param ap
|
||||
* absolute pitch
|
||||
* absolute pitch.
|
||||
* @param x
|
||||
* gravity force on x axis
|
||||
* gravity force on x axis.
|
||||
* @param y
|
||||
* gravity force on y axis
|
||||
* gravity force on y axis.
|
||||
* @param z
|
||||
* gravity force on z axis
|
||||
* gravity force on z axis.
|
||||
* @param xx
|
||||
* raw acceleration on x axis
|
||||
* raw acceleration on x axis.
|
||||
* @param yy
|
||||
* raw acceleration on y axis
|
||||
* raw acceleration on y axis.
|
||||
* @param zz
|
||||
* raw acceleration on z axis
|
||||
* raw acceleration on z axis.
|
||||
*/
|
||||
public void setMotionSensingEvent(float orientationThreshold,
|
||||
int accelerationThreshold, boolean smoothingState,
|
||||
@@ -229,14 +230,82 @@ public class WiimoteEvent extends WiiUseApiEvent {
|
||||
motionSensingEvent = new MotionSensingEvent(getWiimoteId(),
|
||||
orientationThreshold, accelerationThreshold, smoothingState,
|
||||
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
|
||||
@@ -261,7 +330,7 @@ public class WiimoteEvent extends WiiUseApiEvent {
|
||||
out += "/******** Motion sensing ********/\n";
|
||||
out += "--- Motion sensing : false \n";
|
||||
}
|
||||
|
||||
|
||||
if (expansionEvent != null) {
|
||||
out += expansionEvent;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user