diff options
author | Kichan Kwon <k_c.kwon@samsung.com> | 2016-12-06 16:43:19 +0900 |
---|---|---|
committer | Kichan Kwon <k_c.kwon@samsung.com> | 2016-12-06 17:38:13 +0900 |
commit | 4bfa965bcc00d971af882377287b47e427194aaf (patch) | |
tree | e90f86b92b1cf144e2795f051a6a9fa8a7a31a06 | |
parent | 21f0379fbdff5be35bfb9a0474e988e5ea778ef9 (diff) | |
download | resourced-4bfa965bcc00d971af882377287b47e427194aaf.tar.gz resourced-4bfa965bcc00d971af882377287b47e427194aaf.tar.bz2 resourced-4bfa965bcc00d971af882377287b47e427194aaf.zip |
heart : fix wrong battery indexingsubmit/tizen_3.0/20161206.084145accepted/tizen/3.0/wearable/20161207.012400accepted/tizen/3.0/tv/20161207.012342accepted/tizen/3.0/mobile/20161207.012325accepted/tizen/3.0/ivi/20161207.012417accepted/tizen/3.0/common/20161207.194604
- When current index is 0, then temp index should be INDEX_WINDOW_SIZE - 1
- However, temp is set to 0, so we have to fix it
- Meanwhile, some comments and logs are modified
Change-Id: Iefe85b2f3b4987cb4dec9d034b16a626d70f0a58
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
-rw-r--r-- | src/heart/heart-battery.c | 74 |
1 files changed, 47 insertions, 27 deletions
diff --git a/src/heart/heart-battery.c b/src/heart/heart-battery.c index 3e9348d9..89bcb1e8 100644 --- a/src/heart/heart-battery.c +++ b/src/heart/heart-battery.c @@ -1149,7 +1149,7 @@ static void heart_battery_power_off_time_adjustment(void) curr_time = heart_battery_logging_get_time_sec_new(); - index = ((batt_stat.curr_index - 1) + INDEX_WINDOW_SIZE) % INDEX_WINDOW_SIZE; + index = BATTERY_WINDOW_INDEX(batt_stat.curr_index - 1); if (batt_stat.last_wall_time[index] == 0) index = 0; @@ -1245,7 +1245,7 @@ static int heart_battery_get_time_diff_avg(int time_diff_avg) * to minimize the time diff fluctuation */ time_diff_avg = (time_diff_avg+BATTERY_C_RATE)/2; - _I("time_diff after averaging= %d\n", time_diff_avg); + _I("time_diff after averaging= %d seconds\n", time_diff_avg); return time_diff_avg; } @@ -1275,6 +1275,7 @@ static void heart_battery_cal_charging_rem_time(void) int rem_time; int time_diff; int time_diff_avg; + double temp_cv; if (batt_stat.last_capacity_chg == batt_stat.curr_capacity) { _I("Last capacity %d is same as current capacity %d\n", @@ -1298,28 +1299,36 @@ static void heart_battery_cal_charging_rem_time(void) * heart_battery_charger_status() and set to FALSE in function * heart_battery_capacity_status() */ - _I("time diff %d is less than min value of lvl change %d\n",time_diff, MIN_TIME_FOR_LVL_CHANGE); + _I("time diff %d is less than min value of lvl change %d\n", + time_diff, MIN_TIME_FOR_LVL_CHANGE); time_diff = BATTERY_C_RATE; } - _I("data_avail_chg = %d, index_chg = %d\n",data_avail_chg, batt_stat.index_chg); - _I("last_wall_time_chg = %ld, curr_wall_time = %ld\n", batt_stat.last_wall_time_chg, curr_wall_time); - _I("time diff before averaging = %d\n",time_diff); + _I("data_avail_chg = %d, index_chg = %d\n", + data_avail_chg, batt_stat.index_chg); + _I("last_wall_time_chg = %ld, curr_wall_time = %ld\n", + batt_stat.last_wall_time_chg, curr_wall_time); + _I("time diff before averaging = %d seconds\n",time_diff); /* * get the average of all time diff values stored including current */ time_diff_avg = heart_battery_get_time_diff_avg(time_diff); + if (time_diff_avg > BATTERY_C_RATE && batt_stat.curr_capacity <= 30) + time_diff_avg = BATTERY_C_RATE; + if (batt_stat.curr_capacity == FULL_CAPACITY) { batt_stat.remaining_time_chg = 0; } else { /* * calculate the remaining charge time based on constant current * and constant votlage(CCCV) logic. 'time_diff_avg' is for CC and - * square(time_diff_avg/BATTERY_C_RATE) is for CV part. + * 'temp_cv' is for CV part. */ - rem_time = (time_diff_avg + (time_diff_avg/BATTERY_C_RATE)*(time_diff_avg/BATTERY_C_RATE))*(FULL_CAPACITY- batt_stat.curr_capacity); + temp_cv = ((double)time_diff_avg)/((double)BATTERY_C_RATE); + temp_cv = temp_cv * temp_cv; + rem_time = (time_diff_avg + temp_cv)*(FULL_CAPACITY - batt_stat.curr_capacity); batt_stat.remaining_time_chg = SEC_TO_MIN(rem_time); } @@ -1329,13 +1338,13 @@ static void heart_battery_cal_charging_rem_time(void) batt_stat.last_capacity_chg = batt_stat.curr_capacity; batt_stat.last_clock_tick = logging_get_time(CLOCK_BOOTTIME); - _I("Capacity = %d, charging remaining time = %d\n", batt_stat.curr_capacity, batt_stat.remaining_time_chg); + _I("Capacity = %d, charging remaining time = %d minutes\n", + batt_stat.curr_capacity, batt_stat.remaining_time_chg); if (batt_stat.index_chg+1 == BATTERY_LEVEL_GAP) data_avail_chg = true; } - /* * This function will calculate the battery estimation time for every battery * level change @@ -1372,17 +1381,22 @@ static void heart_battery_cal_discharge_rem_time(void) if (batt_stat.last_capacity < batt_stat.curr_capacity) { /* - *this indicates that device was put for charging so need to reject all the previous data except - *'batt_stat.data_available' and 'batt_stat.last_pwr_bchg'. - *Use last available battery power before connecting the charger as current average power. - */ + *this indicates that device was put for charging so need to reject + *all the previous data except 'batt_stat.data_available' and + *'batt_stat.last_pwr_bchg'. Use last available battery power + *before connecting the charger as current average power. + */ batt_pwr = batt_stat.last_pwr_bchg; heart_battery_reject_data(); } else { - index = ((batt_stat.curr_index - BATTERY_LEVEL_GAP) + INDEX_WINDOW_SIZE)%INDEX_WINDOW_SIZE; - if (batt_stat.last_wall_time[index] == 0 && batt_stat.last_volt_intg[index] == 0) { - /* do not have enough previous data so take 1st stored data as reference */ + index = BATTERY_WINDOW_INDEX(batt_stat.curr_index - BATTERY_LEVEL_GAP); + if (batt_stat.last_wall_time[index] == 0 && + batt_stat.last_volt_intg[index] == 0) { + /* + *do not have enough previous data so take 1st stored data + *as reference + */ time_diff1 = curr_wall_time - batt_stat.last_wall_time[0]; volt_intg_diff = batt_stat.last_volt_intg[0] - curr_volt_intg; if (volt_intg_diff < DOUBLE_ZERO) @@ -1451,14 +1465,14 @@ static void heart_battery_cal_discharge_rem_time(void) _I("pivot_nor = %lf, curr_volt_intg = %lf , volt_intg_full %lf, batt_pwr = %lf", pivot_nor, curr_volt_intg,volt_intg_full, batt_pwr); /* calculate remaining time for normal mode */ - update_time = (pivot_nor * curr_volt_intg)/volt_intg_full; - batt_stat.remaining_time = (LONG_TIME_WEIGHT*update_time + SHORT_TIME_WEIGHT*CAL_MIN(update_time, rem_time)); + update_time = (pivot_nor * curr_volt_intg) / volt_intg_full; + batt_stat.remaining_time = (LONG_TIME_WEIGHT * update_time + SHORT_TIME_WEIGHT * CAL_MIN(update_time, rem_time)); /* calculate remaining time for UPS mode */ - update_time = (pivot_ups * curr_volt_intg)/volt_intg_full; - batt_stat.remaining_time_ups = (LONG_TIME_WEIGHT*update_time + SHORT_TIME_WEIGHT*CAL_MIN(update_time, rem_time)); + update_time = (pivot_ups * curr_volt_intg) / volt_intg_full; + batt_stat.remaining_time_ups = (LONG_TIME_WEIGHT * update_time + SHORT_TIME_WEIGHT * CAL_MIN(update_time, rem_time)); - _I("normal mode remaining time = %d, ups remaining time = %d\n", + _I("normal mode remaining time = %d minutes, ups remaining time = %d minutes\n", batt_stat.remaining_time, batt_stat.remaining_time_ups); batt_stat.last_volt_intg[batt_stat.curr_index] = curr_volt_intg; @@ -1468,14 +1482,19 @@ static void heart_battery_cal_discharge_rem_time(void) batt_stat.last_clock_tick = logging_get_time(CLOCK_BOOTTIME); if (batt_pwr > DOUBLE_ZERO) { - /*when battery percentage is 0 then available power will be 0 so do not store this value. - keep previous value only. */ + /* + *when battery percentage is 0 then available power will be 0 so + *do not store this value. keep previous value only. + */ batt_stat.last_pwr_bchg = batt_pwr; } if (batt_stat.curr_index > BATTERY_LEVEL_GAP) { - /* When enough data to estimate the available battery time are stored, no need to update the status - of batt_stat.data_available untill we are flashing new binary. */ + /* + *When enough data to estimate the available battery time are + *stored, no need to update the status of batt_stat. data_available + *untill we are flashing new binary. + */ batt_stat.data_available = TRUE; } @@ -2020,7 +2039,8 @@ static void heart_battery_capacity_status(void *data, DBusMessage *msg) /* for every battery level change, calculate the battery estimation time using new logic*/ heart_battery_cal_discharge_rem_time(); - if (batt_stat.curr_charger_status == CHARGING) { + if (batt_stat.curr_charger_status == CHARGING && + batt_stat.last_capacity_chg < batt_stat.curr_capacity) { heart_battery_cal_charging_rem_time(); first_level_change = FALSE; } |