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

Thread: Change Teensy HID Capabilities

  1. #1
    Junior Member
    Join Date
    Oct 2016
    Posts
    17

    Change Teensy HID Capabilities

    I have a single axis joystick I have wired to a Teensy 3.2 and would like it to coexist with an XBox style Game Pad, but they both return the first 5 Joystick values and so conflict. If I could remove them from the standard teensy joystick capabilities that would solve the issue. Does anyone have code examples to do this. Do I have to use Raw HID? At the moment I have hacked the receiver to make it work but that is not elegant.

    it also has 3 buttons, but I have offset them to be after the gamepad buttons

    At the moment i just selected Joystick as recommended in the sample I used:
    Thanks,
    Simon

    /* Complete USB Joystick Example
    Teensy becomes a USB joystick with 16 or 32 buttons and 6 axis input

    You must select Joystick from the "Tools > USB Type" menu

    Pushbuttons should be connected between the digital pins and ground.
    Potentiometers should be connected to analog inputs 0 to 5.

    This example code is in the public domain.
    */

    // Configure the number of buttons. Be careful not
    // to use a pin for both a digital button and analog
    // axis. The pullup resistor will interfere with
    // the analog voltage.
    const int numButtons = 3; // Only using 3 atm

    int led = 13;
    int on = 0;
    void setup()
    {
    // you can print to the serial monitor while the joystick is active!
    Serial.begin(9600);

    pinMode(led, OUTPUT);

    // configure the joystick to manual send mode. This gives precise
    // control over when the computer receives updates, but it does
    // require you to manually call Joystick.send_now().
    Joystick.useManualSend(true);

    for (int i = 0; i < numButtons; i++)
    {
    pinMode(i, INPUT_PULLUP);
    }

    Serial.println("Begin Complete Joystick Test");
    }

    byte allButtons[numButtons];
    byte prevButtons[numButtons];
    int angle = 0;
    int count = -256;
    void loop()
    {

    Joystick.X(512);
    Joystick.Y(512);
    Joystick.Z(512);
    Joystick.sliderLeft(512);
    Joystick.sliderRight(512);

    // Not used by the Game Pad
    Joystick.Zrotate(analogRead(0));

    if (count >= 256)
    {
    if (on)
    digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
    else
    digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)

    on = !on;
    count = -256;
    }


    // read digital pins and use them for the buttons
    // Just using 3 Inputs for now
    for (int i = 0; i < numButtons; i++)
    {
    if (digitalRead(i))
    {
    // when a pin reads high, the button is not pressed
    // the pullup resistor creates the "on" signal
    allButtons[i] = 0;
    }
    else
    {
    // when a pin reads low, the button is connecting to ground.
    allButtons[i] = 1;
    }
    // Offset to write to the 12,13 and 14th button
    // Button 10 & 11 is used by pushing down on the XBox joysticks
    Joystick.button(i + 11, allButtons[i]);
    }

    // Because setup configured the Joystick manual send,
    // the computer does not see any of the changes yet.
    // This send_now() transmits everything all at once.
    Joystick.send_now();

    // check to see if any button changed since last time
    boolean anyChange = false;
    for (int i = 0; i < numButtons; i++)
    {
    if (allButtons[i] != prevButtons[i])
    anyChange = true;
    prevButtons[i] = allButtons[i];
    }

    // if any button changed, print them to the serial monitor
    if (anyChange)
    {
    Serial.print("Buttons: ");
    for (int i = 0; i < numButtons; i++)
    {
    Serial.print(allButtons[i], DEC);
    }
    Serial.println();
    }

    // a brief delay, so this runs "only" 20 times per second
    delay(50);
    }

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,737
    Maybe try editing the HID report descriptor in usb_desc.c. Look for "joystick_report_desc" starting on line 226.

Posting Permissions

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