Hello Guest it is March 28, 2024, 06:54:52 PM

Author Topic: Wiimote plugin  (Read 10723 times)

0 Members and 1 Guest are viewing this topic.

Offline rcrabb

*
  •  146 146
    • View Profile
Wiimote plugin
« on: December 29, 2009, 05:09:51 PM »
I'm working on a wiimote plugin for mach. Im using Ed's plugin wizard and the wiiuse lib. First I must say Ed did a fantastic job with this wizard and the videos gave my a huge leap forward with my learning curve. I have connected the wiimote to mach and displayed limited data in a dialog. Now Im stuck. The code below works great.

   WiiMoteStatus^   wiimotestatus = MG::wiimotestatus;
   WiiMoteConfig^   wiimoteconfig = MG::wiimoteconfig;
   wiimote** wiimotes;
   
   wiimotes =  wiiuse_init(wiimoteconfig->maxwiimotes);   // Send the max wiimotes to init (max of 1)
   

//--------------------------------------------------------------------
//   find and connect to the wiimotes
//--------------------------------------------------------------------

if (MG::wiimotestatus) // crashes without this line. learned the hard way
{
   if (!wiimotestatus->found)   // if we found one wiimote stop looking
   {
      wiimotestatus->found = wiiuse_find(wiimotes, wiimoteconfig->maxwiimotes, 10);   // We look for wiimotes (max of one, look for 10sec)

   }
   if (!wiimotestatus->connected)   //   if we are connected dont try to connect
   {
      wiimotestatus->connected = wiiuse_connect(wiimotes, wiimoteconfig->maxwiimotes);



Now my problem is in the next part-------------------------------------------------------------------------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>


      wiiuse_poll(wiimotes, 1);

      wiiuse_motion_sensing(wiimotes[0], 1);

      wiimotestatus->roll = wiimotes[0]->orient.roll;

      
      if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_A))
      {
         wiimotestatus->debug = (true);
 



Everything compiles ok but mach crashes. Now wiiuse_poll is the function to poll the data from the wiiuse dll. it seems im having trouble getting to arrays of data returned.

I hope someone has an idea.
« Last Edit: December 29, 2009, 05:15:30 PM by rcrabb »
Ryan

Offline ART

*
  • *
  •  1,702 1,702
  • Tough as soggy paper.
    • View Profile
Re: Wiimote plugin
« Reply #1 on: December 29, 2009, 09:14:32 PM »
Hi:

>>wiimotestatus->connected = wiiuse_connect(wiimotes, wiimoteconfig->maxwiimotes);
Now my problem is in the next part-------------------------------------------------------------------------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>
     wiiuse_poll(wiimotes, 1);
     wiiuse_motion_sensing(wiimotes[0], 1);
     wiimotestatus->roll = wiimotes[0]->orient.roll;
 
   ....

   Im not familiar with the wii motes calls, but it seems to me youd want to check to make sure the connection worked by checking
 is true or not before calling poll, and after calling connect..

Art


   

Offline rcrabb

*
  •  146 146
    • View Profile
Re: Wiimote plugin
« Reply #2 on: December 29, 2009, 10:03:52 PM »
Thanks Art.
 
Ill try that. What kills me is that I get that 9988 error and mach blows up. I have to reboot my computer everytime. And if I dont reboot after some time I get the blue screen. I will say im just learning c++ .NET and I have a long way to go. I was very exited when I got the wiimote connected and toggled one of the wiimote's leds. Now I hit a wall and need help. 
Ryan

Offline ART

*
  • *
  •  1,702 1,702
  • Tough as soggy paper.
    • View Profile
Re: Wiimote plugin
« Reply #3 on: December 29, 2009, 10:51:49 PM »
Hi:

 Yeah, Fatal errors tend to do that.. better then the old days of instant blue screen though. Take out a few lines to find what line exactly is causing it. Your code is assuming sucessfull completion by the look of it, if the calls dont properly send you a pointer to the remote though, youll end up querying a null pointer.. and that may be the cause of your trouble..

Art

Offline ART

*
  • *
  •  1,702 1,702
  • Tough as soggy paper.
    • View Profile
Re: Wiimote plugin
« Reply #4 on: December 29, 2009, 10:52:49 PM »
If it were me, Id breakpoint on the poll line and check the contents of the wiimotes[0] variable..

Art

Offline rcrabb

*
  •  146 146
    • View Profile
Re: Wiimote plugin
« Reply #5 on: December 29, 2009, 11:16:22 PM »
This line crashed me.  wiimotes =  wiiuse_init(wiimoteconfig->maxwiimotes);

wiimoteconfig->maxwiimotes was the null. I added it and forgot that wiimoteconfig doesnt get gcnew till after postinit.

Now i need to figure out why I dont see any data after the poll. I cant get my code to run in debug so this will be a chalenge.
Ryan

Offline rcrabb

*
  •  146 146
    • View Profile
Re: Wiimote plugin
« Reply #6 on: December 30, 2009, 11:17:11 AM »
I set a breakpoint at the poll line. There is no data in the wiimotes[0]. Now my code sets the first led on the wiimote after it connects so the wiiuse dll must be working. But I cant poll any data.
Ryan

Offline rcrabb

*
  •  146 146
    • View Profile
Re: Wiimote plugin
« Reply #7 on: December 30, 2009, 04:04:15 PM »
Found my problem. I was sending an init call to the dll causing my variables to get wiped out. Now I have a new prob.

My array for the wiimote data is setup with this line.
wiimote** wiimotes;
wiimotes =  wiiuse_init(2);  <--------size of the array

But the data is gone after each pass through the code.

If i change it to this line.
static wiimote** wiimotes;
wiimotes =  wiiuse_init(2);  <--------size of the array

The data stays but the array is only one element. Now this is ok because I only plan to connect one wiimote but I would like to know the proper way to setup the arrays to work properly.
Ryan

Offline ART

*
  • *
  •  1,702 1,702
  • Tough as soggy paper.
    • View Profile
Re: Wiimote plugin
« Reply #8 on: December 30, 2009, 05:27:26 PM »
Hi :

 Seems that that would be specific to the wii dll as to function, but I suspect if more than one ispresent, that the dll will create the additional arrays..
Since its a pointer to a pointer its probably simply sending you the internal pointer to that data..

Art

Offline rcrabb

*
  •  146 146
    • View Profile
Re: Wiimote plugin
« Reply #9 on: December 31, 2009, 12:09:42 AM »
Thanks Art for your responses. I have all the accelerometer data and all buttons working. I also have the smoothing algorithm working. Of course all this is a part of the wiiuse dll and only needs to be called, for me it was a huge mountian to climb. A fun project.
Ryan