Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 6040 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;

if(e.getSource().equals(button1))
{
        ce = new DefaultControllerEnviornment();
       
        Controller[] controller = ce.getControllers();
       
        for(int i = 0; i < controller.length; i++)
        {
                 System.out.println(controller.getName());
         }
}

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


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

Endolf

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
Online Nate

JGO Kernel


Medals: 147
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.

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (21 views)
2014-09-19 03:14:18

Dwinin (35 views)
2014-09-12 09:08:26

Norakomi (62 views)
2014-09-10 13:57:51

TehJavaDev (87 views)
2014-09-10 06:39:09

Tekkerue (42 views)
2014-09-09 02:24:56

mitcheeb (65 views)
2014-09-08 06:06:29

BurntPizza (47 views)
2014-09-07 01:13:42

Longarmx (35 views)
2014-09-07 01:12:14

Longarmx (40 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!