This commit is contained in:
2011-02-01 18:38:43 +00:00
parent 2516e790ff
commit 683ed112d4
99 changed files with 19949 additions and 0 deletions

View File

@@ -0,0 +1,179 @@
/**
* This file is part of WiiuseJ.
*
* WiiuseJ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WiiuseJ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
*/
package wiiusej.test;
import wiiusej.WiiUseApiManager;
import wiiusej.Wiimote;
import wiiusej.utils.ClassicControllerButtonsEventPanel;
import wiiusej.wiiusejevents.physicalevents.ClassicControllerEvent;
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
import wiiusej.wiiusejevents.utils.WiimoteListener;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
/**
* This frame is used to display events from a classic controller.
*
* @author guiguito
*/
public class ClassicControllerGuiTest extends javax.swing.JFrame implements WiimoteListener {
private Wiimote wiimote;
private static int MAX_SHOULDER = 100;
/** Creates new form ClassicControllerGuiTest */
public ClassicControllerGuiTest(Wiimote wiimote) {
initComponents();
this.wiimote = wiimote;
registerListeners();
leftShoulderBar.setMaximum(MAX_SHOULDER);
rightShoulderBar.setMaximum(MAX_SHOULDER);
}
private void registerListeners() {
wiimote.addWiiMoteEventListeners(this);
wiimote.addWiiMoteEventListeners((ClassicControllerButtonsEventPanel) classicControllerPanel);
}
public void unRegisterListeners() {
wiimote.removeWiiMoteEventListeners(this);
wiimote.removeWiiMoteEventListeners((ClassicControllerButtonsEventPanel) classicControllerPanel);
}
/** 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() {
shouldersPanel = new javax.swing.JPanel();
leftShoulderBar = new javax.swing.JProgressBar();
rightShoulderBar = new javax.swing.JProgressBar();
classicControllerPanel = new wiiusej.utils.ClassicControllerButtonsEventPanel();
setTitle("WiiuseJ Classic Controller Test GUI");
setResizable(false);
getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.Y_AXIS));
shouldersPanel.setMaximumSize(new java.awt.Dimension(350, 16));
shouldersPanel.setMinimumSize(new java.awt.Dimension(350, 16));
shouldersPanel.setPreferredSize(new java.awt.Dimension(350, 16));
shouldersPanel.setLayout(new javax.swing.BoxLayout(shouldersPanel, javax.swing.BoxLayout.LINE_AXIS));
shouldersPanel.add(leftShoulderBar);
shouldersPanel.add(rightShoulderBar);
getContentPane().add(shouldersPanel);
classicControllerPanel.setMaximumSize(new java.awt.Dimension(350, 182));
classicControllerPanel.setMinimumSize(new java.awt.Dimension(350, 182));
javax.swing.GroupLayout classicControllerPanelLayout = new javax.swing.GroupLayout(classicControllerPanel);
classicControllerPanel.setLayout(classicControllerPanelLayout);
classicControllerPanelLayout.setHorizontalGroup(
classicControllerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 350, Short.MAX_VALUE)
);
classicControllerPanelLayout.setVerticalGroup(
classicControllerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 182, Short.MAX_VALUE)
);
getContentPane().add(classicControllerPanel);
pack();
}// </editor-fold>//GEN-END:initComponents
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
// nothing to do
}
public void onIrEvent(IREvent arg0) {
// nothing to do
}
public void onMotionSensingEvent(MotionSensingEvent arg0) {
// nothing to do
}
public void onExpansionEvent(ExpansionEvent arg0) {
if (arg0 instanceof ClassicControllerEvent) {
ClassicControllerEvent classicController = (ClassicControllerEvent) arg0;
float leftShoulder = classicController.getLeftShoulder();
float rightShoulder = classicController.getRightShoulder();
leftShoulderBar.setValue(Math.round(leftShoulder * MAX_SHOULDER));
rightShoulderBar.setValue(Math.round(rightShoulder * MAX_SHOULDER));
}
}
public void onStatusEvent(StatusEvent arg0) {
// nothing to do
}
public void onDisconnectionEvent(DisconnectionEvent arg0) {
// nothing to do
}
public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
// nothing to do
}
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
// nothing to do
}
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {
// nothing to do
}
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {
// nothing to do
}
public void onClassicControllerInsertedEvent(ClassicControllerInsertedEvent arg0) {
// nothing to do
}
public void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent arg0) {
// nothing to do
}
public static void main(String[] args) {
Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1, true);
ClassicControllerGuiTest gui = null;
if (wiimotes.length > 0) {
gui = new ClassicControllerGuiTest(wiimotes[0]);
}
gui.setDefaultCloseOperation(WiiuseJGuiTest.EXIT_ON_CLOSE);
gui.setVisible(true);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel classicControllerPanel;
private javax.swing.JProgressBar leftShoulderBar;
private javax.swing.JProgressBar rightShoulderBar;
private javax.swing.JPanel shouldersPanel;
// End of variables declaration//GEN-END:variables
}

View File

@@ -0,0 +1,58 @@
/**
* This file is part of WiiuseJ.
*
* WiiuseJ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WiiuseJ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
*/
package wiiusej.test;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import wiiusej.WiiUseApiManager;
/**
* This class is used to close wiiusej cleanly.
*
* @author guiguito
*/
public class CloseGuiTestCleanly implements WindowListener {
public void windowOpened(WindowEvent e) {
// nothing
}
public void windowClosing(WindowEvent e) {
WiiUseApiManager.definitiveShutdown();
}
public void windowClosed(WindowEvent e) {
// nothing
}
public void windowIconified(WindowEvent e) {
// nothing
}
public void windowDeiconified(WindowEvent e) {
// nothing
}
public void windowActivated(WindowEvent e) {
// nothing
}
public void windowDeactivated(WindowEvent e) {
// nothing
}
}

View File

@@ -0,0 +1,168 @@
/*
* GuitarHeroGUITest.java
*
* Created on 12 juin 2008, 23:10
*/
package wiiusej.test;
import wiiusej.Wiimote;
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
import wiiusej.wiiusejevents.physicalevents.GuitarHeroEvent;
import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
import wiiusej.wiiusejevents.utils.WiimoteListener;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
/**
* This frame is used to display events from a Guitar Hero 3.
* @author guiguito
*/
public class GuitarHero3GuiTest extends javax.swing.JFrame implements WiimoteListener {
private Wiimote wiimote;
private static int MAX_WHAMMY_BAR = 100;
/** Creates new form GuitarHeroGUITest */
public GuitarHero3GuiTest(Wiimote wiimote) {
initComponents();
this.wiimote = wiimote;
whammyProgressBar.setMaximum(MAX_WHAMMY_BAR);
registerListeners();
}
private void registerListeners() {
wiimote.addWiiMoteEventListeners(this);
//register panel buttons
wiimote.addWiiMoteEventListeners(guitarHero3ButtonsEventPanel);
//register joystick panel
wiimote.addWiiMoteEventListeners(guitarHero3JoystickPanel);
}
public void unRegisterListeners() {
wiimote.removeWiiMoteEventListeners(this);
wiimote.removeWiiMoteEventListeners(guitarHero3ButtonsEventPanel);
wiimote.removeWiiMoteEventListeners(guitarHero3JoystickPanel);
}
/** 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() {
buttonsEventPanel = new javax.swing.JPanel();
guitarHero3ButtonsEventPanel = new wiiusej.utils.GuitarHero3ButtonsEventPanel();
bottomPanel = new javax.swing.JPanel();
guitarHero3JoystickPanel = new wiiusej.utils.GuitarHeroJoystickEventPanel();
whammyProgressBar = new javax.swing.JProgressBar();
setTitle("WiiuseJ Guitar Hero 3 Test GUI");
getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.Y_AXIS));
buttonsEventPanel.setBackground(new java.awt.Color(0, 0, 0));
javax.swing.GroupLayout buttonsEventPanelLayout = new javax.swing.GroupLayout(buttonsEventPanel);
buttonsEventPanel.setLayout(buttonsEventPanelLayout);
buttonsEventPanelLayout.setHorizontalGroup(
buttonsEventPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 526, Short.MAX_VALUE)
.addGroup(buttonsEventPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(buttonsEventPanelLayout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(guitarHero3ButtonsEventPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
);
buttonsEventPanelLayout.setVerticalGroup(
buttonsEventPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 96, Short.MAX_VALUE)
.addGroup(buttonsEventPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(buttonsEventPanelLayout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(guitarHero3ButtonsEventPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
);
getContentPane().add(buttonsEventPanel);
bottomPanel.setBackground(new java.awt.Color(0, 0, 0));
bottomPanel.setLayout(new javax.swing.BoxLayout(bottomPanel, javax.swing.BoxLayout.X_AXIS));
bottomPanel.add(guitarHero3JoystickPanel);
whammyProgressBar.setBackground(new java.awt.Color(255, 255, 255));
whammyProgressBar.setForeground(new java.awt.Color(255, 0, 255));
bottomPanel.add(whammyProgressBar);
getContentPane().add(bottomPanel);
pack();
}// </editor-fold>//GEN-END:initComponents
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
// nothing to do
}
public void onIrEvent(IREvent arg0) {
// nothing to do
}
public void onMotionSensingEvent(MotionSensingEvent arg0) {
// nothing to do
}
public void onExpansionEvent(ExpansionEvent arg0) {
if (arg0 instanceof GuitarHeroEvent) {
GuitarHeroEvent guitar = (GuitarHeroEvent) arg0;
//move progress bar for whammy bar
whammyProgressBar.setValue(Math.round(MAX_WHAMMY_BAR*guitar.getWhammyBar()));
}
}
public void onStatusEvent(StatusEvent arg0) {
// nothing to do
}
public void onDisconnectionEvent(DisconnectionEvent arg0) {
// nothing to do
}
public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
// nothing to do
}
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
// nothing to do
}
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {
// nothing to do
}
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {
// nothing to do
}
public void onClassicControllerInsertedEvent(ClassicControllerInsertedEvent arg0) {
// nothing to do
}
public void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent arg0) {
// nothing to do
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel bottomPanel;
private javax.swing.JPanel buttonsEventPanel;
private wiiusej.utils.GuitarHero3ButtonsEventPanel guitarHero3ButtonsEventPanel;
private wiiusej.utils.GuitarHeroJoystickEventPanel guitarHero3JoystickPanel;
private javax.swing.JProgressBar whammyProgressBar;
// End of variables declaration//GEN-END:variables
}

View File

@@ -0,0 +1,45 @@
/**
* This file is part of WiiuseJ.
*
* WiiuseJ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WiiuseJ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
*/
package wiiusej.test;
import wiiusej.WiiUseApiManager;
import wiiusej.Wiimote;
/**
* Main Class to launch WiiuseJ GUI Test.
*
* @author guiguito
*/
public class Main {
/**
* @param args
* the command line arguments
*/
public static void main(String[] args) {
Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1, true);
WiiuseJGuiTest gui = null;
if (wiimotes.length > 0) {
gui = new WiiuseJGuiTest(wiimotes[0]);
} else {
gui = new WiiuseJGuiTest();
}
gui.setDefaultCloseOperation(WiiuseJGuiTest.EXIT_ON_CLOSE);
gui.setVisible(true);
}
}

View File

@@ -0,0 +1,450 @@
/**
* This file is part of WiiuseJ.
*
* WiiuseJ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WiiuseJ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
*/
package wiiusej.test;
import wiiusej.Wiimote;
import wiiusej.utils.AccelerationExpansionEventPanel;
import wiiusej.utils.AccelerationPanel;
import wiiusej.utils.GForceExpansionEventPanel;
import wiiusej.utils.GForcePanel;
import wiiusej.utils.NunchukJoystickEventPanel;
import wiiusej.utils.OrientationExpansionEventPanel;
import wiiusej.utils.OrientationPanel;
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.NunchukButtonsEvent;
import wiiusej.wiiusejevents.physicalevents.NunchukEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
import wiiusej.wiiusejevents.utils.WiimoteListener;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
/**
* This frame is used to display events from a nunchuk.
*
* @author guiguito
*/
public class NunchukGuiTest extends javax.swing.JFrame implements
WiimoteListener {
private Wiimote wiimote;
private boolean isThresholdsRequested = true;
/** Creates new form NunchukGuiTest */
public NunchukGuiTest(Wiimote wiimote) {
initComponents();
this.wiimote = wiimote;
registerListeners();
}
private void registerListeners() {
wiimote.addWiiMoteEventListeners(this);
wiimote.addWiiMoteEventListeners((OrientationPanel) orientationPanel);
wiimote.addWiiMoteEventListeners((GForcePanel) gForcePanel);
wiimote
.addWiiMoteEventListeners((AccelerationPanel) rawAccelerationPanel);
wiimote
.addWiiMoteEventListeners((NunchukJoystickEventPanel) joystickEventsPanel);
}
public void unRegisterListeners() {
wiimote
.removeWiiMoteEventListeners((OrientationPanel) orientationPanel);
wiimote.removeWiiMoteEventListeners((GForcePanel) gForcePanel);
wiimote
.removeWiiMoteEventListeners((AccelerationPanel) rawAccelerationPanel);
wiimote
.removeWiiMoteEventListeners((NunchukJoystickEventPanel) joystickEventsPanel);
wiimote.removeWiiMoteEventListeners(this);
}
public void requestThresholdsUpdate() {
isThresholdsRequested = true;
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated
// <editor-fold defaultstate="collapsed" desc="Generated
// Code">//GEN-BEGIN:initComponents
private void initComponents() {
topPanels = new javax.swing.JPanel();
joystickEventsPanel = new NunchukJoystickEventPanel();
motionSensingEventsPanel = new javax.swing.JPanel();
motionSensingEventsTabbedPanels = new javax.swing.JTabbedPane();
rawAccelerationPanel = new AccelerationExpansionEventPanel();
orientationPanel = new OrientationExpansionEventPanel();
gForcePanel = new GForceExpansionEventPanel();
setNunchukValuesPanel = new javax.swing.JPanel();
nunchukButtonsEventPanel = new javax.swing.JPanel();
cButton = new javax.swing.JButton();
zButton = new javax.swing.JButton();
nunchukOrientationPanel = new javax.swing.JPanel();
nunchukOrientationTextField = new javax.swing.JTextField();
nunchukOrientationButton = new javax.swing.JButton();
nunchukAccelerationPanel = new javax.swing.JPanel();
nunchukAccelerationTextField = new javax.swing.JTextField();
nunchukAccelerationButton = new javax.swing.JButton();
messagePanel = new javax.swing.JPanel();
messageText = new javax.swing.JLabel();
setTitle("WiiuseJ Nunchuk Test GUI");
setMinimumSize(new java.awt.Dimension(400, 400));
getContentPane().setLayout(
new javax.swing.BoxLayout(getContentPane(),
javax.swing.BoxLayout.Y_AXIS));
topPanels.setMinimumSize(new java.awt.Dimension(400, 200));
topPanels.setPreferredSize(new java.awt.Dimension(400, 200));
topPanels.setLayout(new javax.swing.BoxLayout(topPanels,
javax.swing.BoxLayout.LINE_AXIS));
joystickEventsPanel.setBackground(new java.awt.Color(0, 0, 0));
joystickEventsPanel.setBorder(javax.swing.BorderFactory
.createTitledBorder(new javax.swing.border.LineBorder(
new java.awt.Color(51, 153, 0), 2, true),
"Joystick View",
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
javax.swing.border.TitledBorder.DEFAULT_POSITION,
new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(
204, 102, 0)));
joystickEventsPanel.setToolTipText("JoystickEvent");
joystickEventsPanel.setMinimumSize(new java.awt.Dimension(200, 200));
javax.swing.GroupLayout joystickEventsPanelLayout = new javax.swing.GroupLayout(
joystickEventsPanel);
joystickEventsPanel.setLayout(joystickEventsPanelLayout);
joystickEventsPanelLayout.setHorizontalGroup(joystickEventsPanelLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 601, Short.MAX_VALUE));
joystickEventsPanelLayout.setVerticalGroup(joystickEventsPanelLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 174, Short.MAX_VALUE));
topPanels.add(joystickEventsPanel);
joystickEventsPanel.getAccessibleContext()
.setAccessibleName("Joystick");
motionSensingEventsPanel
.setMinimumSize(new java.awt.Dimension(200, 200));
rawAccelerationPanel.setToolTipText("Nunchuk MotionSensingEvent");
javax.swing.GroupLayout rawAccelerationPanelLayout = new javax.swing.GroupLayout(
rawAccelerationPanel);
rawAccelerationPanel.setLayout(rawAccelerationPanelLayout);
rawAccelerationPanelLayout
.setHorizontalGroup(rawAccelerationPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 597, Short.MAX_VALUE));
rawAccelerationPanelLayout.setVerticalGroup(rawAccelerationPanelLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 175, Short.MAX_VALUE));
motionSensingEventsTabbedPanels.addTab("RawAcceleration",
rawAccelerationPanel);
javax.swing.GroupLayout orientationPanelLayout = new javax.swing.GroupLayout(
orientationPanel);
orientationPanel.setLayout(orientationPanelLayout);
orientationPanelLayout.setHorizontalGroup(orientationPanelLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 597, Short.MAX_VALUE));
orientationPanelLayout.setVerticalGroup(orientationPanelLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 175, Short.MAX_VALUE));
motionSensingEventsTabbedPanels.addTab("Orientation", orientationPanel);
javax.swing.GroupLayout gForcePanelLayout = new javax.swing.GroupLayout(
gForcePanel);
gForcePanel.setLayout(gForcePanelLayout);
gForcePanelLayout.setHorizontalGroup(gForcePanelLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 597, Short.MAX_VALUE));
gForcePanelLayout.setVerticalGroup(gForcePanelLayout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 175, Short.MAX_VALUE));
motionSensingEventsTabbedPanels.addTab("GForce", gForcePanel);
javax.swing.GroupLayout motionSensingEventsPanelLayout = new javax.swing.GroupLayout(
motionSensingEventsPanel);
motionSensingEventsPanel.setLayout(motionSensingEventsPanelLayout);
motionSensingEventsPanelLayout
.setHorizontalGroup(motionSensingEventsPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(motionSensingEventsTabbedPanels,
javax.swing.GroupLayout.DEFAULT_SIZE, 602,
Short.MAX_VALUE));
motionSensingEventsPanelLayout
.setVerticalGroup(motionSensingEventsPanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(motionSensingEventsTabbedPanels,
javax.swing.GroupLayout.DEFAULT_SIZE, 200,
Short.MAX_VALUE));
topPanels.add(motionSensingEventsPanel);
getContentPane().add(topPanels);
setNunchukValuesPanel.setMinimumSize(new java.awt.Dimension(400, 200));
setNunchukValuesPanel
.setPreferredSize(new java.awt.Dimension(400, 200));
setNunchukValuesPanel.setLayout(new javax.swing.BoxLayout(
setNunchukValuesPanel, javax.swing.BoxLayout.Y_AXIS));
nunchukButtonsEventPanel.setToolTipText("Nunchuk ButtonsEvent");
nunchukButtonsEventPanel
.setMinimumSize(new java.awt.Dimension(100, 100));
nunchukButtonsEventPanel.setPreferredSize(new java.awt.Dimension(100,
100));
nunchukButtonsEventPanel.setLayout(new javax.swing.BoxLayout(
nunchukButtonsEventPanel, javax.swing.BoxLayout.LINE_AXIS));
cButton.setText("C");
cButton.setMaximumSize(new java.awt.Dimension(50, 50));
cButton.setMinimumSize(new java.awt.Dimension(50, 50));
cButton.setPreferredSize(new java.awt.Dimension(50, 50));
nunchukButtonsEventPanel.add(cButton);
zButton.setText("Z");
zButton.setMaximumSize(new java.awt.Dimension(50, 50));
zButton.setMinimumSize(new java.awt.Dimension(50, 50));
zButton.setPreferredSize(new java.awt.Dimension(50, 50));
nunchukButtonsEventPanel.add(zButton);
setNunchukValuesPanel.add(nunchukButtonsEventPanel);
nunchukOrientationTextField.setPreferredSize(new java.awt.Dimension(60,
20));
nunchukOrientationPanel.add(nunchukOrientationTextField);
nunchukOrientationButton.setText("Set Orientation Threshold");
nunchukOrientationButton
.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
nunchukOrientationButtonMousePressed(evt);
}
});
nunchukOrientationPanel.add(nunchukOrientationButton);
setNunchukValuesPanel.add(nunchukOrientationPanel);
nunchukAccelerationTextField.setPreferredSize(new java.awt.Dimension(
60, 20));
nunchukAccelerationPanel.add(nunchukAccelerationTextField);
nunchukAccelerationButton.setText("Set Acceleration Threshold");
nunchukAccelerationButton
.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
nunchukAccelerationButtonMousePressed(evt);
}
});
nunchukAccelerationPanel.add(nunchukAccelerationButton);
setNunchukValuesPanel.add(nunchukAccelerationPanel);
messageText.setText("Message:");
javax.swing.GroupLayout messagePanelLayout = new javax.swing.GroupLayout(
messagePanel);
messagePanel.setLayout(messagePanelLayout);
messagePanelLayout
.setHorizontalGroup(messagePanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 1216, Short.MAX_VALUE)
.addGroup(
messagePanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
messagePanelLayout
.createSequentialGroup()
.addGap(0, 0,
Short.MAX_VALUE)
.addComponent(
messageText)
.addGap(0, 0,
Short.MAX_VALUE))));
messagePanelLayout
.setVerticalGroup(messagePanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 34, Short.MAX_VALUE)
.addGroup(
messagePanelLayout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
messagePanelLayout
.createSequentialGroup()
.addGap(0, 0,
Short.MAX_VALUE)
.addComponent(
messageText)
.addGap(0, 0,
Short.MAX_VALUE))));
setNunchukValuesPanel.add(messagePanel);
getContentPane().add(setNunchukValuesPanel);
pack();
}// </editor-fold>//GEN-END:initComponents
private void nunchukOrientationButtonMousePressed(
java.awt.event.MouseEvent evt) {// GEN-FIRST:event_nunchukOrientationButtonMousePressed
try {
float nb = Float.parseFloat(nunchukOrientationTextField.getText());
wiimote.setNunchukOrientationThreshold(nb);
messageText.setText("Nunchuk orientation threshold set to " + nb);
} catch (NumberFormatException e) {
messageText
.setText("Number is not an integer, nunchuk orientation threshold not set !");
}
}// GEN-LAST:event_nunchukOrientationButtonMousePressed
private void nunchukAccelerationButtonMousePressed(
java.awt.event.MouseEvent evt) {// GEN-FIRST:event_nunchukAccelerationButtonMousePressed
try {
int nb = Integer.parseInt(nunchukAccelerationTextField.getText());
wiimote.setNunchukAccelerationThreshold(nb);
messageText.setText("Nunchuk acceleration threshold set to " + nb);
} catch (NumberFormatException e) {
messageText
.setText("Number is not an integer, nunchuk acceleration threshold not set !");
}
}// GEN-LAST:event_nunchukAccelerationButtonMousePressed
public void onButtonsEvent(WiimoteButtonsEvent arg0) {
// nothing to do
}
public void onIrEvent(IREvent arg0) {
// nothing to do
}
public void onMotionSensingEvent(MotionSensingEvent arg0) {
// nothing to do
}
public void onExpansionEvent(ExpansionEvent arg0) {
if (arg0 instanceof NunchukEvent) {
NunchukEvent nunchuk = (NunchukEvent) arg0;
NunchukButtonsEvent buttons = nunchuk.getButtonsEvent();
//C button
if (buttons.isButtonCJustPressed()) {
cButton.setEnabled(false);
}else if (buttons.isButtonCJustReleased()) {
cButton.setEnabled(true);
}
//Z button
if(buttons.isButtonZJustPressed()) {
zButton.setEnabled(false);
}else if (buttons.isButtonZJustReleased()) {
zButton.setEnabled(true);
}
if (isThresholdsRequested) {
MotionSensingEvent evt = nunchuk.getNunchukMotionSensingEvent();
nunchukAccelerationTextField.setText(evt
.getAccelerationThreshold()
+ "");
nunchukOrientationTextField.setText(evt
.getOrientationThreshold()
+ "");
isThresholdsRequested = false;
}
}
}
public void onStatusEvent(StatusEvent arg0) {
// nothing to do
}
public void onDisconnectionEvent(DisconnectionEvent arg0) {
// nothing
}
public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {
// nothing
}
public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {
// nothing
}
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {
// nothing
}
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {
// nothing
}
public void onClassicControllerInsertedEvent(
ClassicControllerInsertedEvent arg0) {
// nothing
}
public void onClassicControllerRemovedEvent(
ClassicControllerRemovedEvent arg0) {
// nothing
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cButton;
private javax.swing.JPanel gForcePanel;
private javax.swing.JPanel joystickEventsPanel;
private javax.swing.JPanel messagePanel;
private javax.swing.JLabel messageText;
private javax.swing.JPanel motionSensingEventsPanel;
private javax.swing.JTabbedPane motionSensingEventsTabbedPanels;
private javax.swing.JButton nunchukAccelerationButton;
private javax.swing.JPanel nunchukAccelerationPanel;
private javax.swing.JTextField nunchukAccelerationTextField;
private javax.swing.JPanel nunchukButtonsEventPanel;
private javax.swing.JButton nunchukOrientationButton;
private javax.swing.JPanel nunchukOrientationPanel;
private javax.swing.JTextField nunchukOrientationTextField;
private javax.swing.JPanel orientationPanel;
private javax.swing.JPanel rawAccelerationPanel;
private javax.swing.JPanel setNunchukValuesPanel;
private javax.swing.JPanel topPanels;
private javax.swing.JButton zButton;
// End of variables declaration//GEN-END:variables
}

View File

@@ -0,0 +1,389 @@
/**
* This file is part of WiiuseJ.
*
* WiiuseJ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WiiuseJ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WiiuseJ. If not, see <http://www.gnu.org/licenses/>.
*/
package wiiusej.test;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import wiiusej.WiiUseApiManager;
import wiiusej.Wiimote;
import wiiusej.values.IRSource;
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
import wiiusej.wiiusejevents.utils.WiimoteListener;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
/**
* This class used to test WiiuseJ in text mode.
*
* @author guiguito
*/
public class Tests implements WiimoteListener {
Robot robot;
private static int DISPLAY_EACH_VALUE = 1;
private static int DUMP = 2;
private static int MOVE_MOUSE = 3;
private static int TEST_LEDS = 5;
private Wiimote wiimote;
int dump = DISPLAY_EACH_VALUE;
public Tests(Wiimote wim) {
wiimote = wim;
wiimote.addWiiMoteEventListeners(this);
try {
robot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
}
public void onButtonsEvent(WiimoteButtonsEvent e) {
if (dump == DISPLAY_EACH_VALUE) {
// System.out.println("*********** WIIMOTE ID : "+
// e.getWiimoteId() + " **************");
/* button ONE */
if (e.isButtonOneJustPressed()) {
System.out.println("button one pressed");
}
if (e.isButtonOneHeld()) {
System.out.println("button one held");
}
if (e.isButtonOneJustReleased()) {
System.out.println("button one released");
}
/* button TWO */
if (e.isButtonTwoJustPressed()) {
System.out.println("button two pressed");
}
if (e.isButtonTwoHeld()) {
System.out.println("button two held");
}
if (e.isButtonTwoJustReleased()) {
System.out.println("button two released");
}
/* button A */
if (e.isButtonAJustPressed()) {
System.out.println("button A pressed");
}
if (e.isButtonAHeld()) {
System.out.println("button A held");
}
if (e.isButtonAJustReleased()) {
System.out.println("button A released");
}
/* button B */
if (e.isButtonBJustPressed()) {
System.out.println("button B pressed");
}
if (e.isButtonBHeld()) {
System.out.println("button B held");
}
if (e.isButtonBJustReleased()) {
System.out.println("button B released");
}
/* button LEFT */
if (e.isButtonLeftJustPressed()) {
System.out.println("button Left pressed");
}
if (e.isButtonLeftHeld()) {
System.out.println("button Left held");
}
if (e.isButtonLeftJustReleased()) {
System.out.println("button Left released");
}
/* button RIGHT */
if (e.isButtonRightJustPressed()) {
System.out.println("button Right pressed");
}
if (e.isButtonRightHeld()) {
System.out.println("button Right held");
}
if (e.isButtonRightJustReleased()) {
System.out.println("button Right released");
}
/* button UP */
if (e.isButtonUpJustPressed()) {
System.out.println("button UP pressed");
}
if (e.isButtonUpHeld()) {
System.out.println("button UP held");
}
if (e.isButtonUpJustReleased()) {
System.out.println("button UP released");
}
/* button DOWN */
if (e.isButtonDownJustPressed()) {
System.out.println("button DOWN pressed");
}
if (e.isButtonDownHeld()) {
System.out.println("button DOWN held");
}
if (e.isButtonDownJustReleased()) {
System.out.println("button DOWN released");
}
/* button MINUS */
if (e.isButtonMinusJustPressed()) {
System.out.println("button MINUS pressed");
}
if (e.isButtonMinusHeld()) {
System.out.println("button MINUS held");
}
if (e.isButtonMinusJustReleased()) {
System.out.println("button MINUS released");
}
/* button PLUS */
if (e.isButtonPlusJustPressed()) {
System.out.println("button PLUS pressed");
}
if (e.isButtonPlusHeld()) {
System.out.println("button PLUS held");
}
if (e.isButtonPlusJustReleased()) {
System.out.println("button PLUS released");
}
/* button HOME */
if (e.isButtonHomeJustPressed()) {
System.out.println("button HOME pressed");
}
if (e.isButtonHomeHeld()) {
System.out.println("button HOME held");
}
if (e.isButtonHomeJustReleased()) {
System.out.println("button HOME released");
}
/* get status */
if (e.isButtonUpJustPressed()) {
wiimote.getStatus();
}
/* Activate rumble */
if (e.isButtonOneJustPressed()) {
System.out.println("Rumble Activated");
wiimote.activateRumble();
}
if (e.isButtonTwoJustPressed()) {
System.out.println("Rumble Deactivated");
wiimote.deactivateRumble();
}
/* Activate IR Tracking */
if (e.isButtonAJustPressed()) {
System.out.println("IR Activated");
wiimote.activateIRTRacking();
}
if (e.isButtonBJustPressed()) {
System.out.println("IR Deactivated");
wiimote.deactivateIRTRacking();
}
/* Activate Motion sensing */
if (e.isButtonPlusJustPressed()) {
System.out.println("Motion sensing Activated");
wiimote.activateMotionSensing();
}
if (e.isButtonMinusJustPressed()) {
System.out.println("Motion sensing Deactivated");
wiimote.deactivateMotionSensing();
}
/* leave test */
if (e.isButtonHomeJustPressed()) {
System.out.println("LEAVING TEST");
wiimote.disconnect();
WiiUseApiManager.definitiveShutdown();
}
} else if (dump == DUMP) {
System.out.println(e);
/* Activate all */
if (e.isButtonAJustPressed()) {
System.out.println("IR, rumble and motion sensing Activated");
wiimote.activateIRTRacking();
wiimote.activateMotionSensing();
wiimote.activateRumble();
}
if (e.isButtonBJustPressed()) {
System.out.println("IR, rumble and motion sensing Deactivated");
wiimote.deactivateIRTRacking();
wiimote.deactivateMotionSensing();
wiimote.deactivateRumble();
}
/* leave test */
if (e.isButtonHomeJustPressed()) {
System.out.println("LEAVING TEST");
wiimote.disconnect();
}
} else if (dump == MOVE_MOUSE) {
/* Activate IR Tracking */
if (e.isButtonOneJustPressed()) {
System.out.println("IR Activated");
wiimote.activateIRTRacking();
}
if (e.isButtonTwoJustPressed()) {
System.out.println("IR Deactivated");
wiimote.deactivateIRTRacking();
}
/* button A */
if (e.isButtonAJustPressed()) {
robot.mousePress(InputEvent.BUTTON1_MASK);
}
if (e.isButtonAJustReleased()) {
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
/* button B */
if (e.isButtonBJustPressed()) {
robot.mousePress(InputEvent.BUTTON2_MASK);
}
if (e.isButtonBJustReleased()) {
robot.mouseRelease(InputEvent.BUTTON2_MASK);
}
/* leave test */
if (e.isButtonHomeJustPressed()) {
System.out.println("LEAVING TEST");
wiimote.disconnect();
}
} else if (dump == TEST_LEDS) {
wiimote.activateMotionSensing();
if (e.isButtonUpJustPressed()) {
wiimote.setLeds(true, false, false, false);
}
if (e.isButtonDownJustPressed()) {
wiimote.setLeds(false, true, false, false);
}
if (e.isButtonLeftJustPressed()) {
wiimote.setLeds(false, false, true, false);
}
if (e.isButtonRightJustPressed()) {
wiimote.setLeds(false, false, false, true);
}
/* leave test */
if (e.isButtonHomeJustPressed()) {
System.out.println("LEAVING TEST");
wiimote.disconnect();
}
}
}
public void onIrEvent(IREvent e) {
if (dump == MOVE_MOUSE) {
IRSource[] list = e.getIRPoints();
if (list.length > 0) {
int x1 = (int) list[0].getX();
int y1 = (int) list[0].getY();
int mousex = (int) Math.round(((double) x1 / 1024.0) * 1280.0);
int mousey = (int) Math.round(((double) y1 / 768.0) * 1024.0);
robot.mouseMove(mousex, mousey);
}
} else {
System.out.println(e);
}
}
public void onMotionSensingEvent(MotionSensingEvent e) {
/* display motion sensing */
System.out.println(e);
}
public void onExpansionEvent(ExpansionEvent e) {
System.out.println(e);
}
public void onStatusEvent(StatusEvent e) {
// Display status variables
System.out.println(e);
}
public void onDisconnectionEvent(DisconnectionEvent e) {
System.out.println(" wiimote " + e.getWiimoteId()
+ "has been disconnected !!");
}
public void onNunchukInsertedEvent(NunchukInsertedEvent e) {
System.out.println(e);
}
public void onNunchukRemovedEvent(NunchukRemovedEvent e) {
System.out.println(e);
}
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent e) {
System.out.println(e);
}
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent e) {
System.out.println(e);
}
public void onClassicControllerInsertedEvent(
ClassicControllerInsertedEvent e) {
System.out.println(e);
}
public void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent e) {
System.out.println(e);
}
/**
* @param args
*/
public static void main(String[] args) {
Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1, true);
if (wiimotes.length > 0) {
System.out.println(wiimotes[0]);
new Tests(wiimotes[0]);
} else {
System.out.println("No wiimotes found !!!");
}
// java.util.Timer timer = new java.util.Timer();
// timer.scheduleAtFixedRate(new LedsTask(), 0, 100);
}
}

File diff suppressed because it is too large Load Diff