HiPi::Interface::DS18X20
The HiPi::Interface::DS18X20 module provides simple read access for Maxim 18S20 and 18B20 temperature sensors connected to the W1 kernel device driver for the 1 Wire bus.
It uses HiPi::Device::OneWire as a backend.
Methods
Class Functions
Returns a new instance of the HiPi::Interface::DS18X20 class for the temperature device with the unique 1 Wire ID $uniqueid.
my $sensor = HiPi::Interface::DS18X20->new( id => $uniqueid );
You can optionally provide additional key => value pairs as shown below with thier defaults.
my $sensor = HiPi::Interface::DS18X20->new( id => $uniqueid, correction => 0, divider => 1, );
id
The unique 1 Wire ID for your sensor.
correction
To be added to the temperature value returned from the device.
divider
To be applied as a divider to the value returned by the device. This is useful if you want to convert the raw value from your device to an actual temperature within this module.
Get or reset the value as passed in the constructor
Get or reset the value as passed in the constructor
returns the value read from the sensor added to the correction value, divided by the divider value:
return ( $sensorval + $correction ) / $divider;
With default values this is simply
return ( $sensorval + 0 ) / 1;
my $temp = $sensor->temperature;
Filters a call to HiPi::Device::OneWire->list_devices() to return only devices in the families 10 and 28 ( temperature sensors of the types 18S20 and 18B20 )
my @devices = HiPi::Interface::DS18X20->list_devices(); for my $w1 ( @devices ) { for ( qw( id family name description ) ) { print qq($_ = $w1->{$_}\n); } }