mirror of
https://github.com/kidoman/embd
synced 2025-07-04 20:37:46 +02:00
fix rounding and precision when setting temperature
This commit is contained in:
parent
bb7032efe8
commit
c68eca29cc
1 changed files with 5 additions and 1 deletions
|
@ -322,7 +322,11 @@ func convertWordToTempC(temp uint16) float64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *MCP9808) setTemp(reg byte, newTemp float64) error {
|
func (d *MCP9808) setTemp(reg byte, newTemp float64) error {
|
||||||
return d.Bus.WriteWordToReg(address, reg, uint16(newTemp*16)&0x1fff)
|
rounder := 2.0
|
||||||
|
if newTemp < 0 {
|
||||||
|
rounder = 0.0
|
||||||
|
}
|
||||||
|
return d.Bus.WriteWordToReg(address, reg, uint16(newTemp*16+rounder)&0x1ffc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AmbientTemp reads the current sensor value along with the flags denoting what boundaries the
|
// AmbientTemp reads the current sensor value along with the flags denoting what boundaries the
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue