Commit Graph
1 Commits
Author SHA1 Message Date
Zhaoqi Xu 60aa84841d [INA226] Read the shunt voltage as a signed value (#2410)
The shunt voltage register is a 16-bit two's complement value. The
old conversion tested `shuntvolt && 0x8000` (always true for a
non-zero reading) and then negated the complement of the zero-extended
value, which gives back the raw register value. Positive readings came
out right by accident, but a reverse current was published as a large
positive current (0xFFF0 -> 1.638 A instead of -0.4 mA with the
default 0.1 ohm shunt).

Cast the register to int16_t instead.

Fixes #2395

Signed-off-by: Zhaoqi Xu <lzy00419@outlook.com>
2026-10-15 05:20:38 -05:00