Skip to content

Commit

Permalink
Fix float conversion issue
Browse files Browse the repository at this point in the history
  • Loading branch information
willgorman committed May 24, 2021
1 parent 8e7ed59 commit da43c27
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions govee.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ func decodeReading(a ble.Advertisement) (float32, float32, error) {
if err != nil {
return 0.0, 0.0, fmt.Errorf("parsing payload: %s", err)
}
humidity := float32((val % 1000) / 10) // TODO: doesn't seem to match iOS reading

humidity := float32(val%1000) / 10.0
if (val & 0x800000) != 0 {
return float32((val ^ 0x800000) / -10000), humidity, nil
return float32(val^0x800000) / -10000.0, humidity, nil
}

return float32(val / 10000), humidity, nil
return float32(val) / 10000.0, humidity, nil
}

0 comments on commit da43c27

Please sign in to comment.