Device::USB::PCSensor::HidTEMPer::Sensor - Generic sensor class


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

Index


Code Index:

Top

Device::USB::PCSensor::HidTEMPer::Sensor - Generic sensor class

VERSION

Top

Version 0.02

SYNOPSIS

Top

None

DESCRIPTION

Top

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.

CONSTANTS

* MAX_TEMPERATURE

The highest temperature(Celsius) this sensor can detect.

* MIN_TEMPERATURE

The lowest temperature(Celsius) this sensor can detect.

METHODS

* 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.

* fahrenheit()

Reads the current temperature and returns the corresponding value in fahrenheit degrees.

* max()

Returns the highest temperature(Celsius) the sensor can detect.

* min()

Returns the lowest temperature(Celsius) the sensor can detect.

* celsius()

Empty method that should be implemented in each sensor, returing the current degrees in celsius.

DEPENDENCIES

Top

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

  use Scalar::Util qw/ weaken /;

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

None

COPYRIGHT & LICENSE

Top


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

use strict;
use warnings;

use Scalar::Util qw/ weaken /;

our $VERSION = 0.02;

use constant MAX_TEMPERATURE    => 0;

use constant MIN_TEMPERATURE    => 0;

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;
}

sub fahrenheit
{
    my $self    = shift;
    my $celsius = $self->celsius() // 0;
    
    # Calculate and return the newly created degrees
    return ( ( $celsius * 9 ) / 5 ) + 32;
}

sub max
{ 
    return $_[0]->MAX_TEMPERATURE;
}

sub min
{
    return $_[0]->MIN_TEMPERATURE;
}

sub celsius { 
    return undef; 
}

1;