4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: DongGi Jang <dg0402.jang@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
27 #include <sys/types.h>
34 #include "device_haptic.h"
36 #include "devman_haptic.h"
37 #include "devman_haptic_ext.h"
38 #include "devman_haptic_plugin_intf.h"
39 /* START: Will be excluded by removing pattern */
40 #include "device_haptic_tsp4000_pattern.h"
41 /* END: Will be excluded */
44 #define EXTAPI __attribute__ ((visibility("default")))
47 #define HAPTIC_DEVICE_NODE_PATH "/dev/tspdrv"
48 #define HAPTIC_MODULE_PATH "/usr/lib/devman/libdevman_haptic.so"
50 /* START: Will be removed by removing pattern */
51 #define HAPTIC_PLAY_FILE_EXT ".ivt"
52 #define HAPTIC_BUILT_IN_FILE_PATH "/usr/share/immersion"
56 char file_name[NAME_MAX];
57 unsigned char *ivt_pt;
61 struct g_pivt_list_t g_haptic_internal_pattern_list[EFFCTVIBE_PATTERN_END] = {
63 [EFFCTVIBE_TOUCH] = { "/01_Touch/touch_20ms_sharp", touch_ivt, 15},
64 [EFFCTVIBE_HW_TOUCH] = { "/01_Touch/HW_touch_30ms_sharp", hw_touch_ivt, 15},
66 [EFFCTVIBE_NOTIFICATION] = { "/02_Notification/Notification", noti_ivt, 7},
67 [EFFCTVIBE_INCOMING_CALL01] = { "/02_Notification/Incoming call_01", incomming_01_ivt, 7},
68 [EFFCTVIBE_INCOMING_CALL02] = { "/02_Notification/Incoming call_02", incomming_02_ivt, 7},
69 [EFFCTVIBE_INCOMING_CALL03] = { "/02_Notification/Incoming call_03", incomming_03_ivt, 7},
71 [EFFCTVIBE_ALERTS_CALL] = { "/03_Operation/Alerts on Call", alerts_call_ivt, 15},
72 [EFFCTVIBE_OPERATION] = { "/03_Operation/Operation", operation_ivt, 7},
73 [EFFCTVIBE_SILENT_MODE] = { "/03_Operation/Silent mode", silent_ivt, 7},
75 /* END: Will be removed */
77 static int has_haptic_module = -1;
78 static int master_callback_enable = 0;
79 static int setting_fb_level = -1;
80 static int device_handle_count = 0;
82 /* Device Manager Haptic Plugin Interface */
83 static void *dlopen_handle;
84 static const devman_haptic_plugin_interface *plugin_intf;
87 MODE_DEFAULT = 0x0000,
88 MODE_FEEDBACK_LEVEL_CHECK_DISABLE = 0x0001,
91 /* START of Static Function Section */
92 static int __get_master_strength_value()
94 int input_strength = 0;
96 switch (setting_fb_level) {
97 case SETTING_VIB_FEEDBACK_LEVEL0:
98 DBG("get setting value = 0 , so can not vibe");
101 case SETTING_VIB_FEEDBACK_LEVEL1:
102 input_strength = VIBE_FEEDBACK_LEVEL_1;
105 case SETTING_VIB_FEEDBACK_LEVEL2:
106 input_strength = VIBE_FEEDBACK_LEVEL_2;
109 case SETTING_VIB_FEEDBACK_LEVEL3:
110 input_strength = VIBE_FEEDBACK_LEVEL_3;
113 case SETTING_VIB_FEEDBACK_LEVEL4:
114 input_strength = VIBE_FEEDBACK_LEVEL_4;
117 case SETTING_VIB_FEEDBACK_LEVEL5:
118 input_strength = VIBE_FEEDBACK_LEVEL_5;
122 ERR("error get VCONF_SETAPPL_VIB_FEEDBACK_INT value (= %d) invalid", setting_fb_level);
127 return input_strength;
130 static int __convert_strength_level(int base_level)
132 int convert_strength = 0;
134 switch (base_level) {
136 ERR("Input base_level == 0(:%d)\n", base_level);
139 case HAPTIC_FEEDBACK_LEVEL_1:
140 convert_strength = VIBE_FEEDBACK_LEVEL_1;
143 case HAPTIC_FEEDBACK_LEVEL_2:
144 convert_strength = VIBE_FEEDBACK_LEVEL_2;
147 case HAPTIC_FEEDBACK_LEVEL_3:
148 convert_strength = VIBE_FEEDBACK_LEVEL_3;
151 case HAPTIC_FEEDBACK_LEVEL_4:
152 convert_strength = VIBE_FEEDBACK_LEVEL_4;
155 case HAPTIC_FEEDBACK_LEVEL_5:
156 convert_strength = VIBE_FEEDBACK_LEVEL_5;
160 ERR("error invalid convertable value (%d)", base_level);
164 return convert_strength;
167 static void __haptic_changed_cb(keynode_t *node, void *data)
171 DBG("[haptic_changed_cb] changed key = %s\n",
172 vconf_keynode_get_name(node));
174 if (vconf_keynode_get_type(node) == VCONF_TYPE_INT) {
176 feedback_level = vconf_keynode_get_int(node);
178 if (feedback_level == -1) {
179 ERR(" [haptic_changed_cb] Err vconf_keynode_get_int fail from key in haptic_changed_cb : %s , fail state : %d ,so set default level", vconf_keynode_get_name(node), feedback_level);
182 DBG("[haptic_changed_cb] get value : %d , from key : %s",
183 feedback_level, vconf_keynode_get_name(node));
185 setting_fb_level = feedback_level;
187 ERR("[haptic_changed_cb] Err changed key_type miss-match!! read_type : %d", vconf_keynode_get_type(node));
190 /* END of Static Function Section */
193 /* START: devman_haptic APIs */
195 int device_haptic_open(haptic_dev_idx dev_idx, unsigned int mode)
198 int device_index = dev_idx >> 1;
201 if (device_handle_count == 0) {
202 if (has_haptic_module == 1) {
203 plugin_intf->haptic_internal_prepare_node();
205 if (plugin_intf->haptic_internal_initialize() < 0) {
206 ERR("plugin_intf->haptic_internal_initialize() failed");
211 if (mode & MODE_FEEDBACK_LEVEL_CHECK_DISABLE) {
214 DBG("NOT USE MAIN VIB_FEEDBACK_CHECK ROUTINE !!, at pid : %d", cpid);
215 setting_fb_level = SETTING_VIB_FEEDBACK_LEVEL3;
216 } else if (master_callback_enable == 0) {
217 status = vconf_get_int(VCONFKEY_SETAPPL_VIB_FEEDBACK_INT, &setting_fb_level);
219 DBG(" vconf_get_int fail from key : %s , fail state : %d ,so set default level", VCONFKEY_SETAPPL_VIB_FEEDBACK_INT, status);
220 setting_fb_level = SETTING_VIB_FEEDBACK_LEVEL3;
222 DBG("get value : %d , from key : %s", setting_fb_level, VCONFKEY_SETAPPL_VIB_FEEDBACK_INT);
224 status = vconf_notify_key_changed (VCONFKEY_SETAPPL_VIB_FEEDBACK_INT, __haptic_changed_cb, NULL);
226 ERR("Device_haptic_open vconf_notify_key_changed fail\n");
230 master_callback_enable = 1;
234 if (has_haptic_module == 1) {
235 if (dev_idx == DEV_IDX_ALL) {
236 status = plugin_intf->haptic_internal_open_composite_device(NULL, device_index, &device_handle);
237 if(HAPTIC_FAILED(status)) {
238 ERR("plugin_intf->haptic_internal_open_composite_device() Failed: %d", status);
242 status = plugin_intf->haptic_internal_open_device(device_index, &device_handle);
243 if(HAPTIC_FAILED(status)) {
244 ERR("plugin_intf->haptic_internal_open_device() Failed: %d", status);
249 ++device_handle_count;
250 return device_handle;
253 ++device_handle_count;
254 return DEFAULT_DEVICE_HANDLE;
258 int device_haptic_close(int device_handle)
262 if (device_handle_count == 0) {
263 ERR("Haptic device already closed");
264 return HAPTIC_NOT_OPENED;
267 if (has_haptic_module == 1) {
268 status = plugin_intf->haptic_internal_close_device(device_handle);
269 if(HAPTIC_FAILED(status)) {
270 ERR("plugin_intf->haptic_internal_close_device(0) fail: %d", status);
275 --device_handle_count;
276 if (device_handle_count == 0) {
277 if (has_haptic_module == 1) {
278 status = plugin_intf->haptic_internal_terminate();
279 if(HAPTIC_FAILED(status)) {
280 ERR("plugin_intf->haptic_internal_terminate(0) fail: %d", status);
285 if (master_callback_enable == 1) {
286 status = vconf_ignore_key_changed(VCONFKEY_SETAPPL_VIB_FEEDBACK_INT, __haptic_changed_cb);
288 ERR("Device_haptic_close vconf_ignore_key_changed fail\n");
291 master_callback_enable = 0;
295 return HAPTIC_SUCCESS;
299 int device_haptic_play_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback_level)
301 int input_feedback_level;
303 if (device_handle_count == 0) {
304 ERR("Haptic device is not opened yet");
305 return HAPTIC_NOT_OPENED;
308 if (has_haptic_module == 0) {
309 ERR("%s() is not supported without specific haptic module", __func__);
310 return HAPTIC_NOT_SUPPORTED;
313 if (feedback_level == HAPTIC_FEEDBACK_LEVEL_AUTO) {
314 input_feedback_level = __get_master_strength_value();
316 input_feedback_level = __convert_strength_level(feedback_level);
319 return plugin_intf->haptic_internal_play_buffer(device_handle, vibe_buffer, iteration, input_feedback_level, HAPTIC_MIN_DEVICE_PRIORITY);
323 int device_haptic_play_file(int device_handle, const char *file_name, int iteration, int feedback_level)
325 int input_feedback_level;
327 if (device_handle_count == 0) {
328 ERR("Haptic device is not opened yet");
329 return HAPTIC_NOT_OPENED;
332 if (has_haptic_module == 0) {
333 ERR("%s() is not supported without specific haptic module", __func__);
334 return HAPTIC_NOT_SUPPORTED;
337 if (feedback_level == HAPTIC_FEEDBACK_LEVEL_AUTO) {
338 input_feedback_level = __get_master_strength_value();
340 input_feedback_level = __convert_strength_level(feedback_level);
343 return plugin_intf->haptic_internal_play_file(device_handle, file_name, iteration, input_feedback_level, HAPTIC_MIN_DEVICE_PRIORITY);
347 int device_haptic_play_pattern(int device_handle, int pattern, int iteration, int feedback_level)
349 char file_name[NAME_MAX];
351 int input_feedback_level;
353 if (device_handle_count == 0) {
354 ERR("Haptic device is not opened yet");
355 return HAPTIC_NOT_OPENED;
358 if (has_haptic_module == 0) {
359 ERR("%s() is not supported without specific haptic module", __func__);
360 return HAPTIC_NOT_SUPPORTED;
363 if (feedback_level == HAPTIC_FEEDBACK_LEVEL_AUTO) {
364 input_feedback_level = __get_master_strength_value();
366 input_feedback_level = __convert_strength_level(feedback_level);
370 if (!g_haptic_internal_pattern_list[pattern].priority) {
371 priority = HAPTIC_MIN_DEVICE_PRIORITY;
373 priority = g_haptic_internal_pattern_list[pattern].priority;
376 if (!g_haptic_internal_pattern_list[pattern].ivt_pt) {
377 /* Pass filename insted of buffer pointer */
378 if (0 > snprintf(file_name, NAME_MAX, "%s%s%s", HAPTIC_BUILT_IN_FILE_PATH, g_haptic_internal_pattern_list[pattern].file_name, HAPTIC_PLAY_FILE_EXT))
380 ERR("snprintf fail in EFFCTVIBE_SET_EFFECT_TYPE");
384 return plugin_intf->haptic_internal_play_file(device_handle, file_name, iteration, input_feedback_level, HAPTIC_MIN_DEVICE_PRIORITY);
387 return plugin_intf->haptic_internal_play_buffer(device_handle, g_haptic_internal_pattern_list[pattern].ivt_pt, iteration, input_feedback_level, priority);
391 int device_haptic_stop_play(int device_handle)
395 if (device_handle_count == 0) {
396 ERR("Haptic device is not opened yet");
397 return HAPTIC_NOT_OPENED;
400 if (has_haptic_module == 1) {
401 status = plugin_intf->haptic_internal_stop_all_playing_effects(device_handle);
402 if(HAPTIC_FAILED(status)) {
403 ERR("plugin_intf->haptic_internal_stop_all_playing_effects(0) fail: %d", status);
407 status = device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_ENABLE, 0);
409 ERR("Haptic device stop failed: %d", status);
414 return HAPTIC_SUCCESS;
418 int device_haptic_play_monotone(int device_handle, int duration)
420 return device_haptic_play_monotone_with_feedback_level(device_handle, duration, HAPTIC_FEEDBACK_LEVEL_AUTO);
424 int device_haptic_play_monotone_with_feedback_level(int device_handle, int duration, int feedback_level)
428 int input_feedback_level;
431 if (device_handle_count == 0) {
432 ERR("Haptic device is not opened yet");
433 return HAPTIC_NOT_OPENED;
437 ERR("Invalid parameter: duration < 0");
441 if (feedback_level == HAPTIC_FEEDBACK_LEVEL_AUTO) {
442 input_feedback_level = __get_master_strength_value();
444 input_feedback_level = __convert_strength_level(feedback_level);
447 if (has_haptic_module == 1) {
448 status = plugin_intf->haptic_internal_play_monotone(device_handle, duration, input_feedback_level, 0x05);
449 if(HAPTIC_FAILED(status)) {
450 ERR("plugin_intf->haptic_internal_play_monotone(0) fail: %d", status);
454 status = device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_LEVEL, input_feedback_level);
456 ERR(" haptic_set_level for strength:%d (error:%d) \n", input_strength, status);
460 status = device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_ONESHOT, duration);
462 ERR(" haptic_oneshot for duration:%d (error:%d) \n", duration, status);
467 return HAPTIC_SUCCESS;
471 int device_haptic_play_monotone_with_detail_feedback_level(int device_handle, int duration, int detail_feedback_level)
475 int input_feedback_level;
478 if (device_handle_count == 0) {
479 ERR("Haptic device is not opened yet");
480 return HAPTIC_NOT_OPENED;
484 ERR("Invalid parameter: duration < 0");
488 if (detail_feedback_level < 0 && detail_feedback_level > 100) {
489 ERR("detail_feedback_level is wrong: %d", detail_feedback_level);
492 if (detail_feedback_level == 0) {
493 input_feedback_level = __get_master_strength_value();
495 input_feedback_level = detail_feedback_level * 100;
499 if (has_haptic_module == 1) {
500 status = plugin_intf->haptic_internal_play_monotone(device_handle, duration, input_feedback_level, 0x05);
501 if(HAPTIC_FAILED(status)) {
502 ERR("plugin_intf->haptic_internal_play_monotone(0) fail: %d", status);
506 status = device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_LEVEL, input_feedback_level);
508 ERR(" haptic_set_level for strength:%d (error:%d) \n", input_strength, status);
512 status = device_set_property(DEVTYPE_HAPTIC, HAPTIC_PROP_ONESHOT, duration);
514 ERR(" haptic_oneshot for duration:%d (error:%d) \n", duration, status);
519 return HAPTIC_SUCCESS;
523 int device_haptic_get_buffer_duration(int device_handle, const unsigned char *vibe_buffer, int *duration)
525 if (device_handle_count == 0) {
526 ERR("Haptic device is not opened yet");
527 return HAPTIC_NOT_OPENED;
530 if (has_haptic_module == 0) {
531 ERR("%s() is not supported without specific haptic module", __func__);
532 return HAPTIC_NOT_SUPPORTED;
535 return plugin_intf->haptic_internal_get_buffer_duration(device_handle, vibe_buffer, duration);
539 int device_haptic_get_file_duration(int device_handle, const char *file_name, int *duration)
541 if (device_handle_count == 0) {
542 ERR("Haptic device is not opened yet");
543 return HAPTIC_NOT_OPENED;
546 if (has_haptic_module == 0) {
547 ERR("%s() is not supported without specific haptic module", __func__);
548 return HAPTIC_NOT_SUPPORTED;
551 return plugin_intf->haptic_internal_get_file_duration(device_handle, file_name, duration);
555 int device_haptic_get_pattern_duration(int device_handle, int pattern, int *duration)
557 if (device_handle_count == 0) {
558 ERR("Haptic device is not opened yet");
559 return HAPTIC_NOT_OPENED;
562 if (has_haptic_module == 0) {
563 ERR("%s() is not supported without specific haptic module", __func__);
564 return HAPTIC_NOT_SUPPORTED;
567 char file_name[NAME_MAX];
569 if (!g_haptic_internal_pattern_list[pattern].ivt_pt) {
570 /* Pass filename insted of buffer pointer */
571 if (0 > snprintf(file_name, NAME_MAX, "%s%s%s", HAPTIC_BUILT_IN_FILE_PATH, g_haptic_internal_pattern_list[pattern].file_name, HAPTIC_PLAY_FILE_EXT))
573 ERR("snprintf fail in EFFCTVIBE_SET_EFFECT_TYPE");
577 return plugin_intf->haptic_internal_get_file_duration(device_handle, file_name, duration);
580 return plugin_intf->haptic_internal_get_buffer_duration(device_handle, g_haptic_internal_pattern_list[pattern].ivt_pt, duration);
584 int device_haptic_get_device_count()
587 int device_count = -1;
589 if (has_haptic_module == 0) {
590 return DEFAULT_MOTOR_COUNT;
593 if (device_handle_count == 0) {
594 plugin_intf->haptic_internal_prepare_node();
596 status = plugin_intf->haptic_internal_initialize();
600 /* Get device count */
601 device_count = plugin_intf->haptic_internal_get_device_count();
602 if(HAPTIC_FAILED(device_count)) {
603 ERR("plugin_intf->haptic_internal_get_device_count(0) fail: %d",status);
607 status = plugin_intf->haptic_internal_terminate();
612 device_count = plugin_intf->haptic_internal_get_device_count();
613 if(HAPTIC_FAILED(device_count)) {
614 ERR("plugin_intf->haptic_internal_get_device_count(0) fail: %d",status);
621 /* END: devman_haptic APIs */
624 /* START: devman_haptic_ext APIs */
626 int device_haptic_get_device_state(int device_index, int *state)
629 int index = device_index >> 1;
631 if (device_handle_count == 0) {
632 ERR("Haptic device is not opened yet");
633 return HAPTIC_NOT_OPENED;
636 if (has_haptic_module == 0) {
637 ERR("%s() is not supported without specific haptic module", __func__);
638 return HAPTIC_NOT_SUPPORTED;
641 return plugin_intf->haptic_internal_get_device_state(index, state);
645 int device_haptic_get_device_capability_bool(int device_index, int device_cap_type, unsigned char *device_cap_value)
648 int index = device_index >> 1;
650 if (device_handle_count == 0) {
651 ERR("Haptic device is not opened yet");
652 return HAPTIC_NOT_OPENED;
655 if (has_haptic_module == 0) {
656 ERR("%s() is not supported without specific haptic module", __func__);
657 return HAPTIC_NOT_SUPPORTED;
660 return plugin_intf->haptic_internal_get_device_capability_bool(index, device_cap_type, device_cap_value);
664 int device_haptic_get_device_capability_int32(int device_index, int device_cap_type, int *device_cap_value)
667 int index = device_index >> 1;
669 if (device_handle_count == 0) {
670 ERR("Haptic device is not opened yet");
671 return HAPTIC_NOT_OPENED;
674 if (has_haptic_module == 0) {
675 ERR("%s() is not supported without specific haptic module", __func__);
676 return HAPTIC_NOT_SUPPORTED;
679 return plugin_intf->haptic_internal_get_device_capability_int32(index, device_cap_type, device_cap_value);
683 int device_haptic_get_device_capability_string(int device_index, int device_cap_type, int size, char *device_cap_value)
686 int index = device_index >> 1;
688 if (device_handle_count == 0) {
689 ERR("Haptic device is not opened yet");
690 return HAPTIC_NOT_OPENED;
693 if (has_haptic_module == 0) {
694 ERR("%s() is not supported without specific haptic module", __func__);
695 return HAPTIC_NOT_SUPPORTED;
698 return plugin_intf->haptic_internal_get_device_capability_string(index, device_cap_type, size, device_cap_value);
702 int device_haptic_get_device_property_bool(int device_handle, int device_prop_type, unsigned char *device_prop_value)
706 if (device_handle_count == 0) {
707 ERR("Haptic device is not opened yet");
708 return HAPTIC_NOT_OPENED;
711 if (has_haptic_module == 0) {
712 ERR("%s() is not supported without specific haptic module", __func__);
713 return HAPTIC_NOT_SUPPORTED;
716 return plugin_intf->haptic_internal_get_device_property_bool(device_handle, device_prop_type, device_prop_value);
720 int device_haptic_set_device_property_bool(int device_handle, int device_prop_type, unsigned char device_prop_value)
724 if (device_handle_count == 0) {
725 ERR("Haptic device is not opened yet");
726 return HAPTIC_NOT_OPENED;
729 if (has_haptic_module == 0) {
730 ERR("%s() is not supported without specific haptic module", __func__);
731 return HAPTIC_NOT_SUPPORTED;
734 return plugin_intf->haptic_internal_set_device_property_bool(device_handle, device_prop_type, device_prop_value);
738 int device_haptic_get_device_property_int32(int device_handle, int device_prop_type, int *device_prop_value)
742 if (device_handle_count == 0) {
743 ERR("Haptic device is not opened yet");
744 return HAPTIC_NOT_OPENED;
747 if (has_haptic_module == 0) {
748 ERR("%s() is not supported without specific haptic module", __func__);
749 return HAPTIC_NOT_SUPPORTED;
752 return plugin_intf->haptic_internal_get_device_property_int32(device_handle, device_prop_type, device_prop_value);
756 int device_haptic_set_device_property_int32(int device_handle, int device_prop_type, int device_prop_value)
760 if (device_handle_count == 0) {
761 ERR("Haptic device is not opened yet");
762 return HAPTIC_NOT_OPENED;
765 if (has_haptic_module == 0) {
766 ERR("%s() is not supported without specific haptic module", __func__);
767 return HAPTIC_NOT_SUPPORTED;
770 return plugin_intf->haptic_internal_set_device_property_int32(device_handle, device_prop_type, device_prop_value);
774 int device_haptic_get_device_property_string(int device_handle, int device_prop_type, int size, char *device_prop_value)
778 if (device_handle_count == 0) {
779 ERR("Haptic device is not opened yet");
780 return HAPTIC_NOT_OPENED;
783 if (has_haptic_module == 0) {
784 ERR("%s() is not supported without specific haptic module", __func__);
785 return HAPTIC_NOT_SUPPORTED;
788 return plugin_intf->haptic_internal_get_device_property_string(device_handle, device_prop_type, size, device_prop_value);
792 int device_haptic_set_device_property_string(int device_handle, int device_prop_type, const char *device_prop_value)
796 if (device_handle_count == 0) {
797 ERR("Haptic device is not opened yet");
798 return HAPTIC_NOT_OPENED;
801 if (has_haptic_module == 0) {
802 ERR("%s() is not supported without specific haptic module", __func__);
803 return HAPTIC_NOT_SUPPORTED;
806 return plugin_intf->haptic_internal_set_device_property_string(device_handle, device_prop_type, device_prop_value);
810 int device_haptic_get_effect_count(const unsigned char *haptic_buffer)
814 if (device_handle_count == 0) {
815 ERR("Haptic device is not opened yet");
816 return HAPTIC_NOT_OPENED;
819 if (has_haptic_module == 0) {
820 ERR("%s() is not supported without specific haptic module", __func__);
821 return HAPTIC_NOT_SUPPORTED;
824 return plugin_intf->haptic_internal_get_IVT_effect_count(haptic_buffer);
828 int device_haptic_get_effect_name(const unsigned char *haptic_buffer, int effect_index, int size, char *effect_name)
832 if (device_handle_count == 0) {
833 ERR("Haptic device is not opened yet");
834 return HAPTIC_NOT_OPENED;
837 if (has_haptic_module == 0) {
838 ERR("%s() is not supported without specific haptic module", __func__);
839 return HAPTIC_NOT_SUPPORTED;
842 return plugin_intf->haptic_internal_get_IVT_effect_name(haptic_buffer, effect_index, size, effect_name);
846 int device_haptic_get_effect_name_u(const unsigned char *haptic_buffer, int effect_index, int size, unsigned short *effect_name)
850 if (device_handle_count == 0) {
851 ERR("Haptic device is not opened yet");
852 return HAPTIC_NOT_OPENED;
855 if (has_haptic_module == 0) {
856 ERR("%s() is not supported without specific haptic module", __func__);
857 return HAPTIC_NOT_SUPPORTED;
860 return plugin_intf->haptic_internal_get_IVT_effect_name_u(haptic_buffer, effect_index, size, effect_name);
864 int device_haptic_get_effect_index_from_name(const unsigned char *haptic_buffer, char const *effect_name, int *effect_index)
868 if (device_handle_count == 0) {
869 ERR("Haptic device is not opened yet");
870 return HAPTIC_NOT_OPENED;
873 if (has_haptic_module == 0) {
874 ERR("%s() is not supported without specific haptic module", __func__);
875 return HAPTIC_NOT_SUPPORTED;
878 return plugin_intf->haptic_internal_get_IVT_effect_index_from_name(haptic_buffer, effect_name, effect_index);
882 int device_haptic_get_effect_index_from_name_u(const unsigned char *haptic_buffer, const unsigned short *effect_name, int *effect_index)
886 if (device_handle_count == 0) {
887 ERR("Haptic device is not opened yet");
888 return HAPTIC_NOT_OPENED;
891 if (has_haptic_module == 0) {
892 ERR("%s() is not supported without specific haptic module", __func__);
893 return HAPTIC_NOT_SUPPORTED;
896 return plugin_intf->haptic_internal_get_IVT_effect_index_from_name_u(haptic_buffer, effect_name, effect_index);
900 int device_haptic_play_effect(int device_handle, const unsigned char *haptic_buffer, int effect_index, int *effect_handle)
904 if (device_handle_count == 0) {
905 ERR("Haptic device is not opened yet");
906 return HAPTIC_NOT_OPENED;
909 if (has_haptic_module == 0) {
910 ERR("%s() is not supported without specific haptic module", __func__);
911 return HAPTIC_NOT_SUPPORTED;
914 return plugin_intf->haptic_internal_play_IVT_effect(device_handle, haptic_buffer, effect_index, effect_handle);
918 int device_haptic_play_effect_repeat(int device_handle, const unsigned char *haptic_buffer, int effect_index, unsigned char repeat, int *effect_handle)
922 if (device_handle_count == 0) {
923 ERR("Haptic device is not opened yet");
924 return HAPTIC_NOT_OPENED;
927 if (has_haptic_module == 0) {
928 ERR("%s() is not supported without specific haptic module", __func__);
929 return HAPTIC_NOT_SUPPORTED;
932 return plugin_intf->haptic_internal_play_IVT_effect_repeat(device_handle, haptic_buffer, effect_index, repeat, effect_handle);
936 int device_haptic_stop_playing_effect(int device_handle, int effect_handle)
940 if (device_handle_count == 0) {
941 ERR("Haptic device is not opened yet");
942 return HAPTIC_NOT_OPENED;
945 if (has_haptic_module == 0) {
946 ERR("%s() is not supported without specific haptic module", __func__);
947 return HAPTIC_NOT_SUPPORTED;
950 return plugin_intf->haptic_internal_stop_playing_effect(device_handle, effect_handle);
954 int device_haptic_get_effect_type(const unsigned char *haptic_buffer, int effect_index, int *effect_type)
958 if (device_handle_count == 0) {
959 ERR("Haptic device is not opened yet");
960 return HAPTIC_NOT_OPENED;
963 if (has_haptic_module == 0) {
964 ERR("%s() is not supported without specific haptic module", __func__);
965 return HAPTIC_NOT_SUPPORTED;
968 return plugin_intf->haptic_internal_get_IVT_effect_type(haptic_buffer, effect_index, effect_type);
972 int device_haptic_get_magsweep_effect_definition(const unsigned char *haptic_buffer, int effect_index,
973 int *duration, int *magnitude, int *style, int *attacktime, int *attacklevel,
974 int *fadetime, int *fadelevel)
978 if (device_handle_count == 0) {
979 ERR("Haptic device is not opened yet");
980 return HAPTIC_NOT_OPENED;
983 if (has_haptic_module == 0) {
984 ERR("%s() is not supported without specific haptic module", __func__);
985 return HAPTIC_NOT_SUPPORTED;
988 return plugin_intf->haptic_internal_get_IVT_magsweep_effect_definition(haptic_buffer, effect_index, duration, magnitude, style, attacktime, attacklevel, fadetime, fadelevel);
992 int device_haptic_get_periodic_effect_definition(const unsigned char *haptic_buffer, int effect_index,
993 int *duration, int *magnitude, int *period, int *style_and_wave_type, int *attacktime, int *attacklevel,
994 int *fadetime, int *fadelevel)
998 if (device_handle_count == 0) {
999 ERR("Haptic device is not opened yet");
1000 return HAPTIC_NOT_OPENED;
1003 if (has_haptic_module == 0) {
1004 ERR("%s() is not supported without specific haptic module", __func__);
1005 return HAPTIC_NOT_SUPPORTED;
1008 return plugin_intf->haptic_internal_get_IVT_periodic_effect_definition(haptic_buffer, effect_index, duration, magnitude, period, style_and_wave_type, attacktime, attacklevel, fadetime, fadelevel);
1012 int device_haptic_get_effect_duration(const unsigned char *haptic_buffer, int effect_index, int *effect_duration)
1016 if (device_handle_count == 0) {
1017 ERR("Haptic device is not opened yet");
1018 return HAPTIC_NOT_OPENED;
1021 if (has_haptic_module == 0) {
1022 ERR("%s() is not supported without specific haptic module", __func__);
1023 return HAPTIC_NOT_SUPPORTED;
1026 return plugin_intf->haptic_internal_get_IVT_effect_duration(haptic_buffer, effect_index, effect_duration);
1030 int device_haptic_play_magsweep_effect(int device_handle,
1031 int duration, int magnitude, int style, int attacktime, int attacklevel,
1032 int fadetime, int fadelevel, int *effect_handle)
1036 if (device_handle_count == 0) {
1037 ERR("Haptic device is not opened yet");
1038 return HAPTIC_NOT_OPENED;
1041 if (has_haptic_module == 0) {
1042 ERR("%s() is not supported without specific haptic module", __func__);
1043 return HAPTIC_NOT_SUPPORTED;
1046 return plugin_intf->haptic_internal_play_magsweep_effect(device_handle, duration, magnitude, style, attacktime, attacklevel, fadetime, fadelevel, effect_handle);
1050 int device_haptic_play_periodic_effect(int device_handle,
1051 int duration, int magnitude, int period, int style_and_wave_type, int attacktime, int attacklevel,
1052 int fadetime, int fadelevel, int *effect_handle)
1056 if (device_handle_count == 0) {
1057 ERR("Haptic device is not opened yet");
1058 return HAPTIC_NOT_OPENED;
1061 if (has_haptic_module == 0) {
1062 ERR("%s() is not supported without specific haptic module", __func__);
1063 return HAPTIC_NOT_SUPPORTED;
1066 return plugin_intf->haptic_internal_play_periodic_effect(device_handle, duration, magnitude, period, style_and_wave_type, attacktime, attacklevel, fadetime, fadelevel, effect_handle);
1070 int device_haptic_modify_playing_magsweep_effect(int device_handle, int effect_handle,
1071 int duration, int magnitude, int style, int attacktime, int attacklevel, int fadetime, int fadelevel)
1075 if (device_handle_count == 0) {
1076 ERR("Haptic device is not opened yet");
1077 return HAPTIC_NOT_OPENED;
1080 if (has_haptic_module == 0) {
1081 ERR("%s() is not supported without specific haptic module", __func__);
1082 return HAPTIC_NOT_SUPPORTED;
1085 return plugin_intf->haptic_internal_modify_playing_magsweep_effect(device_handle, effect_handle, duration, magnitude, style, attacktime, attacklevel, fadetime, fadelevel);
1089 int device_haptic_modify_playing_periodic_effect(int device_handle, int effect_handle,
1090 int duration, int magnitude, int period, int style_and_wave_type, int attacktime, int attacklevel, int fadetime, int fadelevel)
1094 if (device_handle_count == 0) {
1095 ERR("Haptic device is not opened yet");
1096 return HAPTIC_NOT_OPENED;
1099 if (has_haptic_module == 0) {
1100 ERR("%s() is not supported without specific haptic module", __func__);
1101 return HAPTIC_NOT_SUPPORTED;
1104 return plugin_intf->haptic_internal_modify_playing_periodic_effect(device_handle, effect_handle, duration, magnitude, period, style_and_wave_type, attacktime, attacklevel, fadetime, fadelevel);
1108 int device_haptic_create_streaming_effect(int device_handle, int *effect_handle)
1112 if (device_handle_count == 0) {
1113 ERR("Haptic device is not opened yet");
1114 return HAPTIC_NOT_OPENED;
1117 if (has_haptic_module == 0) {
1118 ERR("%s() is not supported without specific haptic module", __func__);
1121 return plugin_intf->haptic_internal_create_streaming_effect(device_handle, effect_handle);
1125 int device_haptic_destroy_streaming_effect(int device_handle, int effect_handle)
1129 if (device_handle_count == 0) {
1130 ERR("Haptic device is not opened yet");
1131 return HAPTIC_NOT_OPENED;
1134 if (has_haptic_module == 0) {
1135 ERR("%s() is not supported without specific haptic module", __func__);
1136 return HAPTIC_NOT_SUPPORTED;
1139 return plugin_intf->haptic_internal_destroy_streaming_effect(device_handle, effect_handle);
1143 int device_haptic_play_streaming_sample(int device_handle, int effect_handle, const unsigned char *streaming_sample, int size)
1147 if (device_handle_count == 0) {
1148 ERR("Haptic device is not opened yet");
1149 return HAPTIC_NOT_OPENED;
1152 if (has_haptic_module == 0) {
1153 ERR("%s() is not supported without specific haptic module", __func__);
1154 return HAPTIC_NOT_SUPPORTED;
1157 return plugin_intf->haptic_internal_play_streaming_sample(device_handle, effect_handle, streaming_sample, size);
1161 int device_haptic_play_streaming_sample_with_offset(int device_handle, int effect_handle, const unsigned char *streaming_sample, int size, int offset_time)
1165 if (device_handle_count == 0) {
1166 ERR("Haptic device is not opened yet");
1167 return HAPTIC_NOT_OPENED;
1170 if (has_haptic_module == 0) {
1171 ERR("%s() is not supported without specific haptic module", __func__);
1172 return HAPTIC_NOT_SUPPORTED;
1175 return plugin_intf->haptic_internal_play_streaming_sample_with_offset(device_handle, effect_handle, streaming_sample, size, offset_time);
1179 int device_haptic_stop_all_playing_effects(int device_handle)
1183 if (device_handle_count == 0) {
1184 ERR("Haptic device is not opened yet");
1185 return HAPTIC_NOT_OPENED;
1188 if (has_haptic_module == 0) {
1189 ERR("%s() is not supported without specific haptic module", __func__);
1190 return HAPTIC_NOT_SUPPORTED;
1193 return plugin_intf->haptic_internal_stop_all_playing_effects(device_handle);
1197 int device_haptic_save_file(const unsigned char *haptic_buffer, const char *path_name)
1199 ERR("%s() is not supported without specific haptic module", __func__);
1204 if (device_handle_count == 0) {
1205 ERR("Haptic device is not opened yet");
1209 if (has_haptic_module == 0) {
1210 ERR("%s() is not supported without specific haptic module", __func__);
1214 return plugin_intf->haptic_internal_save_IVT_file(haptic_buffer, path_name);
1218 int device_haptic_delete_file(const char *path_name)
1222 if (device_handle_count == 0) {
1223 ERR("Haptic device is not opened yet");
1224 return HAPTIC_NOT_OPENED;
1227 if (has_haptic_module == 0) {
1228 ERR("%s() is not supported without specific haptic module", __func__);
1229 return HAPTIC_NOT_SUPPORTED;
1232 return plugin_intf->haptic_internal_delete_IVT_file(path_name);
1236 int device_haptic_pause_playing_effect(int device_handle, int effect_handle)
1240 if (device_handle_count == 0) {
1241 ERR("Haptic device is not opened yet");
1242 return HAPTIC_NOT_OPENED;
1245 if (has_haptic_module == 0) {
1246 ERR("%s() is not supported without specific haptic module", __func__);
1247 return HAPTIC_NOT_SUPPORTED;
1250 return plugin_intf->haptic_internal_pause_playing_effect(device_handle, effect_handle);
1254 int device_haptic_resume_paused_effect(int device_handle, int effect_handle)
1258 if (device_handle_count == 0) {
1259 ERR("Haptic device is not opened yet");
1260 return HAPTIC_NOT_OPENED;
1263 if (has_haptic_module == 0) {
1264 ERR("%s() is not supported without specific haptic module", __func__);
1265 return HAPTIC_NOT_SUPPORTED;
1268 return plugin_intf->haptic_internal_resume_paused_effect(device_handle, effect_handle);
1272 int device_haptic_get_effect_state(int device_handle, int effect_handle, int *effect_state)
1276 if (device_handle_count == 0) {
1277 ERR("Haptic device is not opened yet");
1278 return HAPTIC_NOT_OPENED;
1281 if (has_haptic_module == 0) {
1282 ERR("%s() is not supported without specific haptic module", __func__);
1283 return HAPTIC_NOT_SUPPORTED;
1286 return plugin_intf->haptic_internal_get_effect_state(device_handle, effect_handle, effect_state);
1290 int device_haptic_get_size(const unsigned char *haptic_buffer, int size)
1294 if (device_handle_count == 0) {
1295 ERR("Haptic device is not opened yet");
1296 return HAPTIC_NOT_OPENED;
1299 if (has_haptic_module == 0) {
1300 ERR("%s() is not supported without specific haptic module", __func__);
1301 return HAPTIC_NOT_SUPPORTED;
1304 return plugin_intf->haptic_internal_get_IVT_size(haptic_buffer, size);
1308 int device_haptic_initialize_buffer(unsigned char *haptic_buffer, int size)
1312 if (device_handle_count == 0) {
1313 ERR("Haptic device is not opened yet");
1314 return HAPTIC_NOT_OPENED;
1317 if (has_haptic_module == 0) {
1318 ERR("%s() is not supported without specific haptic module", __func__);
1319 return HAPTIC_NOT_SUPPORTED;
1322 return plugin_intf->haptic_internal_initialize_IVT_buffer(haptic_buffer, size);
1326 int device_haptic_insert_element(unsigned char *haptic_buffer, int size, int timeline_index, const HapticElement *element)
1330 if (device_handle_count == 0) {
1331 ERR("Haptic device is not opened yet");
1332 return HAPTIC_NOT_OPENED;
1335 if (has_haptic_module == 0) {
1336 ERR("%s() is not supported without specific haptic module", __func__);
1337 return HAPTIC_NOT_SUPPORTED;
1340 return plugin_intf->haptic_internal_insert_IVT_element(haptic_buffer, size, timeline_index, element);
1344 int device_haptic_insert_element2(unsigned char *haptic_buffer, int size, int timeline_index, const HapticElement2 *element)
1348 if (device_handle_count == 0) {
1349 ERR("Haptic device is not opened yet");
1350 return HAPTIC_NOT_OPENED;
1353 if (has_haptic_module == 0) {
1354 ERR("%s() is not supported without specific haptic module", __func__);
1355 return HAPTIC_NOT_SUPPORTED;
1358 return plugin_intf->haptic_internal_insert_IVT_element2(haptic_buffer, size, timeline_index, element);
1362 int device_haptic_insert_element3(unsigned char *haptic_buffer, int size, int timeline_index, const HapticElement3 *element)
1366 if (device_handle_count == 0) {
1367 ERR("Haptic device is not opened yet");
1368 return HAPTIC_NOT_OPENED;
1371 if (has_haptic_module == 0) {
1372 ERR("%s() is not supported without specific haptic module", __func__);
1373 return HAPTIC_NOT_SUPPORTED;
1376 return plugin_intf->haptic_internal_insert_IVT_element3(haptic_buffer, size, timeline_index, element);
1380 int device_haptic_read_element(const unsigned char *haptic_buffer, int size, int timeline_index, int element_index, HapticElement *element)
1384 if (device_handle_count == 0) {
1385 ERR("Haptic device is not opened yet");
1386 return HAPTIC_NOT_OPENED;
1389 if (has_haptic_module == 0) {
1390 ERR("%s() is not supported without specific haptic module", __func__);
1391 return HAPTIC_NOT_SUPPORTED;
1394 return plugin_intf->haptic_internal_read_IVT_element(haptic_buffer, size, timeline_index, element_index, element);
1398 int device_haptic_read_element2(const unsigned char *haptic_buffer, int size, int timeline_index, int element_index, HapticElement2 *element)
1402 if (device_handle_count == 0) {
1403 ERR("Haptic device is not opened yet");
1404 return HAPTIC_NOT_OPENED;
1407 if (has_haptic_module == 0) {
1408 ERR("%s() is not supported without specific haptic module", __func__);
1409 return HAPTIC_NOT_SUPPORTED;
1412 return plugin_intf->haptic_internal_read_IVT_element2(haptic_buffer, size, timeline_index, element_index, element);
1416 int device_haptic_read_element3(const unsigned char *haptic_buffer, int size, int timeline_index, int element_index, HapticElement3 *element)
1420 if (device_handle_count == 0) {
1421 ERR("Haptic device is not opened yet");
1422 return HAPTIC_NOT_OPENED;
1425 if (has_haptic_module == 0) {
1426 ERR("%s() is not supported without specific haptic module", __func__);
1427 return HAPTIC_NOT_SUPPORTED;
1430 return plugin_intf->haptic_internal_read_IVT_element3(haptic_buffer, size, timeline_index, element_index, element);
1434 int device_haptic_remove_element(unsigned char *haptic_buffer, int size, int timeline_index, int element_index)
1438 if (device_handle_count == 0) {
1439 ERR("Haptic device is not opened yet");
1440 return HAPTIC_NOT_OPENED;
1443 if (has_haptic_module == 0) {
1444 ERR("%s() is not supported without specific haptic module", __func__);
1445 return HAPTIC_NOT_SUPPORTED;
1448 return plugin_intf->haptic_internal_remove_IVT_element(haptic_buffer, size, timeline_index, element_index);
1450 /* END: devman_haptic_ext APIs */
1452 static void __attribute__ ((constructor)) module_init()
1456 if (access(HAPTIC_DEVICE_NODE_PATH, F_OK) < 0) {
1457 has_haptic_module = 0;
1460 has_haptic_module = 1;
1463 dlopen_handle = dlopen(HAPTIC_MODULE_PATH, RTLD_NOW);
1464 if (!dlopen_handle) {
1465 ERR("dlopen failed: %s", dlerror());
1466 has_haptic_module = 0;
1470 const devman_haptic_plugin_interface *(*get_devman_haptic_plugin_interface) ();
1471 get_devman_haptic_plugin_interface = dlsym(dlopen_handle, "get_devman_haptic_plugin_interface");
1472 if ((error = dlerror()) != NULL) {
1473 ERR("dlsym failed : %s", error);
1474 has_haptic_module = 0;
1475 dlclose(dlopen_handle);
1479 plugin_intf = get_devman_haptic_plugin_interface();
1481 ERR("get_devman_haptic_plugin_interface() failed");
1482 has_haptic_module = 0;
1483 dlclose(dlopen_handle);
1488 static void __attribute__ ((destructor)) module_fini()
1490 if (dlopen_handle) {
1491 dlclose(dlopen_handle);