# HG changeset patch # User Mychaela Falconia # Date 1513276516 0 # Node ID 8a90038c0173969bbac639fab50c8b881cdd8a3d # Parent 70e3acc5d4c8677d640514b897ad62e08cb357da FCHG: store discharge state as threshold index rather than percentage diff -r 70e3acc5d4c8 -r 8a90038c0173 src/cs/drivers/drv_app/fchg/fchg_process.c --- a/src/cs/drivers/drv_app/fchg/fchg_process.c Thu Dec 14 18:16:09 2017 +0000 +++ b/src/cs/drivers/drv_app/fchg/fchg_process.c Thu Dec 14 18:35:16 2017 +0000 @@ -16,7 +16,7 @@ void pwr_init_discharge(void) { - pwr_ctrl->curr_percent = pwr_ctrl->batt_thresholds[0].remain_capa; + pwr_ctrl->curr_disch_thresh = 0; } static void handle_discharge(void) @@ -25,10 +25,7 @@ char trace[64]; /* first we need to find the current threshold we are at */ - for (i = 0; i < pwr_ctrl->nb_thresholds; i++) - if (pwr_ctrl->batt_thresholds[i].remain_capa == - pwr_ctrl->curr_percent) - break; + i = pwr_ctrl->curr_disch_thresh; /* is there one below? */ if (++i == pwr_ctrl->nb_thresholds) return; @@ -41,9 +38,9 @@ i++; /* the last one was it */ i--; - pwr_ctrl->curr_percent = pwr_ctrl->batt_thresholds[i].remain_capa; + pwr_ctrl->curr_disch_thresh = i; sprintf(trace, "Battery fell through %u%% mark", - pwr_ctrl->curr_percent); + pwr_ctrl->batt_thresholds[i].remain_capa); rvf_send_trace(trace, strlen(trace), NULL_PARAM, RV_TRACE_LEVEL_WARNING, FCHG_USE_ID); } diff -r 70e3acc5d4c8 -r 8a90038c0173 src/cs/drivers/drv_app/fchg/fchg_struct.h --- a/src/cs/drivers/drv_app/fchg/fchg_struct.h Thu Dec 14 18:16:09 2017 +0000 +++ b/src/cs/drivers/drv_app/fchg/fchg_struct.h Thu Dec 14 18:35:16 2017 +0000 @@ -42,7 +42,7 @@ /* state */ enum fchg_state state; UINT16 batt_mv; - T_PWR_PERCENT curr_percent; + UINT16 curr_disch_thresh; /* valid only during a charging cycle */ UINT16 i2v_offset; } T_PWR_CTRL_BLOCK;