aboutsummaryrefslogtreecommitdiff
path: root/extra
diff options
context:
space:
mode:
Diffstat (limited to 'extra')
-rw-r--r--extra/Makefile13
-rw-r--r--extra/js1.c57
2 files changed, 70 insertions, 0 deletions
diff --git a/extra/Makefile b/extra/Makefile
new file mode 100644
index 0000000..ff10a08
--- /dev/null
+++ b/extra/Makefile
@@ -0,0 +1,13 @@
+CC=gcc
+SRC = $(wildcard *.c)
+OBJS = $(patsubst %.c, %.o, $(SRC))
+NAME = js1
+
+all: $(NAME)
+.PHONY: clean
+
+$(NAME): $(OBJS)
+ $(CC) $(shell pkg-config --cflags sdl2 ) $< $(shell pkg-config --libs sdl2 ) -o $@
+
+clean:
+ rm -f $(OBJS) $(NAME)
diff --git a/extra/js1.c b/extra/js1.c
new file mode 100644
index 0000000..703332b
--- /dev/null
+++ b/extra/js1.c
@@ -0,0 +1,57 @@
+// File: js1.c
+// Startdate: 2022-06-29
+// Purpose: Test my C skills, while trying to test SDL2 game controller stuff
+// References:
+// http://www.libsdl.org/release/SDL-1.2.15/docs/html/guideinput.html
+// https://wiki.libsdl.org/SDL_GameControllerMapping
+// https://stackoverflow.com/q/29589982
+// https://generalarcade.com/gamepadtool/
+// https://wiki.winehq.org/Useful_Registry_Keys
+// https://wiki.archlinux.org/title/Gamepad
+// https://stackoverflow.com/questions/29589982/does-sdl-on-linux-support-more-than-one-gamepad-joystick
+// Dependencies:
+// libsdl2-dev
+// Documentation:
+// try SDL_GAMECONTROLLERCONFIG env var.
+
+#include "SDL2/SDL.h"
+SDL_Joystick *joy;
+SDL_GameController *ctrl;
+char *guid[33];
+char *mapping;
+const char *newmapping = "03000000bd12000015d0000010010000,Tomee SNES USB Controller,platform:Linux,a:b2,b:b1,x:b3,y:b0,back:b8,start:b9,leftshoulder:b4,rightshoulder:b5,dpup:-a1,dpdown:+a1,dpleft:-a0,dpright:+a0,";
+
+int main () {
+ if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK ) < 0)
+ {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
+ exit(1);
+ }
+ SDL_InitSubSystem(SDL_INIT_JOYSTICK);
+ SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
+ printf("%i joysticks were found.\n\n", SDL_NumJoysticks() );
+ printf("The names of the joysticks are:\n");
+
+ for( int i=0; i < SDL_NumJoysticks(); i++ )
+ {
+ joy = SDL_JoystickOpen(i);
+ if (joy) {
+ printf("Opened joystick #%d \"%s\"\n", i, SDL_JoystickNameForIndex(i));
+ printf("Axes count: %d\n", SDL_JoystickNumAxes(joy));
+ printf("Button count: %d\n", SDL_JoystickNumButtons(joy));
+ printf("Ball count: %d\n", SDL_JoystickNumBalls(joy));
+ SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joy),*guid,sizeof(guid));
+ printf("GUID string: \"%s\"\n",guid);
+ if (SDL_IsGameController(i)) {
+ ctrl = SDL_GameControllerOpen(i);
+ mapping = SDL_GameControllerMapping(ctrl);
+ printf("Mapping: \"%s\"\n", mapping);
+ SDL_free(mapping);
+ printf("Trying new mapping.\n");
+ int r = SDL_GameControllerAddMapping(newmapping);
+ printf("Result: %d.\n", r);
+ }
+ }
+ }
+ return 0;
+}
bgstack15