From: pr.jung Date: Mon, 14 May 2018 06:19:27 +0000 (+0900) Subject: [haptic]Add haptic feature X-Git-Tag: submit/tizen/20180611.005638^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2dc7ec7b2cf22c5df62a1a886030e42dabf4f206;p=platform%2Fcore%2Fapi%2Fdevice.git [haptic]Add haptic feature Change-Id: I260519fc2f56d9c5680d3b5e52b9050ade687f08 Signed-off-by: pr.jung --- diff --git a/doc/device_doc.h b/doc/device_doc.h index 6ffa258..854cd95 100755 --- a/doc/device_doc.h +++ b/doc/device_doc.h @@ -79,7 +79,7 @@ /** * @ingroup CAPI_SYSTEM_DEVICE_MODULE * @defgroup CAPI_SYSTEM_DEVICE_HAPTIC_MODULE Haptic - * @brief The Haptic API provides functions to control a vibrator. + * @brief The Haptic API provides functions to control vibration. * * @section CAPI_SYSTEM_DEVICE_HAPTIC_MODULE_HEADER Required Header * \#include \n @@ -88,6 +88,19 @@ * 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. * + * @section CAPI_SYSTEM_DEVICE_HAPTIC_MODULE__FEATURE Related Features + * This API is related with the following features:\n + * - %http://tizen.org/feature/feedback.vibration\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * 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.\n + * + * More details on featuring your application can be found from Feature List. + * + * */ /** diff --git a/src/haptic.c b/src/haptic.c index b5a0ecd..14aaf03 100644 --- a/src/haptic.c +++ b/src/haptic.c @@ -32,6 +32,8 @@ #define METHOD_STOP_DEVICE "StopDevice" #define METHOD_VIBRATE_MONOTONE "VibrateMonotone" +#define VIBRATION_FEATURE "http://tizen.org/feature/feedback.vibration" + enum feedback_e { HAPTIC_FEEDBACK_MIN = 0, HAPTIC_FEEDBACK_MAX = 100, @@ -50,6 +52,22 @@ struct haptic_handle { static dd_list *handle_list; +static int is_haptic_supported(void) +{ + int ret; + bool haptic_avail; + + ret = system_info_get_platform_bool(VIBRATION_FEATURE, &haptic_avail); + if (ret < 0) { + _E("Failed to get value of haptic feature"); + return false; + } else if (ret == 0 && !haptic_avail) { + _D("Haptic is not supported"); + return false; + } else + return true; +} + int device_haptic_get_count(int *device_number) { int ret; @@ -57,6 +75,10 @@ int device_haptic_get_count(int *device_number) if (!device_number) return DEVICE_ERROR_INVALID_PARAMETER; + ret = is_haptic_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + /* request to deviced to get haptic count */ ret = dbus_method_sync(VIBRATOR_BUS_NAME, VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC, @@ -119,6 +141,10 @@ int device_haptic_open(int device_index, haptic_device_h *device_handle) if (!device_handle) return DEVICE_ERROR_INVALID_PARAMETER; + ret = is_haptic_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + snprintf(str_index, sizeof(str_index), "%d", device_index); arr[0] = str_index; @@ -171,6 +197,10 @@ int device_haptic_close(haptic_device_h device_handle) if (!device_handle) return DEVICE_ERROR_INVALID_PARAMETER; + ret = is_haptic_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + DD_LIST_FOREACH(handle_list, elem, temp) { if (temp->handle != handle->handle) continue; @@ -223,6 +253,10 @@ int device_haptic_vibrate(haptic_device_h device_handle, int duration, int feedb if (feedback < HAPTIC_FEEDBACK_MIN || feedback > HAPTIC_FEEDBACK_MAX) return DEVICE_ERROR_INVALID_PARAMETER; + ret = is_haptic_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + priority = HAPTIC_PRIORITY_MIN; DD_LIST_FOREACH(handle_list, elem, temp) { @@ -269,6 +303,10 @@ int device_haptic_stop(haptic_device_h device_handle, haptic_effect_h effect_han if (!device_handle) return DEVICE_ERROR_INVALID_PARAMETER; + ret = is_haptic_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + DD_LIST_FOREACH(handle_list, elem, temp) { if (temp != handle) continue;