LeapListenerΒΆ

<LeapListener> Protocol Reference

The LeapListener protocol defines a set of methods that you can implement to respond to NSNotification messages dispatched by a LeapController object. More...

Inherits <NSObjectNSObject>.

Instance Methods

(void) - onConnect:
 Dispatched when the LeapController object connects to the Leap software, or when this ListenerListener 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:
 Dispatched when the LeapController object disconnects from the Leap software. More...
 
(void) - onExit:
 Dispatched when this LeapListener 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:
 Dispatched when a new LeapFrame containing hand and finger tracking data is available. More...
 
(void) - onImages:
 Called when new images are available. More...
 
(void) - onInit:
 Dispatched 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:
 Dispatched when the LeapController object connects to the Leap software, or when this ListenerListener object is added to a controller that is already connected. More...
 
(void) - onServiceDisconnect:
 Dispatched when the LeapController object disconnects from the Leap software. More...
 

Detailed Description

The LeapListener protocol defines a set of methods that you can implement to respond to NSNotification messages dispatched by a LeapController object.

To use the LeapListener protocol, implement a class adopting the protocol and assign an instance of that class to a LeapController instance:

MYListener *listener = [[MYListener alloc] init];
LeapController *controller = [[LeapController alloc] initWithListener:listener];

The controller subscribes the LeapListener instance to the appropriate NSNotifications for the Leap events. When a new frame of data is ready, the controller dispatches an NSNotification on the main application thread, which is handled by your [LeapListener onFrame:] implementation.

You can handle the other Leap events, onInit, onConnect, onDisconnect, onServiceConnect, onServiceDisconnect, onDeviceChange, onExit, onFocusGained, and onFocusLost in the same manner.

You must have a running NSRunLoop to receive NSNotification objects. This is usually present and running by default in a Cocoa application. Calling [LeapController addListener:] takes care subscribing the listener object to the appropriate notifications. The LeapListener object is the notification observer, while the LeapController object is the notification sender. You can also subscribe to notifications manually. For example, to subscribe to the OnFrame message, call:

[[NSNotificationCenter defaultCenter] selector:@selector(onFrame:) name:@"OnFrame" object:controller]]

However, at least one listener must be added to the controller with [LeapController addListener:] or the controller does not bother to dispatch notification messages.

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

Since 1.0

Method Documentation

- (void) onConnect: (NSNotification *)  notification
optional

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

  • (void)onConnect:notification { NSLog("Connected"); LeapController *aController = (LeapController *)[notification object]; [aController enableGesture:LEAP_GESTURE_TYPE_CIRCLE enable:YES]; //... }
Parameters
notificationThe LeapController object dispatching the notification.
Since 1.0
- (void) onDeviceChange: (NSNotification *)  notification
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:(NSNotification *)notification
{
    NSLog(@"Device Changed");
}
Parameters
notificationThe LeapController object dispatching the notification.
Since
1.2
- (void) onDeviceFailure: (NSNotification *)  notification
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 [LeapController failedDevices]. The members of this list provide the device pnpID and reason for failure.

Parameters
notificationThe LeapController object dispatching the notification.
Since
3.0
- (void) onDisconnect: (NSNotification *)  notification
optional

Dispatched 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:(NSNotification *)notification
{
    NSLog(@"Disconnected");
}

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
notificationThe LeapController object dispatching the notification.
Since 1.0
- (void) onExit: (NSNotification *)  notification
optional

Dispatched when this LeapListener object is removed from the LeapController or the controller instance is destroyed.

  • (void)onExit:notification { NSLog("Exited"); }
Parameters
notificationThe LeapController object dispatching the notification.
Since 1.0
- (void) onFocusGained: (NSNotification *)  notification
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:(NSNotification *)notification
{
    NSLog(@"Focus Gained");
}
Parameters
notificationThe LeapController object dispatching the notification.
Since 1.0
- (void) onFocusLost: (NSNotification *)  notification
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:(NSNotification *)notification
{
    NSLog(@"Focus Lost");
}
Parameters
controllerThe parent LeapController object.
Since 1.0
- (void) onFrame: (NSNotification *)  notification
optional

Dispatched when a new LeapFrame containing hand and finger tracking data is available.

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

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

Note, the LeapController skips any pending onFrame notifications 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 onFrame events were skipped by comparing the ID of the most recent frame with the ID of the last received frame.

Parameters
notificationThe LeapController object dispatching the notification.
Since 1.0
- (void) onImages: (NSNotification *)  notification
optional

Called when new images are available.

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

- (void)onImages:(NSNotification *)notification
{
     NSLog(@"New image list");
     LeapController *controller = (LeapController *)[notification object];
     NSArray *images = [controller images];
     //...
}
Since
2.2.1
- (void) onInit: (NSNotification *)  notification
optional

Dispatched once, when the LeapController has finished initializing.

Only the first LeapListener added to the controller receives this notification.

- (void)onInit:(NSNotification *)notification
{
    NSLog(@"Initialized");
    //...
}
Parameters
notificationThe LeapController object dispatching the notification.
Since 1.0
- (void) onServiceChange: (NSNotification *)  notification
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 [LeapController isPaused]. You can check the state of those policies you are interested in with [LeapController isPolicySet].

Parameters
notificationThe LeapController object dispatching the notification.
Since
3.0
- (void) onServiceConnect: (NSNotification *)  notification
optional

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

Parameters
notificationThe LeapController object dispatching the notification.
Since 1.0
- (void) onServiceDisconnect: (NSNotification *)  notification
optional

Dispatched 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)onServiceDisconnect:(NSNotification *)notification
{
    NSLog(@"Service Disconnected");
}

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
notificationThe LeapController object dispatching the notification.
Since 1.0