LeapMotionP5 with ControlP5 incompatibility?

I'm creating a program that can send Leap Motion data over OSC. I'm using ControlP5 for the GUI and LeapMotionP5 for retrieving Leap data. I got the following error: "The type Controller is ambiguous" when trying to implement the following (code enormously simplified):

import com.onformative.leap.*;
import com.leapmotion.leap.*;
import com.leapmotion.leap.Controller.PolicyFlag;
import controlP5.*;

LeapMotionP5 leap;
ArrayList<String> status;

void setup()
{
  size(600,600);
  leap = new LeapMotionP5(this);
  leap.getController().setPolicyFlags( PolicyFlag.POLICY_BACKGROUND_FRAMES );
  smooth();
  status = new ArrayList<String>();
  status.add("Program initialized");
}

void draw()
{
  background(0);
  for (int i = 0; i < status.size(); i++)
  {
    text(status.get(i), 10, height-20*status.size()+20*i);
  }
}

public void onConnect(final Controller controller) //Yields the error: The type Controller is ambiguous
{
  status.clear();
  status.add("Leap connected");
}

public void onDisconnect(final Controller controller)
{
  status.clear();
  status.add("Leap disconnected");
}

What I think this means is, Controller is a class in both the ControlP5 and LeapMotionP5 packages, as the error disappears when I comment import controlP5.*;. Is there a way around this? Or are they fundamentally incompatible?

Answers

  • Referring to each controller with its full package name should distinguish them, e.g. final leap.Controller controller (you might have to dig around in the JavaDocs or source to work out what the precise package name is, although based on the imports listed I think that should work).

  • Thanks! It worked, with this syntax: public void onConnect(final com.leapmotion.leap.Controller controller). The error is gone, but the code inside the method doesn't get executed... that one might be harder to solve. When I connect or disconnect the Leap, there is a line printed to the console, but nothing happens with the status arraylist. Annoying.

  • edited December 2013

    A library update solved that problem as well. However, some syntax is now changed. For future reference, here is the updated code.

    import com.leapmotion.leap.Controller;
    import com.leapmotion.leap.processing.LeapMotion;
    import com.leapmotion.leap.Controller.PolicyFlag;
    import controlP5.*;
    
    LeapMotion leap;
    ArrayList<String> status;
    
    void setup()
    {
      size(600,600);
      leap = new LeapMotion(this);
      smooth();
      status = new ArrayList<String>();
      status.add("Program initialized");
    }
    
    void draw()
    {
      background(0);
      for (int i = 0; i < status.size(); i++)
      {
        text(status.get(i), 10, height-20*status.size()+20*i);
      }
    }
    
    public void onInit(final Controller controller)
    {
      controller.setPolicyFlags( PolicyFlag.POLICY_BACKGROUND_FRAMES ); //Necessary to make sure the Leap keeps on sending data when the processing window is no longer active
    }
    
    public void onConnect(final Controller controller) 
    {
      status.clear();
      status.add("Leap connected");
    }
    
    public void onDisconnect(final Controller controller)
    {
      status.clear();
      status.add("Leap disconnected");
    }
    

    Edit: Heh. Just noticed, the update also removed the ambiguous type error, even though both packages are loaded at once! Not sure how that comes, but I'm not complaining.

    Edit 2: Of course the error appeared again as soon as I actually added some ControlP5 controls... No big deal, but the syntax in the leapmotion package is now completely changed :'(

Sign In or Register to comment.