NicoHood / HID

Bring enhanced HID functions to your Arduino!
http://www.nicohood.de
MIT License
2.37k stars 409 forks source link

Gamepad input doesn't register in any game #420

Open biologyscience opened 1 year ago

biologyscience commented 1 year ago

I am trying to make a controller similar to an PS4 controller and use it in some games which I play.

My setup is pretty simple, in a Arduino UNO with a potentiometer:

Vcc, Output, GND refers to pins in a potentiometer

What my code does is as I rotate the potentiometer, the IO MCU reads the analog value and sends it to the USB MCU via the HID Bridge and updates the gamepad's x axis. This actually works exactly as I expected, by confirming with HoodLoader2 16u2 game controller properties in the control panel, Input viewer in Joystick Gremlin, gamepad-tester, gamepadviewer.

But the problem is, these inputs are not being recognized by any game in my PC. I have no idea why. Should I enable something so that I can get this working, or am I missing something ? Please let me know if someone has a solution for this. I have pasted my code below for reference.


Sketch uploaded to USB MCU

#include <HID-Project.h>
#include <HID-Settings.h>

#define MIN16BIT -32768.0
#define MAX16BIT 32767.0

void setup()
{
    Serial.begin(9600);
    Serial1.begin(9600);

    Gamepad.begin();
}

void loop()
{
    int base100 = Serial1.read();

    Serial.print(base100); // to display data received from IO MCU

    float num = (base100 - 50.0) / 50.0;

    int axis = 0;

    if (num > 0) axis = num * MAX16BIT;

    if (num < 0) axis = num * -1 * MIN16BIT;

    Gamepad.xAxis(axis);

    Gamepad.write();
}


Sketch uploaded to IO MCU

#define ANALOGMAX 1023.0

void setup()
{
    Serial.begin(9600);
}

void loop()
{
    float dec = (analogRead(A0) / ANALOGMAX);

    int base100 = dec * 100;

    Serial.write(base100);
}