Game Control Plus - trouble with config

Hello. I’ve been able to use GCP to connect a Logitech game controller to Processing, mostly. I have been trying to set up the configuration file so that it only recognizes 4 buttons.
I started with the “joystick” example and have removed all the parts I don’t want to use, and everything is working fine except I can’t understand one thing.
Whenever I try to remove the “SLIDER” line from the configuration file, the sketch stops responding to the button presses. This is the config file named buttonTest3:

Buttons Only
blue	Blue button	1	BUTTON	0	0	0.0	0.0
green	Green button	1	BUTTON	1	0	0.0	0.0
red	Red button	1	BUTTON	2	0	0.0	0.0
yellow	Yellow button	1	BUTTON	3	0	0.0	0.0
X	X position	3	SLIDER	x	0	1.0	0.0

When I remove the last line in this file, the buttons no longer call the functions. Is there some reason a SLIDER must remain in the config? Or why might this not be working?

I tried creating a configuration with just the 4 buttons using the configuration tool, and it didn’t work. So I started over with the “joystick” example, and kept removing things until it broke, and it turns out that if this “SLIDER” line is not in the config file that’s what makes it stop working.

Can someone please help me understand what’s going on?

Here is the sketch:

import org.gamecontrolplus.gui.*;
import org.gamecontrolplus.*;
import net.java.games.input.*;

ControlIO control;
ControlDevice buttonPad;

public void setup() {
  size(400, 400);

  control = ControlIO.getInstance(this);
  buttonPad = control.getMatchedDevice("buttonTest3");
  if (buttonPad == null) {
    println("No suitable device configured");
    System.exit(-1);
  }

  buttonPad.getButton("blue").plug(this, "blueButton", ControlIO.ON_RELEASE);
  buttonPad.getButton("green").plug(this, "greenButton", ControlIO.ON_RELEASE);
  buttonPad.getButton("red").plug(this, "redButton", ControlIO.ON_RELEASE);
  buttonPad.getButton("yellow").plug(this, "yellowButton", ControlIO.ON_RELEASE);
}

void blueButton() {
  println("Blue button");
}
void greenButton() {
  println("Green button");
}
void redButton() {
  println("Red button");
}
void yellowButton() {
  println("Yellow button");
}

public void draw() {
}

Probably @quark knows, I think he’s the author :slight_smile:

OK from the original post it looks like you are trying to connect a gamepad.

The config file must uniquely identify the device you want to use. The user does this by specifying a list of inputs unique to the device. In the file above you are looking for a device that has four buttons named 0, 1, 2 and 3 plus a slider named X.

If you omit the slider X then it could match the keyboard because the keys are treated as buttons. So the moral is make sure the config file will only match one device, if you have to specify additional inputs - you don’t have to use them. :grinning:

1 Like

Thanks for getting back to me on this! I understand what you are saying, and it does seem to work fine. Thanks!