diff src/cs/drivers/drv_app/fchg/fchg_process.c @ 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 8166b0afcf8c
children d583a1f5bd6a
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);
 }