TeslasuitDocumentation
APIs

Device API

The Device module discovers TESLASUIT devices attached to the system, opens and closes handlers to them, and lets you subscribe to their connection and disconnection events.

It also provides functions for retrieving device information, such as name, serial number, product type and side, which are used both directly and as inputs to other subsystem APIs (mocap, haptic, PPG, EMG, BIA, and so on).

The starting point for the Device API is to enumerate attached devices with ts_get_device_list, then obtain a handler for each attached device with ts_device_open. These device handlers are used to retrieve device information and are passed to other API functions to target operations at a specific device. Because devices can be attached or removed at any time, ts_get_device_list should be called periodically, or ts_set_device_event_callback should be used to react to attach/detach events as they happen.

Functions#

ts_get_device_list#

TsStatusCode ts_get_device_list(TsDevice* list, uint32_t* list_size);

Retrieves a list of Teslasuit devices currently attached to the system.

Parameters

list: TsDevice*, out

Pointer to a preallocated array of TsDevice entries that will be filled with the identifiers of the currently attached devices, up to list_size entries.

list_size: uint32_t*, inout

On input, the number of elements available in the preallocated list array; on output, the actual number of attached devices found (which may be smaller than the input value, or larger if the array was too small to hold them all).

Returns: TsStatusCode

TsStatusCode indicating whether the device list was retrieved successfully.

See also: ts_device_open


ts_set_device_event_callback#

TsStatusCode ts_set_device_event_callback(TsDeviceEventPolicy policy, TsDeviceEventCallback callback, void* user_data);

Registers a callback to be notified when devices attach or detach.

Preconditions

ts_initialize

Parameters

policy: TsDeviceEventPolicy, in

TsDeviceEventPolicy controlling whether already-attached devices are reported immediately upon subscription or only future attach/detach events are delivered.

callback: TsDeviceEventCallback, in

TsDeviceEventCallback that will be invoked whenever a device attaches or detaches.

user_data: void*, in

Opaque pointer that is passed back unchanged to the callback on every invocation, allowing the caller to associate context with the subscription.

Returns: TsStatusCode

TsStatusCode indicating whether the callback was registered successfully.


ts_device_open#

TsDeviceHandle* ts_device_open(const TsDevice* device);

Opens a device handler for a device identifier obtained from ts_get_device_list.

Parameters

device: const TsDevice*, in

Pointer to the TsDevice identifier of the device to open, as previously obtained from ts_get_device_list.

Returns: TsDeviceHandle*

TsDeviceHandle for the opened device, or null if the device is no longer available.


ts_device_close#

void ts_device_close(TsDeviceHandle* dev);

Closes a device handler and releases the resources associated with it.

Parameters

dev: TsDeviceHandle*, in

Device handler previously returned by ts_device_open.

See also: ts_device_open


ts_device_get_id#

const TsDevice* ts_device_get_id(TsDeviceHandle* dev);

Retrieves the device identifier associated with an open device handler.

Preconditions

ts_initialize, ts_device_open

Parameters

dev: TsDeviceHandle*, in

Device handler previously returned by ts_device_open.

Returns: const TsDevice*

const TsDevice* identifying the device, valid as long as dev remains open.


ts_device_get_name#

const char* ts_device_get_name(TsDeviceHandle* dev);

Retrieves the human-readable name of a device.

Parameters

dev: TsDeviceHandle*, in

Device handler previously returned by ts_device_open.

Returns: const char*

const char* pointing to the null-terminated device name, valid as long as dev remains open.


ts_device_get_serial#

const char* ts_device_get_serial(TsDeviceHandle* dev);

Retrieves the serial number of a device.

Parameters

dev: TsDeviceHandle*, in

Device handler previously returned by ts_device_open.

Returns: const char*

const char* pointing to the null-terminated serial number, valid as long as dev remains open.


ts_device_get_product_type#

TsProductType ts_device_get_product_type(TsDeviceHandle* dev);

Retrieves the product type of a device.

Parameters

dev: TsDeviceHandle*, in

Device handler previously returned by ts_device_open.

Returns: TsProductType

TsProductType identifying the kind of device that dev refers to.


ts_device_get_device_side#

TsDeviceSide ts_device_get_device_side(TsDeviceHandle* dev);

Retrieves which side of the body a device is worn on, if applicable.

Parameters

dev: TsDeviceHandle*, in

Device handler previously returned by ts_device_open.

Returns: TsDeviceSide

TsDeviceSide of the device, or Undefined if the device has no defined side.