milador / RaspberryPi-Joystick

A virtual HID USB joystick created using Raspberry Pi
MIT License
117 stars 29 forks source link

I have created my own Virtual joystick project #3

Closed tuxcomputers closed 3 years ago

tuxcomputers commented 3 years ago

Using your USB device creation script and information from other locations I have turned the Zero into a Virtual Joystick with 32 buttons that can be triggered by the GPIO pins

https://github.com/tuxcomputers/Raspberrypi_joystick

I found the data your project sends for the joystick events was totally wrong for me.

https://github.com/tuxcomputers/Raspberrypi_joystick/blob/main/about_joysticks.md

milador commented 3 years ago

I updated the python code to correct the format of sent data. The order of buttons and joystick bytes were reversed.

Great work. Would you like to add your updated code to my repository? We can have 3 versions : 8 buttons version , 16 buttons version , and your 32 button version.

Let me know if you have time to add a bit more instructions.

gdsports commented 3 years ago

The HID report descriptor declares the axes first then the buttons so the script look wrong now. The HID report descriptor parser at http://eleccelerator.com/usbdescreqparser/ shows the following.

0x05, 0x01,        // Usage Page (Generic Desktop Ctrls)
0x09, 0x04,        // Usage (Joystick)
0xA1, 0x01,        // Collection (Application)
0x15, 0x81,        //   Logical Minimum (-127)
0x25, 0x7F,        //   Logical Maximum (127)
0x09, 0x01,        //   Usage (Pointer)
0xA1, 0x00,        //   Collection (Physical)
0x09, 0x30,        //     Usage (X)
0x09, 0x31,        //     Usage (Y)
0x75, 0x08,        //     Report Size (8)
0x95, 0x02,        //     Report Count (2)
0x81, 0x02,        //     Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0xC0,              //   End Collection
0x05, 0x09,        //   Usage Page (Button)
0x19, 0x01,        //   Usage Minimum (0x01)
0x29, 0x08,        //   Usage Maximum (0x08)
0x15, 0x00,        //   Logical Minimum (0)
0x25, 0x01,        //   Logical Maximum (1)
0x75, 0x01,        //   Report Size (1)
0x95, 0x08,        //   Report Count (8)
0x81, 0x02,        //   Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0xC0,              // End Collection

EDIT: The first two bytes are X and Y axes and the last byte is the button bit map. (Fixed a bug in my comment.)

I tinkered with the descriptors but never could get XAC to accept it as a joystick. But the joystick works when connected to Ubuntu Linux.

I am working on a gamepad (2 sticks, 1 dpad, 14 buttons) and will PR it when ready. Not useful for XAC but might be useful for PC or consoles.

milador commented 3 years ago

@gdsports @tuxcomputers I found the issue and corrected the order. I had the incorrect code pushed to github. It's corrected now. Please check and let me know. Thanks

gdsports commented 3 years ago

8_buttons_keyboard.py works fine now.

milador commented 3 years ago

Thanks again @gdsports for testing. I close this issue now.