Game Control Plus - TrackBall v Mouse weirdness

I've been trying to use the 'Game Controller Plus' library to get trackball info for navigating an interface. I'm having problem with Kensington Trackball and the library. Perhaps this is an issue with the trackball but.... Anyway, I can only get it to work when I have also defined a 'binding' for an additional device, ie a mouse. if I then strip out all the code for the mouse the trackball is not recognized. interestingly, if, when both trackball and mouse are set up and producing info to the script, I switch the order of the device setup ie put the trackball above the mouse instead of the other way around, then the data is output as if from the other device.

Any thoughts? Other than try a different track ball.... will I have similar issue with other input devices? Am I missing something?

---------- CODE ------------
// This does work but......
// the order of control setup 1/2 defines which info they will control, 
// not the names of the controller files. Though the controller files need
// to be in the correct places for it to work. 

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

ControlIO control2;  //setup the io from controller
ControlDevice stick2;

ControlIO control;  //setup the io from controller
ControlDevice stick;

// this is the start of a sketch to use controller to navigate thru pics in 3D

String C2, C;

float tankSpeed;
float tankDir;
float tankSpeed2;
float tankDir2;


public void setup() {
  size(640, 480);
  // Initialise the ControlIO

// --- Controller 1 setup ---
  control = ControlIO.getInstance(this);  //  println(this);
  //  Find a device that matches the configuration file
  stick = control.getMatchedDevice("PhotoInterface_LogitechMouse");
  if (stick == null) {
    println("No suitable device configured");
    exit(); // End the program NOW!
  }
// --------------------------

// --- Controller 2 setup ---
  control2 = ControlIO.getInstance(this);
  println(this);
  stick2 = control2.getMatchedDevice("tb3");
  if (stick2 == null) {
    println("No suitable device configured");
    exit(); // End the program NOW!
  }
// --------------------------
}

public void draw() {
  background(0, 64, 0);
  float deltaTime = 0.5;   //(float) timer.getElapsedTime();
  processUserGameInput(deltaTime);
}

public void processUserGameInput(float deltaTime) {  // Calculate the tanks speed and set the sprite animation sequence 
// 'Mouse' in printout below
  tankSpeed = stick.getSlider("xAxis").getValue();
  tankDir = stick.getSlider("yAxis").getValue();
  if (stick.getButton("LEFT").pressed() == true) {
    C = "Left";
  }
  if (stick.getButton("RIGHT").pressed() == true) {
    C = "Right";
  }

// 'TBall' in printout below
  tankSpeed2 = stick2.getSlider("xAxis2").getValue();
  tankDir2 = stick2.getSlider("yAxis2").getValue();
  if (stick2.getButton("LEFT2").pressed() == true) {
    C2 = "Left2";
  }
  if (stick2.getButton("RIGHT2").pressed() == true) {
    C2 = "Right2";
  }

  println("Mouse: ", tankSpeed, " - ", tankDir, " - ", C, " - ", "deltaTime= ", deltaTime);
  println("TBall: ", tankSpeed2, " - ", tankDir2, " - ", C2);
}
Tagged:

Answers

  • The statement ControlIO.getInstance(this) returns a singleton object, which means that it both control and control2 are the same object. So get rid of control2 and use control throughout. It won't change how your sketch works, just simplifies the code.

    The order the devices are matched under normal circumstances shouldn't make a difference. I suspect the config files (what you call bindings) could match either device. This happens because the hardware names given to the inputs (sliders, buttons) are the same for both devices.

    If that is the case you have two options -

    (1) use the display devices example to find one input that is not common to both devices and include it in one of the config files

    (2) get the device name reported by the display devices example and use the getDevice(_name_) method instead of the getMatchedDevice(_file_)

    HTH

  • edited September 2014

    The actual devices do use the same hardware names (example, left - left). But the names I assigned those inputs in config are different for each device, LEFT & LEFT2 for example.

    Interesting. - I made a new config for the Mouse Device with 7 inputs instead of just the 4 needed. typed the new config name into the existing processing sketch (config file was exported to it's data folder before) and ran sketch. The new config comes second in the sketch. On run it brought up a 'GameControlPlus' dialog asking to locate the device, but the only one it presented for linking was the TrackBall Device. Ie I presume, the Mouse Device was already linked and not available. (nb can't link now because script too many inputs for the TrackBall Device, the name in dialog box says 'config. for: Photo Interface' which is the name I gave the Mouse Device in it's config file, but I am linking the TrackBall Device - that's the only thing I could click on.) - Reversing the order of controller initializations, there was no dialog request to link Device, and both returned input data.

    2 sounds like what I should try. Note I'd like to just use the trackball, which won't work alone.

    re controlIO statement - that explains why it seemed to work the same before I put the second instance in. Debugging... I did it to segregate everything I could think of.

  • Answer ✓

    The actual devices do use the same hardware names (example, left - left). But the names I assigned those inputs in config are different for each device, LEFT & LEFT2 for example.

    It is the hardware names that count, the names you asssign will be used as aliases in your software. I ran the ShowDevices example on my computer and it found three devices

     ###########################################################################
                       Game Control Plus  - available devices
                       --------------------------------------
      0  Apple Keyboard     [Keyboard]  on  [USB port]
      1  Peter Lager’s Mouse     [Mouse]  on  [Unknown]
      2  Apple Wireless Trackpad     [Mouse]  on  [Unknown]
    ############################################################################
    

    If I then look at these devices I see

      NAME :     Peter Lager’s Mouse
      Type :     Mouse
      Port :     Unknown
        Buttons (2)
          Type     Name               Multiplier
          button    Left                -
          button    Right               -
        Sliders (2)
          Type     Name               Multiplier     Tolerance
          slider    x                   1.0            0.0            (relative)
          slider    y                   1.0            0.0            (relative)
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      ==========================================================================
      NAME :     Apple Wireless Trackpad
      Type :     Mouse
      Port :     Unknown
        Buttons (2)
          Type     Name               Multiplier
          button    Left                -
          button    Right               -
        Sliders (2)
          Type     Name               Multiplier     Tolerance
          slider    x                   1.0            0.0            (relative)
          slider    y                   1.0            0.0            (relative)
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ############################################################################
    

    Notice that the hardware names are the same for both the trackpad and the mouse. When looking for a device the library gets a list of attached devices, then tries to find a matching device based on the input types (i.e. buttons and sliders) and their names. It does not consider the actual device name because this varies depending on the OS.

    So in this case the trackpad configuration file will match the mouse no matter what names you provide as aliases (e.g. LEFT, LEFT2) for your program.

    In your case I suggest that you use the device name as supplied by the OS , in my case it would be 'Apple Wireless Trackpad' with the getDevice() method. The software will then just work with that device, although the other device will be visible and usable by the OS.

  • So I took approach in 2 and it worked fine with the TrackBall using data from the 'ShowDevices' script. NB using device names for inputs and ignoring config file.

    FYI - Probing the Mouse was actually more of a problem, maybe this is where the problem may lie. I can't get it to initialize the x-y sliders or return values for the buttons.

  • edited September 2014

    But I really mostly care about the trackpad so that's fine.

  • edited September 2014

    Figured out some more. I originally was thrown by the fact that if I turned off the mouse I wasn't getting any info from the trackball...... I just realized that I have to remove the usb wireless dongle from my hub, then the trackball is found. So the wireless 'Mouse' dongle was trapping the info coming from the TrackBall even though the mouse itself had been turned off.

  • Glad you get to use your trackball. :)

Sign In or Register to comment.