mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 16:56:54 +00:00
changed: minor fixes
git-svn-id: https://svn.fhem.de/fhem/trunk@4046 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
191bb58389
commit
e8a4e511ca
@ -1,32 +1,4 @@
|
|||||||
# $Id$
|
package main;
|
||||||
####################################################################################################
|
|
||||||
#
|
|
||||||
# 51_BBB_BMP180.pm
|
|
||||||
#
|
|
||||||
# An FHEM Perl module for reading air pressure from BMP180 sensor connected on I2C.
|
|
||||||
# Developed for use with fhem running on BeagleBoneBlack
|
|
||||||
#
|
|
||||||
# Please read commandref for details on prerequisits!
|
|
||||||
#
|
|
||||||
# Copyright: betateilchen ®
|
|
||||||
# e-mail: fhem.development@betateilchen.de
|
|
||||||
#
|
|
||||||
# This file is part of fhem.
|
|
||||||
#
|
|
||||||
# Fhem is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 2 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Fhem is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with fhem. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
####################################################################################################package main;
|
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
@ -36,19 +8,18 @@ use Time::HiRes qw(gettimeofday);
|
|||||||
sub BBB_BMP180_Define($$);
|
sub BBB_BMP180_Define($$);
|
||||||
sub BBB_BMP180_Undefine($$);
|
sub BBB_BMP180_Undefine($$);
|
||||||
sub BBB_BMP180_Get($@);
|
sub BBB_BMP180_Get($@);
|
||||||
sub BBB_BMP180_Attr($@);
|
|
||||||
sub BBB_BMP180_Notify($$);
|
|
||||||
|
|
||||||
|
|
||||||
|
# $next = gettimeofday()+$hash->{helper}{INTERVAL};
|
||||||
|
# readingsSingleUpdate($hash, "c_nextUpdate", localtime($next), 1);
|
||||||
|
# InternalTimer($next, "GDS_GetUpdate", $hash, 1);
|
||||||
|
|
||||||
sub BBB_BMP180_Initialize($){
|
sub BBB_BMP180_Initialize($){
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
$hash->{DefFn} = "BBB_BMP180_Define";
|
$hash->{DefFn} = "BBB_BMP180_Define";
|
||||||
$hash->{UndefFn} = "BBB_BMP180_Undefine";
|
$hash->{UndefFn} = "BBB_BMP180_Undefine";
|
||||||
$hash->{GetFn} = "BBB_BMP180_Get";
|
$hash->{GetFn} = "BBB_BMP180_Get";
|
||||||
$hash->{NotifyFn} = "BBB_BMP180_Notify";
|
|
||||||
$hash->{AttrFn} = "BBB_BMP180_Attr";
|
$hash->{AttrFn} = "BBB_BMP180_Attr";
|
||||||
$hash->{AttrList} = "bbbRoundPressure:0,1 ".
|
$hash->{AttrList} = "bbbRoundPressure:0,1 bbbRoundTemperature:0,1 ".
|
||||||
"bbbRoundTemperature:0,1 ".
|
|
||||||
"bbbInterval ".
|
"bbbInterval ".
|
||||||
$readingFnAttributes;
|
$readingFnAttributes;
|
||||||
}
|
}
|
||||||
@ -58,38 +29,17 @@ sub BBB_BMP180_Define($$){
|
|||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my @a = split("[ \t][ \t]*", $def);
|
my @a = split("[ \t][ \t]*", $def);
|
||||||
Log3($name, 3, "BBB_BMP180 $name: created");
|
Log3($name, 3, "BBB_BMP180 $name: created");
|
||||||
|
readingsSingleUpdate($hash, "state", "active",1);
|
||||||
|
|
||||||
$hash->{helper}{i2cbus} = '1';
|
$hash->{helper}{i2cbus} = '1';
|
||||||
$hash->{helper}{i2cbus} = $a[2] if(defined($a[2]));
|
$hash->{helper}{i2cbus} = $a[2] if(defined($a[2]));
|
||||||
|
|
||||||
# check availability
|
my $next = gettimeofday()+10;
|
||||||
my $bmpP = '/sys/bus/i2c/drivers/bmp085/'.$hash->{helper}{i2cbus}.'-0077/pressure0_input';
|
InternalTimer($next, "bbb_getValues", $hash, 0);
|
||||||
open (IN,"<$bmpP") || return "\n BBB_BMP180: I2C device not found!";
|
|
||||||
|
|
||||||
if( $init_done ) {
|
|
||||||
delete $modules{BBB_BMP180}->{NotifyFn};
|
|
||||||
bbb_getValues($hash,undef);
|
|
||||||
} else {
|
|
||||||
readingsSingleUpdate($hash, "state", "active",1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub BBB_BMP180_Notify($$) {
|
|
||||||
my ($hash,$dev) = @_;
|
|
||||||
|
|
||||||
if( grep(m/^INITIALIZED$/, @{$dev->{CHANGED}}) ) {
|
|
||||||
delete $modules{BBB_BMP180}->{NotifyFn};
|
|
||||||
|
|
||||||
foreach my $d (keys %defs) {
|
|
||||||
next if($defs{$d}{TYPE} ne "BBB_BMP180");
|
|
||||||
bbb_getValues($hash,undef);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub BBB_BMP180_Undefine($$){
|
sub BBB_BMP180_Undefine($$){
|
||||||
my($hash, $name) = @_;
|
my($hash, $name) = @_;
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
@ -124,7 +74,7 @@ sub BBB_BMP180_Attr($@){
|
|||||||
when("bbbInterval"){
|
when("bbbInterval"){
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
my $next = gettimeofday()+$attrValue;
|
my $next = gettimeofday()+$attrValue;
|
||||||
InternalTimer($next, "bbb_getValues", ($hash,undef), 0);
|
InternalTimer($next, "bbb_getValues", $hash, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,9 +83,10 @@ sub BBB_BMP180_Attr($@){
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub bbb_getValues($;$){
|
sub bbb_getValues($$){
|
||||||
my ($hash,$local) = @_;
|
my ($hash,$local) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
my $a = AttrVal('global','altitude',undef);
|
my $a = AttrVal('global','altitude',undef);
|
||||||
my $t = bbb_temp($hash);
|
my $t = bbb_temp($hash);
|
||||||
my $pa = bbb_absDruck($hash);
|
my $pa = bbb_absDruck($hash);
|
||||||
@ -166,7 +117,8 @@ sub bbb_getValues($;$){
|
|||||||
readingsEndUpdate($hash, 1);
|
readingsEndUpdate($hash, 1);
|
||||||
|
|
||||||
my $next = gettimeofday()+AttrVal($name,'bbbInterval',300);
|
my $next = gettimeofday()+AttrVal($name,'bbbInterval',300);
|
||||||
InternalTimer($next, "bbb_getValues", ($hash,undef), 0) unless $local;
|
InternalTimer($next, "bbb_getValues", $hash, 0) unless $local;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +127,7 @@ sub bbb_temp($){
|
|||||||
my $bmpT = '/sys/bus/i2c/drivers/bmp085/'.$hash->{helper}{i2cbus}.'-0077/temp0_input';
|
my $bmpT = '/sys/bus/i2c/drivers/bmp085/'.$hash->{helper}{i2cbus}.'-0077/temp0_input';
|
||||||
my $temp;
|
my $temp;
|
||||||
|
|
||||||
open (IN,"<$bmpT") || Log3($hash, 2, 'BBB_BMP180: I2C device not found!');
|
open (IN,"<$bmpT") || die $!;
|
||||||
while (<IN>){
|
while (<IN>){
|
||||||
$temp = $_;
|
$temp = $_;
|
||||||
last;
|
last;
|
||||||
@ -192,7 +144,7 @@ sub bbb_absDruck($){
|
|||||||
my $bmpP = '/sys/bus/i2c/drivers/bmp085/'.$hash->{helper}{i2cbus}.'-0077/pressure0_input';
|
my $bmpP = '/sys/bus/i2c/drivers/bmp085/'.$hash->{helper}{i2cbus}.'-0077/pressure0_input';
|
||||||
my $p;
|
my $p;
|
||||||
|
|
||||||
open (IN,"<$bmpP") || Log3($hash, 2, 'BBB_BMP180: I2C device not found!');
|
open (IN,"<$bmpP") || die $!;
|
||||||
while (<IN>){
|
while (<IN>){
|
||||||
$p = $_;
|
$p = $_;
|
||||||
last;
|
last;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user