Commits

Anonymous committed 271c72e

Fixed calculation of the negative temperature (for DS18B20)

Comments (0)

Files changed (1)

             data = [TMTouchByte(self._handle, 0xFF) for i in range(9)]
             temp = ((0x07 & data[1]) << 4) + ((0xF0 & data[0]) >> 4) + (((0x08 & data[0]) >> 3) * 0.5) + (((0x04 & data[0]) >> 2) * 0.25) + (((0x02 & data[0]) >> 1) * 0.125) + (((0x01 & data[0])) * 0.0625)
             if (0x08 & data[1]) == 0x08:
-                temp = -temp
+                temp = temp - 128  # Fixed calculation of the negative temperature
         return {'temperature': temp}
 
     def _read_DS2438(self, deviceId, enableWireLeveling=False):