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

Merge
author heinrichsweikamp
date Fri, 19 Aug 2022 11:30:24 +0200
parents 079bb5b22c06
children
comparison
equal deleted inserted replaced
661:87bee7cc77b3 696:cc542448fb28
26 #include "batteryGasGauge.h" 26 #include "batteryGasGauge.h"
27 #include "baseCPU2.h" 27 #include "baseCPU2.h"
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 = 6.0; /* 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****/