@@ -128,7 +128,6 @@ typedef struct {
128
128
int touchSlot ; // Hold the touch slot number of the currently being sent multitouch block
129
129
130
130
// Gamepad data
131
- pthread_t gamepadThreadId ; // Gamepad reading thread id
132
131
int gamepadStreamFd [MAX_GAMEPADS ]; // Gamepad device file descriptor
133
132
134
133
} PlatformData ;
@@ -191,7 +190,7 @@ static void PollKeyboardEvents(void); // Process evdev keyboard events
191
190
static void * EventThread (void * arg ); // Input device events reading thread
192
191
193
192
static void InitGamepad (void ); // Initialize raw gamepad input
194
- static void * GamepadThread (void * arg ); // Mouse reading thread
193
+ static void PollGamepadEvents (void ); // Gamepad reading function
195
194
196
195
static int FindMatchingConnectorMode (const drmModeConnector * connector , const drmModeModeInfo * mode ); // Search matching DRM mode in connector's mode list
197
196
static int FindExactConnectorMode (const drmModeConnector * connector , uint width , uint height , uint fps , bool allowInterlaced ); // Search exactly matching DRM connector mode in connector's list
@@ -575,14 +574,7 @@ void PollInputEvents(void)
575
574
}
576
575
577
576
// Register gamepads buttons events
578
- for (int i = 0 ; i < MAX_GAMEPADS ; i ++ )
579
- {
580
- if (CORE .Input .Gamepad .ready [i ])
581
- {
582
- // Register previous gamepad states
583
- for (int k = 0 ; k < MAX_GAMEPAD_BUTTONS ; k ++ ) CORE .Input .Gamepad .previousButtonState [i ][k ] = CORE .Input .Gamepad .currentButtonState [i ][k ];
584
- }
585
- }
577
+ PollGamepadEvents ();
586
578
587
579
// Register previous touch states
588
580
for (int i = 0 ; i < MAX_TOUCH_POINTS ; i ++ ) CORE .Input .Touch .previousTouchState [i ] = CORE .Input .Touch .currentTouchState [i ];
@@ -598,9 +590,6 @@ void PollInputEvents(void)
598
590
// stdin reading is still used for legacy purposes, it allows keyboard input trough SSH console
599
591
600
592
if (!platform .eventKeyboardMode ) ProcessKeyboard ();
601
-
602
- // NOTE: Mouse input events polling is done asynchronously in another pthread - EventThread()
603
- // NOTE: Gamepad (Joystick) input events polling is done asynchronously in another pthread - GamepadThread()
604
593
#endif
605
594
606
595
// Handle the mouse/touch/gestures events:
@@ -1228,8 +1217,6 @@ void ClosePlatform(void)
1228
1217
pthread_join (platform .eventWorker [i ].threadId , NULL );
1229
1218
}
1230
1219
}
1231
-
1232
- if (platform .gamepadThreadId ) pthread_join (platform .gamepadThreadId , NULL );
1233
1220
}
1234
1221
1235
1222
// Initialize Keyboard system (using standard input)
@@ -1943,14 +1930,8 @@ static void InitGamepad(void)
1943
1930
{
1944
1931
CORE .Input .Gamepad .ready [i ] = true;
1945
1932
1946
- // NOTE: Only create one thread
1947
- if (i == 0 )
1948
- {
1949
- int error = pthread_create (& platform .gamepadThreadId , NULL , & GamepadThread , NULL );
1950
-
1951
- if (error != 0 ) TRACELOG (LOG_WARNING , "RPI: Failed to create gamepad input event thread" );
1952
- else TRACELOG (LOG_INFO , "RPI: Gamepad device initialized successfully" );
1953
- }
1933
+ // NOTE: Only show message for first gamepad
1934
+ if (i == 0 ) TRACELOG (LOG_INFO , "RPI: Gamepad device initialized successfully" );
1954
1935
1955
1936
ioctl (platform .gamepadStreamFd [i ], JSIOCGNAME (64 ), & CORE .Input .Gamepad .name [i ]);
1956
1937
ioctl (platform .gamepadStreamFd [i ], JSIOCGAXES , & CORE .Input .Gamepad .axisCount [i ]);
@@ -1959,7 +1940,7 @@ static void InitGamepad(void)
1959
1940
}
1960
1941
1961
1942
// Process Gamepad (/dev/input/js0)
1962
- static void * GamepadThread (void * arg )
1943
+ static void PollGamepadEvents (void )
1963
1944
{
1964
1945
#define JS_EVENT_BUTTON 0x01 // Button pressed/released
1965
1946
#define JS_EVENT_AXIS 0x02 // Joystick axis moved
@@ -1975,18 +1956,21 @@ static void *GamepadThread(void *arg)
1975
1956
// Read gamepad event
1976
1957
struct js_event gamepadEvent = { 0 };
1977
1958
1978
- while (! CORE . Window . shouldClose )
1959
+ for ( int i = 0 ; i < MAX_GAMEPADS ; i ++ )
1979
1960
{
1980
- for ( int i = 0 ; i < MAX_GAMEPADS ; i ++ )
1961
+ if ( CORE . Input . Gamepad . ready [ i ] )
1981
1962
{
1982
- if (read (platform .gamepadStreamFd [i ], & gamepadEvent , sizeof (struct js_event )) == (int )sizeof (struct js_event ))
1963
+ // Register previous gamepad states
1964
+ for (int k = 0 ; k < MAX_GAMEPAD_BUTTONS ; k ++ ) CORE .Input .Gamepad .previousButtonState [i ][k ] = CORE .Input .Gamepad .currentButtonState [i ][k ];
1965
+
1966
+ while (read (platform .gamepadStreamFd [i ], & gamepadEvent , sizeof (struct js_event )) == (int )sizeof (struct js_event ))
1983
1967
{
1984
1968
gamepadEvent .type &= ~JS_EVENT_INIT ; // Ignore synthetic events
1985
1969
1986
1970
// Process gamepad events by type
1987
1971
if (gamepadEvent .type == JS_EVENT_BUTTON )
1988
1972
{
1989
- // TRACELOG(LOG_WARNING , "RPI: Gamepad button: %i, value: %i", gamepadEvent.number, gamepadEvent.value);
1973
+ TRACELOG (LOG_DEBUG , "RPI: Gamepad %i button: %i, value: %i" , i , gamepadEvent .number , gamepadEvent .value );
1990
1974
1991
1975
if (gamepadEvent .number < MAX_GAMEPAD_BUTTONS )
1992
1976
{
@@ -1999,7 +1983,7 @@ static void *GamepadThread(void *arg)
1999
1983
}
2000
1984
else if (gamepadEvent .type == JS_EVENT_AXIS )
2001
1985
{
2002
- // TRACELOG(LOG_WARNING , "RPI: Gamepad axis: %i, value: %i", gamepadEvent.number, gamepadEvent.value);
1986
+ TRACELOG (LOG_DEBUG , "RPI: Gamepad %i axis: %i, value: %i" , i , gamepadEvent .number , gamepadEvent .value );
2003
1987
2004
1988
if (gamepadEvent .number < MAX_GAMEPAD_AXIS )
2005
1989
{
@@ -2008,11 +1992,8 @@ static void *GamepadThread(void *arg)
2008
1992
}
2009
1993
}
2010
1994
}
2011
- else WaitTime (0.001 ); // Sleep for 1 ms to avoid hogging CPU time
2012
1995
}
2013
1996
}
2014
-
2015
- return NULL ;
2016
1997
}
2017
1998
2018
1999
// Search matching DRM mode in connector's mode list
0 commit comments