| View previous topic :: View next topic |
| Author |
Message |
diplomat
Joined: 15 Sep 2007 Posts: 20
Digg It |
Posted: Wed Oct 10, 2007 4:35 pm Post subject: Multiple Remotes |
|
|
Hey everybody...I am trying to connect more than one wiimote to the lib.
but somehow I don't really get it working.
Maybe somebody can help my by writing a little example for me.
Greetz |
|
| Back to top |
|
 |
Classiclll
Joined: 10 Feb 2007 Posts: 92 Location: Japan
Digg It |
Posted: Thu Oct 11, 2007 4:16 am Post subject: |
|
|
in wrj4P5(sample implimentation of WiiRemoteJ), the following code runs well.
(This is one of samples, as you know. and not tested)
| Code: | public class Wrj4P5 implements WiiRemoteDiscoveryListener {
public PApplet parent;
public static int rCount;// the number of WiiRemotes connected.(at most 7)
private static WiiRimokon[] rims = new WiiRimokon[7];// connected WiiRemotes(at most 7)
public Wrj4P5(PApplet parent) {
this.parent = parent;
for (int i=0;i<7;i++) rims[i]=new WiiRimokon(this);
}
public Wrj4P5 connect() {
return this.connect(1);
}
public Wrj4P5 connect(long n) {
return this.connect(n, false, false);
}
public Wrj4P5 connect(long n, boolean ir) {
return this.connect(n, ir, false);
}
public Wrj4P5 connect(long n, boolean ir, boolean log)
{
try {
if (log) {WiiRemoteJ.setConsoleLoggingAll();}
else {WiiRemoteJ.setConsoleLoggingOff();}
WiiRemoteJ.findRemotes(this, (int) (0<n&&n<8 ? n : 1));
System.out.println("trying to find a wii");
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return this;
}
public void wiiRemoteDiscovered(WiiRemoteDiscoveredEvent evt) {
int id = evt.getNumber();
WiiRemote found = evt.getWiiRemote();
found.addWiiRemoteListener(rims[id]);
rims[id].addTalker(found,id,isIR);
System.out.println("Discover called # " + id);
}
public void findFinished(int numberFound) {
rCount = numberFound;
}
public boolean isConnecting() {
if (rCount>0) return false;
return true;
}
}
/*************************/
public class WiiRimokon extends WiiRemoteAdapter
{
private Wrj4P5 parent;
private WiiRemote talker;
private int myId;
public WiiRimokon(Wrj4P5 wii)
{
super();
this.parent = wii;
}
public WiiRemote addTalker(WiiRemote talker, int id, boolean ir)
{
myId = id;
this.talker = talker;
try {
if (ir) talker.setIRSensorEnabled(true, WRIREvent.BASIC);
talker.setAccelerometerEnabled(true);
talker.setSpeakerEnabled(true);
talker.setLEDLights(isIlluminated);
} catch(Exception e) {e.printStackTrace();}
return talker;
}
} |
_________________ Classiclll |
|
| Back to top |
|
 |
catalytic
Joined: 24 Mar 2008 Posts: 5
Digg It |
Posted: Mon Mar 24, 2008 7:40 am Post subject: |
|
|
Hi all,
I am trying to get more than one WiiMote receiving button inputs, nothing else.
I have had a look at this example and it is not making a lot of sense when running as an applet (or a PApplet? Processing . org?)
Is it possible to see one that is not using an applet?
I was wondering if someone could explain the correct order the wiimotes need to be initialised in, eg.
1. create WiiRemoteDiscoveryListener
2. find remotes.
3. add wiiRemote Listener to the remotes found.
etc? |
|
| Back to top |
|
 |
Classiclll
Joined: 10 Feb 2007 Posts: 92 Location: Japan
Digg It |
Posted: Mon Mar 24, 2008 1:36 pm Post subject: |
|
|
hi catalytic.
PApplet depends only my implementation, never mind.
my point is
1. one instance for one wiiremote. | Code: |
private static WiiRimokon[] rims = new WiiRimokon[7];
and
for (int i=0;i<7;i++) rims[i]=new WiiRimokon(this); |
2. for each findRemoteEvent, assign a listner corresponding found number. | Code: |
int id = evt.getNumber();
WiiRemote found = evt.getWiiRemote();
found.addWiiRemoteListener(rims[id]); |
is this the answer of your question? _________________ Classiclll |
|
| Back to top |
|
 |
catalytic
Joined: 24 Mar 2008 Posts: 5
Digg It |
Posted: Thu May 01, 2008 8:15 am Post subject: |
|
|
-edit
Last edited by catalytic on Thu May 01, 2008 10:43 am; edited 1 time in total |
|
| Back to top |
|
 |
catalytic
Joined: 24 Mar 2008 Posts: 5
Digg It |
Posted: Thu May 01, 2008 8:44 am Post subject: |
|
|
er ignore all that.
I now have a separate class to run as a driver.
| Code: | import wiiremotej.WiiRemote;
import wiiremotej.WiiRemoteJ;
import wiiremotej.event.WRIREvent;
import wiiremotej.event.WiiRemoteDiscoveredEvent;
import wiiremotej.event.WiiRemoteDiscoveryListener;
public class wiiMoteServer {
public static void main(String[] args) {
// TODO Auto-generated method stub
try
{
Wrj4P5 test = new Wrj4P5();
test.connect(2, false, true);
}
catch(Exception e){e.printStackTrace();}
}
}
|
which is now syncing two remotes, and returning button presses for one of them.
I have
| Code: | public void buttonInputReceived(WRButtonEvent evt)
{
if (evt.isPressed(WRButtonEvent.TWO))System.out.println("2");
if (evt.isPressed(WRButtonEvent.ONE))System.out.println("1");
if (evt.isPressed(WRButtonEvent.B))System.out.println("B");
if (evt.isPressed(WRButtonEvent.A))System.out.println("A");
if (evt.isPressed(WRButtonEvent.MINUS))System.out.println("Minus");
if (evt.isPressed(WRButtonEvent.HOME))System.out.println("Home");
if (evt.isPressed(WRButtonEvent.LEFT))System.out.println("Left");
if (evt.isPressed(WRButtonEvent.RIGHT))System.out.println("Right");
if (evt.isPressed(WRButtonEvent.DOWN))System.out.println("Down");
if (evt.isPressed(WRButtonEvent.UP))System.out.println("Up");
if (evt.isPressed(WRButtonEvent.PLUS))System.out.println("Plus");
/**/
} |
Inside WiiRimokon.
But it is still only picking up one remote.
Last edited by catalytic on Thu May 01, 2008 10:44 am; edited 1 time in total |
|
| Back to top |
|
 |
catalytic
Joined: 24 Mar 2008 Posts: 5
Digg It |
Posted: Thu May 01, 2008 10:42 am Post subject: |
|
|
All working now.
It seems there is a problem between mac osx and wiiremotej.
If I go to System Preferences>Bluetooth and delete any WiiMote entries (Nintendo RVL-CNT-01)
Then run, program works perfect.
If there is already an entry in System Preferences>Bluetooth, then program throws the following error:
| Code: |
BlueCove version 2.0.2-SNAPSHOT on mac
trying to find a wii
May 1, 2008 8:09:54 PM wiiremotej.WiiRemoteDiscoverer deviceDiscovered
FINE: Found Nintendo RVL-CNT-01 (00191DC619B2)
May 1, 2008 8:09:54 PM wiiremotej.WiiRemoteDiscoverer deviceDiscovered
FINE: Nintendo RVL-CNT-01 is a WiiRemote.
May 1, 2008 8:09:58 PM wiiremotej.WiiRemote construct
INFO: btl2cap://00191DC619B2
May 1, 2008 8:09:59 PM wiiremotej.WiiRemoteDiscoverer getWiiRemote
SEVERE: Error getting device!
java.io.IOException: WiiRemote failed to connect!
at wiiremotej.WiiRemote.construct(WiiRemote.java:301)
at wiiremotej.WiiRemote.<init>(WiiRemote.java:214)
at wiiremotej.WiiRemoteDiscoverer.getWiiRemote(WiiRemoteDiscoverer.java:94)
at wiiremotej.WiiRemoteJ.findRemote(WiiRemoteJ.java:208)
at wiiremotej.WiiRemoteJ.access$100(WiiRemoteJ.java:22)
at wiiremotej.WiiRemoteJ$2.run(WiiRemoteJ.java:284)
at java.lang.Thread.run(Thread.java:613)
Caused by: javax.bluetooth.BluetoothConnectionException: Failed to open connection(3)
at com.intel.bluetooth.BluetoothStackOSX.l2OpenClientConnectionImpl(Native Method)
at com.intel.bluetooth.BluetoothStackOSX.l2OpenClientConnection(BluetoothStackOSX.java:583)
at com.intel.bluetooth.BluetoothL2CAPClientConnection.<init>(BluetoothL2CAPClientConnection.java:32)
at com.intel.bluetooth.MicroeditionConnector.openImpl(MicroeditionConnector.java:393)
at com.intel.bluetooth.MicroeditionConnector.open(MicroeditionConnector.java:502)
at javax.microedition.io.Connector.open(Connector.java:95)
at wiiremotej.WiiRemote.construct(WiiRemote.java:295)
... 6 more
May 1, 2008 8:10:16 PM wiiremotej.WiiRemote construct
|
Is there anyway around this? Maybe a way of forcing the mac osx NOT to store the sync'd devices? |
|
| Back to top |
|
 |
|