From 9719bfc61039dde4927ef8fb663da9dd7a84eec3 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 10 Oct 2023 12:55:09 -0400 Subject: [PATCH] Add example to test gamepad info functions Fix typo --- examples/Makefile | 1 + examples/core/core_input_gamepad_info.c | 60 +++++++++++++++++++++++++ src/rcore_drm.c | 2 +- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 examples/core/core_input_gamepad_info.c diff --git a/examples/Makefile b/examples/Makefile index 9404d39cc..6031f05e9 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -365,6 +365,7 @@ CORE = \ core/core_input_mouse \ core/core_input_mouse_wheel \ core/core_input_gamepad \ + core/core_input_gamepad_info \ core/core_input_multitouch \ core/core_input_gestures \ core/core_input_gestures_web \ diff --git a/examples/core/core_input_gamepad_info.c b/examples/core/core_input_gamepad_info.c new file mode 100644 index 000000000..0dcf76928 --- /dev/null +++ b/examples/core/core_input_gamepad_info.c @@ -0,0 +1,60 @@ +/******************************************************************************************* +* +* raylib [core] example - Gamepad information +* +* NOTE: This example requires a Gamepad connected to the system +* Check raylib.h for buttons configuration +* +* Example originally created with raylib 4.6, last time updated with raylib 4.6 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2013-2023 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 3440; + const int screenHeight = 1440; + + SetConfigFlags(FLAG_MSAA_4X_HINT); // Set MSAA 4X hint before windows creation + + InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad information"); + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + int y = 10; + + BeginDrawing(); + + ClearBackground(RAYWHITE); + + for (int i = 0; i < 4; i++) // by default rcore.h has a MAX_GAMEPADS of 4 so mimmic that here. + { + if (IsGamepadAvailable(i)) + { + DrawText(TextFormat("Gamepad:\n\tName: %s\n\tAxes: %d", GetGamepadName(i), GetGamepadAxisCount(i)), 10, y, 20, BLACK); + y += 40; + } + } + + EndDrawing(); + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- +} \ No newline at end of file diff --git a/src/rcore_drm.c b/src/rcore_drm.c index 899f1c047..03ed5888c 100644 --- a/src/rcore_drm.c +++ b/src/rcore_drm.c @@ -1947,7 +1947,7 @@ static void InitGamepad(void) else TRACELOG(LOG_INFO, "RPI: Gamepad device initialized successfully"); } - ioctl(platform.gamepadStreamFd[gamepad], JSIOCGNAME(64), &CORE.Input.Gamepad.name[i]); + ioctl(platform.gamepadStreamFd[i], JSIOCGNAME(64), &CORE.Input.Gamepad.name[i]); } } }