user41746: I'm trying to get two identical joystics (Saitek cyborg 3D) running with the USB-Host-Shield on a Mega 2560 and an USB-Hub.
I already get the event-messages of both of them:
#include <usbhid.h>
#include <hiduniversal.h>
#include <usbhub.h>

// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>

#include "hidjoystickrptparser.h"

USB Usb;
USBHub Hub(&Usb);
HIDUniversal Hid1(&Usb);    // first Joystick
HIDUniversal Hid2(&Usb);    // second Joystick

JoystickEvents Joy1Events;
JoystickEvents Joy2Events;

JoystickReportParser Joy1(&Joy1Events);
JoystickReportParser Joy2(&Joy2Events);

void setup() {
        Serial.begin(115200);
#if !defined(__MIPSEL__)
        while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
        Serial.println("Start");

        if (Usb.Init() == -1)
                Serial.println("OSC did not start.");

        delay(200);

        if (!Hid1.SetReportParser(0, &Joy1))
                ErrorMessage<uint8_t > (PSTR("SetReportParser1"), 1);
        if (!Hid2.SetReportParser(0, &Joy2))
                ErrorMessage<uint8_t > (PSTR("SetReportParser2"), 1);
}

void loop() {
        Usb.Task();
        Serial.print("\tX1: ");
        PrintHex<uint8_t > (JoystickEvents::mostRecentEvent.X, 0x80);
        Serial.print("\tY1: ");
        PrintHex<uint8_t > (JoystickEvents::mostRecentEvent.Y, 0x80);
        Serial.print("\tX2: ");
        PrintHex<uint8_t > (JoystickEvents::mostRecentEvent.Z1, 0x80);
        Serial.print("\tY2: ");
        PrintHex<uint8_t > (JoystickEvents::mostRecentEvent.Z2, 0x80);
        Serial.print("\tRz: ");
        PrintHex<uint8_t > (JoystickEvents::mostRecentEvent.Rz, 0x80);
        Serial.println("");

}

My question is: How can I distinguish the events from the different joysticks.
I'm trying to get some kind of port-information from the USB-Hub. Unfortunately something like 
!hid->GetAddress()

within the JoystickReportParser doesn't do the job as it always returns 0.
Any ideas?

user10394: Not quite the question that was asked but part of the problem.
This is a simple introduction to pointers.
int variable = 42;                              // Create a variable
int* pointer = &variable;                       // Create a pointer to the variable (by getting its address)
*pointer = 99;                                  // Set the address to a new value
printf ("variable has the value %d", variable); // Print 99.

&x get the address of x
*y dereferences the pointer y, which means it 'turns it back to a variable' (this is simplistic view which isn't really true, but will do for now). 
So you could, if you wanted (which you wouldn't) do this *&z which would be the same as doing z.
Basically think of & and * as a pair of complimentary operators like - and + or * and /.  (They aren't operators, but to start with it might help).
The next problem is when you do this
SomeFunction(&variable);

All function parameters in C/C++ are passed by value by default.  This means the function gets a copy of them not the actual value.  So if you had:
void FunctionOne (int val)
{
    val = 99;
}
int val = 4;
FunctionOne(val);
printf("val = %d", val);   // You will see 4 printed.

If you pass by reference then you will see 99 printed, to pass by reference you can do it one of two ways.
void FunctionTwo (int& valByRef);
void FunctionThree (int* valPointer);

FunctionTwo only works with C++ (It will work with an Arduino).
FunctionThree might cause a segmentation error if NULL is passed in and the function writes to it.
If it helps in my opinion pointers was one of the hardest concepts to grasp in classic C/C++ so don't worry if you don't understand it just have a play with it and see what you can do.
Calling Methods

object.method() - Call the function method on the instance called
object which is of type X. 
object->method() - Call the function method on the instance called
object which is a pointer of type X. 
object::method() - call the function method
which is a static member of class object (static means it doesn't
change any data within an instance of a class)
*object->method() - Avoid this like the plague.  It either means *(object->method()) or (*object)->method() to know you would need to look at the type of object and the return type of the function.  Its easier just to bracket it to remove ambiguity.

As for *object.&method() I've never come across that one, but that doesn't mean it doesn't exist. :)

41746: <p>I'm trying to get two identical joystics (Saitek cyborg 3D) running with the USB-Host-Shield on a Mega 2560 and an USB-Hub.</p>

<p>I already get the event-messages of both of them:</p>

<pre><code>#include &lt;usbhid.h&gt;
#include &lt;hiduniversal.h&gt;
#include &lt;usbhub.h&gt;

// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include &lt;spi4teensy3.h&gt;
#endif
#include &lt;SPI.h&gt;

#include "hidjoystickrptparser.h"

USB Usb;
USBHub Hub(&amp;Usb);
HIDUniversal Hid1(&amp;Usb);    // first Joystick
HIDUniversal Hid2(&amp;Usb);    // second Joystick

JoystickEvents Joy1Events;
JoystickEvents Joy2Events;

JoystickReportParser Joy1(&amp;Joy1Events);
JoystickReportParser Joy2(&amp;Joy2Events);

void setup() {
        Serial.begin(115200);
#if !defined(__MIPSEL__)
        while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
        Serial.println("Start");

        if (Usb.Init() == -1)
                Serial.println("OSC did not start.");

        delay(200);

        if (!Hid1.SetReportParser(0, &amp;Joy1))
                ErrorMessage&lt;uint8_t &gt; (PSTR("SetReportParser1"), 1);
        if (!Hid2.SetReportParser(0, &amp;Joy2))
                ErrorMessage&lt;uint8_t &gt; (PSTR("SetReportParser2"), 1);
}

void loop() {
        Usb.Task();
        Serial.print("\tX1: ");
        PrintHex&lt;uint8_t &gt; (JoystickEvents::mostRecentEvent.X, 0x80);
        Serial.print("\tY1: ");
        PrintHex&lt;uint8_t &gt; (JoystickEvents::mostRecentEvent.Y, 0x80);
        Serial.print("\tX2: ");
        PrintHex&lt;uint8_t &gt; (JoystickEvents::mostRecentEvent.Z1, 0x80);
        Serial.print("\tY2: ");
        PrintHex&lt;uint8_t &gt; (JoystickEvents::mostRecentEvent.Z2, 0x80);
        Serial.print("\tRz: ");
        PrintHex&lt;uint8_t &gt; (JoystickEvents::mostRecentEvent.Rz, 0x80);
        Serial.println("");

}
</code></pre>

<p>My question is: How can I distinguish the events from the different joysticks.</p>

<p>I'm trying to get some kind of port-information from the USB-Hub. Unfortunately something like </p>

<pre><code>!hid-&gt;GetAddress()
</code></pre>

<p>within the JoystickReportParser doesn't do the job as it always returns 0.</p>

<p>Any ideas?</p>
 10394: <p>Not quite the question that was asked but part of the problem.</p>

<p>This is a simple introduction to pointers.</p>

<pre><code>int variable = 42;                              // Create a variable
int* pointer = &amp;variable;                       // Create a pointer to the variable (by getting its address)
*pointer = 99;                                  // Set the address to a new value
printf ("variable has the value %d", variable); // Print 99.
</code></pre>

<p><code>&amp;x</code> get the address of <code>x</code></p>

<p><code>*y</code> <code>dereferences</code> the pointer y, which means it 'turns it back to a variable' (this is simplistic view which isn't really true, but will do for now). 
So you could, if you wanted (which you wouldn't) do this <code>*&amp;z</code> which would be the same as doing <code>z</code>.</p>

<p>Basically think of <code>&amp;</code> and <code>*</code> as a pair of complimentary operators like - and + or * and /.  (They aren't operators, but to start with it might help).</p>

<p>The next problem is when you do this</p>

<pre><code>SomeFunction(&amp;variable);
</code></pre>

<p>All function parameters in C/C++ are passed by value by default.  This means the function gets a copy of them not the actual value.  So if you had:</p>

<pre><code>void FunctionOne (int val)
{
    val = 99;
}
int val = 4;
FunctionOne(val);
printf("val = %d", val);   // You will see 4 printed.
</code></pre>

<p>If you pass by reference then you will see 99 printed, to pass by reference you can do it one of two ways.</p>

<pre><code>void FunctionTwo (int&amp; valByRef);
void FunctionThree (int* valPointer);
</code></pre>

<p><code>FunctionTwo</code> only works with C++ (It will work with an Arduino).</p>

<p><code>FunctionThree</code> might cause a segmentation error if NULL is passed in and the function writes to it.</p>

<p>If it helps in my opinion pointers was one of the hardest concepts to grasp in classic C/C++ so don't worry if you don't understand it just have a play with it and see what you can do.</p>

<p><strong>Calling Methods</strong></p>

<ul>
<li><code>object.method()</code> - Call the function method on the instance called
object which is of type <code>X</code>. </li>
<li><code>object-&gt;method()</code> - Call the function method on the instance called
object which is a <strong>pointer</strong> of type <code>X</code>. </li>
<li><code>object::method()</code> - call the function method
which is a static member of class object (static means it doesn't
change any data within an instance of a class)</li>
<li>*object->method() - Avoid this like the plague.  It either means <code>*(object-&gt;method())</code> or <code>(*object)-&gt;method()</code> to know you would need to look at the type of object and the return type of the function.  Its easier just to bracket it to remove ambiguity.</li>
</ul>

<p>As for <code>*object.&amp;method()</code> I've never come across that one, but that doesn't mean it doesn't exist. :)</p>
