bool found;
found = find_from_list(device_handle);
- if (!found)
+ if (!found) {
+ _E("Handle %d fail to check info", device_handle);
return -EINVAL;
+ }
if (fd_stop < 0) {
fd_stop = open(CIRCLE_OFF_PATH, O_RDONLY);
- if (fd_stop < 0)
+ if (fd_stop < 0) {
+ _E("Handle %d fail to check fd", device_handle);
return -ENODEV;
+ }
}
/* stop vibration */
r = stop_device(device_handle);
if (r < 0)
- _I("already stopped or failed to stop effect : %d", r);
+ _I("Handle %d already stopped or failed to stop effect : %d", device_handle, r);
DD_LIST_REMOVE(handle_list, (gpointer)(long)device_handle);
bool found;
found = find_from_list(device_handle);
- if (!found)
+ if (!found) {
+ _E("Handle %d fail to check list", device_handle);
return -EINVAL;
+ }
if (fd_play < 0) {
fd_play = open(CIRCLE_ON_PATH, O_RDONLY);
- if (fd_play < 0)
+ if (fd_play < 0) {
+ _E("Handle %d fail to check handle", device_handle);
return -ENODEV;
+ }
+ }
+
+ if (duration <= 0) {
+ _E("handle %d skip requested with 0", device_handle);
+ return -EINVAL;
}
/* Zero(0) is the infinitely vibration value */
/* play vibration */
ret = read(fd_play, buf, BUF_SIZE);
if (ret < 0) {
- _E("failed to play");
+ _E("Handle %d failed to play", device_handle);
return -errno;
}
bool found;
found = find_from_list(device_handle);
- if (!found)
+ if (!found) {
+ _E("Handle %d fail to check info", device_handle);
return -EINVAL;
+ }
if (cur_h_data.handle > 0 && cur_h_data.handle != device_handle) {
_E("Only same handle can stop current vibration");
if (fd_stop < 0) {
fd_stop = open(CIRCLE_OFF_PATH, O_RDONLY);
- if (fd_stop < 0)
+ if (fd_stop < 0) {
+ _E("Handle %d fail to check fd", device_handle);
return -ENODEV;
+ }
}
ret = read(fd_stop, buf, BUF_SIZE);
if (ret < 0) {
- _E("failed to stop");
+ _E("Failed to stop");
return -errno;
}
if (stop_timer) {
.get_device_count = get_device_count,
.open_device = open_device,
.close_device = close_device,
- .vibrate_monotone = vibrate_monotone,
+ .vibrate_monotone = standard_vibrate_monotone,
.vibrate_effect = standard_vibrate_effect,
.is_supported = standard_is_supported,
.stop_device = stop_device,
.get_device_count = gpio_haptic_get_device_count,
.open_device = gpio_haptic_open_device,
.close_device = gpio_haptic_close_device,
- .vibrate_monotone = gpio_haptic_vibrate_monotone,
+ .vibrate_monotone = standard_vibrate_monotone,
.vibrate_effect = standard_vibrate_effect,
.is_supported = standard_is_supported,
.stop_device = gpio_haptic_stop_device,
static void vibrate_monotone_idler_cb(void *data)
{
- struct vibrate_monotone_info *vibrate_info = (struct vibrate_monotone_info *)data;
- int ret;
+ struct vibrate_monotone_info *vibrate_info;
+
+ if (!data)
+ return;
+
+ vibrate_info = (struct vibrate_monotone_info *)data;
- ret = device_power_request_lock(POWER_LOCK_CPU, vibrate_info->duration);
- if (ret != DEVICE_ERROR_NONE)
- _E("Failed to request power lock");
h_ops->vibrate_monotone(vibrate_info->handle, vibrate_info->duration,
vibrate_info->level, vibrate_info->priority);
free(vibrate_info);
static void vibrate_effect_idler_cb(void *data)
{
- struct vibrate_effect_info *vibrate_info = (struct vibrate_effect_info *)data;
+ struct vibrate_effect_info *vibrate_info;
+
+ if (!data)
+ return;
+
+ vibrate_info = (struct vibrate_effect_info *)data;
h_ops->vibrate_effect(vibrate_info->handle, vibrate_info->pattern,
vibrate_info->level, vibrate_info->priority);
g_variant_get(param, "(u)", &handle);
+ if (cur_h_data.handle != handle) {
+ _D("Not the request from current vibration handle :%d. Skip", handle);
+ goto exit;
+ }
+
ret = h_ops->stop_device(handle);
exit:
return 0;
}
+int standard_vibrate_monotone(int device_handle, int duration, int feedback, int priority)
+{
+ int ret;
+
+ if (priority < cur_h_data.priority) {
+ _I("Handle %d skip low priority(pre:%d now:%d)", device_handle, cur_h_data.priority, priority);
+ return 0;
+ }
+
+ cur_h_data.vibration_data = NULL;
+ cur_h_data.handle = device_handle;
+ cur_h_data.level = feedback;
+ cur_h_data.priority = priority;
+ cur_h_data.stop = false;
+ cur_h_data.unlimit = false;
+
+ ret = device_power_request_lock(POWER_LOCK_CPU, duration);
+ if (ret != DEVICE_ERROR_NONE)
+ _E("Failed to request power lock");
+ real_vibrate_monotone(cur_h_data.handle, duration, cur_h_data.level, cur_h_data.priority);
+
+ return 0;
+}
+
int standard_vibrate_effect(int device_handle, const char *requested_pattern, int feedback, int priority)
{
dd_list *elem;
/* Same or higher priority pattern should be played */
if (priority < cur_h_data.priority) {
- _E("Priority of new request is lower than old request");
- return -EPERM;
+ _I("Handle %d skip low priority(pre:%d now:%d)", device_handle, cur_h_data.priority, priority);
+ return 0;
}
snprintf(pattern, sizeof(pattern), "%s", requested_pattern);
void standard_config_parse(void);
int standard_is_supported(const char *pattern);
+int standard_vibrate_monotone(int device_handle, int duration, int feedback, int priority);
int standard_vibrate_effect(int device_handle, const char *pattern, int feedback, int priority);
int standard_set_vib_function(t_vibrate_monotone func);
int standard_vibrate_close(void);
return true;
}
-static int ff_stop(const char *func, int fd, struct ff_effect *effect);
+static int ff_stop(int fd, struct ff_effect *effect);
static gboolean timer_cb(void *data)
{
struct ff_info *info = (struct ff_info *)data;
_I("stop vibration by timer : id(%d)", info->effect.id);
/* stop previous vibration */
- ff_stop(__func__, ff_fd, &info->effect);
+ ff_stop(ff_fd, &info->effect);
/* reset timer */
info->timer = 0;
effect->replay.length = 0;
effect->replay.delay = 10;
effect->id = -1;
- effect->u.rumble.strong_magnitude = 0x8000;
- effect->u.rumble.weak_magnitude = 0xc000;
+ effect->u.rumble.strong_magnitude = 0;
return 0;
}
{
double magnitude;
- if (!effect)
+ if (!effect) {
+ _E("There is no valid effect");
return -EINVAL;
+ }
magnitude = (double)level/HAPTIC_MODULE_FEEDBACK_MAX;
magnitude *= RUMBLE_MAX_MAGNITUDE;
return 0;
}
-static int ff_play(const char *func, int fd, struct ff_effect *effect)
+static int ff_play(int fd, struct ff_effect *effect)
{
struct input_event play;
int ret;
if (fd < 0 || !effect) {
- if (fd < 0)
- _E("%s: failed to check fd", func);
- else
- _E("%s: failed to check effect", func);
+ _E("Fd(%d) or effect(%s) is invalid", fd, effect ? "not null" : "null");
return -EINVAL;
}
/* upload an effect */
if (ioctl(fd, EVIOCSFF, effect) == -1) {
- _E("%s: failed to ioctl", func);
+ _E("Failed to ioctl");
return -errno;
}
ret = write(fd, (const void *)&play, sizeof(play));
if (ret == -1) {
- _E("%s: failed to write", func);
+ _E("Failed to write");
return -errno;
}
return 0;
}
-static int ff_stop(const char *func, int fd, struct ff_effect *effect)
+static int ff_stop(int fd, struct ff_effect *effect)
{
struct input_event stop;
int ret;
struct ff_info *info;
int ret;
- if (priority < cur_h_data.priority) {
- _I("Handle %d skip low priority(pre:%d now:%d)", device_handle, cur_h_data.priority, priority);
- return 0;
- }
-
info = read_from_list(device_handle);
if (!info) {
_E("Handle %d failed to check list", device_handle);
/* unregister existing timer */
if (info->timer) {
- ff_stop(__func__, ff_fd, &info->effect);
+ ff_stop(ff_fd, &info->effect);
g_source_remove(info->timer);
info->timer = 0;
}
}
/* play effect as per arguments */
- ret = ff_play(__func__, ff_fd, &info->effect);
+ ret = ff_play(ff_fd, &info->effect);
if (ret < 0) {
_E("Handle %d fail to play haptic effect(fd:%d id:%d) : %d",
device_handle, ff_fd, info->effect.id, ret);
standard_vibrate_close();
/* stop effect */
- r = ff_stop(__func__, ff_fd, &info->effect);
+ r = ff_stop(ff_fd, &info->effect);
if (r < 0)
_E("failed to stop effect(id:%d) : %d", info->effect.id, r);
else
.get_device_count = get_device_count,
.open_device = open_device,
.close_device = close_device,
- .vibrate_monotone = vibrate_monotone,
+ .vibrate_monotone = standard_vibrate_monotone,
.vibrate_effect = standard_vibrate_effect,
.is_supported = standard_is_supported,
.stop_device = stop_device,