|
|
@ -88,14 +88,14 @@ void _glfwInitJoysticks( void ) |
|
|
|
int i; |
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
|
// Start by saying that there are no sticks
|
|
|
|
// Start by saying that there are no sticks
|
|
|
|
for( i = 0; i <= GLFW_JOYSTICK_LAST; ++ i ) |
|
|
|
for (i = 0; i <= GLFW_JOYSTICK_LAST; i++) |
|
|
|
_glfwJoy[i].Present = GL_FALSE; |
|
|
|
_glfwJoy[i].Present = GL_FALSE; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef _GLFW_USE_LINUX_JOYSTICKS |
|
|
|
#ifdef _GLFW_USE_LINUX_JOYSTICKS |
|
|
|
|
|
|
|
|
|
|
|
// Try to open joysticks (nonblocking)
|
|
|
|
// Try to open joysticks (nonblocking)
|
|
|
|
joy_count = 0; |
|
|
|
joy_count = 0; |
|
|
|
for( k = 0; k <= 1 && joy_count <= GLFW_JOYSTICK_LAST; ++ k ) |
|
|
|
for (k = 0; k <= 1 && joy_count <= GLFW_JOYSTICK_LAST; k++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Pick joystick base name
|
|
|
|
// Pick joystick base name
|
|
|
|
switch (k) |
|
|
|
switch (k) |
|
|
@ -111,7 +111,7 @@ void _glfwInitJoysticks( void ) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Try to open a few of these sticks
|
|
|
|
// Try to open a few of these sticks
|
|
|
|
for( i = 0; i <= 50 && joy_count <= GLFW_JOYSTICK_LAST; ++ i ) |
|
|
|
for (i = 0; i <= 50 && joy_count <= GLFW_JOYSTICK_LAST; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
sprintf(joy_dev_name, "%s%d", joy_base_name, i); |
|
|
|
sprintf(joy_dev_name, "%s%d", joy_base_name, i); |
|
|
|
fd = open(joy_dev_name, O_NONBLOCK); |
|
|
|
fd = open(joy_dev_name, O_NONBLOCK); |
|
|
@ -157,10 +157,10 @@ void _glfwInitJoysticks( void ) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Clear joystick state
|
|
|
|
// Clear joystick state
|
|
|
|
for( n = 0; n < _glfwJoy[ joy_count ].NumAxes; ++ n ) |
|
|
|
for (n = 0; n < _glfwJoy[joy_count].NumAxes; n++) |
|
|
|
_glfwJoy[joy_count].Axis[n] = 0.0f; |
|
|
|
_glfwJoy[joy_count].Axis[n] = 0.0f; |
|
|
|
|
|
|
|
|
|
|
|
for( n = 0; n < _glfwJoy[ joy_count ].NumButtons; ++ n ) |
|
|
|
for (n = 0; n < _glfwJoy[joy_count].NumButtons; n++) |
|
|
|
_glfwJoy[joy_count].Button[n] = GLFW_RELEASE; |
|
|
|
_glfwJoy[joy_count].Button[n] = GLFW_RELEASE; |
|
|
|
|
|
|
|
|
|
|
|
// The joystick is supported and connected
|
|
|
|
// The joystick is supported and connected
|
|
|
@ -169,9 +169,7 @@ void _glfwInitJoysticks( void ) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif // _GLFW_USE_LINUX_JOYSTICKS
|
|
|
|
#endif // _GLFW_USE_LINUX_JOYSTICKS
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -187,13 +185,14 @@ void _glfwTerminateJoysticks( void ) |
|
|
|
int i; |
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
|
// Close any opened joysticks
|
|
|
|
// Close any opened joysticks
|
|
|
|
for( i = 0; i <= GLFW_JOYSTICK_LAST; ++ i ) |
|
|
|
for (i = 0; i <= GLFW_JOYSTICK_LAST; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (_glfwJoy[i].Present) |
|
|
|
if (_glfwJoy[i].Present) |
|
|
|
{ |
|
|
|
{ |
|
|
|
close(_glfwJoy[i].fd); |
|
|
|
close(_glfwJoy[i].fd); |
|
|
|
free(_glfwJoy[i].Axis); |
|
|
|
free(_glfwJoy[i].Axis); |
|
|
|
free(_glfwJoy[i].Button); |
|
|
|
free(_glfwJoy[i].Button); |
|
|
|
|
|
|
|
|
|
|
|
_glfwJoy[i].Present = GL_FALSE; |
|
|
|
_glfwJoy[i].Present = GL_FALSE; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -209,14 +208,13 @@ void _glfwTerminateJoysticks( void ) |
|
|
|
|
|
|
|
|
|
|
|
static void pollJoystickEvents(void) |
|
|
|
static void pollJoystickEvents(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
#ifdef _GLFW_USE_LINUX_JOYSTICKS |
|
|
|
#ifdef _GLFW_USE_LINUX_JOYSTICKS |
|
|
|
|
|
|
|
|
|
|
|
struct js_event e; |
|
|
|
struct js_event e; |
|
|
|
int i; |
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
|
// Get joystick events for all GLFW joysticks
|
|
|
|
// Get joystick events for all GLFW joysticks
|
|
|
|
for( i = 0; i <= GLFW_JOYSTICK_LAST; ++ i ) |
|
|
|
for (i = 0; i <= GLFW_JOYSTICK_LAST; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Is the stick present?
|
|
|
|
// Is the stick present?
|
|
|
|
if (_glfwJoy[i].Present) |
|
|
|
if (_glfwJoy[i].Present) |
|
|
@ -231,15 +229,11 @@ static void pollJoystickEvents( void ) |
|
|
|
switch (e.type) |
|
|
|
switch (e.type) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case JS_EVENT_AXIS: |
|
|
|
case JS_EVENT_AXIS: |
|
|
|
_glfwJoy[ i ].Axis[ e.number ] = (float) e.value / |
|
|
|
_glfwJoy[i].Axis[e.number] = (float) e.value / 32767.0f; |
|
|
|
32767.0f; |
|
|
|
|
|
|
|
// We need to change the sign for the Y axes, so that
|
|
|
|
// We need to change the sign for the Y axes, so that
|
|
|
|
// positive = up/forward, according to the GLFW spec.
|
|
|
|
// positive = up/forward, according to the GLFW spec.
|
|
|
|
if (e.number & 1) |
|
|
|
if (e.number & 1) |
|
|
|
{ |
|
|
|
_glfwJoy[i].Axis[e.number] = -_glfwJoy[i].Axis[e.number]; |
|
|
|
_glfwJoy[ i ].Axis[ e.number ] = |
|
|
|
|
|
|
|
-_glfwJoy[ i ].Axis[ e.number ]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case JS_EVENT_BUTTON: |
|
|
|
case JS_EVENT_BUTTON: |
|
|
@ -253,9 +247,7 @@ static void pollJoystickEvents( void ) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif // _GLFW_USE_LINUX_JOYSTICKS
|
|
|
|
#endif // _GLFW_USE_LINUX_JOYSTICKS
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -310,7 +302,7 @@ int _glfwPlatformGetJoystickPos( int joy, float *pos, int numaxes ) |
|
|
|
numaxes = _glfwJoy[joy].NumAxes; |
|
|
|
numaxes = _glfwJoy[joy].NumAxes; |
|
|
|
|
|
|
|
|
|
|
|
// Copy axis positions from internal state
|
|
|
|
// Copy axis positions from internal state
|
|
|
|
for( i = 0; i < numaxes; ++ i ) |
|
|
|
for (i = 0; i < numaxes; i++) |
|
|
|
pos[i] = _glfwJoy[joy].Axis[i]; |
|
|
|
pos[i] = _glfwJoy[joy].Axis[i]; |
|
|
|
|
|
|
|
|
|
|
|
return numaxes; |
|
|
|
return numaxes; |
|
|
@ -337,7 +329,7 @@ int _glfwPlatformGetJoystickButtons( int joy, unsigned char *buttons, |
|
|
|
numbuttons = _glfwJoy[joy].NumButtons; |
|
|
|
numbuttons = _glfwJoy[joy].NumButtons; |
|
|
|
|
|
|
|
|
|
|
|
// Copy button states from internal state
|
|
|
|
// Copy button states from internal state
|
|
|
|
for( i = 0; i < numbuttons; ++ i ) |
|
|
|
for (i = 0; i < numbuttons; i++) |
|
|
|
buttons[i] = _glfwJoy[joy].Button[i]; |
|
|
|
buttons[i] = _glfwJoy[joy].Button[i]; |
|
|
|
|
|
|
|
|
|
|
|
return numbuttons; |
|
|
|
return numbuttons; |
|
|
|