user28802: I'm building my own quadcopter and going to use an Arduino for this. An Arduino Micro for the quadcopter and an Arduino UNO for the controller. I want to use an USB host shield with a Logitech Extreme 3D Pro to control the quadcopter. 
I have the joystick already working with de example from the USB host shield example, but I can't get the values to my void loop(). There is not much information on the internet about this. 
The link to the library and example I'm using: https://github.com/felis/USB_Host_Shield_2.0/tree/master/examples/HID/le3dp
.INO file:
/* Simplified Logitech Extreme 3D Pro Joystick Report Parser */

#include <hid.h>
#include <hiduniversal.h>
#include <usbhub.h>

#include "le3dp_rptparser.h"

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

USB                                             Usb;
USBHub                                          Hub(&Usb);
HIDUniversal                                    Hid(&Usb);
JoystickEvents                                  JoyEvents;
JoystickReportParser                            Joy(&JoyEvents);

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 (!Hid.SetReportParser(0, &Joy))
      ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1  );
}

void loop()
{
    Usb.Task();
}

.cpp file:
#include "le3dp_rptparser.h"

JoystickReportParser::JoystickReportParser(JoystickEvents *evt) :
    joyEvents(evt)
{}

void JoystickReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
{
    bool match = true;

    // Checking if there are changes in report since the method was last called
    for (uint8_t i=0; i<RPT_GAMEPAD_LEN; i++) {
        if( buf[i] != oldPad[i] ) {
            match = false;
            break;
        }
  }
    // Calling Game Pad event handler
    if (!match && joyEvents) {
        joyEvents->OnGamePadChanged((const GamePadEventData*)buf);

        for (uint8_t i=0; i<RPT_GAMEPAD_LEN; i++) oldPad[i] = buf[i];
    }
}

void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt)
{
    Serial.print("X: ");
    PrintHex<uint16_t>(evt->x, 0x80);
    Serial.print(" Y: ");
    PrintHex<uint16_t>(evt->y, 0x80);
    Serial.print(" Hat Switch: ");
    PrintHex<uint8_t>(evt->hat, 0x80);
    Serial.print(" Twist: ");
    PrintHex<uint8_t>(evt->twist, 0x80);
    Serial.print(" Slider: ");
    PrintHex<uint8_t>(evt->slider, 0x80);
    Serial.print(" Buttons A: ");
    PrintHex<uint8_t>(evt->buttons_a, 0x80);
    Serial.print(" Buttons B: ");
    PrintHex<uint8_t>(evt->buttons_b, 0x80);
    Serial.println("");
}

.h file:
#if !defined(__HIDJOYSTICKRPTPARSER_H__)
#define __HIDJOYSTICKRPTPARSER_H__

#include <hid.h>

struct GamePadEventData
{
  union { //axes and hut switch
    uint32_t axes;
    struct {
      uint32_t x : 10;
      uint32_t y : 10;
      uint32_t hat : 4;
      uint32_t twist : 8;      
    };
  };
  uint8_t buttons_a;
  uint8_t slider;
  uint8_t buttons_b;
};

class JoystickEvents
{
public:
    virtual void OnGamePadChanged(const GamePadEventData *evt);
};

#define RPT_GAMEPAD_LEN sizeof(GamePadEventData)/sizeof(uint8_t)

class JoystickReportParser : public HIDReportParser
{
    JoystickEvents      *joyEvents;

  uint8_t oldPad[RPT_GAMEPAD_LEN];

public:
    JoystickReportParser(JoystickEvents *evt);

    virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
};

#endif // __HIDJOYSTICKRPTPARSER_H__

So I hope that someone can give me a solution how I can get the value out of the code below (I changed the code a bit, so that I get decimal values) into the void loop().
void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt)
{
    Serial.print("X: ");
    Serial.print(evt->x);
    Serial.print("\t Y: ");
    Serial.print(evt->y);
    Serial.print("\t Hat Switch: ");
    Serial.print(evt->hat);
    Serial.print("\t Twist: ");
    Serial.print(evt->twist);
    Serial.print("\t Slider: ");
    Serial.print(evt->slider);
    Serial.print("\t Buttons A: ");
    Serial.print(evt->buttons_a);
    Serial.print("\t Buttons B: ");
    Serial.print(evt->buttons_b);
    Serial.println("");
}

I've some experience with Arduino programming but not much.
Please ask me if you need more information.

user16085: The following assumes you are seeing OnGamePadChanged being called.
One way you could get the values you want (GamePadEventData *evt) into the loop() would be to add a member variable to the JoystickEvents class, so that class would become something like
class JoystickEvents
{
public:
    virtual void OnGamePadChanged(const GamePadEventData *evt);
    static GamePadEventData mostRecentEvent;
};

In OnGamePadChanged, make a copy of evt:
GamePadEventData JoystickEvents::mostRecentEvent;
void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt)
{
    mostReventEvent = *evt;
}

Now you can read it from loop() using something like
Serial.print("X: ");
Serial.print(JoystickEvents::mostReventEvent.x);

A significant limitation of this method is that it will only keep the most recent event.  Maybe that's OK for your purpose.
It's probably not quite what the author of that code had in mind: he probably expected you to do the work in OnGamePadChanged: his implementation of that method looks like an example so you can see how it works.

28802: <p>I'm building my own quadcopter and going to use an Arduino for this. An Arduino Micro for the quadcopter and an Arduino UNO for the controller. I want to use an USB host shield with a Logitech Extreme 3D Pro to control the quadcopter. </p>

<p>I have the joystick already working with de example from the USB host shield example, but I can't get the values to my <code>void loop()</code>. There is not much information on the internet about this. </p>

<p>The link to the library and example I'm using: <a href="https://github.com/felis/USB_Host_Shield_2.0/tree/master/examples/HID/le3dp" rel="nofollow noreferrer">https://github.com/felis/USB_Host_Shield_2.0/tree/master/examples/HID/le3dp</a></p>

<p>.INO file:</p>

<pre><code>/* Simplified Logitech Extreme 3D Pro Joystick Report Parser */

#include &lt;hid.h&gt;
#include &lt;hiduniversal.h&gt;
#include &lt;usbhub.h&gt;

#include "le3dp_rptparser.h"

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

USB                                             Usb;
USBHub                                          Hub(&amp;Usb);
HIDUniversal                                    Hid(&amp;Usb);
JoystickEvents                                  JoyEvents;
JoystickReportParser                            Joy(&amp;JoyEvents);

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 (!Hid.SetReportParser(0, &amp;Joy))
      ErrorMessage&lt;uint8_t&gt;(PSTR("SetReportParser"), 1  );
}

void loop()
{
    Usb.Task();
}
</code></pre>

<p>.cpp file:</p>

<pre><code>#include "le3dp_rptparser.h"

JoystickReportParser::JoystickReportParser(JoystickEvents *evt) :
    joyEvents(evt)
{}

void JoystickReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
{
    bool match = true;

    // Checking if there are changes in report since the method was last called
    for (uint8_t i=0; i&lt;RPT_GAMEPAD_LEN; i++) {
        if( buf[i] != oldPad[i] ) {
            match = false;
            break;
        }
  }
    // Calling Game Pad event handler
    if (!match &amp;&amp; joyEvents) {
        joyEvents-&gt;OnGamePadChanged((const GamePadEventData*)buf);

        for (uint8_t i=0; i&lt;RPT_GAMEPAD_LEN; i++) oldPad[i] = buf[i];
    }
}

void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt)
{
    Serial.print("X: ");
    PrintHex&lt;uint16_t&gt;(evt-&gt;x, 0x80);
    Serial.print(" Y: ");
    PrintHex&lt;uint16_t&gt;(evt-&gt;y, 0x80);
    Serial.print(" Hat Switch: ");
    PrintHex&lt;uint8_t&gt;(evt-&gt;hat, 0x80);
    Serial.print(" Twist: ");
    PrintHex&lt;uint8_t&gt;(evt-&gt;twist, 0x80);
    Serial.print(" Slider: ");
    PrintHex&lt;uint8_t&gt;(evt-&gt;slider, 0x80);
    Serial.print(" Buttons A: ");
    PrintHex&lt;uint8_t&gt;(evt-&gt;buttons_a, 0x80);
    Serial.print(" Buttons B: ");
    PrintHex&lt;uint8_t&gt;(evt-&gt;buttons_b, 0x80);
    Serial.println("");
}
</code></pre>

<p>.h file:</p>

<pre><code>#if !defined(__HIDJOYSTICKRPTPARSER_H__)
#define __HIDJOYSTICKRPTPARSER_H__

#include &lt;hid.h&gt;

struct GamePadEventData
{
  union { //axes and hut switch
    uint32_t axes;
    struct {
      uint32_t x : 10;
      uint32_t y : 10;
      uint32_t hat : 4;
      uint32_t twist : 8;      
    };
  };
  uint8_t buttons_a;
  uint8_t slider;
  uint8_t buttons_b;
};

class JoystickEvents
{
public:
    virtual void OnGamePadChanged(const GamePadEventData *evt);
};

#define RPT_GAMEPAD_LEN sizeof(GamePadEventData)/sizeof(uint8_t)

class JoystickReportParser : public HIDReportParser
{
    JoystickEvents      *joyEvents;

  uint8_t oldPad[RPT_GAMEPAD_LEN];

public:
    JoystickReportParser(JoystickEvents *evt);

    virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
};

#endif // __HIDJOYSTICKRPTPARSER_H__
</code></pre>

<p>So I hope that someone can give me a solution how I can get the value out of the code below (I changed the code a bit, so that I get decimal values) into the void loop().</p>

<pre><code>void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt)
{
    Serial.print("X: ");
    Serial.print(evt-&gt;x);
    Serial.print("\t Y: ");
    Serial.print(evt-&gt;y);
    Serial.print("\t Hat Switch: ");
    Serial.print(evt-&gt;hat);
    Serial.print("\t Twist: ");
    Serial.print(evt-&gt;twist);
    Serial.print("\t Slider: ");
    Serial.print(evt-&gt;slider);
    Serial.print("\t Buttons A: ");
    Serial.print(evt-&gt;buttons_a);
    Serial.print("\t Buttons B: ");
    Serial.print(evt-&gt;buttons_b);
    Serial.println("");
}
</code></pre>

<p>I've some experience with Arduino programming but not much.</p>

<p>Please ask me if you need more information.</p>
 16085: <p>The following assumes you are seeing <code>OnGamePadChanged</code> being called.</p>

<p>One way you could get the values you want (<code>GamePadEventData *evt</code>) into the <code>loop()</code> would be to add a member variable to the <code>JoystickEvents</code> class, so that class would become something like</p>

<pre><code>class JoystickEvents
{
public:
    virtual void OnGamePadChanged(const GamePadEventData *evt);
    static GamePadEventData mostRecentEvent;
};
</code></pre>

<p>In <code>OnGamePadChanged</code>, make a copy of <code>evt</code>:</p>

<pre><code>GamePadEventData JoystickEvents::mostRecentEvent;
void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt)
{
    mostReventEvent = *evt;
}
</code></pre>

<p>Now you can read it from <code>loop()</code> using something like</p>

<pre><code>Serial.print("X: ");
Serial.print(JoystickEvents::mostReventEvent.x);
</code></pre>

<p>A significant limitation of this method is that it will only keep the most recent event.  Maybe that's OK for your purpose.</p>

<p>It's probably not quite what the author of that code had in mind: he probably expected you to do the work in <code>OnGamePadChanged</code>: his implementation of that method looks like an example so you can see how it works.</p>
