annotate Small_CPU/Src/batteryGasGauge.c @ 867:3311b720a072 Evo_2_23

Decrease calculation interval for ascend speed: In the previous version the ascend speed was calculated every 2 seconds. To improve the visualization the interval has been reduced to 400ms. The average function of the depth calculation ensures a smooth dynamic transition of the values. For testing a simulation profile, which changes between several speeds, may be acivated using the compile switch.
author Ideenmodellierer
date Mon, 12 Aug 2024 14:30:22 +0200
parents 079bb5b22c06
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file batteryGasGauge.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V0.0.1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 09-Dec-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @brief LTC2942 Battery Gas Gauge
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 ##### stm32f4xx_hal_i2c.c modification #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 The LTC2942 requires an repeated start condition without stop condition
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 for data reception.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 * <h2><center>&copy; COPYRIGHT(c) 2014 heinrichs weikamp</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 /* Includes ------------------------------------------------------------------*/
330
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
25 #include <string.h> /* memset */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 #include "batteryGasGauge.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 #include "baseCPU2.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 #include "i2c.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 433
diff changeset
31 static float battery_f_voltage = BATTERY_DEFAULT_VOLTAGE; /* max assumed voltage */
228
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
32 static float battery_f_charge_percent = 0;
668
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
33 static uint8_t chargeValueKnown = 0; /* indicator if the charge of the battery is known (for example after a full charge cycle) */
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
34
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 #define BGG_BATTERY_OFFSET (26123) //; 65536-(3,35Ah/0,085mAh)
228
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
37 #define BGG_BATTERY_DIVIDER (394) //; 3,35Ah/0,085mAh/100 [%]
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 float get_voltage(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 return 3.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 return battery_f_voltage;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 float get_charge(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 return 100.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 return battery_f_charge_percent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 void init_battery_gas_gauge(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 uint8_t buffer[2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 buffer[0] = 0x01;
228
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
67
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
68 // F8 = 11111000:
433
aa286a4926c2 Detect startup after power off:
ideenmodellierer
parents: 408
diff changeset
69 // ADC auto mode (11)
228
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
70 // Prescale M = 128 (111)
668
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
71 // AL/CC pin disable (00)
228
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
72 // Shutdown (0)
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
73 buffer[1] = 0xF8;
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
74 I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76
330
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
77 uint8_t battery_gas_gauge_CheckConfigOK(void)
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
78 {
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
79 #ifdef OSTC_ON_DISCOVERY_HARDWARE
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
80 return;
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
81 #endif
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
82
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
83 uint8_t retval = 0;
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
84 uint8_t bufferReceive[10];
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
85
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
86 memset(bufferReceive,0,sizeof(bufferReceive));
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
87
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
88 I2C_Master_Receive(DEVICE_BATTERYGAUGE, bufferReceive, 10);
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
89 if(bufferReceive[1] == 0xf8)
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
90 {
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
91 retval = 1;
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
92 }
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
93 return retval;
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
94 }
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
95
242
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
96 static void disable_adc(void)
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
97 {
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
98 uint8_t buffer[2];
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
99 buffer[0] = 0x01;
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
100
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
101 // according to the datasheet of the LTC2942, the adc shall
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
102 // be disabled when writing to the gauge registers
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
103
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
104 // 0xF9 = 11111001:
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
105 // see init_battery_gas_gauge()
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
106 // Shutdown (1)
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
107 buffer[1] = 0xF9;
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
108 I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2);
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
109 }
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
110
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 void battery_gas_gauge_get_data(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 float battery_f_voltage_local;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 float battery_f_charge_percent_local;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 uint8_t bufferReceive[10];
408
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
122
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
123 if(I2C_Master_Receive(DEVICE_BATTERYGAUGE, bufferReceive, 10) == HAL_OK)
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
124 {
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
125 battery_f_voltage_local = (float)(bufferReceive[8] * 256);
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
126 battery_f_voltage_local += (float)(bufferReceive[9]);
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
127 battery_f_voltage_local *= (float)6 / (float)0xFFFF;
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
128
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
129 // max/full: 0.085 mAh * 1 * 65535 = 5570 mAh
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
130 battery_f_charge_percent_local = (float)(bufferReceive[2] * 256);
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
131 battery_f_charge_percent_local += (float)(bufferReceive[3]);
433
aa286a4926c2 Detect startup after power off:
ideenmodellierer
parents: 408
diff changeset
132 battery_f_charge_percent_local -= BGG_BATTERY_OFFSET; /* Because of the prescalar 128 the counter assumes a max value of 5570mAh => normalize to 3350mAh*/
aa286a4926c2 Detect startup after power off:
ideenmodellierer
parents: 408
diff changeset
133 battery_f_charge_percent_local /= BGG_BATTERY_DIVIDER; /* transform to percentage */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134
408
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
135 if(battery_f_charge_percent_local < 0)
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
136 battery_f_charge_percent_local = 0;
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
137
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
138 battery_f_voltage = battery_f_voltage_local;
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
139 battery_f_charge_percent = battery_f_charge_percent_local;
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
140 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 void battery_gas_gauge_set_charge_full(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 {
242
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
146 disable_adc();
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 uint8_t bufferSend[3];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 bufferSend[0] = 0x02;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 bufferSend[1] = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 bufferSend[2] = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 I2C_Master_Transmit( DEVICE_BATTERYGAUGE, bufferSend, 3);
242
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
156 init_battery_gas_gauge();
668
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
157 chargeValueKnown = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 void battery_gas_gauge_set(float percentage)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 {
242
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
163
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
164 disable_adc();
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 uint16_t mAhSend;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 if(percentage >= 100)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 mAhSend = 0xFFFF;
228
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
173 else {
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
174 mAhSend = (percentage * BGG_BATTERY_DIVIDER) + BGG_BATTERY_OFFSET;
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
175 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 uint8_t bufferSend[3];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 bufferSend[0] = 0x02;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 bufferSend[1] = (uint8_t)(mAhSend / 256);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 bufferSend[2] = (uint8_t)(mAhSend & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 I2C_Master_Transmit( DEVICE_BATTERYGAUGE, bufferSend, 3);
242
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
182 init_battery_gas_gauge();
668
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
183 chargeValueKnown = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185
668
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
186 uint8_t battery_gas_gauge_isChargeValueValid(void)
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
187 {
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
188 return chargeValueKnown;
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
189 }
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
190
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
191 void battery_gas_gauge_setChargeValueValid(void)
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
192 {
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
193 chargeValueKnown = 1;
079bb5b22c06 Rework charge cycle:
Ideenmodellierer
parents: 662
diff changeset
194 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/