1
0
Fork 0
mirror of https://github.com/kidoman/embd synced 2025-07-03 03:47:33 +02:00

simplify sign bit extraction and remove extraneous error check'

'
This commit is contained in:
Adam Bright 2016-09-26 02:29:10 +00:00
parent d938e007ff
commit afc8c08cff
2 changed files with 24 additions and 22 deletions

View file

@ -324,7 +324,8 @@ func convertWordToTempC(temp uint16) float64 {
tempRead := wholeNum + fraction
if !(temp&(1<<12) == 0) { // read sign bit
// read sign bit
if temp>>12 == 1 {
tempRead *= -1
}
return tempRead
@ -355,11 +356,7 @@ func (d *MCP9808) setTemp(reg byte, newTemp float64) error {
roundedFrac = 4
}
newTempWord := signBit + uint16(wholeNum)*16 + roundedFrac*4
if err := d.Bus.WriteWordToReg(address, reg, newTempWord); err != nil {
return err
}
return nil
return d.Bus.WriteWordToReg(address, reg, newTempWord)
}
// AmbientTemp reads the current sensor value along with the flags denoting what boundaries the