| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
######################################################################################### |
|
2
|
|
|
|
|
|
|
# Package HiPi::Interface::DS18X20 |
|
3
|
|
|
|
|
|
|
# Description : 1 Wire Thermometers |
|
4
|
|
|
|
|
|
|
# Copyright : Copyright (c) 2013-2017 Mark Dootson |
|
5
|
|
|
|
|
|
|
# License : This is free software; you can redistribute it and/or modify it under |
|
6
|
|
|
|
|
|
|
# the same terms as the Perl 5 programming language system itself. |
|
7
|
|
|
|
|
|
|
######################################################################################### |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package HiPi::Interface::DS18X20; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
######################################################################################### |
|
12
|
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
1094
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
31
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
28
|
|
|
15
|
1
|
|
|
1
|
|
5
|
use parent qw( HiPi::Interface ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
4
|
|
|
16
|
1
|
|
|
1
|
|
70
|
use HiPi::Device::OneWire; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
42
|
|
|
17
|
1
|
|
|
1
|
|
15
|
use Carp; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
465
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION ='0.81'; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
__PACKAGE__->create_accessors( qw( id correction divider) ); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub list_slaves { |
|
24
|
0
|
|
|
0
|
0
|
|
my($class) = @_; |
|
25
|
0
|
|
|
|
|
|
my @slaves = grep { $_->{family} =~ /^(10|28)$/ } ( HiPi::Device::OneWire->list_slaves() ); |
|
|
0
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
return @slaves; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new { |
|
30
|
0
|
|
|
0
|
0
|
|
my($class, %params) = @_; |
|
31
|
0
|
|
0
|
|
|
|
$params{correction} ||= 0.0; |
|
32
|
0
|
|
0
|
|
|
|
$params{divider} ||= 1.0; |
|
33
|
0
|
0
|
|
|
|
|
unless ( HiPi::Device::OneWire->id_exists( $params{id} ) ){ |
|
34
|
0
|
|
|
|
|
|
croak qq($params{id} is not present on 1 wire bus); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new( %params ); |
|
37
|
0
|
|
|
|
|
|
return $self; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub temperature { |
|
41
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
42
|
0
|
|
|
|
|
|
my $data = HiPi::Device::OneWire->read_data( $self->id ); |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
if($data !~ /YES/) { |
|
45
|
|
|
|
|
|
|
# invalid crc |
|
46
|
0
|
|
|
|
|
|
croak qq(CRC check failed or invalid device for id ) . $self->id; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
0
|
0
|
|
|
|
|
if($data =~ /t=(\D*\d+)/i) { |
|
49
|
0
|
|
|
|
|
|
return ( $1 + $self->correction ) / $self->divider; |
|
50
|
|
|
|
|
|
|
} else { |
|
51
|
0
|
|
|
|
|
|
croak qq(Could not parse temperature data for device ) . $self->id; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |