# \[SOLVED\] Game Control Plus: how to reconnect wireless XBOX controller after it turned off

**URL:** <https://discourse.processing.org/t/solved-game-control-plus-how-to-reconnect-wireless-xbox-controller-after-it-turned-off/9698>\
**Category:** Libraries\
**Created:** [March 27, 2019, 11:48pm UTC](https://discourse.processing.org/t/solved-game-control-plus-how-to-reconnect-wireless-xbox-controller-after-it-turned-off/9698 "2019-03-27T23:48:47Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![clausrogisch](https://avatars.discourse-cdn.com/v4/letter/c/a8b319/32.png) [@clausrogisch](https://discourse.processing.org/u/clausrogisch)\
**Post date:** [March 27, 2019, 11:48pm UTC](https://discourse.processing.org/t/solved-game-control-plus-how-to-reconnect-wireless-xbox-controller-after-it-turned-off/9698/1 "2019-03-27T23:48:47Z")

</div>

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)

 ![grafik](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/99a7a90e96b89aa9bd655b50fe4b8e7a8e11ea9f.png)

Code used to set up the controller:

```auto
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);
  }
}

```

---

<div class="post-metadata">

**Author:** ![figraham](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/figraham/32/4161_2.png) [@figraham](https://discourse.processing.org/u/figraham)\
**Post date:** [March 28, 2019, 2:13am UTC](https://discourse.processing.org/t/solved-game-control-plus-how-to-reconnect-wireless-xbox-controller-after-it-turned-off/9698/2 "2019-03-28T02:13:52Z")

</div>

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](http://lagers.org.uk/gamecontrol/). 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:

```auto
boolean successfulPoll = controller.poll(); // this
// instead of
controller.poll(); // this

```

You’ll probably have to use an IDE to like [eclipse](https://www.eclipse.org/) 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.

---

<div class="post-metadata">

**Author:** ![clausrogisch](https://avatars.discourse-cdn.com/v4/letter/c/a8b319/32.png) [@clausrogisch](https://discourse.processing.org/u/clausrogisch)\
**Post date:** [March 28, 2019, 2:51pm UTC](https://discourse.processing.org/t/solved-game-control-plus-how-to-reconnect-wireless-xbox-controller-after-it-turned-off/9698/3 "2019-03-28T14:51:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [March 30, 2019, 2:04am UTC](https://discourse.processing.org/t/solved-game-control-plus-how-to-reconnect-wireless-xbox-controller-after-it-turned-off/9698/4 "2019-03-30T02:04:39Z")

</div>

> [@figraham](#):
>
> 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.

If somebody gets this working… submit the patch to @quark as a pull request?

**Edit** – actually, I forgot:

> [Quarks Place](http://lagers.org.uk/gamecontrol/)  
> GCP is provided as is and will not be updated further except to fix bugs in the code I added.

…although I believe there is a recent fork:

- [Repository search results · GitHub](https://github.com/search?q=gamecontrolplus)

---

<div class="post-metadata">

**Author:** ![clausrogisch](https://avatars.discourse-cdn.com/v4/letter/c/a8b319/32.png) [@clausrogisch](https://discourse.processing.org/u/clausrogisch)\
**Post date:** [March 31, 2019, 2:26am UTC](https://discourse.processing.org/t/solved-game-control-plus-how-to-reconnect-wireless-xbox-controller-after-it-turned-off/9698/5 "2019-03-31T02:26:34Z")

</div>

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”.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [March 31, 2019, 10:08am UTC](https://discourse.processing.org/t/solved-game-control-plus-how-to-reconnect-wireless-xbox-controller-after-it-turned-off/9698/6 "2019-03-31T10:08:41Z")

</div>

> [@clausrogisch](#):
>
> the `matches()` funtion is called, which includes setting the matches `availability=false`

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.

---

<div class="post-metadata">

**Author:** ![clausrogisch](https://avatars.discourse-cdn.com/v4/letter/c/a8b319/32.png) [@clausrogisch](https://discourse.processing.org/u/clausrogisch)\
**Post date:** [March 31, 2019, 10:37am UTC](https://discourse.processing.org/t/solved-game-control-plus-how-to-reconnect-wireless-xbox-controller-after-it-turned-off/9698/7 "2019-03-31T10:37:07Z")

</div>

@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:

```auto
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.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [March 31, 2019, 11:02am UTC](https://discourse.processing.org/t/solved-game-control-plus-how-to-reconnect-wireless-xbox-controller-after-it-turned-off/9698/8 "2019-03-31T11:02:33Z")

</div>

> [@clausrogisch](#):
>
> As you are the creator of GCP:

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

```auto
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!

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [March 31, 2019, 11:03am UTC](https://discourse.processing.org/t/solved-game-control-plus-how-to-reconnect-wireless-xbox-controller-after-it-turned-off/9698/9 "2019-03-31T11:03:53Z")

</div>

Sorry ignore the last sentence, the answer is in the title. 😀

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [March 31, 2019, 11:04am UTC](https://discourse.processing.org/t/solved-game-control-plus-how-to-reconnect-wireless-xbox-controller-after-it-turned-off/9698/10 "2019-03-31T11:04:49Z")

</div>

Having said that why turn off the wireless controller?

---

<div class="post-metadata">

**Author:** ![clausrogisch](https://avatars.discourse-cdn.com/v4/letter/c/a8b319/32.png) [@clausrogisch](https://discourse.processing.org/u/clausrogisch)\
**Post date:** [March 31, 2019, 11:23am UTC](https://discourse.processing.org/t/solved-game-control-plus-how-to-reconnect-wireless-xbox-controller-after-it-turned-off/9698/11 "2019-03-31T11:23:31Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [March 31, 2019, 11:33am UTC](https://discourse.processing.org/t/solved-game-control-plus-how-to-reconnect-wireless-xbox-controller-after-it-turned-off/9698/12 "2019-03-31T11:33:08Z")

</div>

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

```auto
//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.

---

<div class="post-metadata">

**Author:** ![clausrogisch](https://avatars.discourse-cdn.com/v4/letter/c/a8b319/32.png) [@clausrogisch](https://discourse.processing.org/u/clausrogisch)\
**Post date:** [March 31, 2019, 11:38am UTC](https://discourse.processing.org/t/solved-game-control-plus-how-to-reconnect-wireless-xbox-controller-after-it-turned-off/9698/13 "2019-03-31T11:38:27Z")

</div>

@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](https://github.com/briankendall/xboxToVJoy) 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.

Thanks to all for the time and help.
