diff --git a/examples/HID/le3dp/le3dp.pde b/examples/HID/le3dp/le3dp.pde new file mode 100644 index 00000000..b52bb28d --- /dev/null +++ b/examples/HID/le3dp/le3dp.pde @@ -0,0 +1,47 @@ +/* Simplified Logitech Extreme 3D Pro Joystick Report Parser */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "le3dp_rptparser.h" + +#include +#include +#include +#include + +USB Usb; +USBHub Hub(&Usb); +HIDUniversal Hid(&Usb); +JoystickEvents JoyEvents; +JoystickReportParser Joy(&JoyEvents); + +void setup() +{ + Serial.begin( 115200 ); + Serial.println("Start"); + + if (Usb.Init() == -1) + Serial.println("OSC did not start."); + + delay( 200 ); + + if (!Hid.SetReportParser(0, &Joy)) + ErrorMessage(PSTR("SetReportParser"), 1 ); +} + +void loop() +{ + Usb.Task(); +} + diff --git a/examples/HID/le3dp/le3dp_rptparser.cpp b/examples/HID/le3dp/le3dp_rptparser.cpp new file mode 100644 index 00000000..016f8fb7 --- /dev/null +++ b/examples/HID/le3dp/le3dp_rptparser.cpp @@ -0,0 +1,43 @@ +#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; iOnGamePadChanged((const GamePadEventData*)buf); + + for (uint8_t i=0; i(evt->x); + Serial.print(" Y: "); + PrintHex(evt->y); + Serial.print(" Hat Switch: "); + PrintHex(evt->hat); + Serial.print(" Twist: "); + PrintHex(evt->twist); + Serial.print(" Slider: "); + PrintHex(evt->slider); + Serial.print(" Buttons A: "); + PrintHex(evt->buttons_a); + Serial.print(" Buttons B: "); + PrintHex(evt->buttons_b); + Serial.println(""); +} diff --git a/examples/HID/le3dp/le3dp_rptparser.h b/examples/HID/le3dp/le3dp_rptparser.h new file mode 100644 index 00000000..36e13d5b --- /dev/null +++ b/examples/HID/le3dp/le3dp_rptparser.h @@ -0,0 +1,60 @@ +#if !defined(__HIDJOYSTICKRPTPARSER_H__) +#define __HIDJOYSTICKRPTPARSER_H__ + +#include +#include +#include "avrpins.h" +#include "max3421e.h" +#include "usbhost.h" +#include "usb_ch9.h" +#include "Usb.h" + +#if defined(ARDUINO) && ARDUINO >=100 +#include "Arduino.h" +#else +#include +#endif + +#include "printhex.h" +#include "hexdump.h" +#include "message.h" +#include "confdescparser.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__ \ No newline at end of file diff --git a/hiduniversal.cpp b/hiduniversal.cpp index a5d70143..9bffe3b7 100644 --- a/hiduniversal.cpp +++ b/hiduniversal.cpp @@ -178,7 +178,7 @@ uint8_t HIDUniversal::Init(uint8_t parent, uint8_t port, bool lowspeed) p->lowspeed = lowspeed; - delay(200); + delay(500); if (len) rcode = pUsb->getDevDescr( bAddress, 0, len, (uint8_t*)buf );