Skip to content

Commit

Permalink
mag3110: change method name/signature for obtaining temperature to be…
Browse files Browse the repository at this point in the history
… uniform with other similar drivers

Signed-off-by: Ron Evans <ron@hybridgroup.com>
  • Loading branch information
deadprogram authored and aykevl committed May 3, 2019
1 parent 35a7590 commit b7fe897
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion examples/mag3110/main.go
Expand Up @@ -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)
}
}
7 changes: 4 additions & 3 deletions mag3110/mag3110.go
Expand Up @@ -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
}

0 comments on commit b7fe897

Please sign in to comment.