WiiLi Wiki frontpage Include your post in the News Get links Hoteles Quito
WiiLi.org Forum Index WiiLi.org
a new revolution
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Wiimote via Java
Goto page Previous  1, 2, 3, 4 ... 29, 30, 31  Next
 
Post new topic   Reply to topic    WiiLi.org Forum Index -> WiiremoteJ
View previous topic :: View next topic  
Author Message
Cha0s
Site Admin


Joined: 17 Jan 2007
Posts: 493

Digg It
PostPosted: Mon Jan 22, 2007 10:13 pm    Post subject:

With 2, the devices would be registered on demand, however, you'd have to get references to all the WiiRemotes (you wouldn't know when this was done either) and then apply listeners. I got pissed off with the annoyance of 2, so I've moved it to 3. Now what happens is that it starts looking for WiiRemotes and returns them via a WiiRemoteDiscoveryListener.wiiRemoteDiscovered(WiiRemote remote). I know that's not quite standard in that it should probably have an event in that method (wiiRemoteDiscovered) instead of just a remote, but there really was nothing else to put in the event, so I didn't bother with it. Wink
So, if you want multiple WiiRemotes, you can do it one of two ways:
1.
Code:

ArrayList<WiiRemote> remotes = new ArrayList<WiiRemote>(7);
for (int c = 0; c < 7; c++)
{
    WiiRemote found = WiiRemoteJ.findRemote();
    if (found != null)remotes.add(found);
}

The problem with this is that it blocks (i.e. the current thread waits for a remote to be found before proceeding).

2.
Code:

ArrayList<WiiRemote> remotes = new ArrayList<WiiRemote>(7);
WiiRemoteDiscoveryListener listener = new WiiRemoteDiscoveryListener()
{
    public void wiiRemoteDiscovered(WiiRemote remote)
    {
        remotes.add(remote);
    }

    public void findFinished(int numberFound)
    {
        System.out.println("Found " + numberFound + " remotes!");
    }
};
WiiRemoteJ.findRemotes(listener);
Thread.currentThread().sleep(50000);
WiiRemoteJ.stopFind();

This allows you to do other things while waiting for the remotes to be found (in the above example, sleep), as it is nonblocking. As an added bonus, this method will never pass a null remote to the listener. You can also use: WiiRemoteJ.findRemotes(listener, numRemotes). In that case it will search until a specific number of remotes are found OR until stopFind is called. Note that a user can technically search for more than 7 remotes. As specified in the documentation, the user should not do this and it is the user's responsibility to ensure that this doesn't happen... cause if it does, it probably won't be pretty. Razz

EDIT: I did leave out some try-catches up there. Those find methods throw a host of exceptions. Razz
P.S. This library does not work by magic. You will still need a working JSR082 and JRE 1.5.0. Sad
mik, Maybe we should make a petition to Avetana complaining about their failure to support the Mac version correctly... or we can just continue sending angry emails. Smile
EDIT2: Changed my mind and made wiiRemoteDiscovered actually use an event. First, it's more standard. Second, the event can contain the number of the remote, so that the user can, for instance, set the LEDs up.
_________________
Cha0s
Back to top
View user's profile Send private message
mik



Joined: 10 Jan 2007
Posts: 26

Digg It
PostPosted: Tue Jan 23, 2007 7:47 am    Post subject:

That looks nice to me.
I already had contact with avetana, as we're having some licences.

He already send me a new jnilib as a quickfix. Looks like the connection via PSM 11 and 13 is possible now. Had not time/code to check more, though.
The problem ist that he has to sync-open, instead of async-open the connection, because PSM 11 is reserved for HID devices by the Kernel...or something.

I will be after it. Maybe it already works?! But my test code didn't receive a single byte with the fixed version. Though, that alos might be my fault.
Back to top
View user's profile Send private message
Wyrmwand



Joined: 23 Jan 2007
Posts: 6

Digg It
PostPosted: Tue Jan 23, 2007 2:31 pm    Post subject: Wii Java on a mobile...

Hi,

We started looking into these things last Friday and only found this thread today. Cool that a lot of people think the same!

What I'm trying to achieve what is a bit different to Cha0s stuff though quite similar anyway. We have a project here at work(research institute) where we want to connect one or several wiimotes to a mobile phone. For this I started look into if it would be possible and it does certainly look doable as Cha0s proven as well, though I ran into a real bummer...

Apparently according to the JSR-82 specification one is not allowed to open channels below 1001 which is really stupid! Thus my code casts exceptions if I try to open a connection to port 11 or 13 as I should do to implement the HID stuff. It would be really interesting to hear what Avetana has to say about these things. We have used their implementation on PDAs before and I got really good support from those guys.

Cha0s do you have plans to open source your code? We would be much interested in doing so with ours. It seems you have come a bit further on the Wii API while I have struggled with the communication. Another things I saw in your example code is that you use a lot of Java 1.5 stuff, that will never compile under J2ME. I would very much like to see a Java library for teh Wii that is independent whether it runs on J2SE or J2ME.
Back to top
View user's profile Send private message
Cha0s
Site Admin


Joined: 17 Jan 2007
Posts: 493

Digg It
PostPosted: Tue Jan 23, 2007 5:37 pm    Post subject:

An Avetana fix would be great, as I'd love to be able to be able do the testing on my Mac. It would speed things up considerably. Please keep me posted on that! Smile

mik: regarding your connections, when opening try the following:
L2CAPConnection controlCon = (L2CAPConnection)Connector.open("btl2cap://"+remoteBTAddress+":11", Connector.WRITE);
L2CAPConnection receiveCon = (L2CAPConnection)Connector.open("btl2cap://"+remoteBTAddress+":13", Connector.READ);

Wyrmwand, there actually isn't that much 1.5.0 stuff in my code. I'll cut what I do have out later today. In that case, you can use my library as-is, as there isn't really anything else... Oh, I need to make my ArrayList into a Vector, but other than that... On second thought, there could be an issue with the speaker, as I plan to use the Java built-in libraries for sound encoding. That's a minor issue, though. I'm sure there's an easy way to work around that.

And yes, I think I will open-source it at some point, though probably not until after the library itself is released. What I'm thinking about doing is finishing documentation and putting in a bunch of stub methods. Then I can release the docs if you guys want to start writing some code. If all goes as planned, the library should be pretty much done within the next two weeks, depending on how long it takes me to mess with IR and the Speaker. I think I'm going to jump ahead and do the extension stuff (nunchuck and classic controller) this week, since it seems to be less complicated. We'll have to see though. Smile

EDIT: I actually have an app that will revert a 1.5.0 class to 1.4.0. It's called retroweaver and it works really well. So I'll leave in Generics, etc, and then retroweave everything back to 1.4.0. Smile I did change the ArrayList for a Vector, though.
_________________
Cha0s
Back to top
View user's profile Send private message
mik



Joined: 10 Jan 2007
Posts: 26

Digg It
PostPosted: Wed Jan 24, 2007 8:33 am    Post subject:

Cha0s wrote:

mik: regarding your connections, when opening try the following:
L2CAPConnection controlCon = (L2CAPConnection)Connector.open("btl2cap://"+remoteBTAddress+":11", Connector.WRITE);
L2CAPConnection receiveCon = (L2CAPConnection)Connector.open("btl2cap://"+remoteBTAddress+":13", Connector.READ);


Opening the connection this way seems to work.
Although it doesn't seem to be very reliable.
Anyway, I am going to tell the avetana guy, and ask if he is planning to
include this fix in the normal releases.


Last edited by mik on Wed Jan 24, 2007 5:15 pm; edited 1 time in total
Back to top
View user's profile Send private message
Cadex



Joined: 25 Dec 2006
Posts: 9

Digg It
PostPosted: Wed Jan 24, 2007 9:11 am    Post subject: Re: Wii Java on a mobile...

Wyrmwand wrote:
Apparently according to the JSR-82 specification one is not allowed to open channels below 1001 which is really stupid! Thus my code casts exceptions if I try to open a connection to port 11 or 13 as I should do to implement the HID stuff.

Just yesterday a guy on a Wii developer IRC channel and I were doing the same thing. We tried for hours, but we got exactly the same results: The JSR-82 specification only allows for dynamic PSMs >= 0x1001 for L2CAP connections. I see absolutely no sense behind that restriction, but all three mobile phones we were trying seemed to strictly comply to the specification: We tried everything, but it was simply impossible to connect to the Wiimote due to this restriction.

For example we did a service discovery, and tried to connect to the Wiimote every time the ServiceRecord.getConnectionURL() did provide something.
Funny thing was: On my Wiimote this returned the connection URL "btl2cap://[bluetooth address]:13;authenticate=false;encrypt=false;master=false" (which is exactly how I connect to my Wiimote on my desktop PC, using the Avetana JSR-82 implementation, and which works fine there), but as soon as the phone tried to connect to this URL it just told me, it would throw an exception because of the PSM value... Evil or Very Mad

For example we tried the following PSM values:
13 (didn't work because the PSM value officially has to be 4 hex digits)
0013 (didn't work because the PSM value is < 0x1001)
1013 (didn't work because PSM 1013 is different from PSM 13)
1300 (we tried this because googling the web we found a post where someone claimed this might work; it didn't)
1124 (tried it because HID service class is 0x1124 and that would be a legal value, but didn't work either)
etc.

In the end we've given up, it simply doesn't seem to work with the strict JSR-82 implementation on most mobiles:
Using the Wiimote with the JSR-82 Java bluetooth extensions is currently only possible if the JSR-82 implementation being used is violating the official specification.

Maybe that's why that previous version of Avetana bluetooth for OS X didn't work either.
Back to top
View user's profile Send private message
Wyrmwand



Joined: 23 Jan 2007
Posts: 6

Digg It
PostPosted: Wed Jan 24, 2007 10:07 am    Post subject:

Cadex, had the exact same experience as you! The really annoying thing is that you get an URL from the discovery but its illegal due to the stupid restrictions in the spec!

Another thing,
Cadex wrote:
1124 (tried it because HID service class is 0x1124 and that would be a legal value, but didn't work either)
etc.

No, its not legal, from JSR-82 definition: page 87:
Legal PSM values are in the range (0x1001..0xFFFF), and the least significant byte must be odd and all other bytes must be even.

So it should have been 1125 or 1123 to be legal.

Cadex wrote:
Using the Wiimote with the JSR-82 Java bluetooth extensions is currently only possible if the JSR-82 implementation being used is violating the official specification.


Yes, I just got this confirmed by the people behind JSR-82. He was not perfectly clear with the reason but if I got it right JSR-82 was developed BEFORE the HID profile and actually before several other profiles. And at that time, no-one could see any value in allowing applications to connect to ports(PSMs) in the reserved range(0x0001 to 0x1000) and thus JSR-82 does not allow it!

So basically we can forget connecting a WiiMote to phone. In our research project we have both Sony and Nokia but I doubt I'll be able to convince them to break the specification, but I'll try:-)

mik:
Next time you talk to Avetana, could you ask if they plan to include this fix in all their stacks? E.g. would it also be available on the Windows Mobile implementation?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    WiiLi.org Forum Index -> WiiremoteJ All times are GMT
Goto page Previous  1, 2, 3, 4 ... 29, 30, 31  Next
Page 3 of 31

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group