changeset 333:8a90038c0173

FCHG: store discharge state as threshold index rather than percentage
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 14 Dec 2017 18:35:16 +0000
parents 70e3acc5d4c8
children d583a1f5bd6a
files src/cs/drivers/drv_app/fchg/fchg_process.c src/cs/drivers/drv_app/fchg/fchg_struct.h
diffstat 2 files changed, 5 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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);
 }
--- 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;