BrianPeek.com

A Compendium of Random Uselessness
in Search

Multiple Wiimotes without using WiimoteCollection

Last post Wed, Jul 30 2008 8:00 AM by Caio. 13 replies.
Page 1 of 1 (14 items)
Sort Posts: Previous Next
  • Tue, Jul 29 2008 9:26 AM

    • Caio
    • Top 10 Contributor
      Male
    • Joined on Thu, Jun 12 2008
    • São Paulo, SP
    • Posts 19

    Multiple Wiimotes without using WiimoteCollection

    Hi,

    I'm developing a C# program with my own classes. One class that I've created is called Camera which inherits from Wiimote class. My Camera class calls Connect() on its constructor and Disconnect() on its destructor. Then I have another class called Watcher which creates an array of Cameras. So when I instantiate the latter it creates two Cameras which is supposed to connect automatically.

    Until now I have only one Wiimote Controler (device) so I cannot foresee what will happen, that's why I'm posting here, therefore my question is if on the described situation each Camera would automatically connect on the correct Wiimote or not.

    This is more about how the Wiimote.Connect() class works for example, if there are 10 Wiimote devices, 8 being used and 2 free. If I instantiate two Camera classes, will each of one connect on the 2 available devices automatically or I have to do that my own, if the latter is needed how it could be done

    Regards.

  • Tue, Jul 29 2008 1:40 PM In reply to

    • Zee
    • Top 25 Contributor
      Male
    • Joined on Thu, Jul 24 2008
    • Denmark
    • Posts 8

    Re: Multiple Wiimotes without using WiimoteCollection

    I haven't tried it but my guess it that it will connect to device 1 each time you call it.
    But why don't you just pass a reference to the device you want to use in the "Camera" constructor, using WimoteCollection[x] from the Watcher class?

  • Tue, Jul 29 2008 1:44 PM In reply to

    • Caio
    • Top 10 Contributor
      Male
    • Joined on Thu, Jun 12 2008
    • São Paulo, SP
    • Posts 19

    Re: Multiple Wiimotes without using WiimoteCollection

    "But why don't you just pass a reference to the device you want to use in the "Camera" constructor, using WimoteCollection[x] from the Watcher class?"

    Watcher does not have a WiimoteCollection. It just has two Cameras (Camera[2]) which are two Wiimote classes.

  • Tue, Jul 29 2008 2:14 PM In reply to

    • Zee
    • Top 25 Contributor
      Male
    • Joined on Thu, Jul 24 2008
    • Denmark
    • Posts 8

    Re: Multiple Wiimotes without using WiimoteCollection

    No maybe it doesn't, but if it already includes the lib ("using WiimoteLib"), is there then any reasion why you shouldn't do e.g. like this:

    WiimoteCollection col = new WiimoteCollection();
    Camera[ cameras =
    new Camera[ { new Camera(col[0]), new Camera(col[1]) };

    Or if does not include it then you might just do it..

  • Tue, Jul 29 2008 2:27 PM In reply to

    • Caio
    • Top 10 Contributor
      Male
    • Joined on Thu, Jun 12 2008
    • São Paulo, SP
    • Posts 19

    Re: Multiple Wiimotes without using WiimoteCollection

    Hi Zee,

    I can manage my code to do exactly what you just said, I agree with you that it will work, but the thing is that I have a project in my hands (Class Diagram) and I'm trying to make things fit perfectly on it, until now evertyhing is going wonderfully.

    The point I'm trying to get is if it would work if I do not use the WiimoteCollection, just as I mentioned before. It is not that I abominate WiimoteCollection, but it would not let me implement the project as it is structured, please don't ask me why :-)

    Regards.
  • Tue, Jul 29 2008 3:58 PM In reply to

    Re: Multiple Wiimotes without using WiimoteCollection

    Zee is correct above.  Calling Connect() will always find and connect to the first device in the HID list.
  • Tue, Jul 29 2008 4:04 PM In reply to

    • Caio
    • Top 10 Contributor
      Male
    • Joined on Thu, Jun 12 2008
    • São Paulo, SP
    • Posts 19

    Re: Multiple Wiimotes without using WiimoteCollection

    Hi Brian,

    So let's say for example I have 2 wiimote devices available and then I instantiate two Camera classes which themselves inherit from Wiimote, both will get connected to the right wiimote?

    class Camera : Wiimote
    {
        Camera()
        {
            Connect();
        }
        ~Camera()
        {
            Disconnect();
        }
    }

  • Tue, Jul 29 2008 4:06 PM In reply to

    Re: Multiple Wiimotes without using WiimoteCollection

    No, both will find the first Wiimote in the HID device list and connect to it.  That is, you'll get two instances of the same Wiimote.

    At the moment, the only way to use multiple Wiimotes is via the WiimoteCollection object.

  • Tue, Jul 29 2008 6:33 PM In reply to

    Re: Multiple Wiimotes without using WiimoteCollection

    actually, before Brain (misspelling intentional (: ) updated his library to handle multiple Wiimotes, I made a modification to the connect function that will in fact connecting to multiple Wiimotes one by one, going up the HID list. I'm not at my home PC at the moment so i can get the code here, but it was a very small hack (i think 2 lines) nad it was something like this (warning I dont know the variable names off the top of my head) open up the wiimote.cs and get to the Connect funtion body. find a variable thats called something like index. Make that a static variable. Now find out where Brian actually find a wiimote. And is about the exit the function. Quickly add 1 to the index variable before returning. Why it works: You should already know... the static variable type does all the work! When Wiimote1.connect() is called it starts at index 0 and keeps adding 1 until it find a wiimote. Because the variable is static, the next time you enter the function with wiimote2.Connect(), index will NOT be 0 but instead the same number it was after the previous call, wiimote2 will then search for a the first wiimote it can find in the HID. Just think of it as a global, which it practically is, but it's scope is still only with in Wiimote::Connect(). The second change is obviously needed so that you don't attempt to connect to the index that worked before. Beware: This is a hack. Not very bullet proof. If you disconnect and reconnected that static index aint going to find the wiimote again, it'll just keep going up up and up until... something happens. If you want to solve this make disconnect set a static bool inside the wiimote class. Next time you call connected, connect should check the bool and if true, set index back to 0. There are still problems, like you call disconnect on wiimote2() then connected on Wiimote2.()... what happens, Wiimote2() connects to Wiimote1()... darn! This is why Brian made a WiimoteCollection() class. It does all this stupid managing for you, so you can connect and disconnect and reconnect all you want. Something strange: I did try to store the index with in the Wiimote class. Then when I call connect again, it checks if that variable has a value and if it does try connecting to that index (cause the index should never change... right....) apparently I was wrong. Cause it simply did not work... ): Happy Hacking! ~Quinn
  • Tue, Jul 29 2008 6:34 PM In reply to

    Re: Multiple Wiimotes without using WiimoteCollection

    wtf!!! can someone teach how to put in paragraphs... is it two lines test... ~Quinn
  • Tue, Jul 29 2008 6:36 PM In reply to

    Re: Multiple Wiimotes without using WiimoteCollection

    Quinn's idea is a good one if you absolutely need it without WiimoteCollection.  I'll think about doing something like this in a future version so one can use multiple Wiimotes without WiimoteCollection.

  • Tue, Jul 29 2008 6:40 PM In reply to

    Re: Multiple Wiimotes without using WiimoteCollection

    And the paragraph thing isn't you...it's the stupid plain text editor setup for the anonymous user.  I tried tried changing it to the "enhanced" editor.  I think that will help.  Try creating a reply to this with multiple lines and you should see a new editor.

    If not, sign up with a real acct and you definitely will.

  • Tue, Jul 29 2008 6:52 PM In reply to

    • GameQ
    • Top 50 Contributor
    • Joined on Tue, Jul 29 2008
    • Posts 4

    Re: Multiple Wiimotes without using WiimoteCollection

    (reposted with formatting) 

    actually, before Brain (misspelling intentional Smile ) updated his library to handle multiple Wiimotes, I made a modification to the connect function that will in fact connecting to multiple Wiimotes one by one, going up the HID list. I'm not at my home PC at the moment so i can get the code here, but it was a very small hack (i think 2 lines) nad it was something like this

    (warning I dont know the variable names off the top of my head) open up the wiimote.cs and get to the Connect funtion body. find a variable thats called something like index. Make that a static variable. Now find out where Brian actually find a wiimote. And is about the exit the function. Quickly add 1 to the index variable before returning.

    Why it works: You should already know... the static variable type does all the work! When Wiimote1.connect() is called it starts at index 0 and keeps adding 1 until it find a wiimote. Because the variable is static, the next time you enter the function with wiimote2.Connect(), index will NOT be 0 but instead the same number it was after the previous call, wiimote2 will then search for a the first wiimote it can find in the HID. Just think of it as a global, which it practically is, but it's scope is still only with in Wiimote::Connect(). The second change is obviously needed so that you don't attempt to connect to the index that worked before.

    Beware: This is a hack. Not very bullet proof. If you disconnect and reconnected that static index aint going to find the wiimote again, it'll just keep going up up and up until... something happens. If you want to solve this make disconnect set a static bool inside the wiimote class. Next time you call connected, connect should check the bool and if true, set index back to 0. There are still problems, like you call disconnect on wiimote2() then connected on Wiimote2.()... what happens, Wiimote2() connects to Wiimote1()... darn! This is why Brian made a WiimoteCollection() class. It does all this stupid managing for you, so you can connect and disconnect and reconnect all you want.

    Something strange: I did try to store the index with in the Wiimote class. Then when I call connect again, it checks if that variable has a value and if it does try connecting to that index (cause the index should never change... right....) apparently I was wrong. Cause it simply did not work... ):

    Happy Hacking!

    ~Quinn

  • Wed, Jul 30 2008 8:00 AM In reply to

    • Caio
    • Top 10 Contributor
      Male
    • Joined on Thu, Jun 12 2008
    • São Paulo, SP
    • Posts 19

    Re: Multiple Wiimotes without using WiimoteCollection

    Hello Quinn,

    Your idea could be used, but yesterday I decided to add the WiimoteCollection inside my Watcher class (the same thing which comes with the example on the WiimoteLibrary) removing the Camera class from the project. It is working pretty well.

    I don't want to customize the WiimoteLibrary because if I do, on newer releases, I'd have to perform all changes again.

    Maybe in future releases of it Brian (or Brain :P) could make this treatment.

    Regards,

Page 1 of 1 (14 items)
Copyright (C) 2008 Brian Peek
Powered by Community Server (Commercial Edition), by Telligent Systems