Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  JInput Controller connect disconnect problem SOVLED!!!  (Read 10053 times)
0 Members and 1 Guest are viewing this topic.
Offline Jnsanders1983

Junior Newbie

« Posted 2011-03-15 16:28:02 »

Greetings fellow developers. I have been searching this topic only to find that one has succeeded and failed to provide their results because they like proprietary bullshit.

I have been looking to make a push to talk handset for a project I am doing with the United States Air Force. I found it necessary that I must be able to find a device that I plug/unplug during the program running.
I come to find that the immediate issue was that "ControllerEnvironment.getDefaultEnvironment().getControllers()" never changed the list of Controllers while the program is running. So why is that?

Well lets start with the the call "ControllerEnvironment.getDefaultEnvironment().getControllers()". This class does not have a protected Constructor. so in order to have access to the constructor you have to be part of the package it is contained in. This is not practical. So I made this public, but only to find that I still could not call construction on it. so I undid that.

The next thing I notice is the getDefaultEnvironment(). Ths actually uses a constructor. Once again, this is protected. So I made it public.

Next, for testing purpose I programmed a button like so in my GUI;

        ce = new DefaultControllerEnviornment();
        Controller[] controller = ce.getControllers();
        for(int i = 0; i < controller.length; i++)

every time i press this button, it reconstructs the list of controllers and prints them out.

so i removed and added devices while pressing this button. Viola!! it worked, the list was updating the devices.

so for the next part you basically want to created a TimerTask that runs this code every so often to update the list. How often is up to the use of your software and how important an updated list of controllers is.

I have yet to test how this effects the rest of my code polling the controllers, but this is a start, and it is far easier than try to understand and edit the native code.

I hope this helps all of you out, i have spent a couple weeks researching this, and I solved it in a matter of half an hour just mucking through the code.
Offline endolf

JGO Coder

Medals: 7
Exp: 15 years

Current project release date: sometime in 3003

« Reply #1 - Posted 2011-03-15 17:46:42 »

You probably need to make sure that when the new device list is evaluated, all the old handles are removed to the old devices in the native code, otherwise you might find you run out of file handles under unix systems. I don't know how this handles opening devices in exclusive mode on windows either?

but other than that, it seems like a reasonable work around. Under unix this would be the way to do it anyways, under windows there is a listener interface for the directx bindings IIRC, but that's for a more permanent solution, if anyone fancies the task Smiley


Offline Jnsanders1983

Junior Newbie

« Reply #2 - Posted 2011-03-15 18:00:14 »

by doing it this way your are recalling the native calls, that build the list of devices in java. there was no other way to update the list than to call the native code again, but there was no given method to do that.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Nate

« JGO Bitwise Duke »

Medals: 167
Projects: 4
Exp: 14 years

Esoteric Software

« Reply #3 - Posted 2011-03-15 21:23:50 »

This reminds me, I should put a non-military only clause on my OSS licenses...

Offline deepthought
« Reply #4 - Posted 2011-03-20 19:28:16 »

problem sovled? someone in the military should be able to spell better.

Mad Scientist
Offline xerxes_is_kind

Innocent Bystander

« Reply #5 - Posted 2011-04-14 07:18:35 »

in the latest build you can create an instance of DirectAndRawInputEnvironmentPlugin every time you want to know what is plugged in. then use the getControllers() method and so on.
Pages: [1]
  ignore  |  Print  

EgonOlsen (79 views)
2018-06-10 19:43:48

EgonOlsen (59 views)
2018-06-10 19:43:44

EgonOlsen (78 views)
2018-06-10 19:43:20

DesertCoockie (261 views)
2018-05-13 18:23:11

nelsongames (159 views)
2018-04-24 18:15:36

nelsongames (158 views)
2018-04-24 18:14:32

ivj94 (901 views)
2018-03-24 14:47:39

ivj94 (162 views)
2018-03-24 14:46:31

ivj94 (813 views)
2018-03-24 14:43:53

Solater (177 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!