• Emdioh's avatar
    Correct negative results in DHT driver (#3210) · bf15299c
    Emdioh authored
    
    
    * DHT module: fix the handling of negative temps.
    
    The macro handling the conversion from the 2 bytes buffer to a double
    was handling negative values by checking the sign bit and taking the
    negative value of the number minus the sign bit.
    Unfortunately this does not work as the negative values are represented
    in 1's complement, so for instance -1 was becoming -32767
      * +1 = b0000_0000_0000_ 0001
      * -1 = 1111_1111_1111_1111
    
    This replace the spacial code with a signed 16 bits value.
    
    * Refactoring: removes some code duplication.
    
    * Fixed the conversion of the 8/16 bits values
    Co-authored-by: default avatarMarco Dondero <marco@dondero.eu>
    bf15299c
dht.c 8.22 KB