summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/haptic/CMakeLists.txt4
-rw-r--r--src/haptic/circle.c239
-rw-r--r--src/haptic/standard-vibcore.c257
-rw-r--r--src/haptic/standard-vibcore.h7
-rw-r--r--src/haptic/standard.c238
5 files changed, 283 insertions, 462 deletions
diff --git a/src/haptic/CMakeLists.txt b/src/haptic/CMakeLists.txt
index e0eabe0f..537c938a 100755
--- a/src/haptic/CMakeLists.txt
+++ b/src/haptic/CMakeLists.txt
@@ -44,12 +44,12 @@ SET(SRCS
${CMAKE_SOURCE_DIR}/src/shared/dbus.c
)
IF(CIRCLE STREQUAL on)
- SET(SRCS ${SRCS} circle.c)
+ SET(SRCS ${SRCS} circle.c standard-vibcore.c)
ELSE()
IF(STANDARD_MIX STREQUAL on)
SET(SRCS ${SRCS} standard-mix.c)
ELSE()
- SET(SRCS ${SRCS} standard.c)
+ SET(SRCS ${SRCS} standard.c standard-vibcore.c)
ENDIF()
ENDIF()
diff --git a/src/haptic/circle.c b/src/haptic/circle.c
index 298a46e6..b9b2aa0b 100644
--- a/src/haptic/circle.c
+++ b/src/haptic/circle.c
@@ -29,36 +29,14 @@
#include "core/log.h"
#include "core/list.h"
-#include "core/config-parser.h"
#include "haptic.h"
+#include "standard-vibcore.h"
-#define VIBRATION_CONF_PATH "/usr/share/feedback/vibration.conf"
#define CIRCLE_ON_PATH "/sys/class/sec/motor/motor_on"
#define CIRCLE_OFF_PATH "/sys/class/sec/motor/motor_off"
-
-struct vibration_config {
- char *pattern;
- dd_list *data;
-};
-
-struct duration_data {
- int duration;
- int wait;
-};
-
-struct haptic_data {
- dd_list *vibration_data;
- unsigned int handle;
- int level;
- int priority;
- bool stop;
-};
-
static int fd_play = -1, fd_stop = -1;
static dd_list *handle_list;
-static dd_list *vib_conf_list;
-static Ecore_Timer *duration_timer;
static Ecore_Timer *stop_timer;
static int unique_number;
static bool state = false;
@@ -168,12 +146,10 @@ static int close_device(int device_handle)
ecore_timer_del(stop_timer);
stop_timer = NULL;
}
- if (duration_timer) {
- ecore_timer_del(duration_timer);
- duration_timer = NULL;
- }
}
+ standard_vibrate_close();
+
DD_LIST_REMOVE(handle_list, (gpointer)(long)device_handle);
/* if it is the last element */
@@ -235,120 +211,12 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p
return 0;
}
-static Eina_Bool haptic_duration_play(void *data)
-{
- dd_list *head, *n, *next;
- struct haptic_data *h_data;
- struct duration_data *node;
- int ret = 0;
-
- if (!data)
- goto out;
-
- if (duration_timer) {
- ecore_timer_del(duration_timer);
- duration_timer = NULL;
- }
-
- h_data = (struct haptic_data *)data;
- if (h_data->stop) {
- h_data->stop = false;
- free(h_data);
- goto out;
- }
-
- head = h_data->vibration_data;
- DD_LIST_FOREACH_SAFE(head, n, next, node) {
- _D("Play: %dms and Wait: %dms", node->duration, node->wait);
- if (!node->duration) {
- free(h_data);
- break;
- }
-
- if (node->wait && next) {
- h_data->vibration_data = next;
- duration_timer = ecore_timer_add((node->duration + node->wait)/1000.0f, haptic_duration_play, (void *)h_data);
- }
-
- ret = vibrate_monotone(h_data->handle, node->duration, 0, 0, NULL);
- if (!next) {
- free(h_data);
- goto out;
- }
- break;
- }
- if (ret != 0) {
- _D("auto stop vibration");
- if (h_data)
- h_data->stop = true;
- }
-out:
- return ECORE_CALLBACK_CANCEL;
-}
-
static int vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle)
{
_E("Not support feature");
return -EACCES;
}
-static int vibrate_effect(int device_handle, const char *pattern, int feedback, int priority)
-{
- dd_list *elem;
- struct vibration_config *conf;
- struct haptic_data *data;
- size_t len;
-
- if (device_handle < 0)
- return -EINVAL;
-
- len = strlen(pattern) + 1;
- DD_LIST_FOREACH(vib_conf_list, elem, conf) {
- if (!conf->pattern)
- continue;
- if (strncmp(conf->pattern, pattern, len))
- continue;
-
- data = (struct haptic_data *)malloc(sizeof(struct haptic_data));
- if (!data) {
- _E("fail to alloc");
- return -ENOMEM;
- }
- data->vibration_data = conf->data;
- data->handle = device_handle;
- data->stop = false;
- _D("Play %s", conf->pattern);
- haptic_duration_play((void *)data);
- break;
- }
-
- return 0;
-}
-
-static int is_supported(const char *pattern)
-{
- dd_list *elem;
- struct vibration_config *conf;
- size_t len;
- int ret;
-
- if (!pattern)
- return -EINVAL;
-
- len = strlen(pattern) + 1;
- ret = 0;
- DD_LIST_FOREACH(vib_conf_list, elem, conf) {
- if (!conf->pattern)
- continue;
- if (!strncmp(conf->pattern, pattern, len)) {
- ret = true;
- break;
- }
- }
-
- return ret;
-}
-
static int stop_device(int device_handle)
{
int ret;
@@ -411,8 +279,8 @@ static const struct haptic_plugin_ops default_plugin = {
.close_device = close_device,
.vibrate_monotone = vibrate_monotone,
.vibrate_buffer = vibrate_buffer,
- .vibrate_effect = vibrate_effect,
- .is_supported = is_supported,
+ .vibrate_effect = standard_vibrate_effect,
+ .is_supported = standard_is_supported,
.stop_device = stop_device,
.get_device_state = get_device_state,
.create_effect = create_effect,
@@ -420,98 +288,6 @@ static const struct haptic_plugin_ops default_plugin = {
.convert_binary = convert_binary,
};
-static int vibration_load_config(struct parse_result *result, void *user_data)
-{
- struct vibration_config *conf;
- struct duration_data *data;
- char *value;
- char *check;
- int len;
-
- if (!result)
- return 0;
-
- if (!MATCH(result->section, "Vibration"))
- return 0;
-
-
- if (!result->name || !result->value)
- return 0;
-
- conf = (struct vibration_config *)calloc(1, sizeof(struct vibration_config));
- if (!conf) {
- _E("fail to alloc");
- return -ENOMEM;
- }
-
- conf->pattern = strdup(result->name);
- if (!conf->pattern)
- _E("fail to copy %s pattern data", result->name);
-
- value = result->value;
-
- if (!value)
- len = 0;
- else
- len = strlen(value);
-
- if (len == 0) {
- data = (struct duration_data *)malloc(sizeof(struct duration_data));
- if (!data) {
- _E("not enough memory");
- free(conf->pattern);
- free(conf);
- return -ENOMEM;
- }
- data->duration = 0;
- data->wait = 0;
-
- DD_LIST_APPEND(conf->data, data);
- DD_LIST_APPEND(vib_conf_list, conf);
- return 0;
- }
-
- do {
- data = (struct duration_data *)malloc(sizeof(struct duration_data));
- if (!data) {
- _E("not enough memory");
- free(conf->pattern);
- free(conf);
- return -ENOMEM;
- }
- data->duration = 0;
- data->wait = 0;
-
- check = strchr(value, 'D');
- if (check) {
- *check = '\0';
- data->duration = strtol(value, NULL, 10);
- if (!value)
- len = len - 1;
- else
- len = len - strlen(value) - 1;
- value = check + 1;
- }
- check = strchr(value, 'W');
- if (check) {
- *check = '\0';
- data->wait = strtol(value, NULL, 10);
- if (!value)
- len = len - 1;
- else
- len = len - strlen(value) - 1;
- value = check + 1;
- }
- DD_LIST_APPEND(conf->data, data);
- if (data->duration == 0 && data->wait == 0)
- break;
- } while (value && len > 0);
-
- DD_LIST_APPEND(vib_conf_list, conf);
-
- return 0;
-}
-
static bool is_valid(void)
{
int ret;
@@ -523,9 +299,9 @@ static bool is_valid(void)
return false;
}
- ret = config_parse(VIBRATION_CONF_PATH, vibration_load_config, NULL);
+ ret = standard_config_parse();
if (ret < 0)
- _E("failed to load configuration file(%s) : %d", VIBRATION_CONF_PATH, ret);
+ _E("failed to load standard vibration configuration file : %d", ret);
state = true;
_I("Support wearable haptic device");
@@ -534,6 +310,7 @@ static bool is_valid(void)
static const struct haptic_plugin_ops *load(void)
{
+ standard_set_vib_function(&vibrate_monotone);
return &default_plugin;
}
diff --git a/src/haptic/standard-vibcore.c b/src/haptic/standard-vibcore.c
new file mode 100644
index 00000000..3cd85fee
--- /dev/null
+++ b/src/haptic/standard-vibcore.c
@@ -0,0 +1,257 @@
+#include <stdlib.h>
+#include <stdbool.h>
+#include <Ecore.h>
+
+#include "core/log.h"
+#include "core/list.h"
+#include "core/config-parser.h"
+#include "standard-vibcore.h"
+
+#define VIBRATION_CONF_PATH "/usr/share/feedback/vibration.conf"
+
+struct vibration_config {
+ char *pattern;
+ dd_list *data;
+};
+
+struct duration_data {
+ int duration;
+ int wait;
+};
+
+struct haptic_data {
+ dd_list *vibration_data;
+ unsigned int handle;
+ int level;
+ int priority;
+ bool stop;
+};
+
+static dd_list *vib_conf_list;
+static Ecore_Timer *duration_timer;
+
+static t_vibrate_monotone real_vibrate_monotone;
+
+static int vibration_load_config(struct parse_result *result, void *user_data)
+{
+ struct vibration_config *conf;
+ struct duration_data *data;
+ char *value;
+ char *check;
+ int len;
+
+ if (!result)
+ return 0;
+
+ if (!MATCH(result->section, "Vibration"))
+ return 0;
+
+
+ if (!result->name || !result->value)
+ return 0;
+
+ conf = (struct vibration_config *)calloc(1, sizeof(struct vibration_config));
+ if (!conf) {
+ _E("fail to alloc");
+ return -ENOMEM;
+ }
+
+ conf->pattern = strdup(result->name);
+ if (!conf->pattern)
+ _E("fail to copy %s pattern data", result->name);
+
+ value = result->value;
+
+ if (!value)
+ len = 0;
+ else
+ len = strlen(value);
+
+ if (len == 0) {
+ data = (struct duration_data *)malloc(sizeof(struct duration_data));
+ if (!data) {
+ _E("not enough memory");
+ free(conf->pattern);
+ free(conf);
+ return -ENOMEM;
+ }
+ data->duration = 0;
+ data->wait = 0;
+
+ DD_LIST_APPEND(conf->data, data);
+ DD_LIST_APPEND(vib_conf_list, conf);
+ return 0;
+ }
+
+ do {
+ data = (struct duration_data *)malloc(sizeof(struct duration_data));
+ if (!data) {
+ _E("not enough memory");
+ free(conf->pattern);
+ free(conf);
+ return -ENOMEM;
+ }
+ data->duration = 0;
+ data->wait = 0;
+
+ check = strchr(value, 'D');
+ if (check) {
+ *check = '\0';
+ data->duration = strtol(value, NULL, 10);
+ if (!value)
+ len = len - 1;
+ else
+ len = len - strlen(value) - 1;
+ value = check + 1;
+ }
+ check = strchr(value, 'W');
+ if (check) {
+ *check = '\0';
+ data->wait = strtol(value, NULL, 10);
+ if (!value)
+ len = len - 1;
+ else
+ len = len - strlen(value) - 1;
+ value = check + 1;
+ }
+ DD_LIST_APPEND(conf->data, data);
+ if (data->duration == 0 && data->wait == 0)
+ break;
+ } while (value && len > 0);
+
+ DD_LIST_APPEND(vib_conf_list, conf);
+
+ return 0;
+}
+
+int standard_config_parse()
+{
+ return config_parse(VIBRATION_CONF_PATH, vibration_load_config, NULL);
+}
+
+int standard_is_supported(const char *pattern)
+{
+ dd_list *elem;
+ struct vibration_config *conf;
+ size_t len;
+ int ret;
+
+ if (!pattern)
+ return -EINVAL;
+
+ len = strlen(pattern) + 1;
+ ret = 0;
+ DD_LIST_FOREACH(vib_conf_list, elem, conf) {
+ if (!conf->pattern)
+ continue;
+ if (!strncmp(conf->pattern, pattern, len)) {
+ ret = true;
+ break;
+ }
+ }
+
+ return ret;
+}
+
+static Eina_Bool haptic_duration_play(void *data)
+{
+ dd_list *head, *n, *next;
+ struct haptic_data *h_data;
+ struct duration_data *node;
+ int ret = 0;
+
+ if (!data)
+ goto out;
+
+ if (duration_timer) {
+ ecore_timer_del(duration_timer);
+ duration_timer = NULL;
+ }
+
+ h_data = (struct haptic_data *)data;
+ if (h_data->stop) {
+ h_data->stop = false;
+ free(h_data);
+ goto out;
+ }
+
+ head = h_data->vibration_data;
+ DD_LIST_FOREACH_SAFE(head, n, next, node) {
+ _D("Play: %dms and Wait: %dms", node->duration, node->wait);
+ if (!node->duration) {
+ free(h_data);
+ break;
+ }
+
+ if (node->wait && next) {
+ h_data->vibration_data = next;
+ duration_timer = ecore_timer_add((node->duration + node->wait)/1000.0f, haptic_duration_play, (void *)h_data);
+ }
+
+ ret = real_vibrate_monotone(h_data->handle, node->duration, h_data->level, h_data->priority, NULL);
+ if (!next) {
+ free(h_data);
+ goto out;
+ }
+ break;
+ }
+ if (ret != 0) {
+ _D("auto stop vibration");
+ if (h_data)
+ h_data->stop = true;
+ }
+out:
+ return ECORE_CALLBACK_CANCEL;
+}
+
+int standard_set_vib_function(t_vibrate_monotone func)
+{
+ real_vibrate_monotone = func;
+ return 0;
+}
+
+int standard_vibrate_effect(int device_handle, const char *pattern, int feedback, int priority)
+{
+ dd_list *elem;
+ struct vibration_config *conf;
+ struct haptic_data *data;
+ size_t len;
+
+ if (device_handle < 0)
+ return -EINVAL;
+
+ len = strlen(pattern) + 1;
+ DD_LIST_FOREACH(vib_conf_list, elem, conf) {
+ if (!conf->pattern)
+ continue;
+ if (strncmp(conf->pattern, pattern, len))
+ continue;
+
+ data = (struct haptic_data *)malloc(sizeof(struct haptic_data));
+ if (!data) {
+ _E("fail to alloc");
+ return -ENOMEM;
+ }
+ data->vibration_data = conf->data;
+ data->handle = device_handle;
+ data->level = feedback;
+ data->priority = priority;
+ data->stop = false;
+ _D("Play %s", conf->pattern);
+ haptic_duration_play((void *)data);
+ break;
+ }
+
+ return 0;
+}
+
+int standard_vibrate_close()
+{
+ if (duration_timer) {
+ ecore_timer_del(duration_timer);
+ duration_timer = NULL;
+ }
+
+ return 0;
+}
+
diff --git a/src/haptic/standard-vibcore.h b/src/haptic/standard-vibcore.h
new file mode 100644
index 00000000..ea54e14a
--- /dev/null
+++ b/src/haptic/standard-vibcore.h
@@ -0,0 +1,7 @@
+typedef int (*t_vibrate_monotone)(int device_handle, int duration, int feedback, int priority, int *effect_handle);
+
+int standard_config_parse();
+int standard_is_supported(const char *pattern);
+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();
diff --git a/src/haptic/standard.c b/src/haptic/standard.c
index 3ae2a972..0558e635 100644
--- a/src/haptic/standard.c
+++ b/src/haptic/standard.c
@@ -32,8 +32,8 @@
#include "core/log.h"
#include "core/list.h"
-#include "core/config-parser.h"
#include "haptic.h"
+#include "standard-vibcore.h"
#define MAX_MAGNITUDE 0xFFFF
#define PERIODIC_MAX_MAGNITUDE 0x7FFF /* 0.5 * MAX_MAGNITUDE */
@@ -51,8 +51,6 @@
#define MAX_DATA 16
#define FF_INFO_MAGIC 0xDEADFEED
-#define VIBRATION_CONF_PATH "/usr/share/feedback/vibration.conf"
-
struct ff_info_header {
unsigned int magic;
int iteration;
@@ -78,29 +76,9 @@ struct ff_info {
int currentindex;
};
-struct vibration_config {
- char *pattern;
- dd_list *data;
-};
-
-struct duration_data {
- int duration;
- int wait;
-};
-
-struct haptic_data {
- dd_list *vibration_data;
- unsigned int handle;
- int level;
- int priority;
- bool stop;
-};
-
static int ff_fd;
static dd_list *ff_list;
static dd_list *handle_list;
-static dd_list *vib_conf_list;
-static Ecore_Timer *duration_timer;
static char ff_path[PATH_MAX];
static int unique_number;
@@ -412,6 +390,8 @@ static int close_device(int device_handle)
info->timer = NULL;
}
+ standard_vibrate_close();
+
DD_LIST_REMOVE(handle_list, (gpointer)(long)info->handle);
safe_free(info->ffinfobuffer);
@@ -585,57 +565,6 @@ static int vibrate_custom_buffer(int device_handle, const unsigned char *vibe_bu
return 0;
}
-static Eina_Bool haptic_duration_play(void *data)
-{
- dd_list *head, *n, *next;
- struct haptic_data *h_data;
- struct duration_data *node;
- int ret = 0;
-
- if (!data)
- goto out;
-
- if (duration_timer) {
- ecore_timer_del(duration_timer);
- duration_timer = NULL;
- }
-
- h_data = (struct haptic_data *)data;
- if (h_data->stop) {
- h_data->stop = false;
- free(h_data);
- goto out;
- }
-
- head = h_data->vibration_data;
- DD_LIST_FOREACH_SAFE(head, n, next, node) {
- _D("Play: %dms and Wait: %dms", node->duration, node->wait);
- if (!node->duration) {
- free(h_data);
- break;
- }
-
- if (node->wait && next) {
- h_data->vibration_data = next;
- duration_timer = ecore_timer_add((node->duration + node->wait)/1000.0f, haptic_duration_play, (void *)h_data);
- }
-
- ret = vibrate_monotone(h_data->handle, node->duration, h_data->level, h_data->priority, NULL);
- if (!next) {
- free(h_data);
- goto out;
- }
- break;
- }
- if (ret != 0) {
- _D("auto stop vibration");
- if (h_data)
- h_data->stop = true;
- }
-out:
- return ECORE_CALLBACK_CANCEL;
-}
-
static int vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle)
{
int magic = 0;
@@ -653,65 +582,6 @@ static int vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, i
return vibrate_monotone(device_handle, 300, feedback, priority, effect_handle);
}
-static int vibrate_effect(int device_handle, const char *pattern, int feedback, int priority)
-{
- dd_list *elem;
- struct vibration_config *conf;
- struct haptic_data *data;
- size_t len;
-
- if (device_handle < 0)
- return -EINVAL;
-
- len = strlen(pattern) + 1;
- DD_LIST_FOREACH(vib_conf_list, elem, conf) {
- if (!conf->pattern)
- continue;
- if (strncmp(conf->pattern, pattern, len))
- continue;
-
- data = (struct haptic_data *)malloc(sizeof(struct haptic_data));
- if (!data) {
- _E("fail to alloc");
- return -ENOMEM;
- }
- data->vibration_data = conf->data;
- data->handle = device_handle;
- data->level = feedback;
- data->priority = priority;
- data->stop = false;
- _D("Play %s", conf->pattern);
- haptic_duration_play((void *)data);
- break;
- }
-
- return 0;
-}
-
-static int is_supported(const char *pattern)
-{
- dd_list *elem;
- struct vibration_config *conf;
- size_t len;
- int ret;
-
- if (!pattern)
- return -EINVAL;
-
- len = strlen(pattern) + 1;
- ret = 0;
- DD_LIST_FOREACH(vib_conf_list, elem, conf) {
- if (!conf->pattern)
- continue;
- if (!strncmp(conf->pattern, pattern, len)) {
- ret = true;
- break;
- }
- }
-
- return ret;
-}
-
static int stop_device(int device_handle)
{
struct ff_info *info;
@@ -787,8 +657,8 @@ static const struct haptic_plugin_ops default_plugin = {
.close_device = close_device,
.vibrate_monotone = vibrate_monotone,
.vibrate_buffer = vibrate_buffer,
- .vibrate_effect = vibrate_effect,
- .is_supported = is_supported,
+ .vibrate_effect = standard_vibrate_effect,
+ .is_supported = standard_is_supported,
.stop_device = stop_device,
.get_device_state = get_device_state,
.create_effect = create_effect,
@@ -796,98 +666,6 @@ static const struct haptic_plugin_ops default_plugin = {
.convert_binary = convert_binary,
};
-static int vibration_load_config(struct parse_result *result, void *user_data)
-{
- struct vibration_config *conf;
- struct duration_data *data;
- char *value;
- char *check;
- int len;
-
- if (!result)
- return 0;
-
- if (!MATCH(result->section, "Vibration"))
- return 0;
-
-
- if (!result->name || !result->value)
- return 0;
-
- conf = (struct vibration_config *)calloc(1, sizeof(struct vibration_config));
- if (!conf) {
- _E("fail to alloc");
- return -ENOMEM;
- }
-
- conf->pattern = strdup(result->name);
- if (!conf->pattern)
- _E("fail to copy %s pattern data", result->name);
-
- value = result->value;
-
- if (!value)
- len = 0;
- else
- len = strlen(value);
-
- if (len == 0) {
- data = (struct duration_data *)malloc(sizeof(struct duration_data));
- if (!data) {
- _E("not enough memory");
- free(conf->pattern);
- free(conf);
- return -ENOMEM;
- }
- data->duration = 0;
- data->wait = 0;
-
- DD_LIST_APPEND(conf->data, data);
- DD_LIST_APPEND(vib_conf_list, conf);
- return 0;
- }
-
- do {
- data = (struct duration_data *)malloc(sizeof(struct duration_data));
- if (!data) {
- _E("not enough memory");
- free(conf->pattern);
- free(conf);
- return -ENOMEM;
- }
- data->duration = 0;
- data->wait = 0;
-
- check = strchr(value, 'D');
- if (check) {
- *check = '\0';
- data->duration = strtol(value, NULL, 10);
- if (!value)
- len = len - 1;
- else
- len = len - strlen(value) - 1;
- value = check + 1;
- }
- check = strchr(value, 'W');
- if (check) {
- *check = '\0';
- data->wait = strtol(value, NULL, 10);
- if (!value)
- len = len - 1;
- else
- len = len - strlen(value) - 1;
- value = check + 1;
- }
- DD_LIST_APPEND(conf->data, data);
- if (data->duration == 0 && data->wait == 0)
- break;
- } while (value && len > 0);
-
- DD_LIST_APPEND(vib_conf_list, conf);
-
- return 0;
-}
-
static bool is_valid(void)
{
int ret;
@@ -897,9 +675,10 @@ static bool is_valid(void)
_E("Do not support standard haptic device");
return false;
}
- ret = config_parse(VIBRATION_CONF_PATH, vibration_load_config, NULL);
+
+ ret = standard_config_parse();
if (ret < 0)
- _E("failed to load configuration file(%s) : %d", VIBRATION_CONF_PATH, ret);
+ _E("failed to load standard vibration configuration file : %d", ret);
_I("Support standard haptic device");
return true;
@@ -907,6 +686,7 @@ static bool is_valid(void)
static const struct haptic_plugin_ops *load(void)
{
+ standard_set_vib_function(&vibrate_monotone);
return &default_plugin;
}