haptic: fix standard pattern parsing issue 29/223829/1
authorYunmi Ha <yunmi.ha@samsung.com>
Tue, 4 Feb 2020 07:35:55 +0000 (16:35 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Tue, 4 Feb 2020 07:35:55 +0000 (16:35 +0900)
Change-Id: I8f5af6554b26c7262a3455dd09d7b83ec56bcdc2
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
src/haptic/haptic.c

index 3263ed5..f34e3f3 100644 (file)
@@ -246,9 +246,11 @@ static int insert_raw_data_format(dd_list **conf_data, char *value)
 static int get_config_data(int count, bool *packed, char *val, unsigned int *pattern_duration, struct duration_data *update)
 {
        static int duration = 0;
+       static int intensity = 0;
        int value;
+       int ret;
 
-       if (count > 2 || count <= 0) {
+       if (count > 4 || count <= 0) {
                _E("Invalid parameter: count is invalid");
                return -EINVAL;
        }
@@ -260,33 +262,36 @@ static int get_config_data(int count, bool *packed, char *val, unsigned int *pat
 
        get_pattern_property(&val, 'C', &value);
 
-       if (count == 1) {
+       ret = count;
+       if (count == 1) {               //duration
                duration = value;
                *pattern_duration += duration;
                if (*pattern_duration > VIB_LOCK_TIMEOUT_MAX) {
                        _D("Max pattern duration.");
                        *pattern_duration = VIB_LOCK_TIMEOUT_MAX;
-
                }
-               return count;
-       }
-
-       if (value > INTENSITY_BASE_RATE)
-               value = INTENSITY_BASE_RATE;
-       if (*packed == false) {
-               update->duration = duration;
-               update->intensity = value;
-               *packed = true;
-               return 0;
-       }
-       if (value == 0)
-               update->wait = duration;
-       else
-               update->wait = 0;
-       *packed = false;
-       duration = 0;
+       } else if (count == 2) {
+               /* if intensity is 0, duration use for wait(off) time */
+               if (value > INTENSITY_BASE_RATE)
+                       value = INTENSITY_BASE_RATE;
+               intensity = value;
+               if (*packed == false) {
+                       update->duration = duration;
+                       update->intensity = intensity;
+                       *packed = true;
+               } else {
+                       if (intensity == 0)
+                               update->wait = duration;
+                       else
+                               update->wait = 0;
+                       *packed = false;
+                       duration = 0;
+                       ret = -1;
+               }
+       } else if (count == 4)
+               ret = 0;
 
-       return -1;
+       return ret;
 }
 
 /*