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?