LeapDelegate Protocol Reference
Conforms to | NSObject |
Declared in | LeapObjectiveC.h |
Overview
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
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
,
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).
Tasks
-
– onInit:
Called once, when the LeapController has finished initializing.
-
– 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. -
– onDisconnect:
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. -
– onExit:
Called when this LeapDelegate object is removed from the LeapController
or the controller instance is destroyed. -
– onFrame:
Called when a new frame of hand and finger tracking data is available.
Access the new frame data using the [LeapController frame:] function. -
– onFocusGained:
Called when this application becomes the foreground application.
-
– onFocusLost:
Called when this application loses the foreground focus.
Instance Methods
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.
- (void)onConnect:(LeapController *)controller
Parameters
- controller
The parent LeapController object.
Discussion
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:(LeapController *)controller
{
NSLog(@"Connected");
[controller enableGesture:LEAP_GESTURE_TYPE_CIRCLE enable:YES];
//...
}
Declared In
LeapObjectiveC.h
onDisconnect:
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
Parameters
- controller
The parent LeapController object.
Discussion
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");
}
Declared In
LeapObjectiveC.h
onExit:
Called when this LeapDelegate object is removed from the LeapController
or the controller instance is destroyed.
- (void)onExit:(LeapController *)controller
Parameters
- controller
The parent LeapController object.
Discussion
Called when this LeapDelegate object is removed from the LeapController
or the controller instance is destroyed.
- (void)onExit:(LeapController *)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.
Declared In
LeapObjectiveC.h
onFocusGained:
Called when this application becomes the foreground application.
- (void)onFocusGained:(LeapController *)controller
Parameters
- controller
The parent LeapController object.
Discussion
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");
}
Declared In
LeapObjectiveC.h
onFocusLost:
Called when this application loses the foreground focus.
- (void)onFocusLost:(LeapController *)controller
Parameters
- controller
The parent LeapController object.
Discussion
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");
}
Declared In
LeapObjectiveC.h
onFrame:
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
Parameters
- controller
The parent LeapController object.
Discussion
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.
Declared In
LeapObjectiveC.h
onInit:
Called once, when the LeapController has finished initializing.
- (void)onInit:(LeapController *)controller
Parameters
- controller
The parent LeapController object.
Discussion
Called once, when the LeapController has finished initializing.
- (void)onInit:(LeapController *)controller
{
NSLog(@"Initialized");
//...
}
Declared In
LeapObjectiveC.h