comparison Small_CPU/Src/batteryGasGauge.c @ 668:079bb5b22c06 Betatest

Rework charge cycle: The charge counter is increasing decreasing also if the real value is maybe not defined (definition is done for example by a completed charging cycle). This caused some problems with invalid displayed charge per centage values. To avoid this the state of an unknow counter value was introduced. The indication is done by converting the counter into a negativ value.
author Ideenmodellierer
date Sat, 12 Mar 2022 22:48:45 +0100
parents 1b995079c045
children
comparison
equal deleted inserted replaced
667:8c3d495afc69 668:079bb5b22c06
28 #include "stm32f4xx_hal.h" 28 #include "stm32f4xx_hal.h"
29 #include "i2c.h" 29 #include "i2c.h"
30 30
31 static float battery_f_voltage = BATTERY_DEFAULT_VOLTAGE; /* max assumed voltage */ 31 static float battery_f_voltage = BATTERY_DEFAULT_VOLTAGE; /* max assumed voltage */
32 static float battery_f_charge_percent = 0; 32 static float battery_f_charge_percent = 0;
33 static uint8_t chargeValueKnown = 0; /* indicator if the charge of the battery is known (for example after a full charge cycle) */
34
33 35
34 #define BGG_BATTERY_OFFSET (26123) //; 65536-(3,35Ah/0,085mAh) 36 #define BGG_BATTERY_OFFSET (26123) //; 65536-(3,35Ah/0,085mAh)
35 #define BGG_BATTERY_DIVIDER (394) //; 3,35Ah/0,085mAh/100 [%] 37 #define BGG_BATTERY_DIVIDER (394) //; 3,35Ah/0,085mAh/100 [%]
36 38
37 float get_voltage(void) 39 float get_voltage(void)
64 buffer[0] = 0x01; 66 buffer[0] = 0x01;
65 67
66 // F8 = 11111000: 68 // F8 = 11111000:
67 // ADC auto mode (11) 69 // ADC auto mode (11)
68 // Prescale M = 128 (111) 70 // Prescale M = 128 (111)
69 // AL/CC pin disable (0) 71 // AL/CC pin disable (00)
70 // Shutdown (0) 72 // Shutdown (0)
71 buffer[1] = 0xF8; 73 buffer[1] = 0xF8;
72 I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2); 74 I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2);
73 } 75 }
74 76
150 bufferSend[0] = 0x02; 152 bufferSend[0] = 0x02;
151 bufferSend[1] = 0xFF; 153 bufferSend[1] = 0xFF;
152 bufferSend[2] = 0xFF; 154 bufferSend[2] = 0xFF;
153 I2C_Master_Transmit( DEVICE_BATTERYGAUGE, bufferSend, 3); 155 I2C_Master_Transmit( DEVICE_BATTERYGAUGE, bufferSend, 3);
154 init_battery_gas_gauge(); 156 init_battery_gas_gauge();
157 chargeValueKnown = 1;
155 } 158 }
156 159
157 160
158 void battery_gas_gauge_set(float percentage) 161 void battery_gas_gauge_set(float percentage)
159 { 162 {
175 bufferSend[0] = 0x02; 178 bufferSend[0] = 0x02;
176 bufferSend[1] = (uint8_t)(mAhSend / 256); 179 bufferSend[1] = (uint8_t)(mAhSend / 256);
177 bufferSend[2] = (uint8_t)(mAhSend & 0xFF); 180 bufferSend[2] = (uint8_t)(mAhSend & 0xFF);
178 I2C_Master_Transmit( DEVICE_BATTERYGAUGE, bufferSend, 3); 181 I2C_Master_Transmit( DEVICE_BATTERYGAUGE, bufferSend, 3);
179 init_battery_gas_gauge(); 182 init_battery_gas_gauge();
183 chargeValueKnown = 1;
180 } 184 }
181 185
186 uint8_t battery_gas_gauge_isChargeValueValid(void)
187 {
188 return chargeValueKnown;
189 }
190
191 void battery_gas_gauge_setChargeValueValid(void)
192 {
193 chargeValueKnown = 1;
194 }
182 195
183 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ 196 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/