BenBrewerBowman / Arduino_Logitech_3D_Joystick

Arduino code for interfacing with the "Logitech Extreme 3D Pro Joystick". A more intuitive version of the "le3dp_rptparser".
8 stars 1 forks source link

"Logitech Cordless Joystick Freedom 2.4" is not working with "BenBrewerBowman/Arduino_Logitech_3D_Joystick Library", would you help how to solve it please ? thank you. #1

Open mekaci89 opened 6 years ago

mekaci89 commented 6 years ago

BenBrewerBowman, firstly thank you very much for providing such a library that we can access to joystick values in arduino sketch too.

I am using "USB Host Shield 2.0 Library" and your Arduino_Logitech_3D_Joystick Library to use my "Logitech 3D PRO Extreme" joystick and everything is working nicely. But I was experienced some problem while using nrf24 wireless communication between two arduino devices.

After that, I found a wireless joystick on internet from logitech company and it is similar too "Logitech 3D PRO Extreme Joystick". It's name is "Logitech Cordless Joystick Freedom 2.4".

"Logitech Cordless Joystick Freedom 2.4" is very old joystick and it is the only wireless joystick of its own kind too, I hardly found it on ebay already.

This "Logitech Cordless Joystick Freedom 2.4" is working with "USB Host Shield 2.0 Library"s USBHIDJoystick example sketch; but "Logitech Cordless Joystick Freedom 2.4" is not working with your BenBrewerBowman/Arduino_Logitech_3D_Joystick Library. I don't know why I don't get any reading on serial monitor.

I looked into the USBHIDJoystick example sketch and its cpp, header files and the code written there is more complex than yours; so I failed to modify :(

If it is possible would you make modification on this sketch and its cpp and header files please to access joystick values inside of arduino sketch too ? Then we can use this wireless logitech joystick too.

"USB Host Shield 2.0 Library"s USBHIDJoystick example

USBHIDJoystick example sketch:

`#include

include

include

// Satisfy IDE, which only needs to see the include statment in the ino.

ifdef dobogusinclude

include

endif

include

include "hidjoystickrptparser.h"

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(); } USBHIDJoystick example sketch's cpp file: #include "hidjoystickrptparser.h"

JoystickReportParser::JoystickReportParser(JoystickEvents *evt) : joyEvents(evt), oldHat(0xDE), oldButtons(0) { for (uint8_t i = 0; i < RPT_GEMEPAD_LEN; i++) oldPad[i] = 0xD; }

void JoystickReportParser::Parse(USBHID 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_GEMEPAD_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_GEMEPAD_LEN; i++) oldPad[i] = buf[i];
    }

    uint8_t hat = (buf[5] & 0xF);

    // Calling Hat Switch event handler
    if (hat != oldHat && joyEvents) {
            joyEvents->OnHatSwitch(hat);
            oldHat = hat;
    }

    uint16_t buttons = (0x0000 | buf[6]);
    buttons <<= 4;
    buttons |= (buf[5] >> 4);
    uint16_t changes = (buttons ^ oldButtons);

    // Calling Button Event Handler for every button changed
    if (changes) {
            for (uint8_t i = 0; i < 0x0C; i++) {
                    uint16_t mask = (0x0001 << i);

                    if (((mask & changes) > 0) && joyEvents) {
                            if ((buttons & mask) > 0)
                                    joyEvents->OnButtonDn(i + 1);
                            else
                                    joyEvents->OnButtonUp(i + 1);
                    }
            }
            oldButtons = buttons;
    }

}

void JoystickEvents::OnGamePadChanged(const GamePadEventData *evt) { Serial.print("X1: "); PrintHex (evt->X, 0x80); Serial.print("\tY1: "); PrintHex (evt->Y, 0x80); Serial.print("\tX2: "); PrintHex (evt->Z1, 0x80); Serial.print("\tY2: "); PrintHex (evt->Z2, 0x80); Serial.print("\tRz: "); PrintHex (evt->Rz, 0x80); Serial.println(""); }

void JoystickEvents::OnHatSwitch(uint8_t hat) { Serial.print("Hat Switch: "); PrintHex (hat, 0x80); Serial.println(""); }

void JoystickEvents::OnButtonUp(uint8_t but_id) { Serial.print("Up: "); Serial.println(but_id, DEC); }

void JoystickEvents::OnButtonDn(uint8_t but_id) { Serial.print("Dn: "); Serial.println(but_id, DEC); }`

USBHIDJoystick example sketch's header file: `#if !defined(__HIDJOYSTICKRPTPARSER_H__)

define __HIDJOYSTICKRPTPARSER_H__

include

struct GamePadEventData { uint8_t X, Y, Z1, Z2, Rz; };

class JoystickEvents { public: virtual void OnGamePadChanged(const GamePadEventData *evt); virtual void OnHatSwitch(uint8_t hat); virtual void OnButtonUp(uint8_t but_id); virtual void OnButtonDn(uint8_t but_id); };

define RPT_GEMEPAD_LEN 5

class JoystickReportParser : public HIDReportParser { JoystickEvents *joyEvents;

    uint8_t oldPad[RPT_GEMEPAD_LEN];
    uint8_t oldHat;
    uint16_t oldButtons;

public: JoystickReportParser(JoystickEvents *evt);

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

};

endif // __HIDJOYSTICKRPTPARSER_H__`

If anyone has deep knowledge about this "how to make that modification, please would you help ? thank you very much.

BenBrewerBowman commented 6 years ago

Can you create a pull request with your change? If so I would be happy to integrate it into this repository. This is kind of an old project, and I am sure that the USB 2.0 hosting library has received some updates that this project might not support.