Tizen Native API  9.0

The Haptic API provides functions to control vibration.

Required Header

#include <device/haptic.h>

Overview

The Haptic API provides the way to control vibration functionality of a device. It allows the management of the device's vibrator parameters, such as the vibration count and level.

Related Features

This API is related with the following features:

  • http://tizen.org/feature/feedback.vibration

It is recommended to design feature related codes in your application for reliability.

You can check if a device supports the related features for this API by using System Information, thereby controlling the procedure of your application.

To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.

More details on featuring your application can be found from feature element description.

Functions

int device_haptic_get_count (int *device_number)
 Gets the number of vibrators available on the current device.
int device_haptic_open (int device_index, haptic_device_h *device_handle)
 Opens a haptic-vibration device with the given device_index.
int device_haptic_close (haptic_device_h device_handle)
 Closes a haptic-vibration device by haptic device handler.
int device_haptic_vibrate (haptic_device_h device_handle, int duration, int feedback, haptic_effect_h *effect_handle)
 Vibrates during the specified time with a constant intensity.
int device_haptic_stop (haptic_device_h device_handle, haptic_effect_h effect_handle)
 Stops all vibration effects which are being played by haptic device handler.

Typedefs

typedef void * haptic_device_h
 The haptic device handle.
typedef void * haptic_effect_h
 The haptic effect handle.

Typedef Documentation

typedef void* haptic_device_h

The haptic device handle.

Since :
2.3
typedef void* haptic_effect_h

The haptic effect handle.

Since :
2.3

Function Documentation

int device_haptic_close ( haptic_device_h  device_handle)

Closes a haptic-vibration device by haptic device handler.

Internally, it disconnects the connection to the vibrator by haptic device handler.

Since :
2.3
Privilege Level:
public
Privilege:
http://tizen.org/privilege/haptic
Remarks:
Ensure The device_handle should be get properly by device_haptic_open().
Parameters:
[in]device_handleThe device handle from device_haptic_open()
Returns:
0 on success, otherwise a negative error value
Return values:
DEVICE_ERROR_NONESuccessful
DEVICE_ERROR_INVALID_PARAMETERInvalid parameter
DEVICE_ERROR_PERMISSION_DENIEDPermission denied
DEVICE_ERROR_OPERATION_FAILEDOperation failed
DEVICE_ERROR_NOT_SUPPORTEDNot supported device
 #include <device/haptic.h>
 ...
 haptic_device_h haptic_device;
 int ret = device_haptic_open(0, &haptic_device);
 ...
 ret = device_haptic_close(haptic_device);
 ...
See also:
device_haptic_open()
haptic_device_h
int device_haptic_get_count ( int *  device_number)

Gets the number of vibrators available on the current device.

Retrieves the total number of vibrators available on the device. The number of vibrators is returned in the device_number parameter.

Since :
2.3
Privilege Level:
public
Privilege:
http://tizen.org/privilege/haptic
Remarks:
Ensure that the provided device_number pointer is valid and has enough memory allocated.
Parameters:
[in]device_numberThe number of vibrators
Returns:
0 on success, otherwise a negative error value
Return values:
DEVICE_ERROR_NONESuccessful
DEVICE_ERROR_INVALID_PARAMETERInvalid parameter
DEVICE_ERROR_PERMISSION_DENIEDPermission denied
DEVICE_ERROR_OPERATION_FAILEDOperation failed
DEVICE_ERROR_NOT_SUPPORTEDNot supported device
 #include <device/haptic.h>
 ...
 int num_of_haptic_device = 0;
 int ret = 0;
 ...
 ret = device_haptic_get_count(&num_of_haptic_device);
int device_haptic_open ( int  device_index,
haptic_device_h device_handle 
)

Opens a haptic-vibration device with the given device_index.

Internally, it makes a connection to control the vibrator.

Since :
2.3
Privilege Level:
public
Privilege:
http://tizen.org/privilege/haptic
Remarks:
You must close the Haptic API using device_haptic_close().
The device_handle should be released using device_haptic_close().
Parameters:
[in]device_indexThe index of device what you want to vibrate
The index starts from 0
[out]device_handleThe handle of vibrator
Returns:
0 on success, otherwise a negative error value
Return values:
DEVICE_ERROR_NONESuccessful
DEVICE_ERROR_INVALID_PARAMETERInvalid parameter
DEVICE_ERROR_PERMISSION_DENIEDPermission denied
DEVICE_ERROR_OPERATION_FAILEDOperation failed
DEVICE_ERROR_NOT_SUPPORTEDNot supported device
 #include <device/haptic.h>
 ...
 haptic_device_h haptic_device;
 int ret = device_haptic_open(0, &haptic_device);
 ...
 ret = device_haptic_close(haptic_device);
 ...
See also:
device_haptic_close()
haptic_device_h
int device_haptic_stop ( haptic_device_h  device_handle,
haptic_effect_h  effect_handle 
)

Stops all vibration effects which are being played by haptic device handler.

This function can be used to stop all effects started by device_haptic_vibrate().

Since :
2.3
Privilege Level:
public
Privilege:
http://tizen.org/privilege/haptic
Parameters:
[in]device_handleThe device handle from device_haptic_open()
[in]effect_handleThe effect handle from device_haptic_vibrate()
Returns:
0 on success, otherwise a negative error value
Return values:
DEVICE_ERROR_NONESuccessful
DEVICE_ERROR_INVALID_PARAMETERInvalid parameter
DEVICE_ERROR_PERMISSION_DENIEDPermission denied
DEVICE_ERROR_OPERATION_FAILEDOperation failed
DEVICE_ERROR_NOT_SUPPORTEDNot supported device
 #include <device/haptic.h>
 ...
 haptic_device_h haptic_device;
 haptic_effect_h haptic_effect;
 int ret = device_haptic_open(0, &haptic_device);
 ...
 ret = device_haptic_vibrate(haptic_device, 500, 50, &haptic_effect);
 ...
 ret = device_haptic_stop(haptic_device, haptic_effect);
 ...
 ret = device_haptic_close(haptic_device);
 ...
See also:
device_haptic_vibrate()
haptic_device_h
haptic_effect_h
int device_haptic_vibrate ( haptic_device_h  device_handle,
int  duration,
int  feedback,
haptic_effect_h effect_handle 
)

Vibrates during the specified time with a constant intensity.

This function can be used to start monotonous vibration for the specified time.

Since :
2.3
Privilege Level:
public
Privilege:
http://tizen.org/privilege/haptic
Remarks:
feedback level is reserved for auto changing to save variable in the settings.
effect_handle value can be 0(zero).
To prevent unexpected sleep (suspend) during vibration, please use Power.
Parameters:
[in]device_handleThe device handle from device_haptic_open()
[in]durationThe play duration in milliseconds
[in]feedbackThe amount of the intensity variation (0 ~ 100)
[out]effect_handleThe pointer to the variable that will receive a handle to the playing effect
Returns:
0 on success, otherwise a negative error value
Return values:
DEVICE_ERROR_NONESuccessful
DEVICE_ERROR_INVALID_PARAMETERInvalid parameter
DEVICE_ERROR_PERMISSION_DENIEDPermission denied
DEVICE_ERROR_OPERATION_FAILEDOperation failed
DEVICE_ERROR_NOT_SUPPORTEDNot supported device
 #include <device/haptic.h>
 ...
 haptic_device_h haptic_device;
 haptic_effect_h haptic_effect;
 int ret = device_haptic_open(0, &haptic_device);
 ...
 ret = device_haptic_vibrate(haptic_device, 500, 50, &haptic_effect);
 ...
 ret = device_haptic_close(haptic_device);
 ...
See also:
device_haptic_stop()
haptic_device_h
haptic_effect_h