From a72ac9a0546af9803b0afdd9a37caa05a651608f Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Fri, 20 Nov 2015 16:16:54 +0900 Subject: [PATCH] haptic: Add function to vibrate with buffers and device handle. - Add function to vibrate with buffers beside vibrating monotone which is already existed. - Add device_handle. Change-Id: I575ff6710bf3f13b2c34a898d4ec04d11495c6a1 Signed-off-by: pr.jung --- src/haptic/haptic.c | 14 ++- src/haptic/standard.c | 316 ++++++++++++++++++++++++++++++++++++++---------- src/libdeviced/haptic.c | 112 +++++++++-------- 3 files changed, 319 insertions(+), 123 deletions(-) diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c index 9001a1e..83623a8 100644 --- a/src/haptic/haptic.c +++ b/src/haptic/haptic.c @@ -43,7 +43,7 @@ #define HARDKEY_VIB_ITERATION 1 #define HARDKEY_VIB_FEEDBACK 3 #define HARDKEY_VIB_PRIORITY 2 -#define HARDKEY_VIB_DURATION 300 +#define HARDKEY_VIB_DURATION 30 #define HAPTIC_FEEDBACK_STEP 20 #define DEFAULT_FEEDBACK_LEVEL 3 @@ -60,6 +60,7 @@ #endif #define CHECK_VALID_OPS(ops, r) ((ops) ? true : !(r = -ENODEV)) +#define RETRY_CNT 3 struct haptic_info { char *sender; @@ -79,6 +80,7 @@ static bool haptic_disabled; struct haptic_config { int level; int *level_arr; + int sound_capture; }; static struct haptic_config haptic_conf; @@ -689,7 +691,9 @@ static int parse_section(struct parse_result *result, void *user_data, int index if (!result->section || !result->name || !result->value) return 0; - if (MATCH(result->name, "level")) { + if (MATCH(result->name, "sound_capture")) { + conf->sound_capture = atoi(result->value); + } else if (MATCH(result->name, "level")) { conf->level = atoi(result->value); conf->level_arr = calloc(sizeof(int), conf->level); if (!conf->level_arr) { @@ -793,7 +797,8 @@ static void haptic_init(void *data) register_notifier(DEVICE_NOTIFIER_POWEROFF_HAPTIC, haptic_poweroff_cb); /* add watch for sound capturing value */ - vconf_notify_key_changed(VCONFKEY_RECORDER_STATE, sound_capturing_cb, NULL); + if (haptic_conf.sound_capture) + vconf_notify_key_changed(VCONFKEY_RECORDER_STATE, sound_capturing_cb, NULL); } static void haptic_exit(void *data) @@ -803,7 +808,8 @@ static void haptic_exit(void *data) int r; /* remove watch */ - vconf_ignore_key_changed(VCONFKEY_RECORDER_STATE, sound_capturing_cb); + if (haptic_conf.sound_capture) + vconf_ignore_key_changed(VCONFKEY_RECORDER_STATE, sound_capturing_cb); /* unregister notifier for below each event */ unregister_notifier(DEVICE_NOTIFIER_TOUCH_HARDKEY, haptic_hardkey_changed_cb); diff --git a/src/haptic/standard.c b/src/haptic/standard.c index d9435be..4171ba1 100644 --- a/src/haptic/standard.c +++ b/src/haptic/standard.c @@ -46,16 +46,62 @@ #define LONG(x) ((x)/BITS_PER_LONG) #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1) +#define MAX_DATA 16 +#define FF_INFO_MAGIC 0xDEADFEED + +struct ff_info_header { + unsigned int magic; + int iteration; + int ff_info_data_count; +}; + +struct ff_info_data { + int type;/* play, stop etc */ + int magnitude; /* strength */ + int length; /* in ms for stop, play*/ +}; + +struct ff_info_buffer { + struct ff_info_header header; + struct ff_info_data data[MAX_DATA]; +}; struct ff_info { - unsigned int id; + int handle; Ecore_Timer *timer; struct ff_effect effect; + struct ff_info_buffer *ffinfobuffer; + int currentindex; }; static int ff_fd; static dd_list *ff_list; +static dd_list *handle_list; static char ff_path[PATH_MAX]; +static int unique_number; + +struct ff_info *read_from_list(int handle) +{ + struct ff_info *temp; + dd_list *elem; + + DD_LIST_FOREACH(ff_list, elem, temp) { + if (temp->handle == handle) + return temp; + } + return NULL; +} + +/* for debug */ +static void print_list(void) +{ + struct ff_info *temp; + dd_list *elem; + int i = 0; + + DD_LIST_FOREACH(ff_list, elem, temp) + _D("[%d] %x", i++, temp); +} static bool check_valid_handle(struct ff_info *info) { @@ -72,10 +118,25 @@ static bool check_valid_handle(struct ff_info *info) return true; } +static bool check_fd(int *fd) +{ + int ffd; + + if (*fd > 0) + return true; + + ffd = open(ff_path, O_RDWR); + if (!ffd) + return false; + + *fd = ffd; + return true; +} + static int ff_stop(int fd, struct ff_effect *effect); static Eina_Bool timer_cb(void *data) { - struct ff_info *info = (struct ff_info*)data; + struct ff_info *info = (struct ff_info *)data; if (!info) return ECORE_CALLBACK_CANCEL; @@ -136,7 +197,7 @@ static int ff_find_device(void) if (test_bit(FF_RUMBLE, features)) _D("%s type : rumble", ev_path); - if (test_bit(FF_PERIODIC, features)) { + if (test_bit(FF_RUMBLE, features)) { memcpy(ff_path, ev_path, strlen(ev_path)); close(fd); closedir(dir); @@ -155,23 +216,13 @@ static int ff_init_effect(struct ff_effect *effect) if (!effect) return -EINVAL; - /* initialize member variables in effect struct */ - effect->type = FF_PERIODIC; + /*Only rumble supported as of now*/ + effect->type = FF_RUMBLE; + effect->replay.length = 0; + effect->replay.delay = 10; effect->id = -1; - effect->u.periodic.waveform = FF_SQUARE; - effect->u.periodic.period = 0.1*0x100; /* 0.1 second */ - effect->u.periodic.magnitude = 0; /* temporary value */ - effect->u.periodic.offset = 0; - effect->u.periodic.phase = 0; - effect->direction = 0x4000; /* Along X axis */ - effect->u.periodic.envelope.attack_length = 0; - effect->u.periodic.envelope.attack_level = 0; - effect->u.periodic.envelope.fade_length = 0; - effect->u.periodic.envelope.fade_level = 0; - effect->trigger.button = 0; - effect->trigger.interval = 0; - effect->replay.length = 0; /* temporary value */ - effect->replay.delay = 0; + effect->u.rumble.strong_magnitude = 0x100; + effect->u.rumble.weak_magnitude = 0x50; return 0; } @@ -198,21 +249,32 @@ static int ff_set_effect(struct ff_effect *effect, int length, int level) static int ff_play(int fd, struct ff_effect *effect) { struct input_event play; + int ret; - if (fd < 0 || !effect) + if (fd < 0 || !effect) { + if (fd < 0) + _E("fail to check fd"); + else + _E("fail to check effect"); return -EINVAL; + } /* upload an effect */ - if (ioctl(fd, EVIOCSFF, effect) == -1) + if (ioctl(fd, EVIOCSFF, effect) == -1) { + _E("fail to ioctl"); return -errno; + } /* play vibration*/ play.type = EV_FF; play.code = effect->id; play.value = 1; /* 1 : PLAY, 0 : STOP */ - if (write(fd, (const void*)&play, sizeof(play)) == -1) + ret = write(fd, (const void *)&play, sizeof(play)); + if (ret == -1) { + _E("fail to write"); return -errno; + } return 0; } @@ -220,6 +282,7 @@ static int ff_play(int fd, struct ff_effect *effect) static int ff_stop(int fd, struct ff_effect *effect) { struct input_event stop; + int ret; if (fd < 0) return -EINVAL; @@ -228,8 +291,8 @@ static int ff_stop(int fd, struct ff_effect *effect) stop.type = EV_FF; stop.code = effect->id; stop.value = 0; /* 1 : PLAY, 0 : STOP */ - - if (write(fd, (const void*)&stop, sizeof(stop)) == -1) + ret = write(fd, (const void *)&stop, sizeof(stop)); + if (ret == -1) return -errno; /* removing an effect from the device */ @@ -242,29 +305,6 @@ static int ff_stop(int fd, struct ff_effect *effect) return 0; } -static int create_unique_id(void) -{ - static int i = 0; - return i++; /* TODO: overflow */ -} - -static struct ff_info *get_element_from_list(int id) -{ - dd_list *elem; - struct ff_info *info; - - if (id < 0) - return NULL; - - /* find matched element */ - DD_LIST_FOREACH(ff_list, elem, info) { - if (info->id == id) - return info; - } - - return NULL; -} - /* START: Haptic Module APIs */ static int get_device_count(int *count) { @@ -279,6 +319,8 @@ static int open_device(int device_index, int *device_handle) { struct ff_info *info; int n; + bool found = false; + dd_list *elem; if (!device_handle) return -EINVAL; @@ -302,16 +344,26 @@ static int open_device(int device_index, int *device_handle) return -errno; } - /* create unique id */ - info->id = create_unique_id(); - /* initialize ff_effect structure */ ff_init_effect(&info->effect); + if (unique_number == INT_MAX) + unique_number = 0; + + while (found != true) { + ++unique_number; + elem = DD_LIST_FIND(handle_list, unique_number); + if (!elem) + found = true; + } + + info->handle = unique_number; + /* add info to local list */ DD_LIST_APPEND(ff_list, info); + DD_LIST_APPEND(handle_list, info->handle); - *device_handle = info->id; + *device_handle = info->handle; return 0; } @@ -320,10 +372,16 @@ static int close_device(int device_handle) struct ff_info *info; int r, n; - info = get_element_from_list(device_handle); + info = read_from_list(device_handle); if (!info) return -EINVAL; + if (!check_valid_handle(info)) + return -EINVAL; + + if (!check_fd(&ff_fd)) + return -ENODEV; + /* stop vibration */ r = ff_stop(ff_fd, &info->effect); if (r < 0) @@ -331,10 +389,14 @@ static int close_device(int device_handle) /* unregister existing timer */ if (r >= 0 && info->timer) { + _D("device handle %d is closed and timer deleted", device_handle); ecore_timer_del(info->timer); info->timer = NULL; } + DD_LIST_REMOVE(handle_list, info->handle); + + safe_free(info->ffinfobuffer); /* remove info from local list */ DD_LIST_REMOVE(ff_list, info); safe_free(info); @@ -356,15 +418,33 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p struct ff_info *info; int ret; - info = get_element_from_list(device_handle); - if (!info) + info = read_from_list(device_handle); + if (!info) { + _E("fail to check list"); + return -EINVAL; + } + + if (!check_valid_handle(info)) { + _E("fail to check handle"); return -EINVAL; + } + + if (!check_fd(&ff_fd)) + return -ENODEV; /* Zero(0) is the infinitely vibration value */ if (duration == HAPTIC_MODULE_DURATION_UNLIMITED) duration = 0; + /* unregister existing timer */ + if (info->timer) { + ff_stop(ff_fd, &info->effect); + ecore_timer_del(info->timer); + info->timer = NULL; + } + /* set effect as per arguments */ + ff_init_effect(&info->effect); ret = ff_set_effect(&info->effect, duration, feedback); if (ret < 0) { _E("failed to set effect(duration:%d, feedback:%d) : %d", @@ -375,17 +455,11 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p /* play effect as per arguments */ ret = ff_play(ff_fd, &info->effect); if (ret < 0) { - _E("failed to play haptic effect(id:%d) : %d", - info->effect.id, ret); + _E("failed to play haptic effect(fd:%d id:%d) : %d", + ff_fd, info->effect.id, ret); return ret; } - /* unregister existing timer */ - if (info->timer) { - ecore_timer_del(info->timer); - info->timer = NULL; - } - /* register timer */ if (duration) { info->timer = ecore_timer_add(duration/1000.f, timer_cb, info); @@ -393,17 +467,121 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p _E("Failed to add timer callback"); } - _D("effect id : %d", info->effect.id); + _D("device handle %d effect id : %d %dms", device_handle, info->effect.id, duration); if (effect_handle) *effect_handle = info->effect.id; return 0; } +static Eina_Bool _buffer_play(void *cbdata) +{ + struct ff_info *info = (struct ff_info *)cbdata; + struct ff_info_header *header = &info->ffinfobuffer->header; + struct ff_info_data *data = info->ffinfobuffer->data; + int index = info->currentindex; + int play_type = (index < header->ff_info_data_count) ? data[index].type : 0; + int length = (index < header->ff_info_data_count) ? data[index].length : 1; + int ret; + + ff_set_effect(&info->effect, length, 1); + if (play_type != 0) { + _D("Going to play for %d ms", length); + ret = ff_play(ff_fd, &info->effect); + if (ret < 0) + _D("Failed to play the effect %d", ret); + } else { + _D("Going to stop for %d ms", length); + ret = ff_stop(ff_fd, &info->effect); + if (ret < 0) + _D("Failed to stop the effect %d", ret); + } + + if (info->currentindex < header->ff_info_data_count) { + info->currentindex++; + info->timer = ecore_timer_add(length/1000.0f, _buffer_play, info); + } else { + --header->iteration; + if (header->iteration > 0) { + info->currentindex = 0; + info->timer = ecore_timer_add(0.0, _buffer_play, info); + } else + info->timer = NULL; + } + + return ECORE_CALLBACK_CANCEL; +} + +static void print_buffer(const unsigned char *vibe_buffer) +{ + struct ff_info_buffer fb; + int i = 0; + memcpy(&fb.header, vibe_buffer, sizeof(struct ff_info_header)); + memcpy(&fb.data, (unsigned char *)vibe_buffer+sizeof(struct ff_info_header), + sizeof(struct ff_info_data) * fb.header.ff_info_data_count); + _D("\nMagic %x\niteration %d\ncount %d\n", fb.header.magic, + fb.header.iteration, fb.header.ff_info_data_count); + + for (i = 0; i < fb.header.ff_info_data_count; i++) + _D("type %d\nmagn 0x%x\nlen %d\n", fb.data[i].type, + fb.data[i].magnitude, fb.data[i].length); +} + +static int vibrate_custom_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle) +{ + struct ff_info *info; + struct ff_info_header *header; + struct ff_info_data *data; + + info = read_from_list(device_handle); + if (!info) + return -EINVAL; + + if (!check_valid_handle(info)) + return -EINVAL; + + if (!check_fd(&ff_fd)) + return -ENODEV; + + if (!info->ffinfobuffer) + info->ffinfobuffer = (struct ff_info_buffer *)calloc(sizeof(struct ff_info_buffer), 1); + if (!info->ffinfobuffer) + return -ENOMEM; + + header = &info->ffinfobuffer->header; + data = info->ffinfobuffer->data; + + memcpy(header, vibe_buffer, sizeof(struct ff_info_header)); + if (header->ff_info_data_count < 0 || header->ff_info_data_count > MAX_DATA) + return -EINVAL; + + memcpy(data, vibe_buffer+sizeof(struct ff_info_header), sizeof(struct ff_info_data) * header->ff_info_data_count); + + info->currentindex = 0; + if (info->timer) + ecore_timer_del(info->timer); + + if (header->iteration > 0) + _buffer_play(info); + + return 0; +} + static int vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle) { - /* temporary code */ - return vibrate_monotone(device_handle, 300, feedback, priority, effect_handle); + int magic = 0; + + if (!device_handle) + return -EINVAL; + + if (vibe_buffer) + magic = *(int *)vibe_buffer; + + if (magic == FF_INFO_MAGIC) { + print_buffer(vibe_buffer); + return vibrate_custom_buffer(device_handle, vibe_buffer, iteration, feedback, priority, effect_handle); + } else + return vibrate_monotone(device_handle, 300, feedback, priority, effect_handle); } static int stop_device(int device_handle) @@ -411,10 +589,16 @@ static int stop_device(int device_handle) struct ff_info *info; int r; - info = get_element_from_list(device_handle); + info = read_from_list(device_handle); if (!info) return -EINVAL; + if (!check_valid_handle(info)) + return -EINVAL; + + if (!check_fd(&ff_fd)) + return -ENODEV; + /* stop effect */ r = ff_stop(ff_fd, &info->effect); if (r < 0) diff --git a/src/libdeviced/haptic.c b/src/libdeviced/haptic.c index 81c62e4..528b5d1 100644 --- a/src/libdeviced/haptic.c +++ b/src/libdeviced/haptic.c @@ -48,7 +48,7 @@ #define TEMP_BUFFER_SIZE (64*1024) /* START of Static Function Section */ -static unsigned char* convert_file_to_buffer(const char *file_name, int *size) +static unsigned char *convert_file_to_buffer(const char *file_name, int *size) { FILE *pf; long file_size; @@ -74,7 +74,7 @@ static unsigned char* convert_file_to_buffer(const char *file_name, int *size) if (file_size < 0) goto error; - pdata = (unsigned char*)malloc(file_size); + pdata = (unsigned char *)malloc(file_size); if (!pdata) goto error; @@ -141,12 +141,18 @@ static haptic_feedback_e convert_setting_to_module_level(void) return -1; switch (setting_fb_level) { - case SETTING_VIB_FEEDBACK_LEVEL0 : return HAPTIC_FEEDBACK_0; - case SETTING_VIB_FEEDBACK_LEVEL1 : return HAPTIC_FEEDBACK_1; - case SETTING_VIB_FEEDBACK_LEVEL2 : return HAPTIC_FEEDBACK_2; - case SETTING_VIB_FEEDBACK_LEVEL3 : return HAPTIC_FEEDBACK_3; - case SETTING_VIB_FEEDBACK_LEVEL4 : return HAPTIC_FEEDBACK_4; - case SETTING_VIB_FEEDBACK_LEVEL5 : return HAPTIC_FEEDBACK_5; + case SETTING_VIB_FEEDBACK_LEVEL0: + return HAPTIC_FEEDBACK_0; + case SETTING_VIB_FEEDBACK_LEVEL1: + return HAPTIC_FEEDBACK_1; + case SETTING_VIB_FEEDBACK_LEVEL2: + return HAPTIC_FEEDBACK_2; + case SETTING_VIB_FEEDBACK_LEVEL3: + return HAPTIC_FEEDBACK_3; + case SETTING_VIB_FEEDBACK_LEVEL4: + return HAPTIC_FEEDBACK_4; + case SETTING_VIB_FEEDBACK_LEVEL5: + return HAPTIC_FEEDBACK_5; default: break; } @@ -215,8 +221,8 @@ API int haptic_close(haptic_device_h device_handle) int ret; /* check if handle is valid */ - if (device_handle < 0) { - _E("Invalid parameter : device_handle(0)"); + if (device_handle == NULL) { + _E("Invalid parameter : device_handle"); return HAPTIC_ERROR_INVALID_PARAMETER; } @@ -243,10 +249,10 @@ API int haptic_vibrate_monotone(haptic_device_h device_handle, int duration, hap } API int haptic_vibrate_monotone_with_detail(haptic_device_h device_handle, - int duration, - haptic_feedback_e feedback, - haptic_priority_e priority, - haptic_effect_h *effect_handle) + int duration, + haptic_feedback_e feedback, + haptic_priority_e priority, + haptic_effect_h *effect_handle) { char str_handle[32]; char str_duration[32]; @@ -256,8 +262,8 @@ API int haptic_vibrate_monotone_with_detail(haptic_device_h device_handle, int ret; /* check if handle is valid */ - if (device_handle < 0) { - _E("Invalid parameter : device_handle(0)"); + if (device_handle == NULL) { + _E("Invalid parameter : device_handle"); return HAPTIC_ERROR_INVALID_PARAMETER; } @@ -297,7 +303,7 @@ API int haptic_vibrate_monotone_with_detail(haptic_device_h device_handle, if (ret < 0) return HAPTIC_ERROR_OPERATION_FAILED; - if (effect_handle) + if (effect_handle != NULL) *effect_handle = (haptic_effect_h)ret; return HAPTIC_ERROR_NONE; @@ -326,11 +332,11 @@ API int haptic_vibrate_file(haptic_device_h device_handle, const char *file_path } API int haptic_vibrate_file_with_detail(haptic_device_h device_handle, - const char *file_path, - haptic_iteration_e iteration, - haptic_feedback_e feedback, - haptic_priority_e priority, - haptic_effect_h *effect_handle) + const char *file_path, + haptic_iteration_e iteration, + haptic_feedback_e feedback, + haptic_priority_e priority, + haptic_effect_h *effect_handle) { char *vibe_buffer; int size, ret; @@ -364,11 +370,11 @@ API int haptic_vibrate_buffer(haptic_device_h device_handle, const unsigned char } API int haptic_vibrate_buffer_with_detail(haptic_device_h device_handle, - const unsigned char *vibe_buffer, - haptic_iteration_e iteration, - haptic_feedback_e feedback, - haptic_priority_e priority, - haptic_effect_h *effect_handle) + const unsigned char *vibe_buffer, + haptic_iteration_e iteration, + haptic_feedback_e feedback, + haptic_priority_e priority, + haptic_effect_h *effect_handle) { return haptic_vibrate_buffers_with_detail(device_handle, vibe_buffer, @@ -394,12 +400,12 @@ API int haptic_vibrate_buffers(haptic_device_h device_handle, } API int haptic_vibrate_buffers_with_detail(haptic_device_h device_handle, - const unsigned char *vibe_buffer, - int size, - haptic_iteration_e iteration, - haptic_feedback_e feedback, - haptic_priority_e priority, - haptic_effect_h *effect_handle) + const unsigned char *vibe_buffer, + int size, + haptic_iteration_e iteration, + haptic_feedback_e feedback, + haptic_priority_e priority, + haptic_effect_h *effect_handle) { char str_handle[32]; char str_iteration[32]; @@ -410,8 +416,8 @@ API int haptic_vibrate_buffers_with_detail(haptic_device_h device_handle, int ret; /* check if handle is valid */ - if (device_handle < 0) { - _E("Invalid parameter : device_handle(0)"); + if (device_handle == NULL) { + _E("Invalid parameter : device_handle"); return HAPTIC_ERROR_INVALID_PARAMETER; } @@ -444,7 +450,7 @@ API int haptic_vibrate_buffers_with_detail(haptic_device_h device_handle, arr[0] = str_handle; bytes.size = size; bytes.data = vibe_buffer; - arr[2] = (char*)&bytes; + arr[2] = (char *)&bytes; snprintf(str_iteration, sizeof(str_iteration), "%d", iteration); arr[3] = str_iteration; snprintf(str_feedback, sizeof(str_feedback), "%d", feedback); @@ -459,7 +465,7 @@ API int haptic_vibrate_buffers_with_detail(haptic_device_h device_handle, if (ret < 0) return HAPTIC_ERROR_OPERATION_FAILED; - if (effect_handle >= 0) + if (effect_handle != NULL) *effect_handle = (haptic_effect_h)ret; return HAPTIC_ERROR_NONE; @@ -477,8 +483,8 @@ API int haptic_stop_all_effects(haptic_device_h device_handle) int ret; /* check if handle is valid */ - if (device_handle < 0) { - _E("Invalid parameter : device_handle(0)"); + if (device_handle == NULL) { + _E("Invalid parameter : device_handle"); return HAPTIC_ERROR_INVALID_PARAMETER; } @@ -502,8 +508,8 @@ API int haptic_get_effect_state(haptic_device_h device_handle, haptic_effect_h e int ret; /* check if handle is valid */ - if (device_handle < 0) { - _E("Invalid parameter : device_handle(0)"); + if (device_handle == NULL) { + _E("Invalid parameter : device_handle"); return HAPTIC_ERROR_INVALID_PARAMETER; } @@ -528,9 +534,9 @@ API int haptic_get_effect_state(haptic_device_h device_handle, haptic_effect_h e } API int haptic_create_effect(unsigned char *vibe_buffer, - int max_bufsize, - haptic_effect_element_s *elem_arr, - int max_elemcnt) + int max_bufsize, + haptic_effect_element_s *elem_arr, + int max_elemcnt) { DBusError err; DBusMessage *msg; @@ -574,8 +580,8 @@ API int haptic_create_effect(unsigned char *vibe_buffer, snprintf(str_bufsize, sizeof(str_bufsize), "%d", max_bufsize); arr[0] = str_bufsize; bytes.size = sizeof(haptic_effect_element_s)*max_elemcnt; - bytes.data = (unsigned char*)elem_arr; - arr[2] = (char*)&bytes; + bytes.data = (unsigned char *)elem_arr; + arr[2] = (char *)&bytes; snprintf(str_elemcnt, sizeof(str_elemcnt), "%d", max_elemcnt); arr[3] = str_elemcnt; @@ -615,8 +621,8 @@ err: } API int haptic_save_effect(const unsigned char *vibe_buffer, - int max_bufsize, - const char *file_path) + int max_bufsize, + const char *file_path) { struct stat buf; int size, ret; @@ -688,8 +694,8 @@ API int haptic_get_buffers_duration(haptic_device_h device_handle, const unsigne int ret; /* check if handle is valid */ - if (device_handle < 0) { - _E("Invalid parameter : device_handle(0)"); + if (device_handle == NULL) { + _E("Invalid parameter : device_handle"); return HAPTIC_ERROR_INVALID_PARAMETER; } @@ -708,7 +714,7 @@ API int haptic_get_buffers_duration(haptic_device_h device_handle, const unsigne arr[0] = str_handle; bytes.size = size; bytes.data = vibe_buffer; - arr[2] = (char*)&bytes; + arr[2] = (char *)&bytes; /* request to deviced to open haptic device */ ret = dbus_method_sync(DEVICED_BUS_NAME, @@ -753,8 +759,8 @@ API int haptic_save_led(const unsigned char *vibe_buffer, int max_bufsize, const bytes.size = max_bufsize; bytes.data = vibe_buffer; - arr[1] = (char*)&bytes; - arr[2] = (char*)file_path; + arr[1] = (char *)&bytes; + arr[2] = (char *)file_path; /* request to deviced to open haptic device */ ret = dbus_method_sync(DEVICED_BUS_NAME, -- 2.7.4