Skip to main content
Version: 14 Oct 2024

ml_input.h

Classes

Name
structMLInputControllerTouchpadGesture
structMLInputControllerCallbacksEx
A structure containing callbacks for input controller events.
structMLInputControllerState
A structure containing information about the current state of an input controller.
structMLInputControllerStateEx
A structure containing information about the current state of an input controller.
structMLInputConnectedDevicesList
A structure containing information about the connected devices.
structMLInputPreDefinedPattern
A structure containing information about the Pre-Defined pattern to be played.
structMLInputBuzzCommand
A structure containing information about the Buzz command to be played.
structMLInputCustomHaptics
A structure containing information about the Buzz command and/or pre-defined pattern to be played.
structMLInputCustomHapticsInfo
A structure containing a list of Buzz command and/or pre-defined patterns to be played.
unionMLInputCustomHaptics.MLInputCustomHapticsPattern

Types

Name
typedef struct MLInputControllerTouchpadGestureMLInputControllerTouchpadGesture
typedef struct MLInputControllerCallbacksExMLInputControllerCallbacksEx
A structure containing callbacks for input controller events.
typedef struct MLInputControllerStateMLInputControllerState
A structure containing information about the current state of an input controller.
typedef struct MLInputControllerStateExMLInputControllerStateEx
A structure containing information about the current state of an input controller.
typedef struct MLInputConnectedDevicesListMLInputConnectedDevicesList
A structure containing information about the connected devices.
typedef struct MLInputPreDefinedPatternMLInputPreDefinedPattern
A structure containing information about the Pre-Defined pattern to be played.
typedef struct MLInputBuzzCommandMLInputBuzzCommand
A structure containing information about the Buzz command to be played.
typedef struct MLInputCustomHapticsMLInputCustomHaptics
A structure containing information about the Buzz command and/or pre-defined pattern to be played.
typedef struct MLInputCustomHapticsInfoMLInputCustomHapticsInfo
A structure containing a list of Buzz command and/or pre-defined patterns to be played.

Enums

Name
enumAnonymous Enum 13
{
MLResultAPIPrefix_Input = ( 0x21DC << 16)
}
enumMLInputResult
{
MLInputResult_ServiceNotAvailable = MLResultAPIPrefix_Input,
MLInputResult_PermissionDenied,
MLInputResult_DeviceNotFound,
MLInputResult_IllegalState,
MLInputResult_InternalError,
MLInputResult_SpeechDisabled,
MLInputResult_Ensure32Bits = 0x7FFFFFFF
}
Return values for Input API calls.
enumAnonymous Enum 14
{
MLInput_MaxControllers = 1,
MLInput_MaxControllerTouchpadTouches = 2
}
enumMLInputControllerTouchpadGestureState
{
MLInputControllerTouchpadGestureState_End,
MLInputControllerTouchpadGestureState_Continue,
MLInputControllerTouchpadGestureState_Start,
MLInputControllerTouchpadGestureState_Ensure32Bits = 0x7FFFFFFF
}
enumMLInputControllerTouchpadGestureType
{
MLInputControllerTouchpadGestureType_None,
MLInputControllerTouchpadGestureType_Tap,
MLInputControllerTouchpadGestureType_ForceTapDown,
MLInputControllerTouchpadGestureType_ForceTapUp,
MLInputControllerTouchpadGestureType_ForceDwell,
MLInputControllerTouchpadGestureType_SecondForceDown,
MLInputControllerTouchpadGestureType_RadialScroll,
MLInputControllerTouchpadGestureType_Swipe,
MLInputControllerTouchpadGestureType_Count,
MLInputControllerTouchpadGestureType_Ensure32Bits = 0x7FFFFFFF
}
enumMLInputControllerTouchpadGestureDirection
{
MLInputControllerTouchpadGestureDirection_None,
MLInputControllerTouchpadGestureDirection_Up,
MLInputControllerTouchpadGestureDirection_Down,
MLInputControllerTouchpadGestureDirection_Left,
MLInputControllerTouchpadGestureDirection_Right,
MLInputControllerTouchpadGestureDirection_Clockwise,
MLInputControllerTouchpadGestureDirection_CounterClockwise,
MLInputControllerTouchpadGestureDirection_Count,
MLInputControllerTouchpadGestureDirection_Ensure32Bits = 0x7FFFFFFF
}
enumMLInputControllerType
{
MLInputControllerType_None,
MLInputControllerType_Device,
MLInputControllerType_Ensure32Bits = 0x7FFFFFFF
}
enumMLInputControllerButton
{
MLInputControllerButton_None,
MLInputControllerButton_Bumper,
MLInputControllerButton_Menu,
MLInputControllerButton_Count,
MLInputControllerButton_Ensure32Bits = 0x7FFFFFFF
}
enumMLInputControllerTriggerEvent
{
MLInputControllerTriggerEvent_Pull,
MLInputControllerTriggerEvent_Release,
MLInputControllerTriggerEvent_Click,
MLInputControllerTriggerEvent_Hold,
MLInputControllerTriggerEvent_Ensure32Bits = 0x7FFFFFFF
}
enumMLInputPreDefinedPatternType
{
MLInputPreDefinedPatternType_A = 0,
MLInputPreDefinedPatternType_B = 1,
MLInputPreDefinedPatternType_C = 2,
MLInputPreDefinedPatternType_Ensure32Bits = 0x7FFFFFFF
}
enumMLInputCustomHapticsType
{
MLInputCustomHapticsType_None = 0,
MLInputCustomHapticsType_Buzz = 1,
MLInputCustomHapticsType_Predefined = 2,
MLInputCustomHapticsType_Ensure32Bits = 0x7FFFFFFF
}
enumMLInputControllerHand
{
MLInputControllerHand_None = 0,
MLInputControllerHand_Left = 1,
MLInputControllerHand_Right = 2,
MLInputControllerHand_Both = 3,
MLInputControllerHand_Ensure32Bits = 0x7FFFFFFF
}
Hand in which the controller is held.

Functions

Name
voidMLInputControllerCallbacksExInit(MLInputControllerCallbacksEx * inout_callbacks)
Initializes default values for MLInputControllerCallbacksEx.
voidMLInputControllerStateExInit(MLInputControllerStateEx inout_attr[MLInput_MaxControllers])
Initializes values for MLInputControllerStateEx.
voidMLInputConnectedDevicesListInit(MLInputConnectedDevicesList * inout_devices_list)
Initializes default values for MLInputConnectedDevicesList.
voidMLInputPreDefinedPatternInit(MLInputPreDefinedPattern * inout_pattern)
Initializes default values for MLInputPreDefinedPattern.
voidMLInputBuzzCommandInit(MLInputBuzzCommand * inout_command)
Initializes default values for MLInputBuzzCommand.
voidMLInputCustomHapticsInfoInit(MLInputCustomHapticsInfo * inout_info)
Initializes an array of MLInputCustomHaptics with default values.
const char *MLInputGetResultString(MLResult result)
Returns an ASCII string for MLInputsResult and MLResult codes.
MLResultMLInputCreate(MLHandle * out_handle)
Creates an input tracker.
MLResultMLInputSetControllerCallbacksEx(MLHandle handle, const MLInputControllerCallbacksEx controller_callbacks, void user_data)
Sets the callbacks for controller input events.
MLResultMLInputGetControllerState(MLHandle handle, struct MLInputControllerState out_state[MLInput_MaxControllers])
Returns current state of all possible input controllers.
MLResultMLInputGetControllerStateEx(MLHandle handle, MLInputControllerStateEx out_state[MLInput_MaxControllers])
Returns current state of all possible input controllers.
MLResultMLInputGetConnectedDevices(MLHandle handle, MLInputConnectedDevicesList * inout_devices)
Gets the device IDs of all connected devices.
MLResultMLInputReleaseConnectedDevicesList(MLHandle handle, MLInputConnectedDevicesList * devices)
Releases the contents of MLInputConnectedDevicesList populated by MLInputGetConnectedDevices.
MLResultMLInputStartControllerFeedbackPreDefinedPattern(MLHandle handle, uint8_t controller_id, MLInputPreDefinedPattern * pattern)
Plays the pre-defined pattern.
MLResultMLInputStartControllerFeedbackBuzzCommand(MLHandle handle, uint8_t controller_id, const MLInputBuzzCommand * command)
Plays controller haptic buzz command.
MLResultMLInputCreateCustomHapticsPattern(MLHandle handle, MLInputCustomHapticsInfo info, uint32_t inout_pattern_id)
Creates a custom haptic pattern.
MLResultMLInputStartControllerFeedbackCustomHapticsPattern(MLHandle handle, uint8_t controller_id, uint32_t pattern_id)
Plays the custom haptic pattern created by MLInputCreateCustomHapticsPattern.
MLResultMLInputDeleteCustomHapticsPattern(MLHandle handle, uint32_t pattern_id)
Deletes the custom haptic pattern created by MLInputCreateCustomHapticsPattern.
MLResultMLInputStopControllerFeedback(MLHandle handle, uint8_t controller_id)
Stops the currently playing haptic pattern.
MLResultMLInputDestroy(MLHandle handle)
Destroys an input tracker.

Enums Documentation

Anonymous Enum 13

EnumeratorValueDescription
MLResultAPIPrefix_Input( 0x21DC << 16)Defines the prefix for MLInputResult codes.

MLInputResult

EnumeratorValueDescription
MLInputResult_ServiceNotAvailableMLResultAPIPrefix_Input
MLInputResult_PermissionDeniedOperation failed because a required permission has not been granted. Example: This can happen when the app is not in the foreground.
MLInputResult_DeviceNotFoundOperation failed because a required device was not found.
MLInputResult_IllegalStateOperation failed because the service was in an illegal state. Example: This can occur when the service is still initializing.
MLInputResult_InternalErrorOperation failed because of an internal error.
MLInputResult_SpeechDisabledOperation failed because a required speech feature is disabled in system settings.
MLInputResult_Ensure32Bits0x7FFFFFFFEnsure enum is represented as 32 bits.

Return values for Input API calls.


Anonymous Enum 14

EnumeratorValueDescription
MLInput_MaxControllers1Maximum recognized number of input controllers.
MLInput_MaxControllerTouchpadTouches2Maximum recognized number of controller touchpad touches.

MLInputControllerTouchpadGestureState

EnumeratorValueDescription
MLInputControllerTouchpadGestureState_EndEnd(Default).
MLInputControllerTouchpadGestureState_ContinueContinue.
MLInputControllerTouchpadGestureState_StartStart.
MLInputControllerTouchpadGestureState_Ensure32Bits0x7FFFFFFFEnsure enum is represented as 32 bits.

Touchpad gesture state.


MLInputControllerTouchpadGestureType

EnumeratorValueDescription
MLInputControllerTouchpadGestureType_NoneNone.
MLInputControllerTouchpadGestureType_TapTap. This is a discrete gesture.
MLInputControllerTouchpadGestureType_ForceTapDownForce tap down. This is a discrete gesture.
MLInputControllerTouchpadGestureType_ForceTapUpForce tap up. This is a discrete gesture.
MLInputControllerTouchpadGestureType_ForceDwellForce dwell. This is a discrete gesture.
MLInputControllerTouchpadGestureType_SecondForceDownSecond force down. This is a discrete gesture.
MLInputControllerTouchpadGestureType_RadialScrollRadial scroll. This is a continuous gesture.
MLInputControllerTouchpadGestureType_SwipeSwipe. This is a continuous gesture.
MLInputControllerTouchpadGestureType_CountNumber of gesture types.
MLInputControllerTouchpadGestureType_Ensure32Bits0x7FFFFFFFEnsure enum is represented as 32 bits.

Recognized touchpad gesture types.


MLInputControllerTouchpadGestureDirection

EnumeratorValueDescription
MLInputControllerTouchpadGestureDirection_NoneNone.
MLInputControllerTouchpadGestureDirection_UpUp.
MLInputControllerTouchpadGestureDirection_DownDown.
MLInputControllerTouchpadGestureDirection_LeftLeft.
MLInputControllerTouchpadGestureDirection_RightRight.
MLInputControllerTouchpadGestureDirection_ClockwiseClockwise.
MLInputControllerTouchpadGestureDirection_CounterClockwiseCounter clockwise.
MLInputControllerTouchpadGestureDirection_CountNumber of directions.
MLInputControllerTouchpadGestureDirection_Ensure32Bits0x7FFFFFFFEnsure enum is represented as 32 bits.

Direction of touchpad gesture.


MLInputControllerType

EnumeratorValueDescription
MLInputControllerType_NoneNone.
MLInputControllerType_DeviceDevice.
MLInputControllerType_Ensure32Bits0x7FFFFFFFEnsure enum is represented as 32 bits.

Types of input controllers recognized by Magic Leap platform.


MLInputControllerButton

EnumeratorValueDescription
MLInputControllerButton_None
MLInputControllerButton_BumperBumper.
MLInputControllerButton_MenuMenu.
MLInputControllerButton_CountNumber of buttons.
MLInputControllerButton_Ensure32Bits0x7FFFFFFFEnsure enum is represented as 32 bits.

Buttons on input controllers.


MLInputControllerTriggerEvent

EnumeratorValueDescription
MLInputControllerTriggerEvent_PullThis is used when trigger is pulled down, and the normalized value is > 0.
MLInputControllerTriggerEvent_ReleaseThis is used when trigger is fully released, and the normalized value is 0.
MLInputControllerTriggerEvent_ClickThis is used when trigger is pulled and released within a short duration.
MLInputControllerTriggerEvent_HoldThis is used when trigger is pulled and held for a longer duration.
MLInputControllerTriggerEvent_Ensure32Bits0x7FFFFFFFEnsure enum is represented as 32 bits.

Trigger events types.


MLInputPreDefinedPatternType

EnumeratorValueDescription
MLInputPreDefinedPatternType_A0Pre-defined pattern used for VKB hover.
MLInputPreDefinedPatternType_B1Pre-Defined pattern used for VKB select.
MLInputPreDefinedPatternType_C2Pre-Defined pattern used for homemenu hover.
MLInputPreDefinedPatternType_Ensure32Bits0x7FFFFFFFEnsure enum is represented as 32 bits.

Custom haptics pattern types.


MLInputCustomHapticsType

EnumeratorValueDescription
MLInputCustomHapticsType_None0None.
MLInputCustomHapticsType_Buzz1Pattern is a buzz command.
MLInputCustomHapticsType_Predefined2Pattern is a pre-defined pattern.
MLInputCustomHapticsType_Ensure32Bits0x7FFFFFFFEnsure enum is represented as 32 bits.

Custom haptics pattern types.


MLInputControllerHand

EnumeratorValueDescription
MLInputControllerHand_None0None.
MLInputControllerHand_Left1Left hand.
MLInputControllerHand_Right2Right hand.
MLInputControllerHand_Both3Both hand.
MLInputControllerHand_Ensure32Bits0x7FFFFFFFEnsure enum is represented as 32 bits.

Hand in which the controller is held.

API Level:

  • 21

Types Documentation

MLInputControllerTouchpadGesture

typedef struct MLInputControllerTouchpadGesture MLInputControllerTouchpadGesture;

A structure containing information about recognized touchpad gesture.

More Info


MLInputControllerCallbacksEx

typedef struct MLInputControllerCallbacksEx MLInputControllerCallbacksEx;

A structure containing callbacks for input controller events.

The final parameter to all the callbacks is a void *, which will point to whatever payload data the user provides in MLInputSetControllerCallbacksEx. Individual callbacks which are not required by the client can be NULL.

This structure must be initialized by calling MLInputControllerCallbacksExInit() before use.

More Info

API Level:

  • 20

MLInputControllerState

typedef struct MLInputControllerState MLInputControllerState;

A structure containing information about the current state of an input controller.

More Info

Deprecated

Deprecated since 1.1.0. Scheduled for removal.


MLInputControllerStateEx

typedef struct MLInputControllerStateEx MLInputControllerStateEx;

A structure containing information about the current state of an input controller.

More Info

API Level:

  • 21

MLInputConnectedDevicesList

typedef struct MLInputConnectedDevicesList MLInputConnectedDevicesList;

A structure containing information about the connected devices.

More Info

API Level:

  • 20

MLInputPreDefinedPattern

typedef struct MLInputPreDefinedPattern MLInputPreDefinedPattern;

A structure containing information about the Pre-Defined pattern to be played.

When playing haptic pre-defined pattern, needed information is stored in this structure.

More Info

API Level:

  • 20

MLInputBuzzCommand

typedef struct MLInputBuzzCommand MLInputBuzzCommand;

A structure containing information about the Buzz command to be played.

When playing haptic buzz command, needed information is stored in this structure.

More Info

API Level:

  • 20

MLInputCustomHaptics

typedef struct MLInputCustomHaptics MLInputCustomHaptics;

A structure containing information about the Buzz command and/or pre-defined pattern to be played.

A custom haptics pattern can be played by combining Buzz haptic command and/or a pre-defined pattern, this structure will hold info of a pattern to be added to the custom haptics array. A MLInputCustomHapticsType should be set while initializing the struct to indicate whether the to-be set pattern is a buzz command or a pre-defined pattern.

The #duration will set the time for which a pattern is played:

  • If the inherited duration of a pre-defined pattern is greater, then it will be cut short and the next pattern will start playing.
  • If the inherited duration of a pre-defined pattern is smaller, then it will not repeat itself and will wait for the #duration to complete before starting to play the next pattern.
  • Buzz command's duration will supersede the #duration. Above caveat is true in case buzz command's duration is smaller.
  • The last pattern of the array will continue playing even if the inherited duration is longer than #duration unless the pattern is interrupted by another pattern in the pipeline.

More Info


MLInputCustomHapticsInfo

typedef struct MLInputCustomHapticsInfo MLInputCustomHapticsInfo;

A structure containing a list of Buzz command and/or pre-defined patterns to be played.

A custom haptics pattern can be played by combining Buzz haptic command and/or a pre-defined pattern, this structure holds a list of such a combination.

More Info

API Level:

  • 20

Functions Documentation

MLInputControllerCallbacksExInit

static inline void MLInputControllerCallbacksExInit(
MLInputControllerCallbacksEx * inout_callbacks
)

Initializes default values for MLInputControllerCallbacksEx.

Parameters

MLInputControllerCallbacksEx *inout_callbacksThe object to initialize with default settings.

API Level:

  • 20

MLInputControllerStateExInit

static inline void MLInputControllerStateExInit(
MLInputControllerStateEx inout_attr[MLInput_MaxControllers]
)

Initializes values for MLInputControllerStateEx.

Parameters

MLInputControllerStateExinout_attrThe object to initialize.

API Level:

  • 21

MLInputConnectedDevicesListInit

static inline void MLInputConnectedDevicesListInit(
MLInputConnectedDevicesList * inout_devices_list
)

Initializes default values for MLInputConnectedDevicesList.

Parameters

MLInputConnectedDevicesList *inout_devices_listThe object to initialize with default settings.

API Level:

  • 20

MLInputPreDefinedPatternInit

static inline void MLInputPreDefinedPatternInit(
MLInputPreDefinedPattern * inout_pattern
)

Initializes default values for MLInputPreDefinedPattern.

Parameters

MLInputPreDefinedPattern *inout_patternThe object to initialize with default settings.

MLInputBuzzCommandInit

static inline void MLInputBuzzCommandInit(
MLInputBuzzCommand * inout_command
)

Initializes default values for MLInputBuzzCommand.

Parameters

MLInputBuzzCommand *inout_commandThe object to initialize with default settings.

MLInputCustomHapticsInfoInit

static inline void MLInputCustomHapticsInfoInit(
MLInputCustomHapticsInfo * inout_info
)

Initializes an array of MLInputCustomHaptics with default values.

Parameters

MLInputCustomHapticsInfo *inout_infoThe object to MLInputCustomHapticsInfo struct to initialize the array elements with default settings.

MLInputGetResultString

const char * MLInputGetResultString(
MLResult result
)

Returns an ASCII string for MLInputsResult and MLResult codes.

Parameters

MLResultresultThe input MLResult enum from MLInput functions.

Required Permissions:

  • None

Return: ASCII string containing readable version of result code.

API Level:

  • 8

MLInputCreate

MLResult MLInputCreate(
MLHandle * out_handle
)

Creates an input tracker.

Parameters

MLHandle *out_handleA handle to the created input tracker. Only valid if the return value is MLResult_Ok.

Returns

MLResultMLResult_InvalidParamFailed to create the input tracker to an invalid input parameter.
MLResultMLResult_OkSuccessfully created the input tracker.
MLResultMLResult_UnspecifiedFailureFailed to create the input tracker due to an unknown error.
MLResultMLInputResult_IllegalStateFailed to create the input tracker due to an unexpected state.

Required Permissions:

  • None

API Level:

  • 20

MLInputSetControllerCallbacksEx

MLResult MLInputSetControllerCallbacksEx(
MLHandle handle,
const MLInputControllerCallbacksEx * controller_callbacks,
void * user_data
)

Sets the callbacks for controller input events.

Parameters

MLHandlehandleHandle to the input tracker.
const MLInputControllerCallbacksEx *controller_callbacksPointer to MLInputControllerCallbacksEx structure (can be NULL).
void *user_dataPointer to user payload data; this will be the first argument passed to all the callback functions (can be NULL).

Returns

MLResultMLResult_InvalidParamFailed to set the callback for controller input events due to an invalid input parameter.
MLResultMLResult_OkSuccessfully set the callback for controller input events.
MLResultMLResult_UnspecifiedFailureFailed to set the callback for the controller input events due to an unknown error.

Required Permissions:

  • None

API Level:

  • 8

MLInputGetControllerState

MLResult MLInputGetControllerState(
MLHandle handle,
struct MLInputControllerState out_state[MLInput_MaxControllers]
)

Returns current state of all possible input controllers.

Parameters

MLHandlehandleHandle to the input tracker.
struct MLInputControllerStateout_stateArray of MLInputControllerState structures that will be populated. The size of this array is at least the size MLInput_MaxControllers.

Returns

MLResultMLResult_InvalidParamFailed to fetch the controller state due to an invalid input parameter.
MLResultMLResult_OkSuccessfully fetched the controller state.
MLResultMLResult_UnspecifiedFailureFailed to fetch the controller state due to an unknown error.

Required Permissions:

  • None
Deprecated

Deprecated since 1.1.0. Scheduled for removal.


MLInputGetControllerStateEx

MLResult MLInputGetControllerStateEx(
MLHandle handle,
MLInputControllerStateEx out_state[MLInput_MaxControllers]
)

Returns current state of all possible input controllers.

Parameters

MLHandlehandleHandle to the input tracker.
MLInputControllerStateExout_stateArray of MLInputControllerStateEx structures that will be populated. The size of this array is at least the size MLInput_MaxControllers.

Returns

MLResultMLResult_InvalidParamFailed to fetch the controller state due to an invalid input parameter.
MLResultMLResult_OkSuccessfully fetched the controller state.
MLResultMLResult_UnspecifiedFailureFailed to fetch the controller state due to an unknown error.

Required Permissions:

  • None

API Level:

  • 21

MLInputGetConnectedDevices

MLResult MLInputGetConnectedDevices(
MLHandle handle,
MLInputConnectedDevicesList * inout_devices
)

Gets the device IDs of all connected devices.

Parameters

MLHandlehandleHandle to the input tracker.
MLInputConnectedDevicesList *inout_devicesPointer to MLInputConnectedDevicesList structure that will be populated. The app should call MLInputReleaseConnectedDevicesList to release the contents after use.

Returns

MLResultMLResult_InvalidParamFailed to get the IDs of all connected devices due to an invalid input parameter.
MLResultMLResult_OkSuccessfully fetched the IDs of the connected devices.
MLResultMLResult_UnspecifiedFailureFailed to get the IDs of all connected devices due to an unknown error.

Required Permissions:

  • None

API Level:

  • 5

MLInputReleaseConnectedDevicesList

MLResult MLInputReleaseConnectedDevicesList(
MLHandle handle,
MLInputConnectedDevicesList * devices
)

Releases the contents of MLInputConnectedDevicesList populated by MLInputGetConnectedDevices.

Parameters

MLHandlehandleHandle to the input tracker.
MLInputConnectedDevicesList *devicesPointer to MLInputConnectedDevicesList struct. Its contents will be released.

Returns

MLResultMLResult_OkSuccessfully released the contents of the device list.
MLResultMLResult_InvalidParamFailed to release the contents of the device list due to an invalid input parameter.
MLResultMLResult_UnspecifiedFailureFailed to release the contents of the device list due to an unknown error.

Required Permissions:

  • None

API Level:

  • 5

MLInputStartControllerFeedbackPreDefinedPattern

MLResult MLInputStartControllerFeedbackPreDefinedPattern(
MLHandle handle,
uint8_t controller_id,
MLInputPreDefinedPattern * pattern
)

Plays the pre-defined pattern.

Parameters

MLHandlehandleHandle to the input tracker.
uint8_tcontroller_idId of the input controller 0 ~ MLInput_MaxControllers.
MLInputPreDefinedPattern *patternA pointer to #MLInputPredefinedPattern structure (can be NULL).

Returns

MLResultMLInputResult_IllegalStateThe service is either not initialized or terminated or the app is not in focus.
MLResultMLResult_DeviceNotFoundThe haptic device could not be found.
MLResultMLResult_InvalidParamFailed to start a pre-defined pattern due to an invalid input parameter.
MLResultMLResult_OkSuccessfully started a pre-defined pattern on the specified controller.
MLResultMLResult_UnspecifiedFailureFailed to start a pre-defined pattern due to an unknown error.

Required Permissions:

  • None

API Level:

  • 20

MLInputStartControllerFeedbackBuzzCommand

MLResult MLInputStartControllerFeedbackBuzzCommand(
MLHandle handle,
uint8_t controller_id,
const MLInputBuzzCommand * command
)

Plays controller haptic buzz command.

Parameters

MLHandlehandleHandle to the input tracker.
uint8_tcontroller_idId of the input controller 0 ~ MLInput_MaxControllers.
const MLInputBuzzCommand *commandA pointer to MLInputBuzzCommand structure (can be NULL).

Returns

MLResultMLInputResult_IllegalStateThe service is either not initialized or terminated or the app is not in focus.
MLResultMLResult_DeviceNotFoundThe haptic device could not be found.
MLResultMLResult_InvalidParamFailed to start the buzz command due to an invalid input parameter.
MLResultMLResult_OkSuccessfully started the buzz command on the specified controller.
MLResultMLResult_UnspecifiedFailureFailed to start the buzz command due to an unknown error.

Required Permissions:

  • None

API Level:

  • 20

MLInputCreateCustomHapticsPattern

MLResult MLInputCreateCustomHapticsPattern(
MLHandle handle,
MLInputCustomHapticsInfo * info,
uint32_t * inout_pattern_id
)

Creates a custom haptic pattern.

Parameters

MLHandlehandleHandle to the input tracker.
MLInputCustomHapticsInfo *infoPointer to MLInputCustomHapticsInfo struct.
uint32_t *inout_pattern_idA pattern Id created by the API, to be used by MLInputStartControllerFeedbackCustomHapticsPattern.

Returns

MLResultMLInputResult_IllegalStateThe service is either not initialized or terminated.
MLResultMLResult_InvalidParamFailed to create a custom haptic pattern due to an invalid input parameter.
MLResultMLResult_OkSuccessfully created a custom haptic pattern.
MLResultMLResult_UnspecifiedFailureFailed to create a custom haptic pattern due to an unknown error.

Required Permissions:

  • None

A custom haptics pattern is defined as a set of either buzz command and/or pre-defined patterns. Each pattern is played for a duration defined as the #duration_ms member of each element of the MLInputCustomHaptics array.

API Level:

  • 20

MLInputStartControllerFeedbackCustomHapticsPattern

MLResult MLInputStartControllerFeedbackCustomHapticsPattern(
MLHandle handle,
uint8_t controller_id,
uint32_t pattern_id
)

Plays the custom haptic pattern created by MLInputCreateCustomHapticsPattern.

Parameters

MLHandlehandleHandle to the input tracker.
uint8_tcontroller_idId of the input controller 0 ~ MLInput_MaxControllers.
uint32_tpattern_idCustom pattern id created by MLInputCreateCustomHapticsPattern.

Returns

MLResultMLInputResult_IllegalStateThe service is either not initialized or terminated or the app is not in focus.
MLResultMLResult_DeviceNotFoundThe haptic device could not be found.
MLResultMLResult_InvalidParamFailed to start the custom haptic pattern due to an invalid input parameter.
MLResultMLResult_OkSuccessfully started the custom haptic pattern on the specified controller.
MLResultMLResult_UnspecifiedFailureFailed to start the custom haptic pattern due to an unknown error.

Required Permissions:

  • None

API Level:

  • 20

MLInputDeleteCustomHapticsPattern

MLResult MLInputDeleteCustomHapticsPattern(
MLHandle handle,
uint32_t pattern_id
)

Deletes the custom haptic pattern created by MLInputCreateCustomHapticsPattern.

Parameters

MLHandlehandleHandle to the input tracker.
uint32_tpattern_idCustom pattern Id created by MLInputCreateCustomHapticsPattern.

Returns

MLResultMLInputResult_IllegalStateThe service is either not initialized or terminated.
MLResultMLResult_InvalidParamFailed to destroy the custom haptic pattern due to an invalid input parameter.
MLResultMLResult_OkSuccessfully destroyed the custom haptic pattern on the specified controller.
MLResultMLResult_UnspecifiedFailureFailed to destroy the custom haptic pattern due to an unknown error.

Required Permissions:

  • None

API Level:

  • 20

MLInputStopControllerFeedback

MLResult MLInputStopControllerFeedback(
MLHandle handle,
uint8_t controller_id
)

Stops the currently playing haptic pattern.

Parameters

MLHandlehandleHandle to the input tracker.
uint8_tcontroller_idId of the input controller 0 ~ MLInput_MaxControllers.

Returns

MLResultMLInputResult_IllegalStateThe service is either not initialized or terminated or the app is not in focus.
MLResultMLResult_DeviceNotFoundThe haptic device could not be found.
MLResultMLResult_InvalidParamFailed to stop the pattern due to an invalid input parameter.
MLResultMLResult_OkSuccessfully stopped the pattern on the specified controller.
MLResultMLResult_UnspecifiedFailureFailed to stop the pattern due to an unknown error.

Required Permissions:

  • None

API Level:

  • 20

MLInputDestroy

MLResult MLInputDestroy(
MLHandle handle
)

Destroys an input tracker.

Parameters

MLHandlehandleMLHandle to the input tracker to destroy.

Returns

MLResultMLResult_InvalidParamFailed to destroy the input tracker due to an invalid input parameter.
MLResultMLResult_OkSuccessfully destroyed the input tracker.
MLResultMLResult_UnspecifiedFailureFailed to destroy the input handler due to an unknown error.
MLResultMLInputResult_IllegalStateFailed to destroy the input handler due to an unexpected state.

Required Permissions:

  • None

Source code

// %BANNER_BEGIN%
// ---------------------------------------------------------------------
// %COPYRIGHT_BEGIN%
// Copyright (c) 2017 Magic Leap, Inc. All Rights Reserved.
// Use of this file is governed by the Software License Agreement,
// located here: https://www.magicleap.com/software-license-agreement-ml2
// Terms and conditions applicable to third-party materials accompanying
// this distribution may also be found in the top-level NOTICE file
// appearing herein.
// %COPYRIGHT_END%
// ---------------------------------------------------------------------
// %BANNER_END%
#pragma once
#include "ml_api.h"
#include "ml_types.h"

ML_EXTERN_C_BEGIN
enum {
MLResultAPIPrefix_Input = MLRESULT_PREFIX(0x21DC)
};

typedef enum MLInputResult {
MLInputResult_ServiceNotAvailable = MLResultAPIPrefix_Input,
MLInputResult_PermissionDenied,
MLInputResult_DeviceNotFound,
MLInputResult_IllegalState,
MLInputResult_InternalError,
MLInputResult_SpeechDisabled,
MLInputResult_Ensure32Bits = 0x7FFFFFFF
} MLInputResult;

enum {
MLInput_MaxControllers = 1,
MLInput_MaxControllerTouchpadTouches = 2
};

typedef enum MLInputControllerTouchpadGestureState {
MLInputControllerTouchpadGestureState_End,
MLInputControllerTouchpadGestureState_Continue,
MLInputControllerTouchpadGestureState_Start,
MLInputControllerTouchpadGestureState_Ensure32Bits = 0x7FFFFFFF
} MLInputControllerTouchpadGestureState;

typedef enum MLInputControllerTouchpadGestureType {
MLInputControllerTouchpadGestureType_None,
MLInputControllerTouchpadGestureType_Tap,
MLInputControllerTouchpadGestureType_ForceTapDown,
MLInputControllerTouchpadGestureType_ForceTapUp,
MLInputControllerTouchpadGestureType_ForceDwell,
MLInputControllerTouchpadGestureType_SecondForceDown,
MLInputControllerTouchpadGestureType_RadialScroll,
MLInputControllerTouchpadGestureType_Swipe,
MLInputControllerTouchpadGestureType_Count,
MLInputControllerTouchpadGestureType_Ensure32Bits = 0x7FFFFFFF
} MLInputControllerTouchpadGestureType;

typedef enum MLInputControllerTouchpadGestureDirection {
MLInputControllerTouchpadGestureDirection_None,
MLInputControllerTouchpadGestureDirection_Up,
MLInputControllerTouchpadGestureDirection_Down,
MLInputControllerTouchpadGestureDirection_Left,
MLInputControllerTouchpadGestureDirection_Right,
MLInputControllerTouchpadGestureDirection_Clockwise,
MLInputControllerTouchpadGestureDirection_CounterClockwise,
MLInputControllerTouchpadGestureDirection_Count,
MLInputControllerTouchpadGestureDirection_Ensure32Bits = 0x7FFFFFFF
} MLInputControllerTouchpadGestureDirection;

typedef struct MLInputControllerTouchpadGesture {
MLVec3f pos_and_force;
MLInputControllerTouchpadGestureType type;
MLInputControllerTouchpadGestureDirection direction;
float speed;
float distance;
float radius;
float angle;
} MLInputControllerTouchpadGesture;

typedef enum MLInputControllerType {
MLInputControllerType_None,
MLInputControllerType_Device,
MLInputControllerType_Ensure32Bits = 0x7FFFFFFF
} MLInputControllerType;

typedef enum MLInputControllerButton {
MLInputControllerButton_None,
MLInputControllerButton_Bumper,
MLInputControllerButton_Menu,
MLInputControllerButton_Count,
MLInputControllerButton_Ensure32Bits = 0x7FFFFFFF
} MLInputControllerButton;

typedef enum MLInputControllerTriggerEvent {
MLInputControllerTriggerEvent_Pull,
MLInputControllerTriggerEvent_Release,
MLInputControllerTriggerEvent_Click,
MLInputControllerTriggerEvent_Hold,
MLInputControllerTriggerEvent_Ensure32Bits = 0x7FFFFFFF
} MLInputControllerTriggerEvent;

typedef enum MLInputPreDefinedPatternType {
MLInputPreDefinedPatternType_A = 0,
MLInputPreDefinedPatternType_B = 1,
MLInputPreDefinedPatternType_C = 2,
MLInputPreDefinedPatternType_Ensure32Bits = 0x7FFFFFFF
} MLInputPreDefinedPatternType;

typedef enum MLInputCustomHapticsType {
MLInputCustomHapticsType_None = 0,
MLInputCustomHapticsType_Buzz = 1,
MLInputCustomHapticsType_Predefined = 2,
MLInputCustomHapticsType_Ensure32Bits = 0x7FFFFFFF
} MLInputCustomHapticsType;

typedef enum MLInputControllerHand {
MLInputControllerHand_None = 0,
MLInputControllerHand_Left = 1,
MLInputControllerHand_Right = 2,
MLInputControllerHand_Both = 3,
MLInputControllerHand_Ensure32Bits = 0x7FFFFFFF
} MLInputControllerHand;

typedef struct MLInputControllerCallbacksEx {
uint32_t version;
void (*on_touchpad_gesture)(uint8_t controller_id, const MLInputControllerTouchpadGesture *touchpad_gesture, void *data);
void (*on_touchpad_gesture_continue)(uint8_t controller_id, const MLInputControllerTouchpadGesture *touchpad_gesture, void *data);
void (*on_touchpad_gesture_end)(uint8_t controller_id, const MLInputControllerTouchpadGesture *touchpad_gesture, void *data);
void (*on_button_down)(uint8_t controller_id, MLInputControllerButton button, void *data);
void (*on_button_up)(uint8_t controller_id, MLInputControllerButton button, void *data);
void (*on_button_click)(uint8_t controller_id, MLInputControllerButton button, void *data);
void (*on_trigger)(uint8_t controller_id, MLInputControllerTriggerEvent event, float depth, void *data);
void (*on_connect)(uint8_t controller_id, void *data);
void (*on_disconnect)(uint8_t controller_id, void *data);
} MLInputControllerCallbacksEx;

ML_STATIC_INLINE void MLInputControllerCallbacksExInit(MLInputControllerCallbacksEx *inout_callbacks) {
if (inout_callbacks) {
inout_callbacks->version = 3u;
inout_callbacks->on_touchpad_gesture = NULL;
inout_callbacks->on_touchpad_gesture_continue = NULL;
inout_callbacks->on_touchpad_gesture_end = NULL;
inout_callbacks->on_button_down = NULL;
inout_callbacks->on_button_up = NULL;
inout_callbacks->on_button_click = NULL;
inout_callbacks->on_trigger = NULL;
inout_callbacks->on_connect = NULL;
inout_callbacks->on_disconnect = NULL;
}
}

typedef ML_DEPRECATED_MSG("Replaced by MLInputControllerStateEx.") struct MLInputControllerState {
MLVec3f touch_pos_and_force[MLInput_MaxControllerTouchpadTouches];
float trigger_normalized;
bool button_state[MLInputControllerButton_Count];
bool is_touch_active[MLInput_MaxControllerTouchpadTouches];
bool is_connected;
MLInputControllerTouchpadGesture touchpad_gesture;
MLInputControllerTouchpadGestureState touchpad_gesture_state;
MLInputControllerType type;
uint8_t hardware_index;
} MLInputControllerState;

typedef struct MLInputControllerStateEx {
uint32_t version;
MLInputControllerType type;
MLInputControllerHand hand;
MLVec3f touch_pos_and_force[MLInput_MaxControllerTouchpadTouches];
float trigger_normalized;
bool button_state[MLInputControllerButton_Count];
bool is_touch_active[MLInput_MaxControllerTouchpadTouches];
bool is_connected;
MLInputControllerTouchpadGesture touchpad_gesture;
MLInputControllerTouchpadGestureState touchpad_gesture_state;
uint8_t hardware_index;
} MLInputControllerStateEx;

ML_STATIC_INLINE void MLInputControllerStateExInit(MLInputControllerStateEx inout_attr[MLInput_MaxControllers]) {
if (NULL != inout_attr) {
for (int i = 0; i < MLInput_MaxControllers; ++i) {
inout_attr[i].version = 1u;
}
}
}

typedef struct MLInputConnectedDevicesList {
uint32_t version;
uint32_t connected_controller_count;
const uint8_t *connected_controller_ids;
} MLInputConnectedDevicesList;

ML_STATIC_INLINE void MLInputConnectedDevicesListInit(MLInputConnectedDevicesList *inout_devices_list) {
if (inout_devices_list) {
inout_devices_list->version = 2u;
inout_devices_list->connected_controller_count = 0u;
inout_devices_list->connected_controller_ids = NULL;
}
}

typedef struct MLInputPreDefinedPattern {
uint32_t version;
uint32_t pattern;
} MLInputPreDefinedPattern;

ML_STATIC_INLINE void MLInputPreDefinedPatternInit(MLInputPreDefinedPattern *inout_pattern) {
if (inout_pattern) {
inout_pattern->version = 1u;
inout_pattern->pattern = (uint32_t)MLInputPreDefinedPatternType_C;
}
}

typedef struct MLInputBuzzCommand {
uint32_t version;
uint16_t start_hz;
uint16_t end_hz;
uint32_t duration_ms;
uint8_t amp;
} MLInputBuzzCommand;

ML_STATIC_INLINE void MLInputBuzzCommandInit(MLInputBuzzCommand *inout_command) {
if (inout_command) {
inout_command->version = 1u;
inout_command->start_hz = 200;
inout_command->end_hz = 800;
inout_command->duration_ms = 1000;
inout_command->amp = 20;
}
}

typedef struct MLInputCustomHaptics {
MLInputCustomHapticsType type;
union {
MLInputBuzzCommand buzz;
MLInputPreDefinedPattern pre_defined;
} MLInputCustomHapticsPattern;
uint32_t duration_ms;
} MLInputCustomHaptics;

typedef struct MLInputCustomHapticsInfo {
uint32_t version;
MLInputCustomHaptics *custom;
uint32_t size;
} MLInputCustomHapticsInfo;

ML_STATIC_INLINE void MLInputCustomHapticsInfoInit(MLInputCustomHapticsInfo *inout_info) {
if (inout_info && inout_info->custom) {
for (uint32_t it = 0; it < inout_info->size; it++) {
inout_info->version = 1u;
inout_info->custom[it].type = MLInputCustomHapticsType_None;
inout_info->custom[it].MLInputCustomHapticsPattern.pre_defined.pattern = 0;
inout_info->custom[it].duration_ms = 0;
}
}
}

ML_API const char *ML_CALL MLInputGetResultString(MLResult result);

ML_API MLResult ML_CALL MLInputCreate(MLHandle *out_handle);

ML_API MLResult ML_CALL MLInputSetControllerCallbacksEx(MLHandle handle, const MLInputControllerCallbacksEx *controller_callbacks, void *user_data);

ML_DEPRECATED_MSG("Replaced by MLInputGetControllerStateEx.")
ML_API MLResult ML_CALL MLInputGetControllerState(MLHandle handle, struct MLInputControllerState out_state[MLInput_MaxControllers]);

ML_API MLResult ML_CALL MLInputGetControllerStateEx(MLHandle handle, MLInputControllerStateEx out_state[MLInput_MaxControllers]);

ML_API MLResult ML_CALL MLInputGetConnectedDevices(MLHandle handle, MLInputConnectedDevicesList *inout_devices);

ML_API MLResult ML_CALL MLInputReleaseConnectedDevicesList(MLHandle handle, MLInputConnectedDevicesList *devices);

ML_API MLResult ML_CALL MLInputStartControllerFeedbackPreDefinedPattern(MLHandle handle, uint8_t controller_id, MLInputPreDefinedPattern* pattern);

ML_API MLResult ML_CALL MLInputStartControllerFeedbackBuzzCommand(MLHandle handle, uint8_t controller_id, const MLInputBuzzCommand* command);

ML_API MLResult ML_CALL MLInputCreateCustomHapticsPattern(MLHandle handle, MLInputCustomHapticsInfo *info, uint32_t *inout_pattern_id);

ML_API MLResult ML_CALL MLInputStartControllerFeedbackCustomHapticsPattern(MLHandle handle, uint8_t controller_id, uint32_t pattern_id);

ML_API MLResult ML_CALL MLInputDeleteCustomHapticsPattern(MLHandle handle, uint32_t pattern_id);

ML_API MLResult ML_CALL MLInputStopControllerFeedback(MLHandle handle, uint8_t controller_id);

ML_API MLResult ML_CALL MLInputDestroy(MLHandle handle);
ML_EXTERN_C_END