From ea603d01fdc86f1a1e6c52a865151f9b05685d2b Mon Sep 17 00:00:00 2001 From: "guilhem.duche" Date: Mon, 10 Mar 2008 20:59:36 +0000 Subject: [PATCH] last small modifications git-svn-id: http://wiiusej.googlecode.com/svn/trunk@85 ae48ae66-6a45-0410-b38e-211266189506 --- WiiUseJ/src/wiiusej/WiiUseApi.java | 3 +- WiiUseJ/src/wiiusej/WiiUseApiManager.java | 17 +++-- WiiUseJ/src/wiiusej/Wiimote.java | 10 ++- .../src/wiiusej/test/CloseGuiTestCleanly.java | 65 +++++++++++++++++++ WiiUseJ/src/wiiusej/test/WiiuseJGuiTest.java | 3 + 5 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 WiiUseJ/src/wiiusej/test/CloseGuiTestCleanly.java diff --git a/WiiUseJ/src/wiiusej/WiiUseApi.java b/WiiUseJ/src/wiiusej/WiiUseApi.java index cb91767..f9be625 100644 --- a/WiiUseJ/src/wiiusej/WiiUseApi.java +++ b/WiiUseJ/src/wiiusej/WiiUseApi.java @@ -32,7 +32,7 @@ public class WiiUseApi { /** * Get the only instance of WiiUseApi. - * @return + * @return the only instace of WiiUseApi. */ static WiiUseApi getInstance(){ return instance; @@ -55,7 +55,6 @@ public class WiiUseApi { /** * Shutdown Wiiuse API. - * @return 0 if there is an error, 1 if everything is ok. */ native void shutdownApi(); diff --git a/WiiUseJ/src/wiiusej/WiiUseApiManager.java b/WiiUseJ/src/wiiusej/WiiUseApiManager.java index aab1409..647fbd8 100644 --- a/WiiUseJ/src/wiiusej/WiiUseApiManager.java +++ b/WiiUseJ/src/wiiusej/WiiUseApiManager.java @@ -100,8 +100,6 @@ public class WiiUseApiManager extends Thread { nbMaxWiimotes = nb; if (connected < 0) { connected = wiiuse.doConnections(nb); - // @TODO - System.out.println(connected + " wiimote(s) connected !!!"); return connected; } else {// library not loaded, no wiimotes connected return 0; @@ -119,7 +117,7 @@ public class WiiUseApiManager extends Thread { wiimotes[id - 1] = null; requests.add(new WiiUseApiRequest(id, 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. */ public void shutdown() { + if (connected > 0) { + for (Wiimote wim : wiimotes) { + if (wim != null) + wim.disconnect(); + } + } running.set(false); wiiuse.shutdownApi(); } @@ -306,8 +310,7 @@ public class WiiUseApiManager extends Thread { requests.add(new FloatValueRequest(id, WiiUseApiRequest.WIIUSE_ALPHA_SMOOTHING_REQUEST, th)); } - - //@TODO not used yet !! + /** * Try to resync with the wiimote by starting a new handshake. * @@ -433,8 +436,8 @@ public class WiiUseApiManager extends Thread { connected--; if (connected == 0) {// stop this thread if there is // no more wiimotes connected. - System.out - .println("No more wiimotes connected !!!"); + // System.out.println("No more wiimotes connected + // !!!"); shutdown(); } } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_STATUS_REQUEST) { diff --git a/WiiUseJ/src/wiiusej/Wiimote.java b/WiiUseJ/src/wiiusej/Wiimote.java index 4108c70..f04e66c 100644 --- a/WiiUseJ/src/wiiusej/Wiimote.java +++ b/WiiUseJ/src/wiiusej/Wiimote.java @@ -24,6 +24,7 @@ import wiiusej.wiiuseapievents.GenericEvent; import wiiusej.wiiuseapievents.WiiUseApiEvent; import wiiusej.wiiuseapievents.WiiUseApiListener; import wiiusej.wiiuseapievents.WiimoteListener; +import wiiusej.wiiuseapirequest.WiiUseApiRequest; /** * Class that represents a wiimote. @@ -41,7 +42,7 @@ public class Wiimote implements WiiUseApiListener { /** - * Contructor. + * Constructor. * @param idd id of the wiimote * @param manager manager wo built it. */ @@ -213,7 +214,12 @@ public class Wiimote implements WiiUseApiListener { 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. diff --git a/WiiUseJ/src/wiiusej/test/CloseGuiTestCleanly.java b/WiiUseJ/src/wiiusej/test/CloseGuiTestCleanly.java new file mode 100644 index 0000000..ae136bf --- /dev/null +++ b/WiiUseJ/src/wiiusej/test/CloseGuiTestCleanly.java @@ -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 . + */ +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 + } + +} diff --git a/WiiUseJ/src/wiiusej/test/WiiuseJGuiTest.java b/WiiUseJ/src/wiiusej/test/WiiuseJGuiTest.java index 014f306..8bac8ae 100644 --- a/WiiUseJ/src/wiiusej/test/WiiuseJGuiTest.java +++ b/WiiUseJ/src/wiiusej/test/WiiuseJGuiTest.java @@ -60,6 +60,7 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements WiimoteListene wiimote.setScreenAspectRatio169(); wiimote.setSensorBarBelowScreen(); getStatusButtonMousePressed(null); + this.addWindowListener(new CloseGuiTestCleanly(wiimote)); } public void onButtonsEvent(ButtonsEvent arg0) { @@ -220,6 +221,8 @@ public class WiiuseJGuiTest extends javax.swing.JFrame implements WiimoteListene messageText = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("WiiuseJ Test GUI"); + setName("WiiuseJ Test GUI"); // NOI18N leftPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());