From ae3205944c1ecde7b2832912c2d2e405dc2ad20a Mon Sep 17 00:00:00 2001 From: eldondevat <31245140+eldondevat@users.noreply.github.com> Date: Tue, 15 Nov 2022 13:17:05 -0500 Subject: [PATCH] ina219: Interpret signed output register values (#54) The current and shunt voltage register values are signed, twos complement format. In my tests interpreting them directly in the way implemented here gave output consistent with other ina219 libraries. Co-authored-by: Eldon Stegall --- ina219/ina219.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ina219/ina219.go b/ina219/ina219.go index 0226ba1..5e2b2c8 100644 --- a/ina219/ina219.go +++ b/ina219/ina219.go @@ -110,7 +110,7 @@ func (d *Dev) Sense() (PowerMonitor, error) { return PowerMonitor{}, errReadShunt } // Least significant bit is 10µV. - pm.Shunt = physic.ElectricPotential(shunt) * 10 * physic.MicroVolt + pm.Shunt = physic.ElectricPotential(int16(shunt)) * 10 * physic.MicroVolt bus, err := d.m.ReadUint16(busVoltageRegister) if err != nil { @@ -128,7 +128,7 @@ func (d *Dev) Sense() (PowerMonitor, error) { if err != nil { return PowerMonitor{}, errReadCurrent } - pm.Current = physic.ElectricCurrent(current) * d.currentLSB + pm.Current = physic.ElectricCurrent(int16(current)) * d.currentLSB power, err := d.m.ReadUint16(powerRegister) if err != nil {