2016-07-26 53 views
0

我试图让我的代码使用Leap Motion在0和255之间的数字向上滚动(所以打印:1,然后2,然后3在cw圆圈和3,2 ,1个圈)。Java:Leap Motion返回值void

手势的操作驻留在void onFrame()方法中。

我需要增加一个数字,每次检测到圆圈手势并输出每一个数字。就目前而言,我的代码在后台递增,只有当我输入数字时才算数(所以我的数字在第二个提示中显示)。这很糟糕,因为用户实际上看不到他们提交阈值提示的数字。

请帮助,我对此很新,它会减慢我的项目速度!

我已经提供了精简类,以突出问题所在。

Listener类:

public class ImageJListener extends Listener { 

public Robot robot; 

public int promptValue; 
// potentially look into atomic objects and non atomic objects in case this has a threading issue 
public ImageJListener() { 
    this.promptValue = 0; 
} 

public int getPromptValue() { 
    return this.promptValue; 
} 

... 

public int onFrame(Controller controller) { 
    com.leapmotion.leap.Frame frame = controller.frame(); 

    for (Gesture gesture : frame.gestures()) { 
     if (gesture.type() == Type.TYPE_CIRCLE) { 
      CircleGesture circle = new CircleGesture(gesture); 
      if (circle.pointable().direction().angleTo(circle.normal()) <= Math.PI/4) { 


       promptValue++; 
       return promptValue; 


      } else { 

       promptValue--; 
       return promptValue; 

      } 

     } else if (gesture.type() == Type.TYPE_KEY_TAP) { 
      KeyTapGesture Tap; 
      Tap = new KeyTapGesture(gesture); 

      try { 
       Robot robot = new Robot(); 
       robot.keyPress(KeyEvent.VK_ENTER); 
       robot.keyRelease(KeyEvent.VK_ENTER); 
      } catch (AWTException awt) { 
      } 
     } 
    } 
} 

}

插件类(即调用promptValue变量来填充提示:

IJ.setRawThreshold(imp, IJ.getNumber("prompt", (listener.getPromptValue())), IJ.getNumber("prompt", (listener.getPromptValue())), null); 

提前许多感谢,

瑞安

回答

0

从OnFrame()返回值无济于事。 OnFrame由Leap Motion代码调用,即使您可以提供值,它也不会执行任何操作。你需要的是一个函数来改变提示值 - 如果这是可能的话。然后OnFrame可以调用该函数。

+0

我正在考虑使用Observable类将更新抽出 - 你认为这会削减吗? –

+0

调用单个函数看起来有点矫枉过正,但是如果您预计需要发送更多的数据,那么只需要这个整数,那么也许这是值得的。不过,我并不是一个真正的Java人,所以我给你Java风格的指导是愚蠢的。 –