Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Having the darndest time modifying the joystick library

  1. #1
    Junior Member
    Join Date
    Dec 2019
    Posts
    3

    Having the darndest time modifying the joystick library

    Teensy LC / Windows 10 / Arduino 1.8.10 / Teensyduino 1.48 /

    I'm having trouble getting anything I write recognized as a USB Game Controller by Windows. I've experimented with adding and subtracting axes and buttons, but when I make any changes (short of changing one axis description for another), the game controller is no longer recognized as such by Windows 10 in Setup USB Game Controllers.

    I'm backing off from modifications and seeing if I can start from scratch to build my own HID descriptor. The Joystick definition in usb_desc.h has a JOYSTICK_SIZE which gets picked up in usb_desc.c to determine which descriptor to apply. After not being able to change anything all day, I said, ok, let's start from scratch in the simplest way possible: Let's do a ONE button joystick. I can do that math.

    Steps I took:
    1. In usb_desc.h - Change JOYSTICK_SIZE to 1.
    2. In usb_desc.c - inserted the following into #ifdef JOYSTICK_INTERFACE:

    Code:
    #elif JOYSTICK_SIZE == 1
    static uint8_t joystick_report_desc[] = {
            0x05, 0x01, //Usage Page (Generic Desktop)
    		0x09, 0x04, //Usage (Joystick)
    		0xA1, 0x01, //Collection (Application)
    		0x15, 0x00, //Logical Minimum 0
    		0x25, 0x01, //Logical Maximum 1
    		0x75, 0x01, //Report Size (1)
    		0x95, 0x01, //Report Count (1)
    		0x05, 0x09, //Usage Page (Button)
    		0x19, 0x01, //Usage_Minimum (Button 1)
    		0x29, 0x01, //Usage Maximum (Button 1)
    		0x81, 0x02, //Input (Data, Var, Abs)
    		0x95, 0x01, //Report Count (1) (filler)
    		0x75, 0x07, //Report Size (7)
    		0x81, 0x03,  //Input (Cnst, Var, Abs)
    		0xC0         // End Collection
    };
    3. Went into joystick.h and maybe a simple condition to match the new joystick size. It's definitely wrong, I know, but I figure (maybe incorrectly) that it doesn't impact whether Windows recognizes the controller, just what it does with the data stream.

    Code:
    #if JOYSTICK_SIZE == 1
    	void button(uint8_t button, bool val) {
    		if (--button >= 32) return;
    		if (val) usb_joystick_data[0] |= (1 << button);
    		else usb_joystick_data[0] &= ~(1 << button);
    		if (!manual_mode) usb_joystick_send();
    	}
    Everything else in usb_desc.h, .c, etc. have remained exactly the same. Since there are no statements anywhere else regarding JOYSTICK_SIZE, I assume they don't need to be updated(?).

    I don't know how much more I can break this one down and I'm stumped.

    Does anyone have the missing piece for me?

  2. #2
    Junior Member
    Join Date
    Dec 2019
    Posts
    3
    Looks like this resolved itself. I have no idea why it's working now. Just recompiled and uploaded and I now have a one button joystick. This is a very finicky process.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •