diff options
-rw-r--r-- | packaging/haptic-module-tizen.spec | 4 | ||||
-rw-r--r-- | test/test.c | 1 | ||||
-rw-r--r-- | tizen/DEVICE/CMakeLists.txt | 6 | ||||
-rw-r--r-- | tizen/DEVICE/src/haptic.c | 515 | ||||
-rw-r--r-- | tizen/SIMULATOR/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tizen/SIMULATOR/src/haptic.c | 2 |
6 files changed, 65 insertions, 465 deletions
diff --git a/packaging/haptic-module-tizen.spec b/packaging/haptic-module-tizen.spec index db4d6bc..75b5fae 100644 --- a/packaging/haptic-module-tizen.spec +++ b/packaging/haptic-module-tizen.spec @@ -6,10 +6,10 @@ Release: 9 Group: System/Libraries License: APLv2 Source0: %{name}-%{version}.tar.gz +ExclusiveArch: %{arm} BuildRequires: cmake BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(vconf) -BuildRequires: pkgconfig(haptic-plugin) +BuildRequires: pkgconfig(deviced) BuildRequires: pkgconfig(device-node) Requires(post): /sbin/ldconfig diff --git a/test/test.c b/test/test.c index b8cb94e..ad012fe 100644 --- a/test/test.c +++ b/test/test.c @@ -23,7 +23,6 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#include <vconf.h> #include <dlfcn.h> #include <haptic_plugin_intf.h> diff --git a/tizen/DEVICE/CMakeLists.txt b/tizen/DEVICE/CMakeLists.txt index 8d68793..6db8080 100644 --- a/tizen/DEVICE/CMakeLists.txt +++ b/tizen/DEVICE/CMakeLists.txt @@ -1,13 +1,11 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) SET(SRCS - src/haptic.c - src/file.c - src/sysnoti.c) + src/haptic.c) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) -SET(DEPENDENTS "dlog vconf haptic-plugin device-node") +SET(DEPENDENTS "dlog deviced device-node") INCLUDE(FindPkgConfig) pkg_check_modules(rpkgs REQUIRED ${DEPENDENTS}) diff --git a/tizen/DEVICE/src/haptic.c b/tizen/DEVICE/src/haptic.c index e7605de..63f58ce 100644 --- a/tizen/DEVICE/src/haptic.c +++ b/tizen/DEVICE/src/haptic.c @@ -25,9 +25,9 @@ #include <fcntl.h> #include <assert.h> #include <time.h> -#include <vconf.h> +#include <device-node.h> -#include <haptic_plugin_intf.h> +#include <haptic-plugin-intf.h> #include "haptic_module_log.h" #include "file.h" @@ -37,194 +37,21 @@ #define DEFAULT_EFFECT_HANDLE 0xFFFF #define DEFAULT_MOTOR_COUNT 1 -#define HAPTIC_PLAY_FILE_EXT ".tht" /* START of Static Function Section */ -static int __to_level(int feedback, int *type) +static int convert_feedback_level(int feedback) { static int max = -1; - int t; + int ret; if (max == -1) { - int status = GetHapticLevelMax(&max); - if (status < 0) { - MODULE_ERROR("GetHapticLevelMax fail : %d", status); - return HAPTIC_MODULE_OPERATION_FAILED; - } + ret = device_get_property(DEVICE_TYPE_VIBRATOR, + PROP_VIBRATOR_LEVEL_MAX, &max); + if (ret < 0) + return ret; } - t = feedback * max / HAPTIC_MODULE_FEEDBACK_MAX; - MODULE_LOG("feedback value is changed : %d -> %d", feedback, t); - - if (type) - *type = t; - - return 0; -} - -static void __trim_name(const char *file_name, char *vibe_buffer, int size) -{ - int length; - - assert(file_name); - assert(vibe_buffer); - assert(size > 0); - - snprintf(vibe_buffer, size, "%s", file_name); - - length = strlen(vibe_buffer); - while (vibe_buffer[--length] == ' '); - vibe_buffer[length + 1] = '\0'; -} - -static int __check_ext(const char *name) -{ - char *ext; - - assert(name); - - ext = strrchr(name, '.'); - if (ext && !strcmp(ext, HAPTIC_PLAY_FILE_EXT)) - return 1; - - return 0; -} - -static int __get_size(FILE *pf, const char *fname) -{ - int status; - int size; - - assert(pf); - - status = fseek(pf, 0, SEEK_END); - if (status == -1) { - MODULE_ERROR("fseek failed: %s", fname); - return -1; - } - - size = ftell(pf); - - status = fseek(pf, 0, SEEK_SET); - if (status == -1) { - MODULE_ERROR("fseek failed: %s", fname); - return -1; - } - - return size; -} - -static unsigned char *__read_file(const char *fname) -{ - int status; - FILE *pf; - long size; - unsigned char *vibe_buffer; - - assert(fname); - - pf = fopen(fname, "rb"); - if (!pf) { - MODULE_ERROR("fopen failed: %s", fname); - return NULL; - } - - size = __get_size(pf, fname); - if (size <= 0) { - fclose(pf); - return NULL; - } - - vibe_buffer = malloc(size); - if (!vibe_buffer) { - fclose(pf); - MODULE_ERROR("buffer alloc failed"); - return NULL; - } - - status = fread(vibe_buffer, 1, size, pf); - if (status != size) { - MODULE_ERROR("fread failed: expect %d read %d", size, status); - free(vibe_buffer); - vibe_buffer = NULL; - } - - fclose(pf); - - return vibe_buffer; -} - -static unsigned char* __convert_file_to_buffer(const char *file_name) -{ - char fname[FILENAME_MAX]; - int status; - - __trim_name(file_name, fname, sizeof(fname)); - status = __check_ext(fname); - if (!status) { - MODULE_ERROR("__check_file faild"); - return NULL; - } - - return __read_file(fname); -} - -static int __save_file(const unsigned char *vibe_buferf, int size, const char *file_name) -{ - int status; - FILE *pf; - int fd; - - pf = fopen(file_name, "wb+"); - if (pf == NULL) { - MODULE_ERROR("To open file is failed"); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - status = fwrite(vibe_buferf, 1, size, pf); - if (status != size) { - MODULE_ERROR("To write file is failed"); - fclose(pf); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - fd = fileno(pf); - if (fd == -1) { - MODULE_ERROR("To get file descriptor is failed"); - fclose(pf); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - status = fsync(fd); - if (status == -1) { - MODULE_ERROR("To be synchronized with the disk is failed"); - fclose(pf); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - fclose(pf); - - return 0; -} - -static int __vibrate(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority) -{ - int status; - int level; - - assert(vibe_buffer); - - status = __to_level(feedback, &level); - if (status != HAPTIC_MODULE_ERROR_NONE) - return status; - - status = PlayBuffer(device_handle, vibe_buffer, iteration, level); - if (status < 0) { - MODULE_ERROR("PlayHapticBuffer fail : %d", status); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - return 0; + return feedback * max / HAPTIC_MODULE_FEEDBACK_MAX; } static void *_create_handle(void) @@ -245,7 +72,6 @@ static int _get_device_count(int *count) static int _open_device(int device_index, int *device_handle) { - int handle; int status; if (device_index < HAPTIC_MODULE_DEVICE_0 || device_index > HAPTIC_MODULE_DEVICE_ALL) @@ -254,14 +80,7 @@ static int _open_device(int device_index, int *device_handle) if (device_handle == NULL) return HAPTIC_MODULE_INVALID_ARGUMENT; - handle = _create_handle(); - status = OpenDevice(handle); - if (status < 0) { - MODULE_ERROR("OpenHapticDevice fail :%d", status); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - *device_handle = handle; + *device_handle = _create_handle(); return HAPTIC_MODULE_ERROR_NONE; } @@ -272,19 +91,12 @@ static int _close_device(int device_handle) if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; - status = CloseDevice(device_handle); - if (status < 0) { - MODULE_ERROR("CloseHapticDevice fail : %d", status); - return HAPTIC_MODULE_OPERATION_FAILED; - } - return HAPTIC_MODULE_ERROR_NONE; } static int _vibrate_monotone(int device_handle, int duration, int feedback, int priority, int *effect_handle) { - int status; - int level; + int level, ret; if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; @@ -304,319 +116,110 @@ static int _vibrate_monotone(int device_handle, int duration, int feedback, int if (feedback == HAPTIC_MODULE_FEEDBACK_MIN) return HAPTIC_MODULE_ERROR_NONE; - status = __to_level(feedback, &level); - if (status != HAPTIC_MODULE_ERROR_NONE) - return status; - - status = PlayOneshot(device_handle, duration, level); - if (status < 0) { - MODULE_ERROR("PlayOneshot fail : %d", status); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - *effect_handle = DEFAULT_EFFECT_HANDLE; - return HAPTIC_MODULE_ERROR_NONE; -} - -static int _vibrate_file(int device_handle, const char *file_path, int iteration, int feedback, int priority, int *effect_handle) -{ - int status; - unsigned char *vibe_buffer; - - if (device_handle < 0) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (file_path == NULL) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (iteration < HAPTIC_MODULE_ITERATION_ONCE || iteration > HAPTIC_MODULE_ITERATION_INFINITE) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (feedback < HAPTIC_MODULE_FEEDBACK_MIN || feedback > HAPTIC_MODULE_FEEDBACK_MAX) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (priority < HAPTIC_MODULE_PRIORITY_MIN || priority > HAPTIC_MODULE_PRIORITY_HIGH) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (effect_handle == NULL) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (feedback == HAPTIC_MODULE_FEEDBACK_MIN) - return HAPTIC_MODULE_ERROR_NONE; - - vibe_buffer = __convert_file_to_buffer(file_path); - if (!vibe_buffer) { - MODULE_ERROR("File load filed"); + level = convert_feedback_level(feedback); + if (level < 0) { + MODULE_ERROR("fail to convert haptic level : %d", ret); return HAPTIC_MODULE_OPERATION_FAILED; } - status = __vibrate(device_handle, vibe_buffer, iteration, feedback, priority); - free(vibe_buffer); - - *effect_handle = DEFAULT_EFFECT_HANDLE; - return status; -} - -static int _vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle) -{ - int status; - - if (device_handle < 0) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (vibe_buffer == NULL) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (iteration < HAPTIC_MODULE_ITERATION_ONCE || iteration > HAPTIC_MODULE_ITERATION_INFINITE) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (feedback < HAPTIC_MODULE_FEEDBACK_MIN || feedback > HAPTIC_MODULE_FEEDBACK_MAX) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (priority < HAPTIC_MODULE_PRIORITY_MIN || priority > HAPTIC_MODULE_PRIORITY_HIGH) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (effect_handle == NULL) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (feedback == HAPTIC_MODULE_FEEDBACK_MIN) - return HAPTIC_MODULE_ERROR_NONE; - - status = __vibrate(device_handle, vibe_buffer, iteration, feedback, priority); - - *effect_handle = DEFAULT_EFFECT_HANDLE; - return status; -} - -static int _stop_effect(int device_handle, int effect_handle) -{ - int status; - - if (device_handle < 0) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (effect_handle < 0) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - status = Stop(device_handle); - if (status < 0) { - MODULE_ERROR("StopHaptic fail : %d", status); + ret = device_set_property(DEVICE_TYPE_VIBRATOR, + PROP_VIBRATOR_LEVEL, level); + if (ret < 0) { + MODULE_ERROR("fail to set haptic level : %d", ret); return HAPTIC_MODULE_OPERATION_FAILED; } - return HAPTIC_MODULE_ERROR_NONE; -} - -static int _stop_all_effects(int device_handle) -{ - int status; - - if (device_handle < 0) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - status = Stop(device_handle); - if (status < 0) { - MODULE_ERROR("StopHaptic fail : %d", status); + ret = device_set_property(DEVICE_TYPE_VIBRATOR, + PROP_VIBRATOR_ONESHOT, duration); + if (ret < 0) { + MODULE_ERROR("fail to set oneshot : %d", ret); return HAPTIC_MODULE_OPERATION_FAILED; } + *effect_handle = DEFAULT_EFFECT_HANDLE; return HAPTIC_MODULE_ERROR_NONE; } -static int _pause_effect(int device_handle, int effect_handle) -{ - if (device_handle < 0) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (effect_handle < 0) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - MODULE_ERROR("This device is not supported this function(%s)", __func__); - return HAPTIC_MODULE_NOT_SUPPORTED; -} - -static int _resume_effect(int device_handle, int effect_handle) +static int _vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle) { - if (device_handle < 0) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (effect_handle < 0) - return HAPTIC_MODULE_INVALID_ARGUMENT; - MODULE_ERROR("This device is not supported this function(%s)", __func__); return HAPTIC_MODULE_NOT_SUPPORTED; } -static int _get_effect_state(int device_handle, int effect_handle, int *state) +static int _stop_device(int device_handle) { - int status; - int cur_state; + int ret; if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; - if (effect_handle < 0) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (state == NULL) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - status = GetState(device_handle, &cur_state); - if (status < 0) { - MODULE_ERROR("GetState fail : %d", status); + ret = device_set_property(DEVICE_TYPE_VIBRATOR, + PROP_VIBRATOR_ENABLE, 0); + if (ret < 0) { + MODULE_ERROR("fail to stop haptic device : %d", ret); return HAPTIC_MODULE_OPERATION_FAILED; } - *state = cur_state; return HAPTIC_MODULE_ERROR_NONE; } -static int _create_effect(unsigned char *vibe_buffer, int max_bufsize, haptic_module_effect_element *elem_arr, int max_elemcnt) +static int _get_device_state(int device_handle, int *state) { - int status; - int i; - HapticElement elem; - - if (vibe_buffer == NULL) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (max_bufsize < 0) - return HAPTIC_MODULE_INVALID_ARGUMENT; + int ret; + int cur_state; - if (elem_arr == NULL) + if (device_handle < 0) return HAPTIC_MODULE_INVALID_ARGUMENT; - if (max_elemcnt < 0) + if (state == NULL) return HAPTIC_MODULE_INVALID_ARGUMENT; - status = InitializeBuffer(vibe_buffer, max_bufsize); - if (status < 0) { - MODULE_ERROR("InitializeHapticBuffer fail: %d", status); + ret = device_get_property(DEVICE_TYPE_VIBRATOR, + PROP_VIBRATOR_ENABLE, &cur_state); + if (ret < 0) { + MODULE_ERROR("fail to get haptic enble value : %d", ret); return HAPTIC_MODULE_OPERATION_FAILED; } - MODULE_LOG("effect count : %d", max_elemcnt); - for (i = 0; i < max_elemcnt; ++i) { - elem.duration = elem_arr[i].haptic_duration; - elem.level = elem_arr[i].haptic_level; - MODULE_LOG("%d) duration : %d, level : %d", i, elem_arr[i].haptic_duration, elem_arr[i].haptic_level); - - status = InsertElement(vibe_buffer, max_bufsize, &elem); - if (status < 0) { - MODULE_ERROR("InsertHapticElement fail: %d", status); - return HAPTIC_MODULE_OPERATION_FAILED; - } - } + *state = (cur_state == 0 ? + HAPTIC_MODULE_STATE_STOP : HAPTIC_MODULE_STATE_PLAYING); return HAPTIC_MODULE_ERROR_NONE; } -static int _save_effect(const unsigned char *vibe_buffer, int max_bufsize, const char *file_path) -{ - int status; - int size; - - if (vibe_buffer == NULL) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (max_bufsize < 0) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (file_path == NULL) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - status = GetBufferSize(vibe_buffer, &size); - if (status < 0) { - MODULE_ERROR("GetHapticBufferSize fail: %d", status); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - return __save_file(vibe_buffer, size, file_path); -} - -static int _get_file_duration(int device_handle, const char *file_path, int *file_duration) +static int _create_effect(unsigned char *vibe_buffer, int max_bufsize, haptic_module_effect_element *elem_arr, int max_elemcnt) { - int status; - unsigned char *vibe_buffer; - int duration; - - if (device_handle < 0) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (file_path == NULL) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (file_duration == NULL) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - vibe_buffer = __convert_file_to_buffer(file_path); - if (!vibe_buffer) { - MODULE_ERROR("File load filed"); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - status = GetBufferDuration(vibe_buffer, &duration); - free(vibe_buffer); - if (status < 0) { - MODULE_ERROR("GetHapticBufferDuration fail: %d", status); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - *file_duration = duration; - return HAPTIC_MODULE_ERROR_NONE; + MODULE_ERROR("This device is not supported this function(%s)", __func__); + return HAPTIC_MODULE_NOT_SUPPORTED; } static int _get_buffer_duration(int device_handle, const unsigned char *vibe_buffer, int *buffer_duration) { - int status; - int duration; - - if (device_handle < 0) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (vibe_buffer == NULL) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - if (buffer_duration == NULL) - return HAPTIC_MODULE_INVALID_ARGUMENT; - - status = GetBufferDuration(vibe_buffer, &duration); - if (status < 0) { - MODULE_ERROR("GetHapticBufferDuration fail: %d", status); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - *buffer_duration = duration; - return HAPTIC_MODULE_ERROR_NONE; + MODULE_ERROR("This device is not supported this function(%s)", __func__); + return HAPTIC_MODULE_NOT_SUPPORTED; } -static int _convert_binary (void) +static int _convert_binary(void) { MODULE_ERROR("This device is not supported this function(%s)", __func__); return HAPTIC_MODULE_NOT_SUPPORTED; } -static const haptic_plugin_interface haptic_plugin_tizen = { - .haptic_internal_get_device_count = _get_device_count, - .haptic_internal_open_device = _open_device, - .haptic_internal_close_device = _close_device, - .haptic_internal_vibrate_monotone = _vibrate_monotone, - .haptic_internal_vibrate_file = _vibrate_file, - .haptic_internal_vibrate_buffer = _vibrate_buffer, - .haptic_internal_stop_effect = _stop_effect, - .haptic_internal_stop_all_effects = _stop_all_effects, - .haptic_internal_pause_effect = _pause_effect, - .haptic_internal_resume_effect = _resume_effect, - .haptic_internal_get_effect_state = _get_effect_state, - .haptic_internal_create_effect = _create_effect, - .haptic_internal_save_effect = _save_effect, - .haptic_internal_get_file_duration = _get_file_duration, - .haptic_internal_get_buffer_duration = _get_buffer_duration, - .haptic_internal_convert_binary = _convert_binary, +static const struct haptic_plugin_ops haptic_plugin_tizen = { + .get_device_count = _get_device_count, + .open_device = _open_device, + .close_device = _close_device, + .vibrate_monotone = _vibrate_monotone, + .vibrate_buffer = _vibrate_buffer, + .stop_device = _stop_device, + .get_device_state = _get_device_state, + .create_effect = _create_effect, + .get_buffer_duration = _get_buffer_duration, + .convert_binary = _convert_binary, }; EXTAPI -const haptic_plugin_interface *get_haptic_plugin_interface() +const struct haptic_plugin_ops *get_haptic_plugin_interface(void) { return &haptic_plugin_tizen; } diff --git a/tizen/SIMULATOR/CMakeLists.txt b/tizen/SIMULATOR/CMakeLists.txt index 91a79a3..35ff3c3 100644 --- a/tizen/SIMULATOR/CMakeLists.txt +++ b/tizen/SIMULATOR/CMakeLists.txt @@ -1,6 +1,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -SET(DEPENDENTS "dlog haptic-plugin") +SET(DEPENDENTS "dlog deviced") SET(SRCS src/haptic.c) diff --git a/tizen/SIMULATOR/src/haptic.c b/tizen/SIMULATOR/src/haptic.c index c81fe2a..4713228 100644 --- a/tizen/SIMULATOR/src/haptic.c +++ b/tizen/SIMULATOR/src/haptic.c @@ -24,7 +24,7 @@ #include <sys/stat.h> #include <fcntl.h> -#include <haptic_plugin_intf.h> +#include <haptic-plugin-intf.h> #include "haptic_module_log.h" #ifndef EXTAPI |