Created
September 24, 2017 12:59
-
-
Save stefansbv/4b22c3e825178eddede1d800f03872a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use HiPi::Device::OneWire; | |
my @devices = HiPi::Device::OneWire->list_slaves(); | |
for my $w1 ( @devices ) { | |
for ( qw( id family name description ) ) { | |
print qq($_ = $w1->{$_}\n); | |
} | |
my $data = HiPi::Device::OneWire->read_data( $w1->{id} ); | |
process($data); | |
} | |
sub process { | |
my $data = shift; | |
my @lines = split /\n/, $data; | |
if ($lines[0] !~ m/YES/){ | |
print "CRC Error:\n$data\n"; | |
} | |
else { | |
print "Temp is ", get_temp($lines[1]), "\n"; | |
} | |
} | |
sub get_temp { | |
my $text = shift; | |
( my $raw ) = $text =~ m/t=(\d+)/; | |
my $temp_c = $raw / 1000.0; | |
return $temp_c; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment