Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Know a good Java library to read from a Gamepad or Joystick? (http://www.chiefdelphi.com/forums/showthread.php?t=138198)

Maxwell777 17-09-2015 20:13

Know a good Java library to read from a Gamepad or Joystick?
 
I'm working on a program for our AUV (Not for FRC) and I need to be able to get values from a gamepad/joystick in a java program.
So far we've tried LWJGL and JInput, and both have issues with detecting if a controller disconnected (they will print an error to command line, but not actually throw an error).
It would also be nice (but not necessary) if the library was packed up into a .jar, so that we wouldn't need to install .dll's for each computer the program would run on.

Thanks in advance for all replies.

RyanCahoon 17-09-2015 21:38

Re: Know a good Java library to read from a Gamepad or Joystick?
 
In JInput, the comment for net.java.games.input.Controller.poll() says:
Code:

/**
 * Polls axes for data.  Returns false if the controller is no longer valid.

In LWJGL's GLFW library, there's
Code:

bool present = org.lwjgl.glfw.GLFW.glfwJoystickPresent(GLFW_JOYSTICK_1) == org.lwjgl.opengl.GL11.GL_TRUE;
[/quote]

Altainia 17-09-2015 21:47

Re: Know a good Java library to read from a Gamepad or Joystick?
 
Yeah. I would just poll the controller with JInput and if you need an exception thrown, do it upon receiving 'false'

Ben Wolsieffer 17-09-2015 21:52

Re: Know a good Java library to read from a Gamepad or Joystick?
 
I'm pretty sure LWJGL uses jinput behind the scenes for input handling (at least it used to), so you will likely get the same behavior with both libraries.

I wrote an application a while back that used some really hacky code to re-initialize Jinput to rescan for joysticks, which might be somewhat helpful. IIRC, the controller listener hooks worked correctly on Windows, but that hack was necessary on Linux.

It's been a while, so I forget how I dealt with the native libraries, but that application might also be able to help with that.

androb4 17-09-2015 22:55

Re: Know a good Java library to read from a Gamepad or Joystick?
 
Here's one I started using. I really like it so far and does everything that you require.

https://github.com/gary-rowe/hid4java

-Andres

Maxwell777 18-09-2015 14:16

Re: Know a good Java library to read from a Gamepad or Joystick?
 
Quote:

Originally Posted by RyanCahoon (Post 1496382)
In JInput, the comment for net.java.games.input.Controller.poll() says:
Code:

/**
 * Polls axes for data.  Returns false if the controller is no longer valid.

In LWJGL's GLFW library, there's
Code:

bool present = org.lwjgl.glfw.GLFW.glfwJoystickPresent(GLFW_JOYSTICK_1) == org.lwjgl.opengl.GL11.GL_TRUE;

[/quote]

Weird. I tried that in LWJGL, but it didn't work. I assumed it wouldn't work in JInput, but looks like it does.

LWJGL's docs

How would you check if the controller has reconnected? Would the .poll work again?
What if you connected a new joystick? How would you rebuild the list attached gamepads, if, say, you started the program and then connected a controller? IIRC, both JInput and LWJGL only build the list the first time you call it, and will give you only that list from that point on.

RyanCahoon 19-09-2015 00:37

Re: Know a good Java library to read from a Gamepad or Joystick?
 
Quote:

Originally Posted by Maxwell777 (Post 1496492)
Weird. I tried that in LWJGL, but it didn't work. I assumed it wouldn't work in JInput, but looks like it does.

Perhaps LWJGL is using an old version of JInput.

Quote:

Originally Posted by Maxwell777 (Post 1496492)
How would you check if the controller has reconnected? Would the .poll work again?

I'm not sure. Why don't you try it?

Quote:

Originally Posted by Maxwell777 (Post 1496492)
What if you connected a new joystick? How would you rebuild the list attached gamepads, if, say, you started the program and then connected a controller?

The GitHub version of JInput allows you to register listeners for controller state changes. That would probably be the most straight forward way.

I assume if JInput is able to fire events on controller state changes that it's also maintaining an updated list, but I haven't verified this.


All times are GMT -5. The time now is 10:21.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi