Game control plus bluetooth controller

@quark, sorry to bother you…
I was wondering if it were possible to connect a bluetooth controller to processing with the game control plus library. I have a playstation 4 2nd gen controller which can connect to my laptop with bluetooth, but when I open the configurator (or the showDevices, or any self-made) sketch, it gives me this error:
ClassCastException: java.lang.String cannot be cast to [Ljava.lang.Object;
it also highlights the code: controlIO = ControlIO.getInstance(this);
somehow when I connect the controller over USB it works just fine. and when I connect another bluetooth device while the controller is disconnected the sketch can run too…

Is there anything else you can fill in instead of “this” in the getInstance() parameter to enable these bluetooth controllers?
or do you have any other idea that causes this problem?

I look forward to hearing from you.

Dennis

1 Like

I have no idea because I don’t have a Bluetooth controller to test it with.

Do the GCP examples work without the Bluetooth controller attached?

No this refers to the PApplet class object that encompasses the sketch code.

GCP is updated and extended version of proCONTROLL created and abandoned by Christian Riekoff in 2005.

The core of the library consists of

  • OS specific system exe files
  • JInput

both of these are very old pre 2005 and I don’t have the resources to modify them so GCP either works with your device or not there is little I can do. Sorry about that.

1 Like

@quark thank you for your reply,
I did some more testing, initially I did it on my macbook on macOS Mojave, which gave the error like described above (and yes, the GCP examples do run without the bluetooth controller attached, even when the same controller is connected via USB).
I also have Windows installed with bootcamp, so I booted that up, tried it and it did work… I did have DS4Windows though. tried the same thing on my pc as well, without ds4windows yet and it also worked…
The final use of the controller would actually be on a raspberry pi and i thought macOS would be more similar to it than windows.
turns out it does also actually work on the Raspberry (model 3 B+ with internal bluetooth), given I did have to download a different jinput-linux.so file to make the library work at all.

All in all I haven’t figured out why it doesn’t work on my macbook, maybe mojave specific?.. But I am glad it does work on both windows and Raspberry Pi.

Happy that you seem to have it working for you. Good luck with your project. :relieved:

haha thank you!

BTW, is there an easy way to know if there is a controller available at all before connecting to it?
Like I would like to just run the sketch autonomously, but when the controller is turned on with bluetooth it connects to the Raspberry and only then processing should start the whole

control = ControlIO.getInstance(this);
  controller = control.getMatchedDevice("DS4");

  if (controller == null) {
    println("no controller found");
    System.exit(-1);
  }

I know this is possible with a mouseclick, but i won’t have a mouse available at that time.
I also noticed when I run ControlIO.getInstance(this) it prints “Linux plugin claims to have found 0/1 controllers” (0/1 depending if it found 1)
Is it possible to compace this object with something? I tried with .equals and the string like above that gets printed, doesn’t work.

Edit: Also tried it with controller (which is control.getMatchedDeviceSilent(“ds4”); )
somehow this will always become null when you recall control.getMatchedDevice, even when the controller is connected.
it also doesn’t update when you disconnect the controller, it will keep saying “wireless controller” but now with and extra: “Failed to poll device: Failed to get key states (19)”
this is why i thought i had to update it again with controller = control.getMatchedDevice’Silent’(“DS4”);

Edit2: even control.getNumberOfDevices() doesn’t get updated unless you restart the entire sketch…

If you could help me with that too, it would be much appreciated! :hugs:

Have you tried ControlIO.getDevices()

control = ControlIO.getInstance(this);

Does not have to be in setup() simply call this code when a certain key is types. To avoid crashing the sketch you should check that control is not null before using it.

1 Like

@quark I’m getting the error “Cannot make a static reference to the non-static method getDevices() from the type ControlIO”
I tried it with control.getDevices, which doesn’t give this error, but it still doesn’t update when I connect or disconnect the controller.

Hi everyone, I’m raising this question again as I am having the same trouble. The controller used with a USB cable works fine, but as soon as it’s connected via bluetooth, the codes crash raising the ClassCastException: java.lang.String cannot be cast to [Ljava.lang.Object; error.
I am aware @quark that you don’t own a wireless controller but your library seems still very useful and stable and as those controllers become more and more available, I’m wondering if anyone would be in to tackle this issue. I got a feeling it’s not a big thing but Java is out of my league… but if I can help in any way…

I suggest that you read the first three paragraphs on my website where it makes it quite clear that this library is based on an old abandoned library written for Processing 2. All I did was take that library and modified the API to work with Processing 3 and added the configurator.

The guts of the library is based on JInput and a number of low level OS specific systems files for reading the USB hardware. These have not been updated in many, many years and I suspect these will not work with wireless devices unless they mimic wired devices. So although I can fix problems with the API I cannot do anything about JInput or the system libraries.

Unfortunately GCP will either detect a device or it won’t, there is absolutely nothing I can do about it. Sorry :disappointed:

Thank you, yes indeed I didn’t really get that part. That’s unforntunate…

• Implemented a workaround RaspberryPI + Processing3 + USB joystick.
• Wanted to implement joystick jogging on my Raspberry Pi, Processing3 GUI on a Grbl CNC machine, but hit the JInput <==> ARM incompatibility. Believe Quark is right in asserting that no ARM compatible JInput exists. This is in contradiction to the StackOverFlow thread JInput on RaspberryPi . Tried Albert’s extended apt-get: but no-joy Tried 2021-05-07-raspios-buster-arm64 from Install Raspberry 64 OS - Q-engineering, but processing would not start. Went back to 32bit raspbian.
• Workaround was to add a second Arduino Uno with a USB host shield and run the Logetech 3D Pro joystick off the shield. Modified the Arduino USB Host Shield Library 2.0 le3dp sketch to have all output include an identifying preamble (J0Y) which allows the processing serialEvent to identify which USB port belongs to the Grbl Arduino and which is the joystick Arduino. Working code is at GitHub - TPMoyer/Grbl4P: Processing3 GRBL GUI and GitHub - TPMoyer/LE3DP_4_Grbl4P: Arduino Uno sketch to stream Logitech 3D Pro Joystick data throug