LeapDelegateΒΆ

<LeapDelegate> Protocol Reference

The LeapDelegate protocol defines a set of methods that you can implement in a delegate object for a LeapController. More...

Inherits <NSObject>.

Instance Methods

(void) - onConnect:
 Called when the LeapController object connects to the Leap software, or when this ListenerDelegate object is added to a controller that is already connected. More...
 
(void) - onDeviceChange:
 Called when a Leap Motion controller plugged in, unplugged, or the device changes state. More...
 
(void) - onDeviceFailure:
 Called when a Leap Motion controller device is plugged into the client computer, but fails to operate properly. More...
 
(void) - onDisconnect:
 Called when the LeapController object disconnects from the Leap software. More...
 
(void) - onExit:
 Called when this LeapDelegate object is removed from the LeapController or the controller instance is destroyed. More...
 
(void) - onFocusGained:
 Called when this application becomes the foreground application. More...
 
(void) - onFocusLost:
 Called when this application loses the foreground focus. More...
 
(void) - onFrame:
 Called when a new frame of hand and finger tracking data is available. More...
 
(void) - onImages:
 Called when new images are available. More...
 
(void) - onInit:
 Called once, when the LeapController has finished initializing. More...
 
(void) - onServiceChange:
 Called when the Leap Motion service is paused or resumed or when a controller policy is changed. More...
 
(void) - onServiceConnect:
 Called if the Leap Motion daemon/service disconnects from your application Controller. More...
 
(void) - onServiceDisconnect:
 Called if the Leap Motion daemon/service disconnects from your application Controller. More...
 

Detailed Description

The LeapDelegate protocol defines a set of methods that you can implement in a delegate object for a LeapController.

The LeapController calls the delegate methods when Leap events occur, such as when a new frame of data is available.

To use the LeapDelegate protocol, implement a class adopting the LeapDelegate protocol and assign it to a LeapController instance:

MYDelegate *delegate = [[MYDelegate alloc] init];
LeapController *controller = [[LeapController alloc] init];
[controller addDelegate:delegate];

When a new frame of data is ready, the controller calls the [LeapDelegate onFrame:] method. The other Leap events, onInit, onConnect, onDisconnect, onServiceConnect, onServiceDisconnect, onExit, onFocusGained, and onFocusLost are handled in the same manner. The Controller object is multithreaded and calls the LeapDelegate functions on its own threads, not on an application thread.

Using the LeapDelegate protocol is not mandatory. You can also use NSNotifications with a LeapListener object or simply poll the controller object (as described in the LeapController class overview).

Since 1.0

Method Documentation

- (void) onConnect: (LeapController *)  controller
optional

Called when the LeapController object connects to the Leap software, or when this ListenerDelegate object is added to a controller that is already connected.

  • (void)onConnect:controller { NSLog("Connected"); [controller enableGesture:LEAP_GESTURE_TYPE_CIRCLE enable:YES]; //... }
Parameters
controllerThe parent LeapController object.
Since 1.0
- (void) onDeviceChange: (LeapController *)  controller
optional

Called when a Leap Motion controller plugged in, unplugged, or the device changes state.

State changes include changes in frame rate and entering or leaving "robust" mode. Note that there is currently no way to query whether a device is in robust mode. You can use Frame::currentFramerate() to get the framerate.

- (void)onDeviceChange:(LeapController *)controller
{
    NSLog(@"Device Changed");
}
Parameters
controllerThe Controller object invoking this callback function.
Since
1.2
- (void) onDeviceFailure: (LeapController *)  controller
optional

Called when a Leap Motion controller device is plugged into the client computer, but fails to operate properly.

Get the list containing all failed devices using Controller::failedDevices(). The members of this list provide the device pnpID and reason for failure.

Parameters
controllerThe Controller object invoking this callback function.
Since
2.2.1
- (void) onDisconnect: (LeapController *)  controller
optional

Called when the LeapController object disconnects from the Leap software.

The controller can disconnect when the Leap device is unplugged, the user shuts the Leap software down, or the Leap software encounters an unrecoverable error.

- (void)onDisconnect:(LeapController *)controller
{
    NSLog(@"Disconnected");
}
Parameters
controllerThe parent LeapController object.
Since 1.0
- (void) onExit: (LeapController *)  controller
optional

Called when this LeapDelegate object is removed from the LeapController or the controller instance is destroyed.

  • (void)onExit:controller { NSLog("Exited"); }

Note: When you launch a Leap-enabled application in a debugger, the Leap library does not disconnect from the application. This is to allow you to step through code without losing the connection because of time outs.

Parameters
controllerThe parent LeapController object.
Since 1.0
- (void) onFocusGained: (LeapController *)  controller
optional

Called when this application becomes the foreground application.

Only the foreground application receives tracking data from the Leap Motion Controller. This function is only called when the controller object is in a connected state.

- (void)onFocusGained:(LeapController *)controller
{
    NSLog(@"Focus Gained");
}
Parameters
controllerThe parent LeapController object.
Since 1.0
- (void) onFocusLost: (LeapController *)  controller
optional

Called when this application loses the foreground focus.

Only the foreground application receives tracking data from the Leap Motion Controller. This function is only called when the controller object is in a connected state.

- (void)onFocusLost:(LeapController *)controller
{
    NSLog(@"Focus Lost");
}
Parameters
controllerThe parent LeapController object.
Since 1.0
- (void) onFrame: (LeapController *)  controller
optional

Called when a new frame of hand and finger tracking data is available.

Access the new frame data using the [LeapController frame:] function.

- (void)onFrame:(LeapController *)controller
{
     NSLog(@"New LeapFrame");
     LeapFrame *frame = [controller frame:0];
     //...
}

Note, the LeapController skips any pending frames while your onFrame handler executes. If your implementation takes too long to return, one or more frames can be skipped. The controller still inserts the skipped frames into the frame history. You can access recent frames by setting the history parameter when calling the [LeapController frame:] function. You can determine if any pending frames were skipped by comparing the ID of the current frame with the ID of the previous received frame.

Parameters
controllerThe parent LeapController object.
Since 1.0
- (void) onImages: (LeapController *)  controller
optional

Called when new images are available.

Access the NSArray containing the new images using the [LeapController images] function.

- (void)onImages:(LeapController *)controller
{
     NSLog(@"New image list");
     NSArray *images = [controller images];
     //...
}
Parameters
controllerThe Controller object invoking this callback function.
Since
2.2.1
- (void) onInit: (LeapController *)  controller
optional

Called once, when the LeapController has finished initializing.

  • (void)onInit:controller { NSLog("Initialized"); //... }
Parameters
controllerThe parent LeapController object.
Since 1.0
- (void) onServiceChange: (LeapController *)  controller
optional

Called when the Leap Motion service is paused or resumed or when a controller policy is changed.

The service can change states because the computer user changes settings in the Leap Motion Control Panel application or because an application connected to the service triggers a change. Any application can pause or unpause the service, but only runtime policy changes you make apply to your own application.

You can query the pause state of the controller with Controller::isPaused(). You can check the state of those policies you are interested in with Controller::isPolicySet().

Parameters
controllerThe Controller object invoking this callback function.
Since
2.2.1
- (void) onServiceConnect: (LeapController *)  controller
optional

Called if the Leap Motion daemon/service disconnects from your application Controller.

Normally, this callback is not invoked. It is only called if some external event or problem shuts down the service or otherwise interrupts the connection.

- (void)onServiceConnect:(LeapController *)controller
{
    NSLog(@"Service Connected");
}
Parameters
controllerThe Controller object invoking this callback function.
Since 1.2
- (void) onServiceDisconnect: (LeapController *)  controller
optional

Called if the Leap Motion daemon/service disconnects from your application Controller.

Normally, this callback is not invoked. It is only called if some external event or problem shuts down the service or otherwise interrupts the connection.

- (void)onServiceDisconnect:(LeapController *)controller
{
    NSLog(@"Service Disconnected");
}
Parameters
controllerThe Controller object invoking this callback function.
Since 1.2