![]() |
Leap Motion C API
4.1.0
The API to the LeapC library.
|
The typical tasks a client application performs to get tracking and status information include:
You can use a message pump to efficiently monitor the LeapC message queue. The message queue provides tracking data and status information from the Leap Motion service.
A typical message pump is a function that runs in its own thread and calls LeapPollConnection() in a tight loop:
The types of messages that can be returned by LeapPollConnection() are defined in the eLeapEventType enumeration. Your application should handle each event type appropriately and synchronize any data that needs to be used by other threads. LeapPollConnection() blocks until a message is available or until the specified timeout period has elapsed.
To start the message pump, you must first open a connection and start the message pump thread:
The LEAP_CONNECTION struct returned by LeapCreateConnection() becomes your handle for referencing this connection in future LeapC API calls. (You can maintain more than one connection, but typically there is no reason to do so.) Pass a NULL value for the LEAP_CONNECTION_CONFIG struct. There aren't currently any config options to set.
LeapOpenConnection() performs client-side verification and starts any operations needed to connect to the service. However, any operations that may block are deferred until the first call to LeapPollConnection().
Note: you do not need to open a device to get tracking data. The device-related functions are only needed to get device properties or to change device state. See Reading Device Properties.
See the Callback Example.
Instead of taking frames at measured at whatever rate the Leap Motion device happens to be producing them, you can request each frame at a particular time. LeapC will then interpolate the nearest measured frames to synthesize a frame at the desired time. In general, requesting frames further in the past will provide improve the perception of smoothness in the tracking data, but at a cost of increased latency. Conversely, requesting frames with a shorter delay will improve perceived responsiveness, but at a cost of increased jitteryness. You should tune the value as best suits your application; if you use the same code on desktop and mobile platforms (when mobile is supported), you will probably need different delay values for each.
A timestamp that is more recent than the timestamp most recently returned by LeapPollConnection() (e.g. for a tracking or image complete event) is considered to be in the future. If an interpolated frame is requested for a timestamp in the future, LeapC will use extrapolation instead of interpolation. If the same call was delayed so that the same timestamp value is no longer in the future, LeapC will choose to interpolate instead of extrapolate.
The LeapGetNow() function returns the current value of the clock used to generate frame timestamps. On Windows, this value is equal to QueryPerformanceCounter divided by QueryPerformanceFrequency, represented in microseconds. On all other platforms, it is the time since epoch of std::chrono::high_resolution_clock::now(), in microseconds. If your application time is derived from the same source as LeapGetNow(), you can calculate the desired frame timestamps directly and do not need to use the LEAP_CLOCK_REBASER object.
To get interpolated frames:
Note that if you have an alternative means of converting your local timestamp units into the same clock domain as that used by LeapGetNow(), you do not need to use the clock rebasing functions and can call LeapInterpolateFrame() using the converted timestamp directly.
When getting interpolated frames, you can safely ignore tracking messages from LeapPollConnection() – but you should still service the message loop to get status and image completion messages.
See the Interpolated Frames Example.
To read the properties of a device, you must get the list of known devices from LeapC using LeapGetDeviceList(). You can then get the specific properties of the devices in the returned list using LeapOpenDevice() and LeapGetDeviceInfo().
you must first open it with LeapOpenDevice(). For that you need a LEAP_DEVICE_REF struct, which you can get from LeapGetDeviceList(). However, you must pass an array to LeapGetDeviceList() to receive the device reference structs. So first, you must get the number of attached devices. You get the device count by calling LeapGetDeviceList() passing in a NULL pointer in place of the device array.
To get device information:
Call LeapGetDeviceList() again, passing in the correct size array and setting pnArray to the number of elements in your array. LeapC fills in the device reference struct for each attached device and updates pnArray to the number of records it actually wrote.
Because LeapGetDeviceList() does not block, the returned list contains references for any devices known to LeapC at the time of the call. This local list can be different than the list of devices know to the Leap Motion service.
Once you have a LEAP_DEVICE_REF struct for a device, you can read its properties:
Policies control whether certain features should be used by an application. Generally, these features affect general usability or change service behavior that will affect all applications on a system.
See Policy for a description of the current policies.
To get and set policies:
To read the current policies without making changes, set both the set and the clear parameters to 0 when calling LeapSetPolicyFlags(). This will generate a LEAP_POLICY_EVENT message containing the current policies.
Note that the other Leap Motion language bindings support a slightly different set of polcies and are based on libraries that enforce these policies differently. For more informations, see https://www.leapmotiontechnology.com/documentation/cpp/devguide/Leap_Policies.html.
The Leap Motion service has several configuration settings. A few are useful to individual applications. For a description of these settings, see Configuration.
To read a config value:
Reading a configuration value requires a round-trip to the Leap Motion service. The routine used to initiate this round-trip does not block, but it also cannot return the current value in the same call. The requested value will be passed back to your application as an event in LeapPollConnection.
To write a config value: