2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "setting_control_haptic.h"
20 static struct _haptic_data h_data;
21 static Ecore_Timer *vibration_timer = NULL;
23 static haptic_device_h hnd_hpt;
27 int haptic_return = 0;
28 haptic_return = haptic_open(HAPTIC_DEVICE_0, &hnd_hpt);
29 if (haptic_return < 0) {
30 DBG("Setting - Failed haptic_open");
34 h_data.is_haptic_opened = 1;
41 return h_data.is_haptic_opened;
44 Eina_Bool __vibration_timeout(void *data)
46 if (_is_haptic_open()) {
50 vibration_timer = NULL;
52 return ECORE_CALLBACK_CANCEL;
55 void _start_vibration(int level, int feedback_rate, char *res_path)
57 if (_is_haptic_open()) {
65 err = haptic_get_file_duration(hnd_hpt, res_path, &duration);
67 DBG("Setting - haptic_get_file_duration() failed");
71 DBG("Setting - duration : %d", duration);
73 err = haptic_vibrate_file_with_detail(hnd_hpt, res_path,
74 HAPTIC_ITERATION_ONCE, feedback_rate, HAPTIC_PRIORITY_HIGH, NULL);
76 DBG("Setting - haptic_vibrate_file_with_detail() failed");
78 double real_duration = (double)(duration / 1000.0);
80 DBG("Setting - duration2 : %f", real_duration);
82 if (vibration_timer) {
83 ecore_timer_del(vibration_timer);
84 vibration_timer = NULL;
86 vibration_timer = ecore_timer_add(real_duration, (Ecore_Task_Cb)__vibration_timeout, NULL);
92 int ret = haptic_close(hnd_hpt);
94 DBG("Setting - Failed haptic_deinitialize");
98 if (vibration_timer) {
99 ecore_timer_del(vibration_timer);
100 vibration_timer = NULL;
103 h_data.is_haptic_opened = 0;