VVu

Member Since: May 3, 2011

Country: United States

  • # see: https://metacpan.org/pod/Device::Temperature::TMP102
    
    my $lsb = ( $value & 0xff00 );
    $lsb = $lsb >> 8;
    my $msb = $value & 0x00ff;
    
    my $temp = ( $msb << 8 ) | $lsb;
    
    # The TMP102 temperature registers are left justified, correctly
    # right justify them
    $temp = $temp >> 4;
    
    # test for negative numbers
    if ( $temp & ( 1 << 11 ) ) {
    
        # twos compliment plus one, per the docs
        $temp = ~$temp + 1;
    
        # keep only our 12 bits
        $temp &= 0xfff;
    
        # negative
        $temp *= -1;
    }
    
    # convert to a celsius temp value
    $temp = $temp / 16;
    

No public wish lists :(