Ejemplo n.º 1
0
int main(int argc, const char *argv[]) {

    if (argc < 2) {
        cout << "Usage: leap_high_five /path/to/serial\n";
        return 1;
    }

    LynxSSC lynx(argv[1], 115200);
//    lynx.move(3, 1500, -1, -1);
    lynx.move(3, 1500, -1, -1);
    sleep(2);
    lynx.move(4, 500, -1, 1000);
    sleep(2);
    lynx.move(
        LynxMoveGroup().move(3,1000,-1,500)
                       .move(4,1500,-1,1000));

return 0;
    cout << "Initializing controller";
    static Leap::Controller s_controller;
    FrameListener listener;
    cout << "Adding listener to controller";
    s_controller.addListener(listener);

    
    // while (running) {
    // 
    //     while (inMotion) {
    //         Jacobian3 J(armCurrent.q, armLengths); 
    //     }
    // }

    cin.get();
    return 0;
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
    EffectRunner r;

     // Create a sample listener and controller
  SampleListener listener;
  Leap::Controller controller;

  // Have the sample listener receive events from the controller
  controller.addListener(listener);

  if (argc > 1 && strcmp(argv[1], "--bg") == 0)
    controller.setPolicy(Leap::Controller::POLICY_BACKGROUND_FRAMES);

  // Keep this process running until Enter is pressed
  //std::cout << "Press Enter to quit..." << std::endl;
  //std::cin.get();

  // Remove the sample listener when done
  //controller.removeListener(listener);

  //return 0;

    MyEffect e;
    r.setEffect(&e);

    // Defaults, overridable with command line options
    r.setMaxFrameRate(100);
    r.setLayout("../layouts/grid32x16z.json");

    return r.main(argc, argv);
}
Ejemplo n.º 3
0
void LeapController::Setup()
{
	resetInitParams();
	
	if (leapDevice && leapDevice->isConnected()) return;
	
	leapDevice 	= Device::create();
	leapDevice->connectEventHandler( &LeapController::onFrame, this );
	
	// Enable all gesture types
	Leap::Controller* controller = leapDevice->getController();
	controller->enableGesture( Leap::Gesture::Type::TYPE_SWIPE );
	controller->enableGesture( Leap::Gesture::Type::TYPE_CIRCLE );


	// Write gesture config to console
	Leap::Config config = controller->config();

	// Update config to make gestures easier
	config.setFloat( "Gesture.Swipe.MinLength", 30.0f );
	config.setFloat( "Gesture.Swipe.MinVelocity", 100.0f );	
	config.save();

	App::get()->getSignalShutdown().connect(bind(&LeapController::Shutdown, this));
	App::get()->getSignalUpdate().connect(bind(&LeapController::Update, this));

}
Ejemplo n.º 4
0
void LeapListener::onConnect(const Leap::Controller& controller) {
  std::cout << "Connected";
  controller.enableGesture(Leap::Gesture::TYPE_CIRCLE);
  controller.enableGesture(Leap::Gesture::TYPE_KEY_TAP);
  controller.enableGesture(Leap::Gesture::TYPE_SCREEN_TAP);
  controller.enableGesture(Leap::Gesture::TYPE_SWIPE);
}
Ejemplo n.º 5
0
void MouseController::onFrame(const Leap::Controller &controller) {
    // get list of detected screens
    const Leap::ScreenList screens = controller.calibratedScreens();
    
    // make sure we have a detected screen
    if (screens.empty()) return;
    const Leap::Screen screen = screens[0];
    
    // find the first finger or tool
    const Leap::Frame frame = controller.frame();
    const Leap::HandList hands = frame.hands();
    if (hands.empty()) return;
    const Leap::PointableList pointables = hands[0].pointables();
    if (pointables.empty()) return;
    const Leap::Pointable firstPointable = pointables[0];
    
    // get x, y coordinates on the first screen
    const Leap::Vector intersection = screen.intersect(
                                                       firstPointable,
                                                       true,  // normalize
                                                       1.0f   // clampRatio
                                                       );
    
    // if the user is not pointing at the screen all components of
    // the returned vector will be Not A Number (NaN)
    // isValid() returns true only if all components are finite
    if (! intersection.isValid()) return;
    
    unsigned int x = screen.widthPixels() * intersection.x;
    // flip y coordinate to standard top-left origin
    unsigned int y = screen.heightPixels() * (1.0f - intersection.y);
    
    CGPoint destPoint = CGPointMake(x, y);
    CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, destPoint);
}
	void LeapMotionHandler::enableGest(Leap::Controller controller)
	{
		controller.enableGesture(Leap::Gesture::TYPE_SWIPE);
		controller.enableGesture(Leap::Gesture::TYPE_CIRCLE);
		controller.enableGesture(Leap::Gesture::TYPE_SCREEN_TAP);
		controller.enableGesture(Leap::Gesture::TYPE_KEY_TAP);
	}
Ejemplo n.º 7
0
//LeapControllerPrivate
void LeapControllerPrivate::SetPolicyStatus(Leap::Controller::PolicyFlag flag, bool status)
{
	if (status)
		leap.setPolicy(flag);
	else
		leap.clearPolicy(flag);
}
void LeapMotionListener::onConnect(const Leap::Controller & controller)
{
    qDebug()<<"Connected Leap Motion";
    controller.enableGesture(Leap::Gesture::TYPE_CIRCLE);
    controller.enableGesture(Leap::Gesture::TYPE_KEY_TAP);
    controller.enableGesture(Leap::Gesture::TYPE_SCREEN_TAP);
    controller.enableGesture(Leap::Gesture::TYPE_SWIPE);

}
Ejemplo n.º 9
0
int main(int argc, const char * argv[]) {
    MouseController listener;
    Leap::Controller controller;
    controller.addListener(listener);
    
    std::cout << "Press any key to exit" << std::endl;
    std::cin.get();
    
    controller.removeListener(listener);
    
    return 0;
}
Ejemplo n.º 10
0
int main(int argc, char **argv){

    ros::init(argc, argv, "leap_tool_control");
    RosListener listener;
    Leap::Controller controller;

    controller.addListener(listener);
    std::cout <<"Press Enter to quit..."<<std::endl;
    std::cin.get();
    controller.removeListener(listener);
    
}
Ejemplo n.º 11
0
int main(int argc, char** argv)
{
	glutInit(&argc, argv);

	int width = 500;
	int height = 500;
	unsigned int displayMode = GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL;
	displayMode = defaults(displayMode, width, height);

	glutInitDisplayMode (displayMode);
	glutInitContextVersion (3, 3);
	glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
	glutInitContextProfile(GLUT_CORE_PROFILE);
#ifdef DEBUG
	glutInitContextFlags(GLUT_DEBUG);
#endif
	glutInitWindowSize (width, height); 
	glutInitWindowPosition (300, 200);
	int window = glutCreateWindow (argv[0]);

	glload::LoadFunctions();

	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);

	if(!glload::IsVersionGEQ(3, 3))
	{
		printf("Your OpenGL version is %i, %i. You must have at least OpenGL 3.3 to run this tutorial.\n",
			glload::GetMajorVersion(), glload::GetMinorVersion());
		glutDestroyWindow(window);
		return 0;
	}

	if(glext_ARB_debug_output)
	{
		glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
		glDebugMessageCallbackARB(DebugFunc, (void*)15);
	}

	init();

	UserListener listener;
	Leap::Controller controller;
	controller.addListener(listener);

	glutDisplayFunc(display); 
	glutReshapeFunc(reshape);
	glutKeyboardFunc(keyboard);
	glutMainLoop();

	controller.removeListener(listener);

	return 0;
}
/*----------------------------------------------------------------------------------------------------*/
OSVR_ReturnCode HardwareDetection::operator()(OSVR_PluginRegContext pContext) {
	Leap::Controller controller;

	if ( !controller.isConnected() ) {
		mFound = false;
		return OSVR_RETURN_FAILURE;
	}

	if ( !mFound ) {
		mFound = true;
		osvr::pluginkit::registerObjectForDeletion(pContext, new ControllerDevice(pContext));
	}

	return OSVR_RETURN_SUCCESS;
}
Ejemplo n.º 13
0
void main()
{
  // リスナーを登録する
  // リスナーとのやり取りは別スレッドにて行われる
  SampleListener listener;
  Leap::Controller leap;
  leap.addListener( listener );

  leap.setPolicyFlags( Leap::Controller::PolicyFlag::POLICY_BACKGROUND_FRAMES );

  std::cout << "終了するには何かキーを押してください" << std::endl;
  std::cin.get();

  leap.removeListener( listener );
}
Ejemplo n.º 14
0
void Quickstart::onFrame(const Leap::Controller &controller) {
    // returns the most recent frame. older frames can be accessed by passing in 
    // a "history" parameter to retrieve an older frame, up to about 60
    // (exact number subject to change)
    const Leap::Frame frame = controller.frame();

    // do nothing unless hands are detected
    if (frame.hands().empty())
        return;
    
    // first detected hand
    const Leap::Hand firstHand = frame.hands()[0];
    // first pointable object (finger or tool)
    const Leap::PointableList pointables = firstHand.pointables();
    if (pointables.empty()) return;
    const Leap::Pointable firstPointable = pointables[0];
    
    // print velocity on the X axis
    cout << "Pointable X velocity: " << firstPointable.tipVelocity()[0] << endl;
    
    const Leap::FingerList fingers = firstHand.fingers();
    if (fingers.empty()) return;
    
    for (int i = 0; i < fingers.count(); i++) {
        const Leap::Finger finger = fingers[i];
        
        std::cout << "Detected finger " << i << " at position (" <<
            finger.tipPosition().x << ", " <<
            finger.tipPosition().y << ", " <<
            finger.tipPosition().z << ")" << std::endl;
    }
}
Ejemplo n.º 15
0
void Quickstart::onInit(const Leap::Controller &controller) {
    if (! controller.isConnected()) {
        // controller is not connected or the driver software is not started.
        // give the user a friendly reminder that we can't do anything yet
        cout << "Please connect your Leap Motion and run the Leap application" << endl;
    }
}
Ejemplo n.º 16
0
void Listener::onControlUpdated(const Leap::Controller &controller, GesturePtr gesture, ControlPtr control) {
    midi_control_index ctrlIdx = control->controlIndex();
    midi_control_value ctrlVal = control->mappedValue();
//    
//    cout << "Recognized control index " << ctrlIdx
//         << " (" << control->description() << ")"
//         << ", raw value: "
//         << control->rawValue() << " mapped value: " << ctrlVal << endl;
    
    if (frameCount <= 10) return;
    
    // control latency
    struct timeval tv;
    gettimeofday(&tv, NULL);
    double elapsedTime = (tv.tv_sec - control->timestamp().tv_sec) * 1000.0;      // sec to ms
    elapsedTime += (tv.tv_usec - control->timestamp().tv_usec) / 1000.0;   // us to ms
    
    // frame latency
    double absoluteTimeOffset = tv_to_usec(tv) - tv_to_usec(firstFrameAbs);
//    cout << "absolute time offset: " << absoluteTimeOffset << endl;
    int64_t curFrameTime = controller.frame().timestamp();
    int64_t frameOffset = curFrameTime - firstFrameLeap;
    int64_t frameLatency = absoluteTimeOffset - frameOffset;
//    cout << "frame: " << curFrameTime << ", absolute offset: " << (absoluteTimeOffset / 1000) << ", frameOffset: " << (frameOffset / 1000) << ", diff: " << (frameLatency / 1000) << endl;
    
    if (minLatency == 0 || frameLatency < minLatency)
        minLatency = frameLatency;
    if (frameLatency > maxLatency)
        maxLatency = frameLatency;
    controlCount++;
    totalLatency += frameLatency;
    
    if (elapsedTime > 3)
        cout << "frame latency: " << (frameLatency / 1000) << ", control output latency: " << elapsedTime << endl;
}
Ejemplo n.º 17
0
void Listener::onFrame(const Leap::Controller &controller) {
    Leap::Frame curFrame = controller.frame();
    if (firstFrameLeap == 0 && ++frameCount > 10) {
        gettimeofday(&firstFrameAbs, NULL);
        firstFrameLeap = curFrame.timestamp();
        cout << "First frame clock time: " << tv_to_usec(firstFrameAbs) << endl;
        cout << "First frame leap time: " << firstFrameLeap << endl;
    }
    
    // use current active gesture recognizers to locate gestures
    // and then trigger appropriate note/controls
    // feed frames to recognizers
    vector<GesturePtr> recognizers = gestureRecognizers();
    for (vector<GesturePtr>::iterator it = recognizers.begin(); it != recognizers.end(); ++it) {
        // get controls recognized from gestures
        GesturePtr gesture = *it;
        std::vector<ControlPtr> gestureControls; // controls from this gesture
        gesture->recognizedControls(controller, gestureControls);
        
        if (! gestureControls.size())
            continue;
        
        // call gesture recognized callback
        onGestureRecognized(controller, gesture);
        
        for (vector<ControlPtr>::iterator ctl = gestureControls.begin(); ctl != gestureControls.end(); ++ctl) {
            ControlPtr control = *ctl;
            
            onControlUpdated(controller, gesture, control);
        }
    }
}
Ejemplo n.º 18
0
void LeapFishyApp::processGesture()
{
	Leap::Frame frame = m_LeapController.frame();

	if( m_LastFrame == frame )
		return;

	Leap::GestureList gestures =	m_LastFrame.isValid()			?
									frame.gestures( m_LastFrame )	:
									frame.gestures();

	m_LastFrame = frame;

	for( int i = 0; i < gestures.count(); i++ )
	{
		if( gestures[i].type() == Leap::Gesture::TYPE_SWIPE )
		{
			Leap::SwipeGesture swipe = gestures[i];
			Leap::Vector diff = 0.006f*(swipe.position() - swipe.startPosition());
			Vec2f curSwipe(diff.x, -diff.y);
			m_pPlayer->AddVelocity( curSwipe );
		}
		else if(	gestures[i].type() == Leap::Gesture::TYPE_KEY_TAP || 
					gestures[i].type() == Leap::Gesture::TYPE_SCREEN_TAP )
		{
			m_pPlayer->KillVelocity();
		}
	}
}
Ejemplo n.º 19
0
void LeapMotionListener::onFrame( const Leap::Controller& controller )
{
	// get least frame
	frame = controller.frame( 0 );
	

}
Ejemplo n.º 20
0
int main()
{
    control.setPolicyFlags(Leap::Controller::POLICY_BACKGROUND_FRAMES);

    pipe = CreateFile(PNAME, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

    atexit(fin);

    //tenfingers = (float*)malloc(sizeof(float)*10*4);

    printf("connected\n");

    //get fist positions as well

    DWORD word = 0;

    while(1)
    {
        fdata ret = get_finger_positions();

        WriteFile(pipe, (char*)&ret, sizeof(fdata), &word, NULL);

        Sleep(1);
    }

    //CloseHandle(pipe);
}
void Listener::onFrame( const Leap::Controller& controller ) 
{
	lock_guard<mutex> lock( *mMutex );
	if ( !mNewFrame ) {
		mFrame		= controller.frame();
		mNewFrame	= true;
	}
}
//Inherited from Cinder - post-graphics initalization setup steps.  Loads our particle texture & sets up the Leap controller.
void GesturesDemo::setup() {
  ci::gl::Texture* particleTexture = new ci::gl::Texture(ci::loadImage(ci::app::loadResource(RES_PARTICLE)));
  ci::gl::disableVerticalSync(); //required for higher than 60fps
  field.SetParticleTexture(particleTexture);
  mouseIsDown = false;
  lastMousePos.set(0, 0);
  controller.addListener( listener );
}
Ejemplo n.º 23
0
int main() {
    // create instance of our Listener subclass
    Quickstart listener;
    
    // create generic Controller to interface with the Leap device
    Leap::Controller controller;
    
    // tell the Controller to start sending events to our Listener
    controller.addListener(listener);
    
    // run until user presses a key
    cin.get();
    
    // clean up
    controller.removeListener(listener);
    
    return 0;
}
Ejemplo n.º 24
0
void LeapListener::onDeviceChange(const Leap::Controller& controller) {
  std::cout << "Device Changed" << std::endl;
  const Leap::DeviceList devices = controller.devices();

  for (int i = 0; i < devices.count(); ++i) {
    std::cout << "id: " << devices[i].toString() << std::endl;
    std::cout << "  isStreaming: " << (devices[i].isStreaming() ? "true" : "false") << std::endl;
  }
}
Ejemplo n.º 25
0
void LeapFishyApp::shutdown()
{
	m_LeapController.removeListener( m_LeapListener );

	delete m_pPlayer;

	killAllEnemyFish();

	delete m_pEnemyFishes;
}
Ejemplo n.º 26
0
 void onFrame(const Leap::Controller& ctrl) override
 {
     if(ctrl.isConnected())
     {
         Leap::GestureList gestures = ctrl.frame().gestures();
         /*
         if(gestures.count())
         {
             Gesture gesture = gestures[0];
             if(gestures[0].isValid())
             {
                 if(gestures[0].type() == Gesture::TYPE_CIRCLE)
                 {
                     ScreenTapGesture screentap = gestures[0];
                     t_atom data[4];
                     Leap::Vector vector = screentap.direction();
                     atom_setsym(data, gensym("direction"));
                     atom_setfloat(data+1, vector.yaw());
                     atom_setfloat(data+1, vector.roll());
                     atom_setfloat(data+1, vector.pitch());
                     outlet_anything(x->f_gesture, leap_sym_circle, 0, NULL);
                 }
                 else if(gesture.type() == Gesture::TYPE_SWIPE)
                 {
                     ;
                 }
                 else if(gesture.type() == Gesture::TYPE_KEY_TAP)
                 {
                     ;
                 }
                 else if(gesture.type() == Gesture::TYPE_SCREEN_TAP)
                 {
                     ;
                 }
                 else
                 {
                     ;
                 }
             }
         }*/
     }
 }
Ejemplo n.º 27
0
fdata get_finger_positions()
{
    Leap::Frame frame = control.frame();
    Leap::FingerList fingers = frame.fingers();
    Leap::ToolList tools = frame.tools();
    Leap::HandList hands = frame.hands();

    //std::vector<std::pair<cl_float4, int>> positions;

    fdata hand_data;


    int p = 0;

    for(int i=0; i<40; i++)
    {
        hand_data.fingers[i] = 0.0f;
    }

    ///will explode if more than 2
    for(int i=0; i<hands.count(); i++)
    {
        const Leap::Hand hand = hands[i];
        Leap::FingerList h_fingers = hand.fingers();

        float grab_strength = hand.grabStrength();

        hand_data.grab_confidence[i] = grab_strength;

        for(int j=0; j<h_fingers.count(); j++)
        {
            const Leap::Finger finger = h_fingers[j];

            float mfingerposx = finger.tipPosition().x;
            float mfingerposy = finger.tipPosition().y;
            float mfingerposz = finger.tipPosition().z;

            //cl_float4 ps = {mfingerposx, mfingerposy, mfingerposz, 0.0f};
            //cl_float4 ps = {mfingerposx, mfingerposy, mfingerposz, 0.0f};

            int id = finger.id();

            hand_data.fingers[p++] = mfingerposx;
            hand_data.fingers[p++] = mfingerposy;
            hand_data.fingers[p++] = mfingerposz;
            hand_data.fingers[p++] = 0.0f;

            //positions.push_back(std::pair<cl_float4, int>(ps, id));

        }
    }

    return hand_data;
}
Ejemplo n.º 28
0
void LeapCinderRainApp::processFingers()
{
	Leap::Frame frame = m_LeapController.frame();
	Leap::FingerList fingers = frame.fingers();

	m_Rain->ClearPointTo();

	for( int i = 0; i < fingers.count(); i++ )
	{
		m_Rain->CheckPointTo( normalizeCoords( fingers[i].tipPosition() ), 40.0f );
	}
}
// This is called every SL viewer frame
void LLLMImpl::stepFrame()
{
	if (mLMController
		&& mFrameAvailable
		&& mLMConnected)
	{
		mFrameAvailable = false;

		// Get the most recent frame and report some basic information
		const Leap::Frame frame = mLMController->frame();
		Leap::HandList hands = frame.hands();
		
		static LLCachedControl<S32> sControllerMode(gSavedSettings, "LeapMotionTestMode", 0);

		if( !mTool || mTool->getId() != sControllerMode )
		{
			delete mTool;
			mTool = nd::leap::constructTool( sControllerMode );
		}

		if( mTool )
			mTool->onRenderFrame( frame );
		else
		{
			switch (sControllerMode)
			{
				case 1:
					modeFlyingControlTest(hands);
					break;
				case 2:
					modeStreamDataToSL(hands);
					break;
				case 3:
					modeGestureDetection1(hands);
					break;
				case 4:
					modeMoveAndCamTest1(hands);
					break;
				// <FS:Zi> Leap Motion flycam
				case 10:
					modeFlycam(hands);
					break;
				// </FS:Zi>
				case 411:
					modeDumpDebugInfo(hands);
					break;
				default:
					// Do nothing
					break;
			}
		}
	}
}
Ejemplo n.º 30
0
void eleap::eleap_t::impl_t::onFrame(const Leap::Controller& controller)
{
    const Leap::Frame frame = controller.frame();
    if (frame.isValid())
    {
        // send the known hands in this frame, this will handle hands coming and going
        const Leap::HandList hands = frame.hands();
        {
            unsigned long long time_encoded = (0&0xffffffff)<<8 | (DATA_KNOWN_HANDS&0xff);

            float *f;
            unsigned char *dp;
            piw::data_nb_t d = ctx_.allocate_host(time_encoded,INT32_MAX,INT32_MIN,0,BCTVTYPE_INT,sizeof(int32_t),&dp,hands.count(),&f);
            memset(f,0,hands.count()*sizeof(int32_t));
            *dp = 0;

            for(int i = 0; i < hands.count(); ++i)
            {
                const Leap::Hand hand = hands[i];
                if(hand.isValid() && hand.fingers().count() > 1)
                {
                    ((int32_t *)f)[i] = hand.id();
                }
            }
            enqueue_fast(d,1);
        }
        
        // handle the actual data for the detected hands
        for(int i = 0; i < hands.count(); ++i)
        {
            const Leap::Hand hand = hands[i];
            if(hand.isValid() && hand.fingers().count() > 1)
            {
                unsigned long long time_encoded = (hand.id()&0xffffffff)<<8 | (DATA_PALM_POSITION&0xff);

                const Leap::Vector palm_pos = hand.palmPosition();

                float *f;
                unsigned char *dp;
                piw::data_nb_t d = ctx_.allocate_host(time_encoded,600,-600,0,BCTVTYPE_FLOAT,sizeof(float),&dp,3,&f);
                memset(f,0,3*sizeof(float));
                *dp = 0;

                f[0] = piw::normalise(600,-600,0,palm_pos.x);
                f[1] = piw::normalise(600,-600,0,palm_pos.y);
                f[2] = piw::normalise(600,-600,0,palm_pos.z);

                enqueue_fast(d,1);
            }
        }
    }
}