Skip to content

Instantly share code, notes, and snippets.

@ivyl
Last active April 5, 2021 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivyl/cb92c7a7e4f5ec5babebca56ff6c1655 to your computer and use it in GitHub Desktop.
Save ivyl/cb92c7a7e4f5ec5babebca56ff6c1655 to your computer and use it in GitHub Desktop.
xpadneo 0.9 enum
ivyl@failcraft $ modinfo hid_xpadneo | head -n 2
filename: /lib/modules/5.11.11-zen1-1-zen/kernel/drivers/hid/hid-xpadneo.ko.xz
version: v0.9-51-gfa41a04
ivyl@failcraft $ SDL_JOYSTICK_HIDAPI=1 ./sdl-enum
Joystick 0: "Xbox One Series X Controller"
PIDVIDVER: 045e:0b13:0000
IsGameController: 1
Joystick 1: "Xbox One S Controller"
PIDVIDVER: 045e:02e0:0903
IsGameController: 1
ivyl@failcraft $ SDL_JOYSTICK_HIDAPI=0 ./sdl-enum
Joystick 0: "Xbox One S Controller"
PIDVIDVER: 045e:02e0:0903
IsGameController: 1
/* gcc sdl-enum.c -o sdl-enum `pkg-config --libs sdl2` */
#include <SDL2/SDL.h>
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <inttypes.h>
SDL_Window *window;
SDL_Renderer *renderer;
SDL_GameController *controller;
int main(int argc, char *argv[])
{
int num_joysticks;
assert(0 == SDL_Init(SDL_INIT_GAMECONTROLLER));
/* SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI, "0"); */
num_joysticks = SDL_NumJoysticks();
for (int i = 0; i < num_joysticks; ++i)
{
SDL_Joystick *joystick = SDL_JoystickOpen(i);
assert(joystick);
printf("Joystick %d: \"%s\"\n", i, SDL_JoystickName(joystick));
printf(" PIDVIDVER: %04hx:%04hx:%04hx\n", SDL_JoystickGetDeviceVendor(i),
SDL_JoystickGetDeviceProduct(i),
SDL_JoystickGetDeviceProductVersion(i));
printf(" IsGameController: %d\n", (int)SDL_IsGameController(i));
SDL_JoystickClose(joystick);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment