From 5ebc7cb09eded6a3f34a10f88a43d0001cb18b7d Mon Sep 17 00:00:00 2001 From: Alan Wang <44191076+alankrantas@users.noreply.github.com> Date: Wed, 8 Jul 2020 05:47:38 +0800 Subject: [PATCH] bmp180: fix temperature type conversion --- bmp180/bmp180.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bmp180/bmp180.go b/bmp180/bmp180.go index ee46beb..6eff0f1 100644 --- a/bmp180/bmp180.go +++ b/bmp180/bmp180.go @@ -125,7 +125,7 @@ func (d *Device) ReadPressure() (pressure int32, err error) { } // rawTemp returns the sensor's raw values of the temperature -func (d *Device) rawTemp() (int16, error) { +func (d *Device) rawTemp() (int32, error) { d.bus.WriteRegister(uint8(d.Address), REG_CTRL, []byte{CMD_TEMP}) time.Sleep(5 * time.Millisecond) data := make([]byte, 2) @@ -133,12 +133,12 @@ func (d *Device) rawTemp() (int16, error) { if err != nil { return 0, err } - return readInt(data[0], data[1]), nil + return int32(uint16(data[0])<<8 | uint16(data[1])), nil } // calculateB5 calculates intermediate value B5 as per page 15 of datasheet -func (d *Device) calculateB5(rawTemp int16) int32 { - x1 := (int32(rawTemp) - int32(d.calibrationCoefficients.ac6)) * int32(d.calibrationCoefficients.ac5) >> 15 +func (d *Device) calculateB5(rawTemp int32) int32 { + x1 := (rawTemp - int32(d.calibrationCoefficients.ac6)) * int32(d.calibrationCoefficients.ac5) >> 15 x2 := int32(d.calibrationCoefficients.mc) << 11 / (x1 + int32(d.calibrationCoefficients.md)) return x1 + x2 }