This commit is contained in:
pahenning
2013-02-04 19:39:45 +00:00
parent 44db238d01
commit c2749908db

View File

@@ -119,7 +119,7 @@ sub OWTHERM_Initialize ($) {
$hash->{GetFn} = "OWTHERM_Get"; $hash->{GetFn} = "OWTHERM_Get";
$hash->{SetFn} = "OWTHERM_Set"; $hash->{SetFn} = "OWTHERM_Set";
$hash->{AttrFn} = "OWTHERM_Attr"; $hash->{AttrFn} = "OWTHERM_Attr";
$hash->{AttrList}= "IODev do_not_notify:0,1 showtime:0,1 model:DS1820,DS18B20,DS1822 loglevel:0,1,2,3,4,5 ". $hash->{AttrList}= "IODev model:DS1820,DS18B20,DS1822 loglevel:0,1,2,3,4,5 ".
"event-on-update-reading event-on-change-reading ". "event-on-update-reading event-on-change-reading ".
"stateAL stateAH ". "stateAL stateAH ".
"tempOffset tempUnit:C,Celsius,F,Fahrenheit,K,Kelvin ". "tempOffset tempUnit:C,Celsius,F,Fahrenheit,K,Kelvin ".
@@ -278,11 +278,8 @@ sub OWTHERM_InitializeDevice($) {
#-- Initial readings temperature sensor #-- Initial readings temperature sensor
$owg_temp = ""; $owg_temp = "";
$owg_tl = defined($attr{$name}{"tempLow"}) ? $attr{$name}{"tempLow"} : ""; $owg_tl = "";
$owg_th = defined($attr{$name}{"tempHigh"}) ? $attr{$name}{"tempHigh"} : "", $owg_th = "",
#-- Output formatting because of reading attributes
OWTHERM_FormatValues($hash);
#-- Set state to initialized #-- Set state to initialized
readingsSingleUpdate($hash,"state","initialized",1); readingsSingleUpdate($hash,"state","initialized",1);
@@ -300,6 +297,7 @@ sub OWTHERM_FormatValues($) {
my ($hash) = @_; my ($hash) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $interface = $hash->{IODev}->{TYPE};
my ($unit,$offset,$factor,$abbr,$vval,$vlow,$vhigh,$statef); my ($unit,$offset,$factor,$abbr,$vval,$vlow,$vhigh,$statef);
my $svalue = ""; my $svalue = "";
@@ -339,9 +337,28 @@ sub OWTHERM_FormatValues($) {
$vlow = ($owg_tl + $offset)*$factor; $vlow = ($owg_tl + $offset)*$factor;
$vhigh = ($owg_th + $offset)*$factor; $vhigh = ($owg_th + $offset)*$factor;
#-- check if the device has to be corrected
if( AttrVal($name,"tempLow",undef) ){
if( $main::attr{$name}{"tempLow"} != $vlow ){
OWTHERM_Set( $hash,("tempLow",$main::attr{$name}{"tempLow"}));
$vlow = $main::attr{$name}{"tempLow"};
}
} else {
$main::attr{$name}{"tempLow"} = $vlow;
}
if( AttrVal($name,"tempHigh",undef) ){
if( $main::attr{$name}{"tempHigh"} != $vhigh ){
OWTHERM_Set( $hash,("tempHigh",$main::attr{$name}{"tempHigh"}));
$vhigh = $main::attr{$name}{"tempHigh"};
}
} else {
$main::attr{$name}{"tempHigh"} = $vhigh;
}
#-- formats for output #-- formats for output
$statef = "%5.2f ".$abbr; $statef = "T: %5.2f ".$abbr;
$svalue = "temperature: ".sprintf($statef,$vval); $svalue = sprintf($statef,$vval);
#-- Test for alarm condition #-- Test for alarm condition
$hash->{ALARM} = 1; $hash->{ALARM} = 1;
@@ -355,9 +372,7 @@ sub OWTHERM_FormatValues($) {
$hash->{ALARM} = 0; $hash->{ALARM} = 0;
} }
#-- put into READINGS and attributes #-- put into READINGS
$main::attr{$name}{"tempLow"} = $vlow;
$main::attr{$name}{"tempHigh"} = $vhigh;
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsBulkUpdate($hash,"temperature",$vval); readingsBulkUpdate($hash,"temperature",$vval);
#-- STATE #-- STATE
@@ -501,7 +516,6 @@ sub OWTHERM_GetValues($@) {
$value=OWTHERM_FormatValues($hash); $value=OWTHERM_FormatValues($hash);
Log 5, $value; Log 5, $value;
#-- one thing remains to do:
return undef; return undef;
} }
@@ -547,6 +561,7 @@ sub OWTHERM_Set($@) {
} }
#-- set tempLow or tempHigh #-- set tempLow or tempHigh
if( (lc($key) eq "templow") || (lc($key) eq "temphigh")) {
my $interface = $hash->{IODev}->{TYPE}; my $interface = $hash->{IODev}->{TYPE};
my $offset = defined($hash->{tempf}{offset}) ? $hash->{tempf}{offset} : 0.0; my $offset = defined($hash->{tempf}{offset}) ? $hash->{tempf}{offset} : 0.0;
my $factor = defined($hash->{tempf}{factor}) ? $hash->{tempf}{factor} : 1.0; my $factor = defined($hash->{tempf}{factor}) ? $hash->{tempf}{factor} : 1.0;
@@ -561,23 +576,22 @@ sub OWTHERM_Set($@) {
$a[2] = int($value/$factor-$offset); $a[2] = int($value/$factor-$offset);
#-- OWX interface #-- OWX interface
Log 1,"SETTING DEVICE with ".join(' ',@a)." and present=".$hash->{PRESENT}.
" and state=".$hash->{READINGS}{"state"}{VAL};
if( $interface eq "OWX" ){ if( $interface eq "OWX" ){
$ret = OWXTHERM_SetValues($hash,@a); $ret = OWXTHERM_SetValues($hash,@a);
#-- OWFS interface #-- OWFS interface
}elsif( $interface eq "OWServer" ){ }elsif( $interface eq "OWServer" ){
$ret = OWFSTHERM_SetValues($hash,@a); $ret = OWFSTHERM_SetValues($hash,@a);
return $ret
if(defined($ret));
} else { } else {
return "OWTHERM: Set with wrong IODev type $interface"; return "OWTHERM: Set with wrong IODev type $interface";
} }
return $ret
if(defined($ret));
}
#-- process results - we have to reread the device #-- process results - we have to reread the device
$hash->{PRESENT} = 1; $hash->{PRESENT} = 1;
#OWTHERM_GetValues($hash); #OWTHERM_GetValues($hash);
OWTHERM_FormatValues($hash); #OWTHERM_FormatValues($hash);
Log 4, "OWTHERM: Set $hash->{NAME} $key $value"; Log 4, "OWTHERM: Set $hash->{NAME} $key $value";
return undef; return undef;
@@ -666,25 +680,9 @@ sub OWFSTHERM_GetValues($) {
return "empty return from OWServer" return "empty return from OWServer"
if( ($owg_temp eq "") || ($ow_thn eq "") || ($ow_tln eq "") ); if( ($owg_temp eq "") || ($ow_thn eq "") || ($ow_tln eq "") );
#return "wrong data length from OWServer"
# if( (int(@ral) != $cnumber{$attr{$name}{"model"}}) || (int(@rax) != $cnumber{$attr{$name}{"model"}}) );
#-- process alarm settings #-- process alarm settings
#-- first reading of the device
if( $owg_th eq ""){
$owg_th = $ow_thn;
#-- device must be changed
}elsif( $owg_th != $ow_thn ){
OWFSTHERM_SetValues($hash,"temphigh",$owg_th);
}
#-- first reading of the device
if( $owg_tl eq ""){
$owg_tl = $ow_tln; $owg_tl = $ow_tln;
#-- device must be changed $owg_th = $ow_thn;
}elsif( $owg_tl != $ow_tln ){
OWFSTHERM_SetValues($hash,"templow",$owg_tl);
}
return undef return undef
} }
@@ -827,25 +825,9 @@ sub OWXTHERM_GetValues($) {
} }
#-- process alarm settings #-- process alarm settings
#-- first reading of the device
if( $owg_th eq ""){
$owg_th = $ow_thn;
#-- device must be changed
}elsif( $owg_th != $ow_thn ){
$change=1;
}
#-- first reading of the device
if( $owg_tl eq ""){
$owg_tl = $ow_tln; $owg_tl = $ow_tln;
#-- device must be changed $owg_th = $ow_thn;
}elsif( $owg_tl != $ow_tln ){
$change=1;
}
#-- change device settings
if( $change==1){
OWXTHERM_SetValues($hash,("both","0.0"));
}
return undef; return undef;
} }
@@ -864,6 +846,7 @@ sub OWXTHERM_SetValues($@) {
my ($i,$j,$k); my ($i,$j,$k);
my $name = $hash->{NAME}; my $name = $hash->{NAME};
#-- ID of the device #-- ID of the device
my $owx_dev = $hash->{ROM_ID}; my $owx_dev = $hash->{ROM_ID};
#-- hash of the busmaster #-- hash of the busmaster
@@ -878,8 +861,8 @@ sub OWXTHERM_SetValues($@) {
if( $value eq ""); if( $value eq "");
#-- $owg_tl and $owg_th are preset and may be changed here #-- $owg_tl and $owg_th are preset and may be changed here
$owg_tl = $value if( $key eq "tempLow" ); $owg_tl = $value if( lc($key) eq "templow" );
$owg_th = $value if( $key eq "tempHigh" ); $owg_th = $value if( lc($key) eq "temphigh");
#-- put into 2's complement formed (signed byte) #-- put into 2's complement formed (signed byte)
my $tlp = $owg_tl < 0 ? 128 - $owg_tl : $owg_tl; my $tlp = $owg_tl < 0 ? 128 - $owg_tl : $owg_tl;
@@ -896,7 +879,7 @@ sub OWXTHERM_SetValues($@) {
# 3. \x48 sent by WriteBytePower after match ROM => command ok, no effect on EEPROM # 3. \x48 sent by WriteBytePower after match ROM => command ok, no effect on EEPROM
my $select=sprintf("\x4E%c%c\x48",$thp,$tlp); my $select=sprintf("\x4E%c%c\x48",$thp,$tlp);
my $res=OWX_Complex($master,$owx_dev,$select,0); my $res=OWX_Complex($master,$owx_dev,$select,3);
if( $res eq 0 ){ if( $res eq 0 ){
return "OWXTHERM: Device $owx_dev not accessible"; return "OWXTHERM: Device $owx_dev not accessible";