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 <periphgithub@eldondev.com>
pull/57/head
eldondevat 4 years ago committed by GitHub
parent 212f060876
commit ae3205944c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -110,7 +110,7 @@ func (d *Dev) Sense() (PowerMonitor, error) {
return PowerMonitor{}, errReadShunt return PowerMonitor{}, errReadShunt
} }
// Least significant bit is 10µV. // 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) bus, err := d.m.ReadUint16(busVoltageRegister)
if err != nil { if err != nil {
@ -128,7 +128,7 @@ func (d *Dev) Sense() (PowerMonitor, error) {
if err != nil { if err != nil {
return PowerMonitor{}, errReadCurrent return PowerMonitor{}, errReadCurrent
} }
pm.Current = physic.ElectricCurrent(current) * d.currentLSB pm.Current = physic.ElectricCurrent(int16(current)) * d.currentLSB
power, err := d.m.ReadUint16(powerRegister) power, err := d.m.ReadUint16(powerRegister)
if err != nil { if err != nil {

Loading…
Cancel
Save