From b7fe897b8ceaea823ac79509a20bdca3182d9737 Mon Sep 17 00:00:00 2001 From: Ron Evans Date: Wed, 24 Apr 2019 10:53:56 +0200 Subject: [PATCH] mag3110: change method name/signature for obtaining temperature to be uniform with other similar drivers Signed-off-by: Ron Evans --- examples/mag3110/main.go | 6 +++++- mag3110/mag3110.go | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/examples/mag3110/main.go b/examples/mag3110/main.go index 8a47e74..869abf9 100644 --- a/examples/mag3110/main.go +++ b/examples/mag3110/main.go @@ -16,7 +16,11 @@ func main() { for { x, y, z := mag.ReadMagnetic() - println(x, y, z) + println("Magnetic readings:", x, y, z) + + c, _ := mag.ReadTemperature() + println("Temperature:", float32(c)/1000, "ºC") + time.Sleep(time.Millisecond * 100) } } diff --git a/mag3110/mag3110.go b/mag3110/mag3110.go index 3f996cd..27e73e8 100644 --- a/mag3110/mag3110.go +++ b/mag3110/mag3110.go @@ -48,9 +48,10 @@ func (d Device) ReadMagnetic() (x int16, y int16, z int16) { return } -// ReadTemperature reads the current die temperature in degrees Celsius. -func (d Device) ReadTemperature() (temp int8) { +// ReadTemperature reads and returns the current die temperature in +// celsius milli degrees (ºC/1000). +func (d Device) ReadTemperature() (int32, error) { data := make([]byte, 1) d.bus.ReadRegister(uint8(d.Address), DIE_TEMP, data) - return int8(data[0]) + return int32(data[0]) * 1000, nil }