From 57fafad066f5134804bc064a1d74c89376c4e81d Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 12 Oct 2023 19:14:19 -0400 Subject: [PATCH] Test polling joystick button events --- src/rcore_drm.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/rcore_drm.c b/src/rcore_drm.c index d2f4fe366..616e81867 100644 --- a/src/rcore_drm.c +++ b/src/rcore_drm.c @@ -156,6 +156,7 @@ static void ProcessKeyboard(void); // Process keyboard even static void InitDrmInput(void); // Initialize inputs for DRM platform static void InitDrmJoystick(int index, const char *path); // Initialize a joystick for DRM platform +static void PollDrmJoystickEvents(); static void InitEvdevInput(void); // Initialize evdev inputs static void ConfigureEvdevDevice(char *device); // Identifies a input device and configures it for use if appropriate @@ -869,6 +870,7 @@ void PollInputEvents(void) CORE.Input.Keyboard.keyRepeatInFrame[i] = 0; } + PollDrmJoystickEvents(); PollKeyboardEvents(); // Register previous mouse states @@ -1534,6 +1536,27 @@ static void InitDrmJoystick(int index, const char *path) CORE.Input.Gamepad.ready[index] = true; } +static void PollDrmJoystickEvents() +{ + struct input_event ev; + + for (int i = 0; i < MAX_GAMEPADS; i++) + { + if (!CORE.Input.Gamepad.ready[i]) + continue; + + while (read(platform.gamepadStreamFd, &ev, sizeof(ev)) > 0) + { + switch(ev.type) + { + case EV_KEY: + printf("Key %d = %d", ev.code, ev.value); + break; + } + } + } +} + // Initialise user input from evdev(/dev/input/event) // this means mouse, keyboard or gamepad devices static void InitEvdevInput(void)