From 0353b8b3ffcbaa102d36fa7e8f2bb218a1374820 Mon Sep 17 00:00:00 2001 From: aszlig Date: Tue, 26 Jan 2016 01:57:30 +0100 Subject: pkgs: Add a small utility to dump joystick GUIDs SDL 2 has an environment variable called SDL_GAMECONTROLLERCONFIG, which lists button/axis mappings of various game controllers attached to the system. The game controllers are themselves identified using a GUID which is SDL 2 specific and this tool is there to just dump the name of a particular game controller along with the GUID so it's easier to get the GUID. Signed-off-by: aszlig --- pkgs/default.nix | 1 + pkgs/list-gamecontrollers/default.nix | 10 ++++++++++ pkgs/list-gamecontrollers/list-gc.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 pkgs/list-gamecontrollers/default.nix create mode 100644 pkgs/list-gamecontrollers/list-gc.c diff --git a/pkgs/default.nix b/pkgs/default.nix index d7057820..6eec67a4 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -15,6 +15,7 @@ let nixops = callPackage ./nixops { }; libCMT = callPackage ./libcmt { }; librxtx_java = callPackage ./librxtx-java { }; + list-gamecontrollers = callPackage ./list-gamecontrollers { }; lockdev = callPackage ./lockdev { }; pvolctrl = callPackage ./pvolctrl { }; show-qr-code = callPackage ./show-qr-code { }; diff --git a/pkgs/list-gamecontrollers/default.nix b/pkgs/list-gamecontrollers/default.nix new file mode 100644 index 00000000..c207d2eb --- /dev/null +++ b/pkgs/list-gamecontrollers/default.nix @@ -0,0 +1,10 @@ +{ runCommand, pkgconfig, SDL2 }: + +runCommand "list-gamecontrollers" { + buildInputs = [ pkgconfig SDL2 ]; +} '' + mkdir -p "$out/bin" + gcc -Werror "${./list-gc.c}" \ + $(pkg-config --libs --cflags sdl2) \ + -o "$out/bin/list-gamecontrollers" +'' diff --git a/pkgs/list-gamecontrollers/list-gc.c b/pkgs/list-gamecontrollers/list-gc.c new file mode 100644 index 00000000..f40b7da6 --- /dev/null +++ b/pkgs/list-gamecontrollers/list-gc.c @@ -0,0 +1,31 @@ +#include + +void dump_guid(SDL_Joystick *js) { + SDL_JoystickGUID guid; + const char *name; + char guidstr[33]; + + guid = SDL_JoystickGetGUID(js); + name = SDL_JoystickName(js); + SDL_JoystickGetGUIDString(guid, guidstr, sizeof(guidstr)); + + printf("%s: %s\n", name, guidstr); +} + +int main() +{ + int i; + SDL_Joystick *js; + + SDL_Init(SDL_INIT_JOYSTICK); + atexit(SDL_Quit); + + for (i = 0; i < SDL_NumJoysticks(); ++i) { + if ((js = SDL_JoystickOpen(i)) != NULL) { + dump_guid(js); + SDL_JoystickClose(js); + } + } + + return EXIT_SUCCESS; +} -- cgit 1.4.1