Device::USB::PCSensor::HidTEMPer::NTC::Internal - The HidTEMPerNTC internal sensor


Device-USB-PCSensor-HidTEMPer documentation Contained in the Device-USB-PCSensor-HidTEMPer distribution.

Index


Code Index:

Top

Device::USB::PCSensor::HidTEMPer::NTC::Internal - The HidTEMPerNTC internal sensor

VERSION

Top

Version 0.03

SYNOPSIS

Top

None

DESCRIPTION

Top

This is the implementation of the HidTEMPerNTC internal sensor.

CONSTANTS

* MAX_TEMPERATURE

The highest temperature(120 degrees celsius) this sensor can detect.

* MIN_TEMPERATURE

The lowest temperature(-40 degrees celsius) this sensor can detect.

METHODS

* celsius()

Returns the current temperature from the device in celsius degrees.

INHERIT METHODS FROM

Top

Device::USB::PCSensor::HidTEMPer::Sensor

DEPENDENCIES

Top

This module internally includes and takes use of the following packages:

  use Device::USB::PCSensor::HidTEMPer::Sensor;

This module uses the strict and warning pragmas.

BUGS

Top

Please report any bugs or missing features using the CPAN RT tool.

FOR MORE INFORMATION

Top

None

AUTHOR

Top

Magnus Sulland < msulland@cpan.org >

ACKNOWLEDGEMENTS

Top

Thanks to Jean F. Delpech for the temperature fix that solves the problem with temperatures bellow 0 Celsius.

This code is inspired by Relavak's source code and the comments found at: http://relavak.wordpress.com/2009/10/17/

COPYRIGHT & LICENSE

Top


Device-USB-PCSensor-HidTEMPer documentation Contained in the Device-USB-PCSensor-HidTEMPer distribution.
package Device::USB::PCSensor::HidTEMPer::NTC::Internal;

use strict;
use warnings;

use Device::USB::PCSensor::HidTEMPer::Sensor;
our @ISA = 'Device::USB::PCSensor::HidTEMPer::Sensor';

our $VERSION = 0.03;

use constant MAX_TEMPERATURE    => 120;

use constant MIN_TEMPERATURE    => -40;

sub celsius
{
    my $self    = shift;
    my @data    = ();
    my $reading = 0;
    
    # Command 0x54 will return the following 8 byte result, repeated 4 times.
    # Position 0: Signed int returning the main temperature reading
    # Position 1: Unsigned int divided by 256 to give presision.
    # Position 2: unknown
    # Position 3: unused
    # Position 4: unused
    # Position 5: unused
    # Position 6: unused
    # Position 7: unused
    
    # First reading
    @data       = $self->{unit}->_read( 0x54 );
    $reading    = ($data[0] < 128) ? $data[0] + ( $data[1] / 256 ) : ($data[0] - 255) - ( $data[1] / 256 );    

    # Secound reading
    @data       = $self->{unit}->_read( 0x54 );
    $reading    += ($data[0] < 128) ? $data[0] + ( $data[1] / 256 ) : ($data[0] - 255) - ( $data[1] / 256 );   

    # Return the average, this adds precision
    return $reading / 2;
}

1;