From 626ddcd4fe16b12b8d7d5bb79b6fb299fe0c836a Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Tue, 10 Mar 2015 15:39:56 +0900 Subject: [PATCH] feedback: Change the vibration play function Common profile does not support to play vibration buffer. So to play vibration is failed. Instead, feedback request to play monotone during some mseconds. Change-Id: Id51e4e23168a28779741842f2165f596c1167ea1 Signed-off-by: Jiyoung Yun Signed-off-by: taeyoung --- CMakeLists.txt | 1 - src/vibrator.c | 90 ++++++++++++++++++++++++---------------------------------- 2 files changed, 37 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4aacbdb..a6ffd2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,7 +55,6 @@ ENDFOREACH(flag) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g") -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") diff --git a/src/vibrator.c b/src/vibrator.c index 3441fc4..b212597 100644 --- a/src/vibrator.c +++ b/src/vibrator.c @@ -50,12 +50,15 @@ enum haptic_iteration HAPTIC_ITERATION_INFINITE = 256, }; -#define VIBRATION_XML "/usr/share/feedback/vibration.xml" +#define VIBRATION_XML "/usr/share/feedback/vibration.xml" -#define METHOD_OPEN "OpenDevice" -#define METHOD_CLOSE "CloseDevice" -#define METHOD_VIBRATE_BUFFER "VibrateBuffer" -#define METHOD_STOP "StopDevice" +#define METHOD_OPEN "OpenDevice" +#define METHOD_CLOSE "CloseDevice" +#define METHOD_VIBRATE_BUFFER "VibrateBuffer" +#define METHOD_VIBRATE_MONOTONE "VibrateMonotone" +#define METHOD_STOP "StopDevice" + +#define DEFAULT_DURATION 100 static int vibstatus; static int vib_level; @@ -92,6 +95,31 @@ static int haptic_close(unsigned int handle) "u", arr); } +static int haptic_vibrate_monotone(unsigned int handle, + int duration, + int feedback, + int priority) +{ + char *arr[4]; + char buf_handle[32]; + char buf_duration[32]; + char buf_feedback[32]; + char buf_priority[32]; + + snprintf(buf_handle, sizeof(buf_handle), "%u", handle); + arr[0] = buf_handle; + snprintf(buf_duration, sizeof(buf_duration), "%d", duration); + arr[1] = buf_duration; + snprintf(buf_feedback, sizeof(buf_feedback), "%d", feedback); + arr[2] = buf_feedback; + snprintf(buf_priority, sizeof(buf_priority), "%d", priority); + arr[3] = buf_priority; + + return dbus_method_sync(DEVICED_BUS_NAME, DEVICED_PATH_HAPTIC, + DEVICED_INTERFACE_HAPTIC, METHOD_VIBRATE_MONOTONE, + "uiii", arr); +} + static int haptic_vibrate_buffer(unsigned int handle, const unsigned char *buffer, int size, @@ -367,10 +395,7 @@ static void vibrator_exit(void) static int vibrator_play(feedback_pattern_e pattern) { - int ret, size; - struct xmlData *data; - char *path; - unsigned char *buf; + int ret; if (!v_handle || !v_doc) { _E("Not initialize"); @@ -392,54 +417,13 @@ static int vibrator_play(feedback_pattern_e pattern) return 0; } - /* if there is a file path user defined */ - path = haptic_file[pattern]; - if (*path) { - buf = convert_file_to_buffer(path, &size); - if (!buf) { - _E("convert_file_to_buffer is failed"); - return -EPERM; - } - - ret = haptic_vibrate_buffer(v_handle, buf, size, HAPTIC_ITERATION_ONCE, - get_haptic_level(pattern), get_priority(pattern)); - if (ret < 0) { - _E("haptic_vibrate_buffer is failed"); - free(buf); - return -EPERM; - } - - free(buf); - return 0; - } - - ret = get_xml_data(v_doc, pattern, &data); - if (ret == -ENOENT) { - _D("No vibration case(%s)", str_pattern[pattern]); - return 0; - } - - if (ret < 0) { - _E("get_xml_data fail"); - return -EPERM; - } - - if (data->data == NULL) { - _D("No vibration case(%s)", str_pattern[pattern]); - release_xml_data(data); - return 0; - } - - /* play haptic buffer */ - ret = haptic_vibrate_buffer(v_handle, (unsigned char*)data->data, data->size, HAPTIC_ITERATION_ONCE, - get_haptic_level(pattern), get_priority(pattern)); + ret = haptic_vibrate_monotone(v_handle, DEFAULT_DURATION, + get_haptic_level(pattern), get_priority(pattern)); if (ret < 0) { - _E("haptic_vibrate_buffer is failed"); - release_xml_data(data); + _E("haptic_vibrate_monotone is failed"); return -EPERM; } - release_xml_data(data); return 0; } -- 2.7.4