Go to Post Meanwhile I'm over here with with my completely see-through poly-carbonate blocker prototype laughing. - JohnFogarty [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 09-17-2015, 08:13 PM
Maxwell777's Avatar
Maxwell777 Maxwell777 is offline
Is allowed to touch stuff now
AKA: Jackson Gray
FRC #0842 (Falcon Robotics)
Team Role: Programmer
 
Join Date: Aug 2013
Rookie Year: 2014
Location: Phoenix, AZ
Posts: 72
Maxwell777 has a spectacular aura aboutMaxwell777 has a spectacular aura aboutMaxwell777 has a spectacular aura about
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.
__________________
But why?
Reply With Quote
  #2   Spotlight this post!  
Unread 09-17-2015, 09:38 PM
RyanCahoon's Avatar
RyanCahoon RyanCahoon is offline
Disassembling my prior presumptions
FRC #0766 (M-A Bears)
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Mountain View
Posts: 688
RyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond repute
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]
__________________
FRC 2046, 2007-2008, Student member
FRC 1708, 2009-2012, College mentor; 2013-2014, Mentor
FRC 766, 2015-, Mentor
Reply With Quote
  #3   Spotlight this post!  
Unread 09-17-2015, 09:47 PM
Altainia Altainia is offline
That one geeky guy...
FRC #5098 (Sting-R)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2007
Location: Kansas City, MO
Posts: 18
Altainia will become famous soon enoughAltainia will become famous soon enough
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'
Reply With Quote
  #4   Spotlight this post!  
Unread 09-17-2015, 09:52 PM
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 520
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
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.
__________________



2016 North Shore District - Semifinalists and Excellence in Engineering Award
2015 Northeastern University District - Semifinalists and Creativity Award
2014 Granite State District - Semifinalists and Innovation in Control Award
2012 Boston Regional - Finalists
Reply With Quote
  #5   Spotlight this post!  
Unread 09-17-2015, 10:55 PM
androb4's Avatar
androb4 androb4 is offline
..is trying to take this year off.
AKA: Andrew A.
no team
Team Role: Alumni
 
Join Date: Feb 2010
Rookie Year: 2003
Location: Houston, TX
Posts: 220
androb4 is a splendid one to beholdandrob4 is a splendid one to beholdandrob4 is a splendid one to beholdandrob4 is a splendid one to beholdandrob4 is a splendid one to beholdandrob4 is a splendid one to beholdandrob4 is a splendid one to behold
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
__________________
FRC 441 Mentor 2012-2015
FRC 441 Alumni 2009-2012
FTC 4673 Alumni 2011-2012
FRC 1484 Alumni 2006-2008

Reply With Quote
  #6   Spotlight this post!  
Unread 09-18-2015, 02:16 PM
Maxwell777's Avatar
Maxwell777 Maxwell777 is offline
Is allowed to touch stuff now
AKA: Jackson Gray
FRC #0842 (Falcon Robotics)
Team Role: Programmer
 
Join Date: Aug 2013
Rookie Year: 2014
Location: Phoenix, AZ
Posts: 72
Maxwell777 has a spectacular aura aboutMaxwell777 has a spectacular aura aboutMaxwell777 has a spectacular aura about
Re: Know a good Java library to read from a Gamepad or Joystick?

Quote:
Originally Posted by RyanCahoon View Post
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.
__________________
But why?

Last edited by Maxwell777 : 09-18-2015 at 02:20 PM. Reason: forgot stuff
Reply With Quote
  #7   Spotlight this post!  
Unread 09-19-2015, 12:37 AM
RyanCahoon's Avatar
RyanCahoon RyanCahoon is offline
Disassembling my prior presumptions
FRC #0766 (M-A Bears)
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Mountain View
Posts: 688
RyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond repute
Re: Know a good Java library to read from a Gamepad or Joystick?

Quote:
Originally Posted by Maxwell777 View Post
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 View Post
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 View Post
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.
__________________
FRC 2046, 2007-2008, Student member
FRC 1708, 2009-2012, College mentor; 2013-2014, Mentor
FRC 766, 2015-, Mentor
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 07:59 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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