new version for linux and now you can choose if you want to make the wiimotes rumble on connections.

git-svn-id: http://wiiusej.googlecode.com/svn/trunk@111 ae48ae66-6a45-0410-b38e-211266189506
This commit is contained in:
guilhem.duche
2008-03-30 17:57:28 +00:00
parent 3223e90f40
commit 49135d88f7
5 changed files with 171 additions and 112 deletions

View File

@@ -20,192 +20,246 @@ import wiiusej.wiiuseapievents.EventsGatherer;
/** /**
* Singleton used to manipulate WiiUse Api. * Singleton used to manipulate WiiUse Api.
*
* @author guiguito * @author guiguito
*/ */
public class WiiUseApi { public class WiiUseApi {
static { static {
System.loadLibrary("libWiiuseJ"); System.loadLibrary("WiiuseJ");
} }
private static WiiUseApi instance = new WiiUseApi(); private static WiiUseApi instance = new WiiUseApi();
/** /**
* Get the only instance of WiiUseApi. * Get the only instance of WiiUseApi.
*
* @return the only instace of WiiUseApi. * @return the only instace of WiiUseApi.
*/ */
static WiiUseApi getInstance(){ static WiiUseApi getInstance() {
return instance; return instance;
} }
/** /**
* Try to connect to 2 wiimotes. Make them rumble to show they are * Try to connect to 2 wiimotes. Make them rumble to show they are
* connected. * connected.
* @param nb number of wiimotes to connect *
* @param nb
* number of wiimotes to connect
* @param rumble
* make the connected wiimotes rumble
* @return 0 if there is an error otherwise it returns the number of * @return 0 if there is an error otherwise it returns the number of
* wiimotes connected. * wiimotes connected.
*/ */
native int doConnections(int nb); native int doConnections(int nb, boolean rumble);
/** /**
* Close connection to the wiimote with the given id. * Close connection to the wiimote with the given id.
* *
*/ */
native void closeConnection(int id); native void closeConnection(int id);
/** /**
* Shutdown Wiiuse API. * Shutdown Wiiuse API.
*/ */
native void shutdownApi(); native void shutdownApi();
/** /**
* Activate rumble on the wiimote with the given id. * Activate rumble on the wiimote with the given id.
* @param id the id of the wiimote. *
* @param id
* the id of the wiimote.
*/ */
native void activateRumble(int id); native void activateRumble(int id);
/** /**
* Deactivate rumble on the wiimote with the given id. * Deactivate rumble on the wiimote with the given id.
* *
* @param id the id of the wiimote. * @param id
* the id of the wiimote.
*/ */
native void deactivateRumble(int id); native void deactivateRumble(int id);
/** /**
* Activate IR Tracking on the wiimote with the given id. * Activate IR Tracking on the wiimote with the given id.
* @param id the id of the wiimote. *
* @param id
* the id of the wiimote.
*/ */
native void activateIRTracking(int id); native void activateIRTracking(int id);
/** /**
* Deactivate IR Tracking on the wiimote with the given id. * Deactivate IR Tracking on the wiimote with the given id.
* @param id the id of the wiimote. *
* @param id
* the id of the wiimote.
*/ */
native void deactivateIRTracking(int id); native void deactivateIRTracking(int id);
/** /**
* Activate motion sensing on the wiimote with the given id. * Activate motion sensing on the wiimote with the given id.
* @param id the id of the wiimote. *
* @param id
* the id of the wiimote.
*/ */
native void activateMotionSensing(int id); native void activateMotionSensing(int id);
/** /**
* Deactivate motion sensing on the wiimote with the given id. * Deactivate motion sensing on the wiimote with the given id.
* @param id the id of the wiimote. *
* @param id
* the id of the wiimote.
*/ */
native void deactivateMotionSensing(int id); native void deactivateMotionSensing(int id);
/** /**
* Set wiimote leds status. * Set wiimote leds status.
* @param id the id of the wiimote concerned *
* @param led1 status of led1: True=ON, False=OFF * @param id
* @param led2 status of led2: True=ON, False=OFF * the id of the wiimote concerned
* @param led3 status of led3: True=ON, False=OFF * @param led1
* @param led4 status of led4: True=ON, False=OFF * status of led1: True=ON, False=OFF
* @param led2
* status of led2: True=ON, False=OFF
* @param led3
* status of led3: True=ON, False=OFF
* @param led4
* status of led4: True=ON, False=OFF
*/ */
native void setLeds(int id, boolean led1, boolean led2, boolean led3, boolean led4); native void setLeds(int id, boolean led1, boolean led2, boolean led3,
boolean led4);
/** /**
* Set how many degrees an angle must change to generate an event. * Set how many degrees an angle must change to generate an event.
* @param id id of the wiimote concerned *
* @param angle minimum angle detected by an event * @param id
* id of the wiimote concerned
* @param angle
* minimum angle detected by an event
*/ */
native void setOrientThreshold(int id, float angle); native void setOrientThreshold(int id, float angle);
/** /**
* Set how much acceleration must change to generate an event. * Set how much acceleration must change to generate an event.
* @param id id of the wiimote concerned *
* @param value minimum value detected by an event * @param id
* id of the wiimote concerned
* @param value
* minimum value detected by an event
*/ */
native void setAccelThreshold(int id, int value); native void setAccelThreshold(int id, int value);
/** /**
* Set alpha smoothing parameter for the given id. * Set alpha smoothing parameter for the given id.
* @param id id of the wiimote concerned *
* @param value alpha smoothing value * @param id
* id of the wiimote concerned
* @param value
* alpha smoothing value
*/ */
native void setAlphaSmoothing(int id, float value); native void setAlphaSmoothing(int id, float value);
/** /**
* Try to resync with the wiimote by starting a new handshake. * Try to resync with the wiimote by starting a new handshake.
* @param id id of the wiimote concerned *
* @param id
* id of the wiimote concerned
*/ */
native void reSync(int id); native void reSync(int id);
/** /**
* Make the the accelerometers give smoother results. * Make the the accelerometers give smoother results. This is set by
* This is set by default. * default.
* @param id the id of the wiimote concerned *
* @param id
* the id of the wiimote concerned
*/ */
native void activateSmoothing(int id); native void activateSmoothing(int id);
/** /**
* Make the the accelerometers give raw results. * Make the the accelerometers give raw results.
* @param id the id of the wiimote concerned *
* @param id
* the id of the wiimote concerned
*/ */
native void deactivateSmoothing(int id); native void deactivateSmoothing(int id);
/** /**
* Make the wiimote generate an event each time we poll. * Make the wiimote generate an event each time we poll. Not set by default.
* Not set by default. *
* @param id the id of the wiimote concerned * @param id
*/ * the id of the wiimote concerned
native void activateContinuous(int id); */
native void activateContinuous(int id);
/**
* Make the wiimote generate an event only when there is one. /**
* @param id the id of the wiimote concerned * Make the wiimote generate an event only when there is one.
*/ *
native void deactivateContinuous(int id); * @param id
* the id of the wiimote concerned
/** */
* Notify wiiuse that your screen has an aspect ratio of 4/3. native void deactivateContinuous(int id);
* @param id the id of the wiimote of which we want the status.
*/ /**
native void setScreenRatio43(int id); * Notify wiiuse that your screen has an aspect ratio of 4/3.
*
/** * @param id
* Notify wiiuse that your screen has an aspect ratio of 16/9. * the id of the wiimote of which we want the status.
* @param id the id of the wiimote of which we want the status. */
*/ native void setScreenRatio43(int id);
native void setScreenRatio169(int id);
/**
/** * Notify wiiuse that your screen has an aspect ratio of 16/9.
* Notify wiiuse that the sensor bar is above your screen. *
* @param id the id of the wiimote of which we want the status. * @param id
*/ * the id of the wiimote of which we want the status.
native void setSensorBarAboveScreen(int id); */
native void setScreenRatio169(int id);
/**
* Notify wiiuse that the sensor bar is below your screen. /**
* @param id the id of the wiimote of which we want the status. * Notify wiiuse that the sensor bar is above your screen.
*/ *
native void setSensorBarBelowScreen(int id); * @param id
* the id of the wiimote of which we want the status.
/** */
* Set virtual screen resolution. It is used to automatically native void setSensorBarAboveScreen(int id);
* compute the position of a cursor on this virtual screen
* using the sensor bar. These results come in the IREvent. /**
* @param id the id of the wiimote of which we want the status. * Notify wiiuse that the sensor bar is below your screen.
* @param x x resolution. *
* @param y y resolution. * @param id
*/ * the id of the wiimote of which we want the status.
native void setVirtualScreenResolution(int id, int x, int y); */
native void setSensorBarBelowScreen(int id);
/**
* Set virtual screen resolution. It is used to automatically compute the
* position of a cursor on this virtual screen using the sensor bar. These
* results come in the IREvent.
*
* @param id
* the id of the wiimote of which we want the status.
* @param x
* x resolution.
* @param y
* y resolution.
*/
native void setVirtualScreenResolution(int id, int x, int y);
/** /**
* Get status and values from the wiimotes and send it through callbacks. * Get status and values from the wiimotes and send it through callbacks.
* *
* @param id the id of the wiimote of which we want the status. * @param id
* the id of the wiimote of which we want the status.
*/ */
native void getStatus(int id); native void getStatus(int id);
/** /**
* Check for new Events and Get it. * Check for new Events and Get it.
* *
* @param gath the object where we store all the new events. * @param gath
* the object where we store all the new events.
*/ */
native void specialPoll(EventsGatherer gath); native void specialPoll(EventsGatherer gath);
} }

View File

@@ -64,12 +64,14 @@ public class WiiUseApiManager extends Thread {
* *
* @param nb * @param nb
* try to connect nb wiimotes * try to connect nb wiimotes
* @param rumble
* make the connected wiimotes rumble
* @return an array with connected wiimotes or NULL. * @return an array with connected wiimotes or NULL.
*/ */
public synchronized static Wiimote[] getWiimotes(int nb) { public synchronized static Wiimote[] getWiimotes(int nb, boolean rumble) {
WiiUseApiManager manager = getInstance(); WiiUseApiManager manager = getInstance();
if (manager.connected < 0) { if (manager.connected < 0) {
int nbWiimotes = manager.connectWiimotes(nb); int nbWiimotes = manager.connectWiimotes(nb, rumble);
manager.wiimotes = new Wiimote[nbWiimotes]; manager.wiimotes = new Wiimote[nbWiimotes];
for (int i = 1; i <= nbWiimotes; i++) { for (int i = 1; i <= nbWiimotes; i++) {
Wiimote wim = new Wiimote(i, manager); Wiimote wim = new Wiimote(i, manager);
@@ -94,12 +96,14 @@ public class WiiUseApiManager extends Thread {
* *
* @param nb * @param nb
* try to connect nb wiimotes * try to connect nb wiimotes
* @param rumble
* make the connected wiimotes rumble
* @return 0 if nothing connected or the number of wiimotes connected. * @return 0 if nothing connected or the number of wiimotes connected.
*/ */
private int connectWiimotes(int nb) { private int connectWiimotes(int nb, boolean rumble) {
nbMaxWiimotes = nb; nbMaxWiimotes = nb;
if (connected < 0) { if (connected < 0) {
connected = wiiuse.doConnections(nb); connected = wiiuse.doConnections(nb, rumble);
return connected; return connected;
} else {// library not loaded, no wiimotes connected } else {// library not loaded, no wiimotes connected
return 0; return 0;

View File

@@ -29,7 +29,7 @@ public class Main {
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main(String[] args) { public static void main(String[] args) {
Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1); Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1, true);
if (wiimotes.length>0){ if (wiimotes.length>0){
WiiuseJGuiTest gui = new WiiuseJGuiTest(wiimotes[0]); WiiuseJGuiTest gui = new WiiuseJGuiTest(wiimotes[0]);
gui.setDefaultCloseOperation(gui.EXIT_ON_CLOSE); gui.setDefaultCloseOperation(gui.EXIT_ON_CLOSE);

View File

@@ -339,7 +339,7 @@ public class Tests implements WiimoteListener {
* @param args * @param args
*/ */
public static void main(String[] args) { public static void main(String[] args) {
Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(4); Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(4, true);
if (wiimotes.length > 0) { if (wiimotes.length > 0) {
System.out.println(wiimotes[0]); System.out.println(wiimotes[0]);
Tests tests = new Tests(wiimotes[0]); Tests tests = new Tests(wiimotes[0]);

View File

@@ -131,6 +131,7 @@ public class IRPanel extends javax.swing.JPanel implements WiimoteListener {
public void onButtonsEvent(ButtonsEvent arg0) { public void onButtonsEvent(ButtonsEvent arg0) {
//nothing //nothing
repaint();
} }
public void onIrEvent(IREvent arg0) { public void onIrEvent(IREvent arg0) {