about summary refs log tree commit diff
path: root/pkgs/list-gamecontrollers/list-gc.c
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2016-01-26 01:57:30 +0100
committeraszlig <aszlig@redmoonstudios.org>2016-01-26 02:01:16 +0100
commit0353b8b3ffcbaa102d36fa7e8f2bb218a1374820 (patch)
tree56fcd560f2a77faba5cf9ed5999993833257670a /pkgs/list-gamecontrollers/list-gc.c
parent3b343e7984ec3f2d2e9c5f02b5205b2aecc5a2dd (diff)
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 <aszlig@redmoonstudios.org>
Diffstat (limited to 'pkgs/list-gamecontrollers/list-gc.c')
-rw-r--r--pkgs/list-gamecontrollers/list-gc.c31
1 files changed, 31 insertions, 0 deletions
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 <SDL.h>
+
+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;
+}