I am writing on a programm where i am using the inputs of an wireless XBOX 360 controller with the gamecontrolplus library. In addition i am using a vJoy device and X2DCLI in order to split the left and right triggers. These inputs are also used without problem.
The problem comes when the controller is not used for a longer time and automatically powers off.
In the console it prints the error from the polling:
“Failed to poll device; Failed to poll device (8007000c)”
When i print the device list: control.getDevices() and remove the battery from the controller (actively turning it off) the XBOX controller is still listed.
When i turn the controller on again it won’t reconnect automatically
I am stuck finding a way to reconnect the controller, without restarting the complete program.
As i am quite unexperienced this question might be totally wrong:
Is there a way to restart the “thread” of gamecontrolplus to get a update on the devices and possibly set the control object up while still running?
I am thankfull for any help or advice on this issue.
Picture: XBOX Controller still in list, even if it is clearly not connected any more (pls ignore log in between)
import org.gamecontrolplus.*;
import org.gamecontrolplus.gui.*;
ControlDevice xbox;
ControlDevice xboxt;
ControlIO control;
setup(){
control = ControlIO.getInstance(this);
xbox= control.getMatchedDevice("360"); //create device with button config from 360
xboxt= control.getMatchedDevice("360t"); //create helper device rooted via vjoy to use left and right trigger independently
if (xbox== null || xboxt==null ) { //exit if no controller found, or comunication failed
println("not");
System.exit(-1);
}
}
I haven’t used this library so I put that at the start as a little disclaimer so I might be entirely wrong. From my quick investigation of the source code which I found under src in the zip from here. I think it’s possible but I think you have to change some code in the library. So fortunately the poll() method in net.java.games.input.AbstractController returns a boolean indicating if the poll was successful or not. Unfortunately that isn’t used in the library. You’d can try changing the update method in org.gamecontrolplus.ControlDevice to pass along that boolean or set a variable in the system. The new update method would have something like:
boolean successfulPoll = controller.poll(); // this
// instead of
controller.poll(); // this
You’ll probably have to use an IDE to like eclipse to export the new .jar files and replace the old ones.
Then if the value is false stop asking the device for information and make a loop that will try to create a new device every few seconds. Like you have in setup. At least that would be my approach, I don’t know if it would work.
Thanks a lot for the fast reply and the advice on the tools to implement it. I am currently looking into the source code, but will definetly need some time to see how i will make it work.
Edit:
would it be possible to use import net.java.games.input.*; to use the from the ControllerEnviroment class the removeControllerListener() to kick the controlIO device and reassign it by simply control = ControlIO.getInstance(this); on a press of a button
Thanks.
if will have a look a the forks.
What i saw from the sourde files in the original library, during the setup of the controldevice, the matches() funtion is called, which includes setting the matches availability=false . As i understand it, this makes it not possible to dispose() the contoller and set it up again (starting it manually as a compromise) because it won’t appear in the devicelist when getDevices(), still beeing seen as previously matched and hence not “available”.
This prevents multiple calls to matches() selecting the same device. This is important if you want to use two identical devices in the same sketch e.g. a two-player game.
@quark i understand the purpose of this method.
As you are the creator of GCP:
Is there a proper way to get rid of a controldevice in a way so you can start the setup of a controller again ()?
Something like:
import org.gamecontrolplus.*;
import org.gamecontrolplus.gui*;
ControlDevice xbox;
ControlIO control;
void setup(){
control = ControlIO.getInstance(this);
xbox= control.getMatchedDevice("360");
}
void draw(){}
//when the controller is disconnected and i turned it on again
void mousePressed(){
//close the device or dispose or proper way to do it...
xbox.close();
//and set it up again maybe like so
xbox= control.getMatchedDevice("360");
}
But this did not work wor me (i don’t know if it has to do thith the controller being connected via the wireless adapter.
This opend the deviclist gui where the controller was not on the list.
I am not the original creator, I simply took an abandoned Processing V2 library, updated it to work with Processing V3 and added some extras e.g. the configurator.
The underlying system libraries to talk to USB devices was unchanged and will not be changed by me as I lack the resources and skills to do it.
The list of devices is created by the instruction
control = ControlIO.getInstance(this);
so any device you want to use with your sketch must be connected before the sketch starts
I don’t see why you would would want to ‘close’ the device simply to ‘reconnect’ it again later. Just don’t use it!
@quark
If by turn off you mean kick the controller in the script:
as a mean to get rid of the availability flag and having it true again.
(as it wont just work again when the controller is on again it seems like something in the config is not exactly the same so the config has to be renewed(?))
If by turn off you mean the actual controller:
the xbox 360 controllers automatically turn off when they are not connected to a power source and are at idle for a certain period of time.
Sadly this option can’t be set differently (to just say it should stay on till battery is down).
This also brings up a point:
in the current form, if you loose connection because the battery is down, you loose the controller.
So any application has to be completely started over when a wireless controller goes out of battery or idles, or am i missing something.
I have only tested this library with a wired XBOX controller and a Joystick because they are the only devices I have. I assume the wireless controller is powered through the USB port but the actual controller is battery operated so will go to sleep if not used.
You might try
//when the controller is disconnected and i turned it on again
void mousePressed(){
//close the device or dispose or proper way to do it...
xbox.available = true;
//and set it up again maybe like so
xbox= control.getMatchedDevice("360");
}
If this doesn’t work then I can’t think what else you might try.
@quark
thanks for this simple hint. I will try it as soon as i am home again (currentlly i have no controller with me). public boolean available so i should be able to call it.
Edit:
sadly i was not able to make it work.
For anyone interested in a Solution/Workaround:
I was indeed able to get a workaround. I realized, that this behavior did not occur with the Triggers i polled from the vJoy Device (to split up the z-Axis into independent values)
Luckily with xboxToVJoy, briankendall supplied all i needed.
This program routes the native XBOX controller to a previously set up vJoy device. (using XInput so also with split up Z-Axis!)
The simple reason why this works: the vJoy Device stays active, even if the controller is gone. The values are just not updated anymore, but GCP can still poll() from the unchanging vJoy Device. When the controlleer is turned on again, the vJoy Device recognizes the values from the controller again.
Now with GCP i simply use the vJoy Device.
Problem not solved, but fixed.