last small modifications
git-svn-id: http://wiiusej.googlecode.com/svn/trunk@85 ae48ae66-6a45-0410-b38e-211266189506
This commit is contained in:
@@ -32,7 +32,7 @@ public class WiiUseApi {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the only instance of WiiUseApi.
|
* Get the only instance of WiiUseApi.
|
||||||
* @return
|
* @return the only instace of WiiUseApi.
|
||||||
*/
|
*/
|
||||||
static WiiUseApi getInstance(){
|
static WiiUseApi getInstance(){
|
||||||
return instance;
|
return instance;
|
||||||
@@ -55,7 +55,6 @@ public class WiiUseApi {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Shutdown Wiiuse API.
|
* Shutdown Wiiuse API.
|
||||||
* @return 0 if there is an error, 1 if everything is ok.
|
|
||||||
*/
|
*/
|
||||||
native void shutdownApi();
|
native void shutdownApi();
|
||||||
|
|
||||||
|
|||||||
@@ -100,8 +100,6 @@ public class WiiUseApiManager extends Thread {
|
|||||||
nbMaxWiimotes = nb;
|
nbMaxWiimotes = nb;
|
||||||
if (connected < 0) {
|
if (connected < 0) {
|
||||||
connected = wiiuse.doConnections(nb);
|
connected = wiiuse.doConnections(nb);
|
||||||
// @TODO
|
|
||||||
System.out.println(connected + " wiimote(s) connected !!!");
|
|
||||||
return connected;
|
return connected;
|
||||||
} else {// library not loaded, no wiimotes connected
|
} else {// library not loaded, no wiimotes connected
|
||||||
return 0;
|
return 0;
|
||||||
@@ -119,7 +117,7 @@ public class WiiUseApiManager extends Thread {
|
|||||||
wiimotes[id - 1] = null;
|
wiimotes[id - 1] = null;
|
||||||
requests.add(new WiiUseApiRequest(id,
|
requests.add(new WiiUseApiRequest(id,
|
||||||
WiiUseApiRequest.WIIUSE_CLOSE_CONNECTION_REQUEST));
|
WiiUseApiRequest.WIIUSE_CLOSE_CONNECTION_REQUEST));
|
||||||
System.out.println("Wiimote " + id + " disconnected !");
|
// System.out.println("Wiimote " + id + " disconnected !");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -135,6 +133,12 @@ public class WiiUseApiManager extends Thread {
|
|||||||
* Stop thread and shutdown wiiuse Api.
|
* Stop thread and shutdown wiiuse Api.
|
||||||
*/
|
*/
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
|
if (connected > 0) {
|
||||||
|
for (Wiimote wim : wiimotes) {
|
||||||
|
if (wim != null)
|
||||||
|
wim.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
running.set(false);
|
running.set(false);
|
||||||
wiiuse.shutdownApi();
|
wiiuse.shutdownApi();
|
||||||
}
|
}
|
||||||
@@ -306,8 +310,7 @@ public class WiiUseApiManager extends Thread {
|
|||||||
requests.add(new FloatValueRequest(id,
|
requests.add(new FloatValueRequest(id,
|
||||||
WiiUseApiRequest.WIIUSE_ALPHA_SMOOTHING_REQUEST, th));
|
WiiUseApiRequest.WIIUSE_ALPHA_SMOOTHING_REQUEST, th));
|
||||||
}
|
}
|
||||||
|
|
||||||
//@TODO not used yet !!
|
|
||||||
/**
|
/**
|
||||||
* Try to resync with the wiimote by starting a new handshake.
|
* Try to resync with the wiimote by starting a new handshake.
|
||||||
*
|
*
|
||||||
@@ -433,8 +436,8 @@ public class WiiUseApiManager extends Thread {
|
|||||||
connected--;
|
connected--;
|
||||||
if (connected == 0) {// stop this thread if there is
|
if (connected == 0) {// stop this thread if there is
|
||||||
// no more wiimotes connected.
|
// no more wiimotes connected.
|
||||||
System.out
|
// System.out.println("No more wiimotes connected
|
||||||
.println("No more wiimotes connected !!!");
|
// !!!");
|
||||||
shutdown();
|
shutdown();
|
||||||
}
|
}
|
||||||
} else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_STATUS_REQUEST) {
|
} else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_STATUS_REQUEST) {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import wiiusej.wiiuseapievents.GenericEvent;
|
|||||||
import wiiusej.wiiuseapievents.WiiUseApiEvent;
|
import wiiusej.wiiuseapievents.WiiUseApiEvent;
|
||||||
import wiiusej.wiiuseapievents.WiiUseApiListener;
|
import wiiusej.wiiuseapievents.WiiUseApiListener;
|
||||||
import wiiusej.wiiuseapievents.WiimoteListener;
|
import wiiusej.wiiuseapievents.WiimoteListener;
|
||||||
|
import wiiusej.wiiuseapirequest.WiiUseApiRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that represents a wiimote.
|
* Class that represents a wiimote.
|
||||||
@@ -41,7 +42,7 @@ public class Wiimote implements WiiUseApiListener {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contructor.
|
* Constructor.
|
||||||
* @param idd id of the wiimote
|
* @param idd id of the wiimote
|
||||||
* @param manager manager wo built it.
|
* @param manager manager wo built it.
|
||||||
*/
|
*/
|
||||||
@@ -213,7 +214,12 @@ public class Wiimote implements WiiUseApiListener {
|
|||||||
manager.setVirtualResolution(id, x ,y);
|
manager.setVirtualResolution(id, x ,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO resync ?
|
/**
|
||||||
|
* Try to resync the wiimote by starting a new handshake.
|
||||||
|
*/
|
||||||
|
public void reSync() {
|
||||||
|
manager.reSync(id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ask for the status of the wiimote.
|
* Ask for the status of the wiimote.
|
||||||
|
|||||||
65
WiiUseJ/src/wiiusej/test/CloseGuiTestCleanly.java
Normal file
65
WiiUseJ/src/wiiusej/test/CloseGuiTestCleanly.java
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
import wiiusej.Wiimote;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is used to close wiiusej cleanly.
|
||||||
|
* @author guiguito
|
||||||
|
*/
|
||||||
|
public class CloseGuiTestCleanly implements WindowListener{
|
||||||
|
|
||||||
|
Wiimote wiimote;
|
||||||
|
|
||||||
|
|
||||||
|
public CloseGuiTestCleanly(Wiimote wim) {
|
||||||
|
wiimote = wim;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void windowOpened(WindowEvent e) {
|
||||||
|
//nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
WiiUseApiManager.getInstance().shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -60,6 +60,7 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements WiimoteListene
|
|||||||
wiimote.setScreenAspectRatio169();
|
wiimote.setScreenAspectRatio169();
|
||||||
wiimote.setSensorBarBelowScreen();
|
wiimote.setSensorBarBelowScreen();
|
||||||
getStatusButtonMousePressed(null);
|
getStatusButtonMousePressed(null);
|
||||||
|
this.addWindowListener(new CloseGuiTestCleanly(wiimote));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onButtonsEvent(ButtonsEvent arg0) {
|
public void onButtonsEvent(ButtonsEvent arg0) {
|
||||||
@@ -220,6 +221,8 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements WiimoteListene
|
|||||||
messageText = new javax.swing.JLabel();
|
messageText = new javax.swing.JLabel();
|
||||||
|
|
||||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
setTitle("WiiuseJ Test GUI");
|
||||||
|
setName("WiiuseJ Test GUI"); // NOI18N
|
||||||
|
|
||||||
leftPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
|
leftPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user