4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
27 #define METHOD_GET_COUNT "GetCount"
28 #define METHOD_OPEN_DEVICE "OpenDevice"
29 #define METHOD_CLOSE_DEVICE "CloseDevice"
30 #define METHOD_STOP_DEVICE "StopDevice"
31 #define METHOD_VIBRATE_MONOTONE "VibrateMonotone"
35 HAPTIC_FEEDBACK_MIN = 0,
36 HAPTIC_FEEDBACK_MAX = 100,
41 HAPTIC_PRIORITY_MIN = 0,
42 HAPTIC_PRIORITY_MIDDLE,
46 int device_haptic_get_count(int *device_number)
51 return DEVICE_ERROR_INVALID_PARAMETER;
53 /* request to deviced to get haptic count */
54 ret = dbus_method_sync(DEVICED_BUS_NAME,
55 DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
56 METHOD_GET_COUNT, NULL, NULL);
58 return errno_to_device_error(ret);
61 return DEVICE_ERROR_NONE;
64 int device_haptic_open(int device_index, haptic_device_h *device_handle)
70 ret = device_haptic_get_count(&max);
74 if (device_index < 0 || device_index >= max)
75 return DEVICE_ERROR_INVALID_PARAMETER;
78 return DEVICE_ERROR_INVALID_PARAMETER;
80 snprintf(str_index, sizeof(str_index), "%d", device_index);
83 /* request to deviced to open haptic device */
84 ret = dbus_method_sync(DEVICED_BUS_NAME,
85 DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
86 METHOD_OPEN_DEVICE, "i", arr);
88 return errno_to_device_error(ret);
90 *device_handle = (haptic_device_h)ret;
91 return DEVICE_ERROR_NONE;
94 int device_haptic_close(haptic_device_h device_handle)
101 return DEVICE_ERROR_INVALID_PARAMETER;
103 snprintf(str_handle, sizeof(str_handle), "%u", (unsigned int)device_handle);
106 /* request to deviced to open haptic device */
107 ret = dbus_method_sync(DEVICED_BUS_NAME,
108 DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
109 METHOD_CLOSE_DEVICE, "u", arr);
111 return errno_to_device_error(ret);
113 return DEVICE_ERROR_NONE;
116 int device_haptic_vibrate(haptic_device_h device_handle, int duration, int feedback, haptic_effect_h *effect_handle)
119 char str_duration[32];
120 char str_feedback[32];
121 char str_priority[32];
126 return DEVICE_ERROR_INVALID_PARAMETER;
129 return DEVICE_ERROR_INVALID_PARAMETER;
131 if (feedback < HAPTIC_FEEDBACK_MIN || feedback > HAPTIC_FEEDBACK_MAX)
132 return DEVICE_ERROR_INVALID_PARAMETER;
134 priority = HAPTIC_PRIORITY_MIN;
136 snprintf(str_handle, sizeof(str_handle), "%u", (unsigned int)device_handle);
138 snprintf(str_duration, sizeof(str_duration), "%d", duration);
139 arr[1] = str_duration;
140 snprintf(str_feedback, sizeof(str_feedback), "%d", feedback);
141 arr[2] = str_feedback;
142 snprintf(str_priority, sizeof(str_priority), "%d", priority);
143 arr[3] = str_priority;
145 /* request to deviced to vibrate haptic device */
146 ret = dbus_method_sync(DEVICED_BUS_NAME,
147 DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
148 METHOD_VIBRATE_MONOTONE, "uiii", arr);
150 return errno_to_device_error(ret);
153 *effect_handle = (haptic_effect_h)ret;
155 return DEVICE_ERROR_NONE;
158 int device_haptic_stop(haptic_device_h device_handle, haptic_effect_h effect_handle)
165 return DEVICE_ERROR_INVALID_PARAMETER;
167 /* TODO : support to stop haptic effect */
168 snprintf(str_handle, sizeof(str_handle), "%u", (unsigned int)device_handle);
171 /* request to deviced to open haptic device */
172 ret = dbus_method_sync(DEVICED_BUS_NAME,
173 DEVICED_PATH_HAPTIC, DEVICED_INTERFACE_HAPTIC,
174 METHOD_STOP_DEVICE, "u", arr);
176 return errno_to_device_error(ret);
178 return DEVICE_ERROR_NONE;