heart : flush and print data when charging is started 81/121581/8
authorKichan Kwon <k_c.kwon@samsung.com>
Tue, 28 Mar 2017 08:52:17 +0000 (17:52 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Fri, 19 May 2017 01:38:14 +0000 (10:38 +0900)
- Flush condition : cap(last_charge_is_ended) - cap(cur) > 10

Change-Id: I11ab67f16abeca8bc9d326bf1b5cc581b4d88157
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/heart/heart-battery.c

index a541a246dbc730740041ee60064c1c35eee0ff9e..6ff0783c476531eced6cf418b3b8d576e7bda274 100644 (file)
@@ -97,6 +97,7 @@
 #define LONG_TIME_WEIGHT               (0.7) /*weightage given for longer time discharge*/
 #define SHORT_TIME_WEIGHT              (1-LONG_TIME_WEIGHT) /*weightage given for short time discharge*/
 #define MIN_TIME_FOR_LVL_CHANGE                50
+#define BATT_CHG_FLUSH_DATA            10
 
 #define UPS_FACTOR                             (2.88)
 #define DOUBLE_ZERO                            (0.000000)
@@ -1257,6 +1258,34 @@ int heart_battery_get_time_diff(long curr_wall_time)
        return (curr_wall_time - batt_stat.last_wall_time_chg);
 }
 
+static void heart_battery_print_prev_charge_data(void)
+{
+       int i;
+
+       _I("Charging stored data, current index = %d", batt_stat.index_chg);
+
+       for (i = 0; i < BATTERY_LEVEL_GAP; i++)
+               _I("Index = %d, time_diff = %d", i, batt_stat.last_wall_time_chg_diff[i]);
+}
+
+/*
+ * This function will flush the stored charge data
+ */
+static void heart_battery_flush_charge_data(void)
+{
+       int i;
+
+        _I("Prev and curr battery lvl gap = %d, flush charge data",
+               batt_stat.last_capacity_chg - batt_stat.curr_capacity);
+
+        for (i = 0; i < BATTERY_LEVEL_GAP; i++)
+               batt_stat.last_wall_time_chg_diff[i] = 0;
+
+        batt_stat.last_wall_time_chg = 0;
+        batt_stat.index_chg = 0;
+        data_avail_chg = false;
+}
+
 /*
  * This function will calculate the battery charging remaining time
  */
@@ -2062,12 +2091,22 @@ static void heart_battery_charger_status(GVariant *params)
        heart_battery_calculate_prediction(batt_stat.curr_charger_status);
 
        if (logic_v2) {
-               /* If charger has been removed then update the battery estimation time */
+               /*
+                * If charger removed/inserted then update the battery estimation time
+                */
                heart_battery_cal_discharge_rem_time();
 
                if (charger_status == CHARGING) {
+                       /*
+                        * if diff is more than 10% then flush the previous charge data
+                        */
+                       if ((batt_stat.last_capacity_chg > 0) &&
+                           (batt_stat.last_capacity_chg - batt_stat.curr_capacity > BATT_CHG_FLUSH_DATA))
+                               heart_battery_flush_charge_data();
+
                        batt_stat.last_wall_time_chg = 0;
                        first_level_change = TRUE;
+                       heart_battery_print_prev_charge_data();
                        heart_battery_cal_charging_rem_time();
                }
        }
@@ -2585,6 +2624,7 @@ static void heart_battery_status_init(void)
 
                batt_stat.data_available = 0;
                batt_stat.last_capacity = 0;
+               batt_stat.last_capacity_chg = 0;
                first_level_change = FALSE;
                batt_stat.curr_index = 0;
                batt_stat.remaining_time = 0;