Author Topic: hook callbacks for Wiimote update  (Read 2746 times)

Offline TL

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
hook callbacks for Wiimote update
« on: November 24, 2012, 07:50:39 AM »
The Wiimote demo shows all hook calls to register callbacks appearing in the same method and initialize a callback to update a single Wiimote controller.  Is it possible to register callbacks to update multiple Wiimote states?

I have written a C++ wrapper class to encapsulate wclWiimote and an OnUpdate method then I create an array of four.
After successfully, connecting each wiimote, I invoke the hook calls to register the OnUpdate callback, but I am doing so within
my wrapper class once per instance rather than in a main method that loads the WCL.

my_wrapper::connect()
... same connect code as in Wiimote demo for MS HID protocol...discovery and connect report success for one Wiimote.
  __hook(&wcl::CwclWiimote::OnChanged, &myWclWiimote, &my_wrapper::Wiimote::OnChanged);

Are there any restrictions on when, where, or how many times code can hook the OnChanged method?

One difference I see is that I am trying to wrap the hook call rather than doing all of the hook calls immediately after loading WCL.

Thanks

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3055
  • Karma: 1000
    • Soft Service Company
Re: hook callbacks for Wiimote update
« Reply #1 on: November 24, 2012, 10:48:54 AM »
Hello,

I am really sorry but I afraid I didn't clear understand what you want to do.

Offline TL

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: hook callbacks for Wiimote update
« Reply #2 on: November 24, 2012, 07:33:40 PM »
Mike,

Sorry for the confusion. 

What I am trying to do is initialize the OnChanged callback to send updated status to between 1 and 4 instances of my own class that contains a wclWiimote and its current button state.

1) After one code module loads WCL and initializes callbacks for discovery, can a separate module or class invoke __hook(&wcl::CwclWiimote::OnChanged, &myWiimote, &myCustomWiimote::OnChanged) so that object myWiimote, an instance of user-defined class myCustomWiimote will receive on-changed callback events?

2) Can the second parameter of the above __hook call be a user-defined class that contains a member variable of type wcl::wclWiimote or must the second parameter be a wcl::wclWiimote object?

3) Can this hook call be invoked multiple times, once per each separate wcl::wiimote object to process updates on multiple wiimotes?

Thank you

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3055
  • Karma: 1000
    • Soft Service Company
Re: hook callbacks for Wiimote update
« Reply #3 on: November 24, 2012, 07:55:52 PM »
So as I aunderstood you have your own class wrapped CwclWiimote. You have 4 instances (up to 4 instances) of your class so each instance of your class has own instance of CwclWiimote.  In this case each instance of your class calls __hook for CwclWiimote hooks only events from THIS own instance of CwclWiimote. So in this case:

1. Yes.
2. No, Second parameter must be instance of the CwclWiimote
3. Yes of course (be sure you call unhook all hooks) but each hook call must have different second parameter instance. For example: if you have 4 instances of CwclWiimote you can call hook for all 4 instances to the one routine but with different instances. Example code:

__hook(&wcl::CwclWiimote::OnChanged, &WCL_Wiimote_Class_Instance_1, &myCustomWiimote::OnChanged)
__hook(&wcl::CwclWiimote::OnChanged, &WCL_Wiimote_Class_Instance_2, &myCustomWiimote::OnChanged)
__hook(&wcl::CwclWiimote::OnChanged, &WCL_Wiimote_Class_Instance_3, &myCustomWiimote::OnChanged)
__hook(&wcl::CwclWiimote::OnChanged, &WCL_Wiimote_Class_Instance_4, &myCustomWiimote::OnChanged)

then in myCustomWiimote::OnChanged function you can check which instance is called by (void* pSender) parameter (which is pointer to instance fires event).

 

Sitemap 1 2 3 4 5 6 7 8 9