diff Small_CPU/Src/batteryGasGauge.c @ 696:cc542448fb28

Merge
author heinrichsweikamp
date Fri, 19 Aug 2022 11:30:24 +0200
parents 079bb5b22c06
children
line wrap: on
line diff
--- a/Small_CPU/Src/batteryGasGauge.c	Mon Nov 01 12:39:34 2021 +0100
+++ b/Small_CPU/Src/batteryGasGauge.c	Fri Aug 19 11:30:24 2022 +0200
@@ -28,8 +28,10 @@
 #include "stm32f4xx_hal.h"
 #include "i2c.h"
 
-static float battery_f_voltage = 6.0;		/* max assumed voltage */
+static float battery_f_voltage = BATTERY_DEFAULT_VOLTAGE;		/* max assumed voltage */
 static float battery_f_charge_percent = 0;
+static uint8_t chargeValueKnown = 0;							/* indicator if the charge of the battery is known (for example after a full charge cycle) */
+
 
 #define BGG_BATTERY_OFFSET          (26123)  //; 65536-(3,35Ah/0,085mAh)
 #define BGG_BATTERY_DIVIDER         (394)    //; 3,35Ah/0,085mAh/100 [%]
@@ -66,7 +68,7 @@
 	// F8 = 11111000:
 	// ADC auto mode (11)
 	// Prescale M = 128 (111)
-	// AL/CC pin disable (0)
+	// AL/CC pin disable (00)
 	// Shutdown (0)
 	buffer[1] = 0xF8;
 	I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2);
@@ -152,6 +154,7 @@
 	bufferSend[2] = 0xFF;
 	I2C_Master_Transmit(  DEVICE_BATTERYGAUGE, bufferSend, 3);
 	init_battery_gas_gauge();
+	chargeValueKnown = 1;
 }
 
 
@@ -177,7 +180,17 @@
 	bufferSend[2] = (uint8_t)(mAhSend & 0xFF);
 	I2C_Master_Transmit(  DEVICE_BATTERYGAUGE, bufferSend, 3);
 	init_battery_gas_gauge();
+	chargeValueKnown = 1;
 }
 
+uint8_t battery_gas_gauge_isChargeValueValid(void)
+{
+	return chargeValueKnown;
+}
+
+void battery_gas_gauge_setChargeValueValid(void)
+{
+	chargeValueKnown = 1;
+}
 
 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/