Add level configuration 23/197223/2
authorpr.jung <pr.jung@samsung.com>
Thu, 10 Jan 2019 08:23:27 +0000 (17:23 +0900)
committerpr.jung <pr.jung@samsung.com>
Thu, 10 Jan 2019 08:28:50 +0000 (17:28 +0900)
- Add 2 level configuration rpms: conf-level3, conf-level6
- Calculate level with intensity

Change-Id: Ied3de559b9ac2dfb6c3e197dce98c44c4969c0c7
Signed-off-by: pr.jung <pr.jung@samsung.com>
CMakeLists.txt
packaging/feedbackd.spec
src/haptic/haptic.c
src/haptic/standard-vibcore.c

index ad93c9b..8950c06 100644 (file)
@@ -70,5 +70,7 @@ INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/systemd/ DESTINATION lib/systemd/system
        FILES_MATCHING
        PATTERN "feedbackd.service")
 INSTALL(FILES ${CMAKE_SOURCE_DIR}/systemd/org.tizen.system.vibrator.service DESTINATION /usr/share/dbus-1/system-services)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/haptic/conf/haptic-level3.conf DESTINATION /etc/feedbackd)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/haptic/conf/haptic-level6.conf DESTINATION /etc/feedbackd)
 
 ADD_SUBDIRECTORY(src/auto-test)
index 0c9fc13..6b801fc 100644 (file)
@@ -30,6 +30,9 @@ Requires(post): /usr/bin/vconftool
 Requires:      %{name}-compat = %{version}-%{release}
 Recommends:    %{name}-driver-standard = %{version}-%{release}
 
+Requires:      configuration-compat = %{version}-%{release}
+Recommends:    %{name}-conf-level6 = %{version}-%{release}
+
 %description
 feedback daemon
 
@@ -91,6 +94,20 @@ Conflicts:   %{name}-driver-standard
 %description driver-circle
 Feedbackd binaries with circle plugin. Required by main feedbackd package
 
+%package conf-level3
+Summary:       Feedbackd level configuration file
+Provides:      configuration-compat = %{version}-%{release}
+Conflicts:     %{name}-conf-level6
+%description conf-level3
+Feedbackd level configuration file. Required by main feedbackd package
+
+%package conf-level6
+Summary:       Feedbackd level configuration file
+Provides:      configuration-compat = %{version}-%{release}
+Conflicts:     %{name}-conf-level3
+%description conf-level6
+Feedbackd level configuration file. Required by main feedbackd package
+
 %package auto-test
 Summary:  Feedbackd auto test tool
 Group:    System/Utilities
@@ -262,7 +279,13 @@ if [ "$1" == "0" ]; then
     systemctl stop feedbackd.service
 fi
 
-%files -n feedbackd 
+%post conf-level3
+mv %{_sysconfdir}/feedbackd/haptic-level3.conf %{_sysconfdir}/feedbackd/haptic.conf
+
+%post conf-level6
+mv %{_sysconfdir}/feedbackd/haptic-level6.conf %{_sysconfdir}/feedbackd/haptic.conf
+
+%files -n feedbackd
 %manifest %{name}.manifest
 %license LICENSE.Apache-2.0
 %config %{_sysconfdir}/dbus-1/system.d/feedbackd.conf
@@ -295,6 +318,16 @@ fi
 %manifest %{name}.manifest
 %{_bindir}/feedbackd.circle
 
+%files conf-level3
+%license LICENSE.Apache-2.0
+%manifest %{name}.manifest
+%config %{_sysconfdir}/feedbackd/haptic-level3.conf
+
+%files conf-level6
+%license LICENSE.Apache-2.0
+%manifest %{name}.manifest
+%config %{_sysconfdir}/feedbackd/haptic-level6.conf
+
 %files auto-test
 %license LICENSE.Apache-2.0
 %manifest %{name}.manifest
index 818210c..30cbaeb 100644 (file)
@@ -33,6 +33,7 @@
 #include "core/config-parser.h"
 #include "haptic.h"
 
+#define HAPTIC_CONF_PATH                "/etc/feedbackd/haptic.conf"
 #define SIGNAL_CHANGE_HARDKEY           "ChangeHardkey"
 #define SIGNAL_POWEROFF_STATE           "ChangeState"
 #define SIGNAL_VIBRATOR_INITIATED       "InitiateVibrator"
@@ -86,6 +87,8 @@ static enum haptic_type h_type;
 static bool haptic_disabled;
 
 struct haptic_config {
+       int level;
+       int *level_arr;
        int sound_capture;
 };
 
@@ -139,6 +142,27 @@ static int haptic_module_load(void)
        return 0;
 }
 
+static int convert_magnitude_by_conf(int level)
+{
+       int i, step;
+
+       if (level < LOW_FEEDBACK_LEVEL)
+               level = LOW_FEEDBACK_LEVEL;
+       else if (level > HIGH_FEEDBACK_LEVEL)
+               level = HIGH_FEEDBACK_LEVEL;
+
+       step = 100 / (haptic_conf.level-1);
+       for (i = 0; i < haptic_conf.level; ++i) {
+               if (level <= i*step) {
+                       _D("Level changed : %d -> %d", level, haptic_conf.level_arr[i]);
+                       return haptic_conf.level_arr[i];
+               }
+       }
+
+       _D("Play default level");
+       return DEFAULT_FEEDBACK_LEVEL * HAPTIC_FEEDBACK_STEP;
+}
+
 GVariant *hdbus_get_count(GDBusConnection *conn,
        const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
        GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
@@ -329,10 +353,12 @@ GVariant *hdbus_vibrate_monotone(GDBusConnection *conn,
 
        g_variant_get(param, "(uiii)", &handle, &duration, &level, &priority);
 
-       if (level < LOW_FEEDBACK_LEVEL)
-               level = LOW_FEEDBACK_LEVEL;
-       else if (level > HIGH_FEEDBACK_LEVEL)
-               level = HIGH_FEEDBACK_LEVEL;
+       /* convert as per conf value */
+       level = convert_magnitude_by_conf(level);
+       if (level < 0) {
+               ret = -EINVAL;
+               goto exit;
+       }
 
        if (priority < PRIORITY_MIN)
                priority = PRIORITY_MIN;
@@ -367,10 +393,12 @@ GVariant *hdbus_vibrate_buffer(GDBusConnection *conn,
        data = g_variant_get_fixed_array(pvar, &size, sizeof(char));
        g_variant_unref(pvar);
 
-       if (level < LOW_FEEDBACK_LEVEL)
-               level = LOW_FEEDBACK_LEVEL;
-       else if (level > HIGH_FEEDBACK_LEVEL)
-               level = HIGH_FEEDBACK_LEVEL;
+       /* convert as per conf value */
+       level = convert_magnitude_by_conf(level);
+       if (level < 0) {
+               ret = -EINVAL;
+               goto exit;
+       }
 
        ret = h_ops->vibrate_buffer(handle, data, iteration, level, priority, &e_handle);
        if (ret >= 0)
@@ -407,10 +435,12 @@ GVariant *hdbus_vibrate_effect(GDBusConnection *conn,
 
        g_variant_get(param, "(usii)",  &handle, &pattern, &level, &priority);
 
-       if (level < LOW_FEEDBACK_LEVEL)
-               level = LOW_FEEDBACK_LEVEL;
-       else if (level > HIGH_FEEDBACK_LEVEL)
-               level = HIGH_FEEDBACK_LEVEL;
+       /* convert as per conf value */
+       level = convert_magnitude_by_conf(level);
+       if (level < 0) {
+               ret = -EINVAL;
+               goto exit;
+       }
        if (priority < PRIORITY_MIN)
                priority = PRIORITY_MIN;
        else if (priority > PRIORITY_TOP)
@@ -717,7 +747,6 @@ static void sound_capturing_cb(keynode_t *key, void *data)
                haptic_start();
 }
 
-/* Left for the case of sound_capture in use
 static int parse_section(struct parse_result *result, void *user_data, int index)
 {
        struct haptic_config *conf = (struct haptic_config *)user_data;
@@ -730,6 +759,21 @@ static int parse_section(struct parse_result *result, void *user_data, int index
 
        if (MATCH(result->name, "sound_capture")) {
                conf->sound_capture = atoi(result->value);
+       } else if (MATCH(result->name, "level")) {
+               conf->level = atoi(result->value);
+               if (conf->level < 0 || conf->level >= INT_MAX - 1) {
+                       _E("You must set level with positive number in integer range");
+                       return -EINVAL;
+               }
+               conf->level_arr = calloc(sizeof(int), conf->level);
+               if (!conf->level_arr) {
+                       _E("failed to allocate memory for level");
+                       return -errno;
+               }
+       } else if (MATCH(result->name, "value")) {
+               if (index < 0)
+                       return -EINVAL;
+               conf->level_arr[index] = atoi(result->value);
        }
 
        return 0;
@@ -737,7 +781,10 @@ static int parse_section(struct parse_result *result, void *user_data, int index
 
 static int haptic_load_config(struct parse_result *result, void *user_data)
 {
+       struct haptic_config *conf = (struct haptic_config *)user_data;
+       char name[NAME_MAX];
        int ret;
+       static int index;
 
        if (!result)
                return 0;
@@ -755,10 +802,22 @@ static int haptic_load_config(struct parse_result *result, void *user_data)
                goto out;
        }
 
+       // Parsing 'level' section
+       for (index = 0; index < conf->level; ++index) {
+               snprintf(name, sizeof(name), "level%d", index);
+               if (MATCH(result->section, name)) {
+                       ret = parse_section(result, user_data, index);
+                       if (ret < 0) {
+                               _E("failed to parse [level] section : %d", ret);
+                               return ret;
+                       }
+                       goto out;
+               }
+       }
+
 out:
        return 0;
 }
-*/
 
 static const dbus_method_s hdbus_methods[] = {
        { "GetCount",          NULL,   "i", hdbus_get_count },
@@ -800,6 +859,13 @@ void haptic_init(void)
 {
        int r;
 
+       /* get haptic data from configuration file */
+       r = config_parse(HAPTIC_CONF_PATH, haptic_load_config, &haptic_conf);
+       if (r < 0) {
+               _E("failed to load configuration file(%s) : %d", HAPTIC_CONF_PATH, r);
+               safe_free(haptic_conf.level_arr);
+       }
+
        /* init dbus interface */
        r = dbus_handle_register_dbus_object(NULL, VIBRATOR_PATH_HAPTIC, &dbus_interface);
        if (r < 0)
@@ -852,6 +918,9 @@ void haptic_exit(void)
        unsubscribe_dbus_signal(NULL, id_sig_change_hardkey);
        unsubscribe_dbus_signal(NULL, id_sig_pwr_off_state);
 
+       /* release haptic data memory */
+       safe_free(haptic_conf.level_arr);
+
        if (!CHECK_VALID_OPS(h_ops, r))
                return;
 
index 92bed2f..0d8f5c0 100644 (file)
@@ -33,6 +33,7 @@
 #define STANDARD_FILE_PATH         FEEDBACK_BASE_PATH"vibration/"
 #define VIBRATION_CONF_PATH        FEEDBACK_BASE_PATH"vibration.conf"
 
+#define INTENSITY_BASE_RATE        (10000)
 #define VALUE_MAX_LEN 10
 #define VIB_LOCK_TIMEOUT_MAX       (300000) /* 5minutes */
 
@@ -407,7 +408,7 @@ int standard_is_supported(const char *pattern)
        len = strlen(pattern) + 1;
        ret = 0;
        DD_LIST_FOREACH(vib_conf_list, elem, conf) {
-               if (!conf->pattern || conf->len  != len)
+               if (!conf->pattern || conf->len != len)
                        continue;
                if (!strncmp(conf->pattern, pattern, len)) {
                        ret = true;
@@ -422,6 +423,7 @@ static gboolean haptic_duration_play(void *data)
 {
        dd_list *head, *n, *next;
        struct duration_data *node;
+       int level;
        int ret = 0;
 
        if (duration_timer) {
@@ -464,9 +466,14 @@ static gboolean haptic_duration_play(void *data)
                        }
                }
 
+               if (node->intensity)
+                       level = (cur_h_data.level * node->intensity) / INTENSITY_BASE_RATE;
+               else
+                       level = cur_h_data.level;
+
                duration_timer = g_timeout_add((node->duration + node->wait), haptic_duration_play, (void *)next);
 
-               ret = real_vibrate_monotone(cur_h_data.handle, node->duration, cur_h_data.level, cur_h_data.priority, NULL);
+               ret = real_vibrate_monotone(cur_h_data.handle, node->duration, level, cur_h_data.priority, NULL);
 
                break;
        }