2 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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() ) {
66 err = haptic_get_file_duration(hnd_hpt, res_path, &duration);
69 DBG("Setting - haptic_get_file_duration() failed");
73 DBG("Setting - duration : %d", duration);
75 err = haptic_vibrate_file_with_detail(hnd_hpt, res_path,
76 HAPTIC_ITERATION_ONCE, feedback_rate, HAPTIC_PRIORITY_HIGH, NULL);
78 DBG("Setting - haptic_vibrate_file_with_detail() failed");
80 double real_duration = (double)(duration / 1000.0);
82 DBG("Setting - duration2 : %f", real_duration);
86 ecore_timer_del(vibration_timer);
87 vibration_timer = NULL;
89 vibration_timer = ecore_timer_add(real_duration, (Ecore_Task_Cb)__vibration_timeout, NULL);
95 int ret = haptic_close(hnd_hpt);
97 DBG("Setting - Failed haptic_deinitialize");
101 if( vibration_timer ) {
102 ecore_timer_del(vibration_timer);
103 vibration_timer = NULL;
106 h_data.is_haptic_opened = 0;