mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-15 20:33:39 +00:00
bmp180: fix temperature type conversion
This commit is contained in:
+4
-4
@@ -125,7 +125,7 @@ func (d *Device) ReadPressure() (pressure int32, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// rawTemp returns the sensor's raw values of the temperature
|
// 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})
|
d.bus.WriteRegister(uint8(d.Address), REG_CTRL, []byte{CMD_TEMP})
|
||||||
time.Sleep(5 * time.Millisecond)
|
time.Sleep(5 * time.Millisecond)
|
||||||
data := make([]byte, 2)
|
data := make([]byte, 2)
|
||||||
@@ -133,12 +133,12 @@ func (d *Device) rawTemp() (int16, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
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
|
// calculateB5 calculates intermediate value B5 as per page 15 of datasheet
|
||||||
func (d *Device) calculateB5(rawTemp int16) int32 {
|
func (d *Device) calculateB5(rawTemp int32) int32 {
|
||||||
x1 := (int32(rawTemp) - int32(d.calibrationCoefficients.ac6)) * int32(d.calibrationCoefficients.ac5) >> 15
|
x1 := (rawTemp - int32(d.calibrationCoefficients.ac6)) * int32(d.calibrationCoefficients.ac5) >> 15
|
||||||
x2 := int32(d.calibrationCoefficients.mc) << 11 / (x1 + int32(d.calibrationCoefficients.md))
|
x2 := int32(d.calibrationCoefficients.mc) << 11 / (x1 + int32(d.calibrationCoefficients.md))
|
||||||
return x1 + x2
|
return x1 + x2
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user