Skip to content

Commit 20f8206

Browse files
seov-nordicrlubos
authored andcommitted
samples: pmic: npm1300_fuel_gauge: reverse current sign
Gauge current convention in Zephyr sensor API is negative=discharging, but nrf_fuel_gauge lib expects the opposite. This fixes calls to nrf_fuel_gauge lib API in the sample. Signed-off-by: Sergei Ovchinnikov <[email protected]>
1 parent a8a5977 commit 20f8206

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

samples/pmic/native/npm1300_fuel_gauge/src/fuel_gauge.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ int fuel_gauge_init(const struct device *charger)
9696
if (ret < 0) {
9797
return ret;
9898
}
99+
/* Zephyr sensor API convention for Gauge current is negative=discharging,
100+
* while nrf_fuel_gauge lib expects the opposite negative=charging
101+
*/
102+
parameters.i0 = -parameters.i0;
99103

100104
/* Store charge nominal and termination current, needed for ttf calculation */
101105
sensor_channel_get(charger, SENSOR_CHAN_GAUGE_DESIRED_CHARGING_CURRENT, &value);
@@ -176,7 +180,10 @@ int fuel_gauge_update(const struct device *charger, bool vbus_connected)
176180

177181
delta = (float)k_uptime_delta(&ref_time) / 1000.f;
178182

179-
soc = nrf_fuel_gauge_process(voltage, current, temp, delta, NULL);
183+
/* Zephyr sensor API convention for Gauge current is negative=discharging,
184+
* while nrf_fuel_gauge lib expects the opposite negative=charging
185+
*/
186+
soc = nrf_fuel_gauge_process(voltage, -current, temp, delta, NULL);
180187
tte = nrf_fuel_gauge_tte_get();
181188
ttf = nrf_fuel_gauge_ttf_get();
182189

0 commit comments

Comments
 (0)