Improved gamepad support on Raspberry Pi
This commit is contained in:
parent
f16f39e8aa
commit
f2d61d4d43
19
src/core.c
19
src/core.c
@ -96,8 +96,8 @@
|
||||
#include <sys/ioctl.h> // UNIX System call for device-specific input/output operations - ioctl()
|
||||
#include <linux/kd.h> // Linux: KDSKBMODE, K_MEDIUMRAM constants definition
|
||||
#include <linux/input.h> // Linux: Keycodes constants definition (KEY_A, ...)
|
||||
#include <linux/joystick.h>
|
||||
|
||||
#include <linux/joystick.h> // Linux: Joystick support library
|
||||
|
||||
#include "bcm_host.h" // Raspberry Pi VideoCore IV access functions
|
||||
|
||||
#include "EGL/egl.h" // Khronos EGL library - Native platform display device control functions
|
||||
@ -175,6 +175,7 @@ static pthread_t mouseThreadId; // Mouse reading thread id
|
||||
// Gamepad input variables
|
||||
static int gamepadStream[MAX_GAMEPADS] = { -1 };// Gamepad device file descriptor
|
||||
static pthread_t gamepadThreadId; // Gamepad reading thread id
|
||||
static char gamepadName[64]; // Gamepad name holder
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
|
||||
@ -1188,6 +1189,10 @@ const char *GetGamepadName(int gamepad)
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
if (gamepadReady[gamepad]) return glfwGetJoystickName(gamepad);
|
||||
else return NULL;
|
||||
#elif defined(PLATFORM_RPI)
|
||||
if (gamepadReady[gamepad]) ioctl(gamepadStream[gamepad], JSIOCGNAME(64), &gamepadName);
|
||||
|
||||
return gamepadName;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
@ -1196,6 +1201,11 @@ const char *GetGamepadName(int gamepad)
|
||||
// Return gamepad axis count
|
||||
int GetGamepadAxisCount(int gamepad)
|
||||
{
|
||||
#if defined(PLATFORM_RPI)
|
||||
int axisCount = 0;
|
||||
if (gamepadReady[gamepad]) ioctl(gamepadStream[gamepad], JSIOCGAXES, &axisCount);
|
||||
gamepadAxisCount = axisCount;
|
||||
#endif
|
||||
return gamepadAxisCount;
|
||||
}
|
||||
|
||||
@ -1939,9 +1949,11 @@ static void PollInputEvents(void)
|
||||
// Reset last key pressed registered
|
||||
lastKeyPressed = -1;
|
||||
|
||||
// Reset last gamepad button pressed registered
|
||||
#if !defined(PLATFORM_RPI)
|
||||
// Reset last gamepad button/axis registered state
|
||||
lastGamepadButtonPressed = -1;
|
||||
gamepadAxisCount = 0;
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||
// Mouse input polling
|
||||
@ -2850,6 +2862,7 @@ static void *GamepadThread(void *arg)
|
||||
currentGamepadState[i][gamepadEvent.number] = (int)gamepadEvent.value;
|
||||
|
||||
if ((int)gamepadEvent.value == 1) lastGamepadButtonPressed = gamepadEvent.number;
|
||||
else lastGamepadButtonPressed = -1;
|
||||
}
|
||||
}
|
||||
else if (gamepadEvent.type == JS_EVENT_AXIS)
|
||||
|
32
src/raylib.h
32
src/raylib.h
@ -216,8 +216,8 @@
|
||||
#define GAMEPAD_PS3_AXIS_LEFT_Y 1
|
||||
#define GAMEPAD_PS3_AXIS_RIGHT_X 2
|
||||
#define GAMEPAD_PS3_AXIS_RIGHT_Y 5
|
||||
#define GAMEPAD_PS3_AXIS_L2 3 // 1.0(not pressed) --> -1.0(completely pressed)
|
||||
#define GAMEPAD_PS3_AXIS_R2 4 // 1.0(not pressed) --> -1.0(completely pressed)
|
||||
#define GAMEPAD_PS3_AXIS_L2 3 // [1..-1] (pressure-level)
|
||||
#define GAMEPAD_PS3_AXIS_R2 4 // [1..-1] (pressure-level)
|
||||
|
||||
// Xbox360 USB Controller Buttons
|
||||
#define GAMEPAD_XBOX_BUTTON_A 0
|
||||
@ -232,27 +232,25 @@
|
||||
#define GAMEPAD_XBOX_BUTTON_RIGHT 11
|
||||
#define GAMEPAD_XBOX_BUTTON_DOWN 12
|
||||
#define GAMEPAD_XBOX_BUTTON_LEFT 13
|
||||
#define GAMEPAD_XBOX_BUTTON_HOME 9
|
||||
#define GAMEPAD_XBOX_BUTTON_HOME 8
|
||||
|
||||
// Xbox360 USB Controller Axis
|
||||
#define GAMEPAD_XBOX_AXIS_LEFT_X 0
|
||||
#define GAMEPAD_XBOX_AXIS_LEFT_Y 1
|
||||
#define GAMEPAD_XBOX_AXIS_RIGHT_X 2
|
||||
#define GAMEPAD_XBOX_AXIS_RIGHT_Y 3
|
||||
#define GAMEPAD_XBOX_AXIS_LT 4 // -1.0(not pressed) --> 1.0(completely pressed)
|
||||
#define GAMEPAD_XBOX_AXIS_RT 5 // -1.0(not pressed) --> 1.0(completely pressed)
|
||||
#define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right)
|
||||
#define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [1..-1] (up->down)
|
||||
#define GAMEPAD_XBOX_AXIS_RIGHT_X 2 // [-1..1] (left->right)
|
||||
#define GAMEPAD_XBOX_AXIS_RIGHT_Y 3 // [1..-1] (up->down)
|
||||
#define GAMEPAD_XBOX_AXIS_LT 4 // [-1..1] (pressure-level)
|
||||
#define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level)
|
||||
|
||||
/*
|
||||
// NOTE: For Raspberry Pi, axis must be reconfigured
|
||||
#if defined(PLATFORM_RPI)
|
||||
#define GAMEPAD_XBOX_AXIS_LEFT_X 7
|
||||
#define GAMEPAD_XBOX_AXIS_LEFT_Y 6
|
||||
#define GAMEPAD_XBOX_AXIS_RIGHT_X 3
|
||||
#define GAMEPAD_XBOX_AXIS_RIGHT_Y 4
|
||||
#define GAMEPAD_XBOX_AXIS_LT 2
|
||||
#define GAMEPAD_XBOX_AXIS_RT 5
|
||||
#define GAMEPAD_XBOX_AXIS_LEFT_X 0 // [-1..1] (left->right)
|
||||
#define GAMEPAD_XBOX_AXIS_LEFT_Y 1 // [-1..1] (up->down)
|
||||
#define GAMEPAD_XBOX_AXIS_RIGHT_X 3 // [-1..1] (left->right)
|
||||
#define GAMEPAD_XBOX_AXIS_RIGHT_Y 4 // [-1..1] (up->down)
|
||||
#define GAMEPAD_XBOX_AXIS_LT 2 // [-1..1] (pressure-level)
|
||||
#define GAMEPAD_XBOX_AXIS_RT 5 // [-1..1] (pressure-level)
|
||||
#endif
|
||||
*/
|
||||
|
||||
// NOTE: MSC C++ compiler does not support compound literals (C99 feature)
|
||||
// Plain structures in C++ (without constructors) can be initialized from { } initializers.
|
||||
|
Loading…
Reference in New Issue
Block a user