Device-USB-PCSensor-HidTEMPer-0.04/000755 000766 000024 00000000000 11621747533 017103 5ustar00Magnusstaff000000 000000 Device-USB-PCSensor-HidTEMPer-0.04/Changes000644 000766 000024 00000002421 11621750550 020366 0ustar00Magnusstaff000000 000000 Revision history for Perl extension Device::USB::PCSensor::HidTEMPer 0.04 14 Aug 2011 - Support for new device added by Daniel Fahlgren (TEMPer2). 0.0302 02 Aug 2011 - Fixed CPAN upload of version 0.0301 (damaged archive). 0.0301 02 Aug 2011 - Removed syntactic sugar that only works with perl 5.10 and newer, thanks to Elan Ruusamäe for spotting and fixing the problems. 0.03 25 Jan 2011 - Added initialization of the devices. Thanks to Jeremy G for noticing that this was missing and providing a fix. - Added fix received from Jean F. Delpech making the device return temperatures bellow 0 Celsius correctly. 0.0201 28 Jul 2010 - Removed the misplaced Makefile from the tarball. - Cleaned up Changes. 0.02 26 Jul 2010 - Updated example in HidTEMPer.pm - Updated Makefile.PL - Updated README. - Updated Changes - Updated documentation in all files. - Removed the self->{devices}=() bug. - Removed Perl 5.10 dependencies. - Change license requirements to normal Perl license. - Removed the transform function, replaced with init to some extent. - Changed bug reporting actions to be used. - Added support for retrieval of a single device without using a array - Changed the function type() info identifier() 0.01 07 Feb 2010 (first release) - Original version. Device-USB-PCSensor-HidTEMPer-0.04/lib/000755 000766 000024 00000000000 11616047775 017656 5ustar00Magnusstaff000000 000000 Device-USB-PCSensor-HidTEMPer-0.04/LICENSE000644 000766 000024 00000000667 11521275454 020116 0ustar00Magnusstaff000000 000000 Copyright (c) 2010-2011 Magnus Sulland < msulland@cpan.org > This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OF ACCURACY OR COMPLETENESS OF ANY INFORMATION CONTAINED IN THE SOFTWARE OR IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Device-USB-PCSensor-HidTEMPer-0.04/Makefile.PL000755 000766 000024 00000001277 11517037005 021055 0ustar00Magnusstaff000000 000000 use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( NAME => 'Device::USB::PCSensor::HidTEMPer', VERSION_FROM => 'lib/Device/USB/PCSensor/HidTEMPer.pm', PREREQ_PM => { 'Device::USB' => "0.31", 'Device::USB::Device' => "0.29", 'Time::HiRes' => 0, 'Carp' => 0, }, AUTHOR => 'Magnus Sulland ', LICENSE => 'perl', ABSTRACT => 'Interface to the PCSensor HidTEMPer thermometers series.', test => {TESTS => 't/*.t'}, ); Device-USB-PCSensor-HidTEMPer-0.04/MANIFEST000644 000766 000024 00000001123 11621750626 020226 0ustar00Magnusstaff000000 000000 Changes LICENSE Makefile.PL MANIFEST README lib/Device/USB/PCSensor/HidTEMPer.pm lib/Device/USB/PCSensor/HidTEMPer/Device.pm lib/Device/USB/PCSensor/HidTEMPer/Sensor.pm lib/Device/USB/PCSensor/HidTEMPer/NTC.pm lib/Device/USB/PCSensor/HidTEMPer/NTC/External.pm lib/Device/USB/PCSensor/HidTEMPer/NTC/Internal.pm lib/Device/USB/PCSensor/HidTEMPer/TEMPer.pm lib/Device/USB/PCSensor/HidTEMPer/TEMPer/Internal.pm lib/Device/USB/PCSensor/HidTEMPer/TEMPer2.pm lib/Device/USB/PCSensor/HidTEMPer/TEMPer2/Internal.pm lib/Device/USB/PCSensor/HidTEMPer/TEMPer2/External.pm t/device.t t/hidtemper.t t/sensor.tDevice-USB-PCSensor-HidTEMPer-0.04/README000644 000766 000024 00000003535 11621746131 017762 0ustar00Magnusstaff000000 000000 Device-USB-PCSensor-HidTEMPer version 0.04 ========================================== This module contains an interface to the PCSensor HidTEMPer and PCSensor HidTEMPerNTC temperature sensors. There are also the common functions for the device itself (Device) and the sensors (Sensor) laying the grounds for other HidTEMPer versions to be added later on. The current temperature can be returned either using the Celsius scale or the Fahrenheit scale. WARNING The results returned from this code needs to undergo more testing. If the code used to write to the device is not used with extreme care it may destroy the device. TODO Please contact me if you find anything to be missing. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This modules uses the following other modules: use Carp use Device::USB use Device::USB::Device use Time::HiRes qw / sleep / This module uses the strict and warning pragmas. DEVICE COMMANDS Get information from the device: Command: 0x52 Returns 8 bytes of interest: 1) Unknown 2) Device ID 3) Inner calibration 4) Inner calibration 5) Outer calibration 6) Outer calibration 7) unknown 8) unknown Command: 0x61 Set gain value, the command equals the gain to be set, 0x61, 0x62....0x68 Command: 0x53 or 0x54 depending on device and sensor Returns 3 bytes of value 1) Primary value 2) Decimal value 3) unknown Command: 0x41 Returns 3 bytes of value 1) Part one of the float number 2) Part two of the float number 3) Part three of the float number Command: 0x43 Set configuration of the device to 0 ACKNOWLEDGEMENTS Thanks to Daniel Fahlgren for updating different commands. COPYRIGHT AND LICENSE 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-0.04/t/000755 000766 000024 00000000000 11614745227 017346 5ustar00Magnusstaff000000 000000 Device-USB-PCSensor-HidTEMPer-0.04/t/device.t000644 000766 000024 00000000570 11517037005 020762 0ustar00Magnusstaff000000 000000 use Test::Simple tests => 3; use Device::USB::PCSensor::HidTEMPer::Device; ok( Device::USB::PCSensor::HidTEMPer::Device::CONNECTION_TIMEOUT eq 60, 'CONNECTION_TIMEOUT'); ok( !defined(Device::USB::PCSensor::HidTEMPer::Device::_write( undef, 0x69 )), 'Upper write limit' ); ok( !defined(Device::USB::PCSensor::HidTEMPer::Device::_write( undef, 0x60 )), 'Lower write limit' ); Device-USB-PCSensor-HidTEMPer-0.04/t/hidtemper.t000644 000766 000024 00000000462 11517037005 021504 0ustar00Magnusstaff000000 000000 use Test::Simple tests => 3; use Device::USB::PCSensor::HidTEMPer; ok(Device::USB::PCSensor::HidTEMPer::VENDOR_ID eq 0x1130, 'VENDOR_ID'); ok(Device::USB::PCSensor::HidTEMPer::PRODUCT_ID eq 0x660c, 'PRODUCT_ID'); my $pcsensor = Device::USB::PCSensor::HidTEMPer->new(); ok( defined($pcsensor), 'new()');Device-USB-PCSensor-HidTEMPer-0.04/t/sensor.t000644 000766 000024 00000000734 11517037005 021036 0ustar00Magnusstaff000000 000000 use Test::Simple tests => 6; use Device::USB::PCSensor::HidTEMPer::Sensor; ok( Device::USB::PCSensor::HidTEMPer::Sensor::MAX_TEMPERATURE eq 0, "MAX_TEMPERATURE"); ok( Device::USB::PCSensor::HidTEMPer::Sensor::MIN_TEMPERATURE eq 0, "MIN_TEMPERATURE"); $sensor = Device::USB::PCSensor::HidTEMPer::Sensor->new( undef ); ok( defined($sensor), 'new()'); ok( $sensor->fahrenheit() == 32, 'fahrenheit()' ); ok ( $sensor->min() == 0, 'min()'); ok ( $sensor->max() == 0, 'max()');Device-USB-PCSensor-HidTEMPer-0.04/lib/Device/000755 000766 000024 00000000000 11616047775 021055 5ustar00Magnusstaff000000 000000 Device-USB-PCSensor-HidTEMPer-0.04/lib/Device/USB/000755 000766 000024 00000000000 11616047775 021506 5ustar00Magnusstaff000000 000000 Device-USB-PCSensor-HidTEMPer-0.04/lib/Device/USB/PCSensor/000755 000766 000024 00000000000 11621745644 023176 5ustar00Magnusstaff000000 000000 Device-USB-PCSensor-HidTEMPer-0.04/lib/Device/USB/PCSensor/HidTEMPer/000755 000766 000024 00000000000 11621747530 024713 5ustar00Magnusstaff000000 000000 Device-USB-PCSensor-HidTEMPer-0.04/lib/Device/USB/PCSensor/HidTEMPer.pm000755 000766 000024 00000011417 11621747737 025271 0ustar00Magnusstaff000000 000000 package Device::USB::PCSensor::HidTEMPer; use strict; use warnings; use Device::USB; use Device::USB::PCSensor::HidTEMPer::Device; use Device::USB::PCSensor::HidTEMPer::NTC; use Device::USB::PCSensor::HidTEMPer::TEMPer; use Device::USB::PCSensor::HidTEMPer::TEMPer2; =head1 NAME Device::USB::PCSensor::HidTEMPer - Device overview =head1 VERSION Version 0.04 =cut our $VERSION = 0.04; =head1 SYNOPSIS Shared code: use Device::USB::PCSensor::HidTEMPer; my $pcsensor = Device::USB::PCSensor::HidTEMPer->new(); Single-device systems: my $device = $pcsensor->device(); print $device->external()->fahrenheit() if defined $device->external(); Multi-device systems: my @devices = $pcsensor->list_devices(); foreach my $device ( @devices ){ print $device->internal()->celsius() if defined $device->internal(); } =head1 DESCRIPTION This module is a simplified interface to the HidTEMPer thermometers created by PCSensor. It hides any problems recognizing the correct objects to initialize and the dependency on Device::USB. Use of the connected thermometers can be done by either creating a array of objects if multiple devices are connected, or the function device() if only one device is present. One example of its usage can be found in the Linux Journal August 2010, "Cool Projects edition" page 32-34. =head2 CONSTANTS The following constants are declared =over 3 =item * PRODUCT_ID Contains the hex value of the product id on the usb chip, in this case 0x660c =cut use constant PRODUCT_ID => 0x660c; =item * VENDOR_ID Contains the hex value representing the manufacturer of the chip, in this case "Tenx Technology, Inc." =cut use constant VENDOR_ID => 0x1130; =item * SUPPORTED_DEVICES Contains the mapping between name and identifiers for all supported thermometers. Hex value Product Internal sensor External sensor 0x5b HidTEMPerNTC Yes Yes 0x58 HidTEMPer Yes No 0x59 HidTEMPer2 Yes Yes =back =cut use constant SUPPORTED_DEVICES => { 0x5b => { 'name' => 'HidTEMPerNTC', 'module' => 'Device::USB::PCSensor::HidTEMPer::NTC' }, 0x58 => { 'name' => 'HidTEMPer', 'module' => 'Device::USB::PCSensor::HidTEMPer::TEMPer' }, 0x59 => { 'name' => 'HidTEMPer2', 'module' => 'Device::USB::PCSensor::HidTEMPer::TEMPer2' } }; =head2 METHODS =over 3 =item * new() Initialize the system, and the USB-connection to be used. =cut sub new { my $class = shift; my $self = { 'usb' => Device::USB->new() }; return bless $self, $class; } =item * device() Return a single thermometer instance. ONLY to be used in systems using a single thermometer device. Returns undef if no devices was found. =cut sub device { my $self = shift; my $device = $self->{usb}->find_device( VENDOR_ID, PRODUCT_ID ); return undef unless defined $device; return _init_device($device); } =item * list_devices() Returns an array of recognized thermometer instances if an array value is expected, otherwise it returns a scalar with the number of devices found. =cut sub list_devices { my $self = shift; my @list = (); @list = grep( defined($_), map( _init_device($_), $self->{usb}->list_devices( VENDOR_ID, PRODUCT_ID ))); return wantarray() ? return @list : scalar @list; } # This functions detects the correct object to be created and returned. # Returns undef if not supported device was found. sub _init_device { my $prototype = Device::USB::PCSensor::HidTEMPer::Device->new( $_[0] ); my $parameters = SUPPORTED_DEVICES->{$prototype->identifier()}; return undef unless defined $parameters; bless $prototype, $parameters->{module}; return $prototype->init(); } =back =head1 DEPENDENCIES This module internally includes and takes use of the following packages: use Device::USB; use Device::USB::PCSensor::HidTEMPer::Device; use Device::USB::PCSensor::HidTEMPer::NTC; use Device::USB::PCSensor::HidTEMPer::TEMPer; use Device::USB::PCSensor::HidTEMPer::TEMPer2; This module uses the strict and warning pragmas. =head1 BUGS Please report any bugs or missing features using the CPAN RT tool. =head1 FOR MORE INFORMATION None =head1 AUTHOR Magnus Sulland < msulland@cpan.org > =head1 ACKNOWLEDGEMENTS Thanks to Elan Ruusamäe for fixing some compatibility issues with perl 5.8. Thanks to Daniel Fahlgren for adding the TEMPer2 device. =head1 COPYRIGHT & LICENSE 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. =cut 1; Device-USB-PCSensor-HidTEMPer-0.04/lib/Device/USB/PCSensor/HidTEMPer/Device.pm000755 000766 000024 00000021602 11521275454 026454 0ustar00Magnusstaff000000 000000 package Device::USB::PCSensor::HidTEMPer::Device; use strict; use warnings; use Carp; =head1 Device::USB::PCSensor::HidTEMPer::Device - Generic device class =head1 VERSION Version 0.02 =cut our $VERSION = 0.02; =head1 SYNOPSIS None =head1 DESCRIPTION This module contains a generic class that all HidTEMPer devices should inherit from, thereby keeping the implemented methods consistent and making it possible to use the same code to contact every supported device. =head2 CONSTANTS =over 3 =item * CONNECTION_TIMEOUT USB communication timeout, specified in milliseconds. =back =cut use constant CONNECTION_TIMEOUT => 60; =head2 METHODS =over 3 =item * new( $usb_device ) Creates a new generic Device object. =cut sub new { my $class = shift; my ( $usb ) = @_; # Device::USB::Device interface that should be used # Make sure that this is always a reference to the device. $usb = ref $usb ? $usb : \$usb; my $self = { device => $usb, }; # Possible sensors $self->{sensor} = { internal => undef, external => undef, }; # If the two interfaces are currently in use, detach them and thereby # make them available for use. $usb->detach_kernel_driver_np(0) if $usb->get_driver_np(0); $usb->detach_kernel_driver_np(1) if $usb->get_driver_np(1); # Opens the device for use by this object. croak 'Error opening device' unless $usb->open(); # It is only needed to set the configuration used under a Windows system. $usb->set_configuration(1) if $^O eq 'MSWin32'; # Claim the two interfaces for use by this object. croak 'Could not claim interface' if $usb->claim_interface(0); croak 'Could not claim interface' if $usb->claim_interface(1); bless $self, $class; return $self; } sub DESTROY { my $self = shift; # Delete sensors delete $self->{sensor}->{internal}; delete $self->{sensor}->{external}; # Release the interfaces back to the operating system. $self->{device}->release_interface(0); $self->{device}->release_interface(1); delete $self->{device}; return undef; } =item * identifier() This method is used to acquire the numerical value representing the device type identifier. =cut sub identifier { my $self = shift; # Command 0x52 will return the following 8 byte result, repeated 4 times. # Position 0: unknown # Position 1: Device ID # Position 2: Calibration value one for the internal sensor # Position 3: Calibration value two for the internal sensor # Position 4: Calibration value one for the external sensor # Position 5: Calibration value two for the external sensor # Position 6: unknown # Position 7: unknown my ( undef, $identifier ) = $self->_read( 0x52 ); return $identifier; } # _read( @command_bytes ) # Used to read information from the device. # Input parameter # @command_bytes = Array of 8 bit hex values, maximum of 32 bytes, # representing the commands that will be executed by the device. # Output parameter # An array of 8 bit hex values or a text string using chars # (from 0x00 to 0xFF) to represent the hex values. Returns undef on error. sub _read { my $self = shift; my ( @bytes ) = @_; my ( $data, $checksum ) = ( 0, 0 ); $checksum += $self->_command(32, 0xA, 0xB, 0xC, 0xD, 0x0, 0x0, 0x2 ); $checksum += $self->_command(32, @bytes ); $checksum += $self->_command(32, 0x0 ); $checksum += $self->_command(32, 0x0 ); $checksum += $self->_command(32, 0x0 ); $checksum += $self->_command(32, 0x0 ); $checksum += $self->_command(32, 0x0 ); $checksum += $self->_command(32, 0x0 ); $checksum += $self->_command(32, 0x0 ); $checksum += $self->_command(32, 0xA, 0xB, 0xC, 0xD, 0x0, 0x0, 0x1 ); # On error a wrong amount of bytes is returened. carp 'The device returned to few bytes' if $checksum < 320; carp 'The device returned to many bytes' if $checksum > 320; return undef if $checksum != 320; # Send a message to the device, capturing the output into into $data $checksum = $self->{device}->control_msg( 0xA1, # Request type 0x1, # Request 0x300, # Value 0x1, # Index $data, # Bytes to be transfeered 32, # Number of bytes to be transferred, more than 32 eq seg fault CONNECTION_TIMEOUT # Timeout ); # Ensure that 32 bytes are read from the device. carp 'Error reading information from device' if $checksum != 32; return wantarray ? unpack "C*", $data : $data; } # _command( $total_byte_size, @data ) # This method is used to send a command to the device, only used for commands # where the output is not needed to be captured. # Input parameters # $total_byte_size = The total size that should be sent. Zero padding will be # added at the end to achieve specified length. # @data = An array of 8bit hex values representing the data that # should be sent. # Output parameter # Returns the number of bytes that where sent to the device if successful # execution. This is the same amout of bytes that where specified as input. # Returns undef on error. sub _command { my $self = shift; my ( $size, @bytes ) = @_; # Convert to char and add zero padding at the end my $data = join '', map{ chr $_ } @bytes; $data .= join '', map{ chr $_ } ( (0)x( $size - $#bytes ) ); # Send the message to the device my $return = $self->{device}->control_msg( 0x21, # Request type 0x9, # Request 0x200, # Value 0x1, # Index $data, # Bytes to be transferred $size, # Number of bytes to be transferred CONNECTION_TIMEOUT # Timeout ); # If the device returns correct amount of bytes return count, all OK. return $return if $return == $size; carp 'The device return less bytes than anticipated' if $return < $size; carp 'The device returned more bytes than anticipated' if $return > $size; return undef; } # _write( @bytes ) # This method is used to write information back to the device. Be carefull # when using this, since any wrong information sent may destroy the device. # Input parameter # @bytes = The bytes that should be written to the device, a maximum of # 32 bytes. # Output parameter # Returns the number of bytes that where sent to the device if successful # execution. This should be 288 if everything is successful. sub _write { my $self = shift; my ( @bytes ) = @_; my ( $data, $checksum ) = ( 0, 0 ); # Filter out possible actions return undef if $bytes[0] > 0x68 || $bytes[0] < 0x61; $checksum += $self->_command(32, 0xA, 0xB, 0xC, 0xD, 0x0, 0x0, 0x2 ); $checksum += $self->_command(32, @bytes ); $checksum += $self->_command(32, 0x0 ); $checksum += $self->_command(32, 0x0 ); $checksum += $self->_command(32, 0x0 ); $checksum += $self->_command(32, 0x0 ); $checksum += $self->_command(32, 0x0 ); $checksum += $self->_command(32, 0x0 ); $checksum += $self->_command(32, 0x0 ); # On error a wrong amount of bytes is returened. carp 'The device returned to few bytes' if $checksum < 288; carp 'The device returned to many bytes' if $checksum > 288; return undef if $checksum != 288; return $checksum; } =item * internal() Returns the corresponding Sensor object representing the internal sensor connected to the device. If the device does not have an internal sensor undef is returned. =cut sub internal { return $_[0]->{sensor}->{internal}; } =item * external() Returns the corresponding Sensor object representing the external sensor connected to the device. If the device does not have an external sensor undef is returned. =cut sub external { return $_[0]->{sensor}->{external}; } =item * init() Empty method that should be implemented in order to be able to initialize a object instance. =cut sub init { return undef; } =back =head1 DEPENDENCIES This module internally includes and takes use of the following packages: use Carp; use Device::USB; use Device::USB::Device; This module uses the strict and warning pragmas. =head1 BUGS Please report any bugs or missing features using the CPAN RT tool. =head1 FOR MORE INFORMATION None =head1 AUTHOR Magnus Sulland < msulland@cpan.org > =head1 ACKNOWLEDGEMENTS None =head1 COPYRIGHT & LICENSE 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. =cut 1; Device-USB-PCSensor-HidTEMPer-0.04/lib/Device/USB/PCSensor/HidTEMPer/NTC/000755 000766 000024 00000000000 11614745227 025342 5ustar00Magnusstaff000000 000000 Device-USB-PCSensor-HidTEMPer-0.04/lib/Device/USB/PCSensor/HidTEMPer/NTC.pm000755 000766 000024 00000003774 11521275454 025713 0ustar00Magnusstaff000000 000000 package Device::USB::PCSensor::HidTEMPer::NTC; use strict; use warnings; use Device::USB::PCSensor::HidTEMPer::Device; use Device::USB::PCSensor::HidTEMPer::NTC::Internal; use Device::USB::PCSensor::HidTEMPer::NTC::External; our @ISA = 'Device::USB::PCSensor::HidTEMPer::Device'; =head1 Device::USB::PCSensor::HidTEMPer::NTC - The HidTEMPerNTC thermometer =head1 VERSION Version 0.03 =cut our $VERSION = 0.03; =head1 SYNOPSIS None =head1 DESCRIPTION This is the implementation of the HidTEMPerNTC thermometer that has both one internal and one external sensor measuring the temperature. =head2 CONSTANTS None =head2 METHODS =over 3 =item * init() Initialize the device, connects the sensors and makes the object ready for use. =cut sub init { my $self = shift; # Add sensor references to this instance $self->{sensor}->{internal} = Device::USB::PCSensor::HidTEMPer::NTC::Internal->new( $self ); $self->{sensor}->{external} = Device::USB::PCSensor::HidTEMPer::NTC::External->new( $self ); # Set configuration $self->_write(0x43); # Rebless bless $self, 'Device::USB::PCSensor::HidTEMPer::NTC'; } sub DESTROY { $_[0]->SUPER::DESTROY; } =back =head1 INHERIT METHODS FROM Device::USB::PCSensor::HidTEMPer::Device =head1 DEPENDENCIES This module internally includes and takes use of the following packages: use Device::USB::PCSensor::HidTEMPer::Device; use Device::USB::PCSensor::HidTEMPer::NTC::Internal; use Device::USB::PCSensor::HidTEMPer::NTC::External; This module uses the strict and warning pragmas. =head1 BUGS Please report any bugs or missing features using the CPAN RT tool. =head1 FOR MORE INFORMATION None =head1 AUTHOR Magnus Sulland < msulland@cpan.org > =head1 ACKNOWLEDGEMENTS Thanks to Jeremy G for the fix on initializing the device configuration. =head1 COPYRIGHT & LICENSE 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. =cut 1; Device-USB-PCSensor-HidTEMPer-0.04/lib/Device/USB/PCSensor/HidTEMPer/Sensor.pm000755 000766 000024 00000005275 11616052110 026521 0ustar00Magnusstaff000000 000000 package Device::USB::PCSensor::HidTEMPer::Sensor; use strict; use warnings; use Scalar::Util qw/ weaken /; =head1 Device::USB::PCSensor::HidTEMPer::Sensor - Generic sensor class =head1 VERSION Version 0.0301 =cut our $VERSION = 0.0301; =head1 SYNOPSIS None =head1 DESCRIPTION This module contains a generic class that all HidTEMPer sensors should inherit from keeping the implemented methods consistent, and making it possible to use the same code to contact every supported device. =head2 CONSTANTS =over 3 =item * MAX_TEMPERATURE The highest temperature(Celsius) this sensor can detect. =cut use constant MAX_TEMPERATURE => 0; =item * MIN_TEMPERATURE The lowest temperature(Celsius) this sensor can detect. =back =cut use constant MIN_TEMPERATURE => 0; =head2 METHODS =over 3 =item * new( $device ) Generic initializing method, creating a sensor object. Input parameter $device = A pre-initialized Device::USB::PCSensor::HidTEMPer::Device that the sensor is connected to. This device will be used to handle communication. =cut sub new { my $class = shift; my ( $unit ) = @_; # All devices are required to spesify the temperature range my $self = { unit => $unit, }; weaken $self->{unit}; bless $self, $class; return $self; } =item * fahrenheit() Reads the current temperature and returns the corresponding value in fahrenheit degrees. =cut sub fahrenheit { my $self = shift; my $celsius = $self->celsius(); $celsius = 0 unless defined $celsius; # Calculate and return the newly created degrees return ( ( $celsius * 9 ) / 5 ) + 32; } =item * max() Returns the highest temperature(Celsius) the sensor can detect. =cut sub max { return $_[0]->MAX_TEMPERATURE; } =item * min() Returns the lowest temperature(Celsius) the sensor can detect. =cut sub min { return $_[0]->MIN_TEMPERATURE; } =item * celsius() Empty method that should be implemented in each sensor, returing the current degrees in celsius. =cut sub celsius { return undef; } =back =head1 DEPENDENCIES This module internally includes and takes use of the following packages: use Scalar::Util qw/ weaken /; This module uses the strict and warning pragmas. =head1 BUGS Please report any bugs or missing features using the CPAN RT tool. =head1 FOR MORE INFORMATION None =head1 AUTHOR Magnus Sulland < msulland@cpan.org > =head1 ACKNOWLEDGEMENTS Thanks to Elan Ruusamäe for fixing some compatibility issues with perl 5.8 =head1 COPYRIGHT & LICENSE 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. =cut 1; Device-USB-PCSensor-HidTEMPer-0.04/lib/Device/USB/PCSensor/HidTEMPer/TEMPer/000755 000766 000024 00000000000 11614745227 026012 5ustar00Magnusstaff000000 000000 Device-USB-PCSensor-HidTEMPer-0.04/lib/Device/USB/PCSensor/HidTEMPer/TEMPer.pm000755 000766 000024 00000003653 11521275454 026357 0ustar00Magnusstaff000000 000000 package Device::USB::PCSensor::HidTEMPer::TEMPer; use strict; use warnings; use Device::USB::PCSensor::HidTEMPer::Device; use Device::USB::PCSensor::HidTEMPer::TEMPer::Internal; our @ISA = 'Device::USB::PCSensor::HidTEMPer::Device'; =head1 Device::USB::PCSensor::HidTEMPer::TEMPer - The HidTEMPer thermometer =head1 VERSION Version 0.03 =cut our $VERSION = 0.03; =head1 SYNOPSIS None =head1 DESCRIPTION This is the implementation of the HidTEMPer thermometer that have only one internal sensor measuring the temperature. It is important to notice that the TEMPer device with one external sensor will not function, although being recognized correctly. =head2 CONSTANTS None =head2 METHODS =over 3 =item * init() Initialize the device, connects the sensors and makes the object ready for use. =cut sub init { my $self = shift; # Add sensor references to this instance $self->{sensor}->{internal} = Device::USB::PCSensor::HidTEMPer::TEMPer::Internal->new( $self ); # Set configuration $self->_write(0x43); # Rebless bless $self, 'Device::USB::PCSensor::HidTEMPer::TEMPer'; } sub DESTROY { $_[0]->SUPER::DESTROY(); } =back =head1 INHERIT METHODS FROM Device::USB::PCSensor::HidTEMPer::Device =head1 DEPENDENCIES This module internally includes and takes use of the following packages: use Device::USB::PCSensor::HidTEMPer::Device; use Device::USB::PCSensor::HidTEMPer::TEMPer::Internal; This module uses the strict and warning pragmas. =head1 BUGS Please report any bugs or missing features using the CPAN RT tool. =head1 FOR MORE INFORMATION None =head1 AUTHOR Magnus Sulland < msulland@cpan.org > =head1 ACKNOWLEDGEMENTS Thanks to Jeremy G for the fix on initializing the device configuration. =head1 COPYRIGHT & LICENSE 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. =cut 1; Device-USB-PCSensor-HidTEMPer-0.04/lib/Device/USB/PCSensor/HidTEMPer/TEMPer2/000755 000766 000024 00000000000 11621747525 026075 5ustar00Magnusstaff000000 000000 Device-USB-PCSensor-HidTEMPer-0.04/lib/Device/USB/PCSensor/HidTEMPer/TEMPer2.pm000644 000766 000024 00000004072 11621750013 026420 0ustar00Magnusstaff000000 000000 package Device::USB::PCSensor::HidTEMPer::TEMPer2; use strict; use warnings; use Device::USB::PCSensor::HidTEMPer::Device; use Device::USB::PCSensor::HidTEMPer::TEMPer2::Internal; use Device::USB::PCSensor::HidTEMPer::TEMPer2::External; our @ISA = 'Device::USB::PCSensor::HidTEMPer::Device'; =head1 Device::USB::PCSensor::HidTEMPer::TEMPer2 - The HidTEMPer2 thermometer =head1 VERSION Version 0.01 =cut our $VERSION = 0.01; =head1 SYNOPSIS None =head1 DESCRIPTION This is the implementation of the HidTEMPer2 thermometer that has both one internal and one external sensor measuring the temperature. =head2 CONSTANTS None =head2 METHODS =over 3 =item * init() Initialize the device, connects the sensors and makes the object ready for use. =cut sub init { my $self = shift; # Add sensor references to this instance $self->{sensor}->{internal} = Device::USB::PCSensor::HidTEMPer::TEMPer2::Internal->new( $self ); $self->{sensor}->{external} = Device::USB::PCSensor::HidTEMPer::TEMPer2::External->new( $self ); # Set configuration $self->_write(0x43); # Rebless bless $self, 'Device::USB::PCSensor::HidTEMPer::TEMPer2'; } sub DESTROY { $_[0]->SUPER::DESTROY(); } =back =head1 INHERIT METHODS FROM Device::USB::PCSensor::HidTEMPer::Device =head1 DEPENDENCIES This module internally includes and takes use of the following packages: use Device::USB::PCSensor::HidTEMPer::Device; use Device::USB::PCSensor::HidTEMPer::TEMPer2::Internal; use Device::USB::PCSensor::HidTEMPer::TEMPer2::External; This module uses the strict and warning pragmas. =head1 BUGS Please report any bugs or missing features using the CPAN RT tool. =head1 FOR MORE INFORMATION None =head1 AUTHOR Daniel Fahlgren (Based on code by Magnus Sulland < msulland@cpan.org >) =head1 ACKNOWLEDGEMENTS Thanks to Jeremy G for the fix on initializing the device configuration. =head1 COPYRIGHT & LICENSE 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. =cut 1; Device-USB-PCSensor-HidTEMPer-0.04/lib/Device/USB/PCSensor/HidTEMPer/TEMPer2/External.pm000644 000766 000024 00000005256 11621750257 030221 0ustar00Magnusstaff000000 000000 package Device::USB::PCSensor::HidTEMPer::TEMPer2::External; use strict; use warnings; use Device::USB::PCSensor::HidTEMPer::Sensor; our @ISA = 'Device::USB::PCSensor::HidTEMPer::Sensor'; =head1 Device::USB::PCSensor::HidTEMPer::TEMPer2::Internal - The HidTEMPer2 external sensor =head1 VERSION Version 0.01 =cut our $VERSION = 0.01; =head1 SYNOPSIS None =head1 DESCRIPTION This is the implementation of the HidTEMPer2 external sensor. =head2 CONSTANTS =over 3 =item * MAX_TEMPERATURE The highest temperature(120 degrees celsius) this sensor can detect. =cut use constant MAX_TEMPERATURE => 120; =item * MIN_TEMPERATURE The lowest temperature(-40 degrees celsius) this sensor can detect. =back =cut use constant MIN_TEMPERATURE => -40; =head2 METHODS =over 3 =item * celsius() Returns the current temperature from the device in celsius degrees. =cut 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( 0x53 ); $reading = ($data[0] < 128) ? $data[0] + ( $data[1] / 256 ) : ($data[0] - 255) - ( $data[1] / 256 ); # Secound reading @data = $self->{unit}->_read( 0x53 ); $reading += ($data[0] < 128) ? $data[0] + ( $data[1] / 256 ) : ($data[0] - 255) - ( $data[1] / 256 ); # Return the average, this adds precision return $reading / 2; } =back =head1 INHERIT METHODS FROM Device::USB::PCSensor::HidTEMPer::Sensor =head1 DEPENDENCIES 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. =head1 BUGS Please report any bugs or missing features using the CPAN RT tool. =head1 FOR MORE INFORMATION None =head1 AUTHOR Daniel Fahlgren (Based on code by Magnus Sulland < msulland@cpan.org >) =head1 ACKNOWLEDGEMENTS 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/ temper-temperature-sensor-linux-driver/ =head1 COPYRIGHT & LICENSE 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. =cut 1; Device-USB-PCSensor-HidTEMPer-0.04/lib/Device/USB/PCSensor/HidTEMPer/TEMPer2/Internal.pm000644 000766 000024 00000005256 11621750201 030200 0ustar00Magnusstaff000000 000000 package Device::USB::PCSensor::HidTEMPer::TEMPer2::Internal; use strict; use warnings; use Device::USB::PCSensor::HidTEMPer::Sensor; our @ISA = 'Device::USB::PCSensor::HidTEMPer::Sensor'; =head1 Device::USB::PCSensor::HidTEMPer::TEMPer2::Internal - The HidTEMPer2 internal sensor =head1 VERSION Version 0.01 =cut our $VERSION = 0.01; =head1 SYNOPSIS None =head1 DESCRIPTION This is the implementation of the HidTEMPer2 internal sensor. =head2 CONSTANTS =over 3 =item * MAX_TEMPERATURE The highest temperature(120 degrees celsius) this sensor can detect. =cut use constant MAX_TEMPERATURE => 120; =item * MIN_TEMPERATURE The lowest temperature(-40 degrees celsius) this sensor can detect. =back =cut use constant MIN_TEMPERATURE => -40; =head2 METHODS =over 3 =item * celsius() Returns the current temperature from the device in celsius degrees. =cut 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; } =back =head1 INHERIT METHODS FROM Device::USB::PCSensor::HidTEMPer::Sensor =head1 DEPENDENCIES 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. =head1 BUGS Please report any bugs or missing features using the CPAN RT tool. =head1 FOR MORE INFORMATION None =head1 AUTHOR Daniel Fahlgren (Based on code by Magnus Sulland < msulland@cpan.org >) =head1 ACKNOWLEDGEMENTS 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/ temper-temperature-sensor-linux-driver/ =head1 COPYRIGHT & LICENSE 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. =cut 1; Device-USB-PCSensor-HidTEMPer-0.04/lib/Device/USB/PCSensor/HidTEMPer/TEMPer/Internal.pm000755 000766 000024 00000005206 11521275454 030127 0ustar00Magnusstaff000000 000000 package Device::USB::PCSensor::HidTEMPer::TEMPer::Internal; use strict; use warnings; use Device::USB::PCSensor::HidTEMPer::Sensor; our @ISA = 'Device::USB::PCSensor::HidTEMPer::Sensor'; =head1 Device::USB::PCSensor::HidTEMPer::TEMPer::Internal - The HidTEMPer internal sensor =head1 VERSION Version 0.03 =cut our $VERSION = 0.03; =head1 SYNOPSIS None =head1 DESCRIPTION This is the implementation of the HidTEMPer internal sensor. =head2 CONSTANTS =over 3 =item * MAX_TEMPERATURE The highest temperature(120 degrees celsius) this sensor can detect. =cut use constant MAX_TEMPERATURE => 120; =item * MIN_TEMPERATURE The lowest temperature(-40 degrees celsius) this sensor can detect. =back =cut use constant MIN_TEMPERATURE => -40; =head2 METHODS =over 3 =item * celsius() Returns the current temperature from the device in celsius degrees. =cut 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; } =back =head1 INHERIT METHODS FROM Device::USB::PCSensor::HidTEMPer::Sensor =head1 DEPENDENCIES 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. =head1 BUGS Please report any bugs or missing features using the CPAN RT tool. =head1 FOR MORE INFORMATION None =head1 AUTHOR Magnus Sulland < msulland@cpan.org > =head1 ACKNOWLEDGEMENTS 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/ temper-temperature-sensor-linux-driver/ =head1 COPYRIGHT & LICENSE 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. =cut 1; Device-USB-PCSensor-HidTEMPer-0.04/lib/Device/USB/PCSensor/HidTEMPer/NTC/External.pm000755 000766 000024 00000025641 11521275454 027472 0ustar00Magnusstaff000000 000000 package Device::USB::PCSensor::HidTEMPer::NTC::External; use strict; use warnings; use Carp; use Time::HiRes qw / sleep /; use Device::USB::PCSensor::HidTEMPer::Sensor; our @ISA = 'Device::USB::PCSensor::HidTEMPer::Sensor'; =head1 Device::USB::PCSensor::HidTEMPer::NTC::Internal - The HidTEMPerNTC external sensor =head1 VERSION Version 0.02 =cut our $VERSION = 0.02; =head1 SYNOPSIS None =head1 DESCRIPTION This is the implementation of the HidTEMPerNTC external sensor. =head2 CONSTANTS =over 3 =item * MAX_TEMPERATURE The highest temperature(150 degrees celsius) this sensor can detect. =cut use constant MAX_TEMPERATURE => 150; =item * MIN_TEMPERATURE The lowest temperature(-50 degrees celsius) this sensor can detect. =cut use constant MIN_TEMPERATURE => -50; =item * INITIAL_GAIN The initial gain value used to calculate voltage returned =cut use constant INITIAL_GAIN => 1; =item * CALIBRATION_VALUES Values used to calculate Volt7705Calibration =cut use constant CALIBRATION_VALUES => [ [ 0.0010888, 0.0012803, 0.000754167, 0.0009208333 ], [ 0.0012803, 0.0017002, 0.0009208333, 0.0012541667 ], [ 0.0017002, 0.002666, 0.0012541667, 0.0021125 ], [ 0.002666, 0.00522, 0.0021125, 0.0041666667 ], [ 0.00522, 0.0149, 0.0041666667, 0.012625 ], [ 0.0149, 0.04683, 0.012625, 0.0413333333 ], [ 0.04683, 0.21342, 0.0413333333, 0.2115416667 ], [ 0.21342, 0.36914, 0.2115416667, 0.346166667 ], [ 0.36914, 0.44121, 0.346166667, 0.4215416667 ], [ 0.44121, 0.65351, 0.4215416667, 0.6208333333 ], [ 0.65351, 0.92445, 0.6208333333, 0.91625 ], [ 0.92445, 1.08022, 0.91625, 1.1375 ], [ 1.08022, 1.8745, 1.1375, 1.91375 ], [ 1.8745, 1.9943, 1.91375, 2.07125 ], [ 1.9943, 2.4589, 2.07125, 2.72125 ], ]; =back =head2 METHODS =over 3 =item * new() Returns a new External sensor object. =cut sub new { my $class = shift; # All devices are required to spesify the temperature range my $self = $class->SUPER::new( @_ ); # Initialize the gain, this will be automatically adjusted later on. $self->{gain} = INITIAL_GAIN; $self->_write_gain( $self->{gain} ); bless $self, $class; return $self; } =item * celsius() Returns the current temperature from the device in celsius degrees. =cut sub celsius { my $self = shift; my @data = (); my $counter = 0; my $volt = 0; my $key = 0; my $temperature = 0; # Command 0x41 will return the following 8 byte result, repeated 4 times. # Position 0: Part one of the float number # Position 1: Part two of the float number # Position 2: Part three of the float number # Position 3: unused # Position 4: unused # Position 5: unused # Position 6: unused # Position 7: unused # This device may return 255*8 until it is ready for use. @data = $self->{unit}->_read( 0x41 ); $counter = 0; READ: until ( $counter > 20 ){ next READ if $data[0] == 0xFF && $data[1] == 0xFF && $data[2] == 0xFF; # Caluculate returned reading $volt = ( ( ( $data[0]-128 ) + ( $data[1] / 256 ) ) / 52.032520325203252 ) / $self->{gain}; last READ if $self->_new_reading_needed( $volt ) == 0; }continue{ $counter++; sleep 0.2; @data = $self->{unit}->_read( 0x41 ); } croak 'Invalid readings returned' if $counter >= 21; # Calculate key $key = $self->_volt_7705_calibration( $volt ); =pod The formula used to calculate value based on a calibrated key value is created using the Eureqa tool from Cornell Computational Synthesis Lab, http://ccsl.mae.cornell.edu/eureqa. Resulting in the use of this formula instead of the provided number list: f(y)=66.7348/(66.7275/(67.8088 - 9.70353*log(0.000251309 + y*y)) - 0.21651) If you find another formula that is more accurate please drop me a line. The data used can be found in the source code of this file. =cut $temperature = 66.7348 / ( 66.7275 / ( 67.8088 - 9.70353 * log( 0.000251309 + ( $key * $key ) ) ) - 0.21651 ); return $temperature; } # Calculate Volt7705Calibration sub _volt_7705_calibration { my $self = shift; my ( $volt ) = @_; my $reference = undef; # Select the correct values needed if( $volt <= 0.0010888 ){ return -0.000334633; }elsif( $volt <= 0.0012803 ){ $reference = CALIBRATION_VALUES->[0]; }elsif( $volt <= 0.0017002 ){ $reference = CALIBRATION_VALUES->[1]; }elsif( $volt <= 0.002666 ){ $reference = CALIBRATION_VALUES->[2]; }elsif( $volt <= 0.00522 ){ $reference = CALIBRATION_VALUES->[3]; }elsif( $volt <= 0.0149 ){ $reference = CALIBRATION_VALUES->[4]; }elsif( $volt <= 0.04683 ){ $reference = CALIBRATION_VALUES->[5]; }elsif( $volt <= 0.21342 ){ $reference = CALIBRATION_VALUES->[6]; }elsif( $volt <= 0.36914 ){ $reference = CALIBRATION_VALUES->[7]; }elsif( $volt <= 0.44121 ){ $reference = CALIBRATION_VALUES->[8]; }elsif( $volt <= 0.65351 ){ $reference = CALIBRATION_VALUES->[9]; }elsif( $volt <= 0.92445 ){ $reference = CALIBRATION_VALUES->[10]; }elsif( $volt <= 1.08022 ){ $reference = CALIBRATION_VALUES->[11]; }elsif( $volt <= 1.8745 ){ $reference = CALIBRATION_VALUES->[12]; }elsif( $volt <= 1.9943 ){ $reference = CALIBRATION_VALUES->[13]; }elsif( $volt <= 2.4589 ){ $reference = CALIBRATION_VALUES->[14]; }else{ return 0.26235000000000008; } return ( ( $volt + ( ( ( ( $reference->[2] * $volt ) / $reference->[0] ) + ( ( ( ( $reference->[3] * $volt ) / $reference->[1] ) - ( ( $reference->[2] * $volt ) / $reference->[0] ) ) * ( ( $volt - $reference->[0] ) / ( $reference->[1] - $reference->[0] ) ) ) ) - $volt ) ) / 0.0000041666666666666669 ) / 1000; } # Returns 0 if the gain has not changed and a new reading is not needed. sub _new_reading_needed { my $self = shift; my ( $volt ) = @_; # Safety filters return 0 if ( $self->{gain} > 128 ) || ( $self->{gain} < 1 ); return 0 if $self->{gain} % 2 != 0; # Adjust gain if( !defined $volt ){ carp 'Undefined voltage'; }elsif( $volt > ( 2.214 / $self->{gain} ) ) { $self->{gain} = $self->{gain}*0.5; $self->_write_gain(); return -1; }elsif( $volt < ( 0.984 / $self->{gain} ) ) { $self->{gain} = $self->{gain}*2; $self->_write_gain(); return 1; }else{ return 0; } croak 'Could not recalculate gain'; } # Write gain value to device sub _write_gain { $_[0]->{unit}->_write( 0x61 + ( log( $_[0]->{gain} ) / log(2) ) ); sleep 0.2; $_[0]->{unit}->_write( 0x61 + ( log( $_[0]->{gain} ) / log(2) ) ); } =back =head1 INHERIT METHODS FROM Device::USB::PCSensor::HidTEMPer::Sensor =head1 DEPENDENCIES This module internally includes and takes use of the following packages: use Carp; use Time::HiRes qw / sleep /; use Device::USB::PCSensor::HidTEMPer::Sensor; This module uses the strict and warning pragmas. =head1 BUGS Please report any bugs or missing features using the CPAN RT tool. =head1 FOR MORE INFORMATION None =head1 AUTHOR Magnus Sulland < msulland@cpan.org > =head1 ACKNOWLEDGEMENTS This code includes findings done by Robin B. Jensen, http://www.drunkardswalk.dk, when converting the received hex values into volt. =head1 COPYRIGHT & LICENSE 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. =cut 1; __END__ Temperature, Calibrated key -50,712.066 -49,661.926 -48,615.656 -47,572.934 -46,533.466 -45,496.983 -44,463.24 -43,432.015 -42,403.104 -41,376.32 -40,351.495 -39,328.472 -38,307.11 -37,287.279 -36,268.859 -35,251.741 -34,235.826 -33,221.021 -32,207.242 -31,194.412 -30,182.46 -29,171.32 -28,160.932 -27,151.241 -26,142.196 -25,133.75 -24,125.859 -23,118.485 -22,111.589 -21,105.139 -20,99.102 -19,93.45 -18,88.156 -17,83.195 -16,78.544 -15,74.183 -14,70.091 -13,66.25 -12,62.643 -11,59.255 -10,56.071 -9,53.078 -8,50.263 -7,47.614 -6,45.121 -5,42.774 -4,40.563 -3,38.48 -2,36.517, -1,34.665, 0,32.919, 1,31.27, 2,29.715, 3,28.246, 4,26.858, 5,25.547, 6,24.307, 7,23.135, 8,22.026, 9,20.977, 10,19.987, 11,19.044, 12,18.154, 13,17.31, 14,16.51 15,15.752 16,15.034 17,14.352 18,13.705 19,13.09 20,12.507 21,11.953 22,11.427 23,10.927 24,10.452 25,10 26,9.57 27,9.161 28,8.771 29,8.401 30,8.048 31,7.712 32,7.391 33,7.086 34,6.795 35,6.518 36,6.254 37,6.001 38,5.761 39,5.531 40,5.311 41,5.102 42,4.902 43,4.71 44,4.528 45,4.353 46,4.186 47,4.026 48,3.874 49,3.728 50,3.588 51,3.454 52,3.326 53,3.203 54,3.085 55,2.973 56,2.865 57,2.761 58,2.662 59,2.567 60,2.476 61,2.388 62,2.304 63,2.223 64,2.146 65,2.072 66,2 67,1.932 68,1.866 69,1.803 70,1.742 71,1.684 72,1.627 73,1.573 74,1.521 75,1.471 76,1.423 77,1.377 78,1.332 79,1.289 80,1.248 81,1.208 82,1.17 83,1.133 84,1.097 85,1.063 86,1.03 87,0.998 88,0.968 89,0.938 90,0.909 91,0.882 92,0.855 93,0.829 94,0.805 95,0.781 96,0.758 97,0.735 98,0.714 99,0.693 100,0.673 101,0.653 102,0.635 103,0.616 104,0.599 105,0.582 106,0.565 107,0.55 108,0.534 109,0.519 110,0.505 111,0.491 112,0.478 113,0.465 114,0.452 115,0.44 116,0.428 117,0.416 118,0.405 119,0.395 120,0.384 121,0.374 122,0.364 123,0.355 124,0.345 125,0.337 126,0.328 127,0.319 128,0.311 129,0.303 130,0.296 131,0.288 132,0.281 133,0.274 134,0.267 135,0.261 136,0.254 137,0.248 138,0.242 139,0.236 140,0.23 141,0.225 142,0.219 143,0.214 144,0.209 145,0.204 146,0.199 147,0.195 148,0.19 149,0.186 150,0.181 Device-USB-PCSensor-HidTEMPer-0.04/lib/Device/USB/PCSensor/HidTEMPer/NTC/Internal.pm000755 000766 000024 00000005141 11521275454 027455 0ustar00Magnusstaff000000 000000 package Device::USB::PCSensor::HidTEMPer::NTC::Internal; use strict; use warnings; use Device::USB::PCSensor::HidTEMPer::Sensor; our @ISA = 'Device::USB::PCSensor::HidTEMPer::Sensor'; =head1 Device::USB::PCSensor::HidTEMPer::NTC::Internal - The HidTEMPerNTC internal sensor =head1 VERSION Version 0.03 =cut our $VERSION = 0.03; =head1 SYNOPSIS None =head1 DESCRIPTION This is the implementation of the HidTEMPerNTC internal sensor. =head2 CONSTANTS =over 3 =item * MAX_TEMPERATURE The highest temperature(120 degrees celsius) this sensor can detect. =cut use constant MAX_TEMPERATURE => 120; =item * MIN_TEMPERATURE The lowest temperature(-40 degrees celsius) this sensor can detect. =back =cut use constant MIN_TEMPERATURE => -40; =head2 METHODS =over 3 =item * celsius() Returns the current temperature from the device in celsius degrees. =cut 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; } =back =head1 INHERIT METHODS FROM Device::USB::PCSensor::HidTEMPer::Sensor =head1 DEPENDENCIES 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. =head1 BUGS Please report any bugs or missing features using the CPAN RT tool. =head1 FOR MORE INFORMATION None =head1 AUTHOR Magnus Sulland < msulland@cpan.org > =head1 ACKNOWLEDGEMENTS 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/ =head1 COPYRIGHT & LICENSE 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. =cut 1;