| Device-USB-PCSensor-HidTEMPer documentation | Contained in the Device-USB-PCSensor-HidTEMPer distribution. |
Device::USB::PCSensor::HidTEMPer::NTC::Internal - The HidTEMPerNTC internal sensor
Version 0.03
None
This is the implementation of the HidTEMPerNTC internal sensor.
The highest temperature(120 degrees celsius) this sensor can detect.
The lowest temperature(-40 degrees celsius) this sensor can detect.
Returns the current temperature from the device in celsius degrees.
Device::USB::PCSensor::HidTEMPer::Sensor
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.
Please report any bugs or missing features using the CPAN RT tool.
None
Magnus Sulland < msulland@cpan.org >
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 (c) 2010-2011 Magnus Sulland
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| 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;