mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-07 16:59:18 +00:00
OWX: auto-detect OWX_ASYNC, fix calls to OWX_Reset in async mode
git-svn-id: https://svn.fhem.de/fhem/trunk@5383 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
39e5612d49
commit
b7e7934450
@ -250,13 +250,15 @@ sub OWAD_Define ($$) {
|
||||
$hash->{PRESENT} = 0;
|
||||
$hash->{INTERVAL} = $interval;
|
||||
$hash->{ERRCOUNT} = 0;
|
||||
$hash->{ASYNC} = 0; #-- false for now
|
||||
|
||||
#-- Couple to I/O device
|
||||
AssignIoPort($hash);
|
||||
if( !defined($hash->{IODev}->{NAME}) | !defined($hash->{IODev}) ){
|
||||
AssignIoPort($hash);
|
||||
if( !defined($hash->{IODev}) or !defined($hash->{IODev}->{NAME}) ){
|
||||
return "OWAD: Warning, no 1-Wire I/O device found for $name.";
|
||||
} else {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0; #-- false for now
|
||||
}
|
||||
|
||||
$main::modules{OWAD}{defptr}{$id} = $hash;
|
||||
#--
|
||||
readingsSingleUpdate($hash,"state","defined",1);
|
||||
@ -307,7 +309,14 @@ sub OWAD_Attr(@) {
|
||||
if( $hash->{READINGS}{"state"}{VAL} eq "defined" );
|
||||
$ret = OWAD_Set($hash,($name,$key,$value));
|
||||
last;
|
||||
}
|
||||
};
|
||||
$key eq "IODev" and do {
|
||||
AssignIoPort($hash,$value);
|
||||
if( defined($hash->{IODev}) ) {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0;
|
||||
}
|
||||
last;
|
||||
};
|
||||
}
|
||||
} elsif ( $do eq "del" ) {
|
||||
ARGUMENT_HANDLER: {
|
||||
@ -566,7 +575,7 @@ sub OWAD_Get($@) {
|
||||
#-- get reading according to interface type
|
||||
if($a[1] eq "reading") {
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
$ret = OWXAD_GetPage($hash,"reading",1);
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
@ -590,7 +599,7 @@ sub OWAD_Get($@) {
|
||||
#-- get alarm values according to interface type
|
||||
if($a[1] eq "alarm") {
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
$ret = OWXAD_GetPage($hash,"alarm",1);
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
@ -622,7 +631,7 @@ sub OWAD_Get($@) {
|
||||
#-- get status values according to interface type
|
||||
if($a[1] eq "status") {
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
$ret = OWXAD_GetPage($hash,"status",1);
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
@ -707,7 +716,7 @@ sub OWAD_GetValues($) {
|
||||
InternalTimer(time()+$hash->{INTERVAL}, "OWAD_GetValues", $hash, 1);
|
||||
|
||||
#-- Get readings, alarms and stati according to interface type
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
#-- max 3 tries
|
||||
#for(my $try=0; $try<3; $try++){
|
||||
$ret1 = OWXAD_GetPage($hash,"reading",0);
|
||||
@ -918,7 +927,7 @@ sub OWAD_Set($@) {
|
||||
}
|
||||
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
$ret = OWXAD_SetPage($hash,"status");
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
@ -964,7 +973,7 @@ sub OWAD_Set($@) {
|
||||
}
|
||||
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
$ret = OWXAD_SetPage($hash,"alarm");
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
|
@ -239,14 +239,13 @@ sub OWCOUNT_Define ($$) {
|
||||
$hash->{OW_FAMILY} = $fam;
|
||||
$hash->{PRESENT} = 0;
|
||||
$hash->{INTERVAL} = $interval;
|
||||
$hash->{ASYNC} = 0; #-- false for now
|
||||
|
||||
#-- Couple to I/O device
|
||||
$hash->{IODev}=$attr{$name}{"IODev"}
|
||||
if( defined($attr{$name}{"IODev"}) );
|
||||
AssignIoPort($hash);
|
||||
if( (!defined($hash->{IODev}->{NAME})) || (!defined($hash->{IODev})) ){
|
||||
return "OWSWITCH: Warning, no 1-Wire I/O device found for $name.";
|
||||
if( !defined($hash->{IODev}) or !defined($hash->{IODev}->{NAME}) ){
|
||||
return "OWCOUNT: Warning, no 1-Wire I/O device found for $name.";
|
||||
} else {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0; #-- false for now
|
||||
}
|
||||
|
||||
$modules{OWCOUNT}{defptr}{$id} = $hash;
|
||||
@ -288,7 +287,14 @@ sub OWCOUNT_Attr(@) {
|
||||
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "OWCOUNT_GetValues", $hash, 1);
|
||||
}
|
||||
last;
|
||||
}
|
||||
};
|
||||
$key eq "IODev" and do {
|
||||
AssignIoPort($hash,$value);
|
||||
if( defined($hash->{IODev}) ) {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0;
|
||||
}
|
||||
last;
|
||||
};
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
@ -792,7 +798,7 @@ sub OWCOUNT_GetPage ($$$) {
|
||||
if( ($nomemory==0) || ($nomemory==1 && (($page==14)||($page==15))) ){
|
||||
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
$ret = OWXCOUNT_GetPage($hash,$page,$final);
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
@ -1102,7 +1108,7 @@ sub OWCOUNT_InitializeDevice($) {
|
||||
# the same family ID although the DS2423emu does not fully support the DS2423 commands.
|
||||
# Model attribute will be modified now after checking for memory
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
$ret = OWXCOUNT_GetPage($hash,14,0);
|
||||
$olddata = $hash->{owg_str}->[14];
|
||||
$ret = OWXCOUNT_SetPage($hash,14,$newdata);
|
||||
@ -1123,7 +1129,7 @@ sub OWCOUNT_InitializeDevice($) {
|
||||
#Log 1,"FIRST CHECK: written $newdata, read ".substr($hash->{owg_str}->[14],0,length($newdata));
|
||||
my $nomid = ( substr($hash->{owg_str}->[14],0,length($newdata)) ne $newdata );
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
$ret = OWXCOUNT_GetPage($hash,0,0);
|
||||
$olddata = $hash->{owg_str}->[0];
|
||||
$ret = OWXCOUNT_SetPage($hash,0,$newdata);
|
||||
@ -1312,7 +1318,7 @@ sub OWCOUNT_SetPage ($$$) {
|
||||
|
||||
if( $nomemory==0 ){
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
$ret = OWXCOUNT_SetPage($hash,$page,$data);
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
|
@ -188,9 +188,12 @@ sub OWID_Define ($$) {
|
||||
|
||||
#-- Couple to I/O device
|
||||
AssignIoPort($hash);
|
||||
if( !defined($hash->{IODev}->{NAME}) | !defined($hash->{IODev}) ){
|
||||
if( !defined($hash->{IODev}) or !defined($hash->{IODev}->{NAME}) ){
|
||||
return "OWID: Warning, no 1-Wire I/O device found for $name.";
|
||||
} else {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0; #-- false for now
|
||||
}
|
||||
|
||||
$modules{OWID}{defptr}{$id} = $hash;
|
||||
#--
|
||||
readingsSingleUpdate($hash,"state","Defined",1);
|
||||
@ -240,7 +243,14 @@ sub OWID_Attr(@) {
|
||||
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "OWID_GetValues", $hash, 1);
|
||||
}
|
||||
last;
|
||||
}
|
||||
};
|
||||
$key eq "IODev" and do {
|
||||
AssignIoPort($hash,$value);
|
||||
if( defined($hash->{IODev}) ) {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0;
|
||||
}
|
||||
last;
|
||||
};
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
|
@ -172,9 +172,12 @@ sub OWLCD_Define ($$) {
|
||||
|
||||
#-- Couple to I/O device
|
||||
AssignIoPort($hash);
|
||||
if( !defined($hash->{IODev}->{NAME}) | !defined($hash->{IODev}) ) {
|
||||
return "OWSWITCH: Warning, no 1-Wire I/O device found for $name.";
|
||||
if( !defined($hash->{IODev}) or !defined($hash->{IODev}->{NAME}) ){
|
||||
return "OWLCD: Warning, no 1-Wire I/O device found for $name.";
|
||||
} else {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0; #-- false for now
|
||||
}
|
||||
|
||||
$modules{OWLCD}{defptr}{$id} = $hash;
|
||||
|
||||
$hash->{STATE} = "Defined";
|
||||
@ -214,15 +217,21 @@ sub OWLCD_Attr(@) {
|
||||
my $hash = $defs{$name};
|
||||
my $ret;
|
||||
|
||||
# if ( $do eq "set") {
|
||||
# ARGUMENT_HANDLER: {
|
||||
# #-- empty so far
|
||||
# };
|
||||
if ( $do eq "set") {
|
||||
ARGUMENT_HANDLER: {
|
||||
$key eq "IODev" and do {
|
||||
AssignIoPort($hash,$value);
|
||||
if( defined($hash->{IODev}) ) {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0;
|
||||
}
|
||||
last;
|
||||
};
|
||||
};
|
||||
#} elsif ( $do eq "del" ) {
|
||||
# ARGUMENT_HANDLER: {
|
||||
# #-- empty so far
|
||||
# }
|
||||
# }
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,14 @@ sub OWMULTI_Attr(@) {
|
||||
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "OWMULTI_GetValues", $hash, 1);
|
||||
}
|
||||
last;
|
||||
}
|
||||
};
|
||||
$key eq "IODev" and do {
|
||||
AssignIoPort($hash,$value);
|
||||
if( defined($hash->{IODev}) ) {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0;
|
||||
}
|
||||
last;
|
||||
};
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
@ -247,13 +254,15 @@ sub OWMULTI_Define ($$) {
|
||||
$hash->{PRESENT} = 0;
|
||||
$hash->{ROM_ID} = "$fam.$id.$crc";
|
||||
$hash->{INTERVAL} = $interval;
|
||||
$hash->{ASYNC} = 0; #-- false for now
|
||||
|
||||
#-- Couple to I/O device
|
||||
AssignIoPort($hash);
|
||||
if( !defined($hash->{IODev}->{NAME}) || !defined($hash->{IODev}) ){
|
||||
if( !defined($hash->{IODev}) or !defined($hash->{IODev}->{NAME}) ){
|
||||
return "OWMULTI: Warning, no 1-Wire I/O device found for $name.";
|
||||
} else {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0; #-- false for now
|
||||
}
|
||||
|
||||
$main::modules{OWMULTI}{defptr}{$id} = $hash;
|
||||
#--
|
||||
readingsSingleUpdate($hash,"state","defined",1);
|
||||
@ -457,7 +466,7 @@ sub OWMULTI_Get($@) {
|
||||
|
||||
#-- for the other readings we need a new reading
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
#-- not different from getting all values ..
|
||||
$ret = OWXMULTI_GetValues($hash);
|
||||
#ASYNC: Need to wait for some return
|
||||
@ -520,7 +529,7 @@ sub OWMULTI_GetValues($) {
|
||||
|
||||
#-- Get values according to interface type
|
||||
my $interface= $hash->{IODev}->{TYPE};
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
#-- max 3 tries
|
||||
for(my $try=0; $try<3; $try++){
|
||||
$ret = OWXMULTI_GetValues($hash);
|
||||
@ -618,7 +627,7 @@ sub OWMULTI_Set($@) {
|
||||
$a[2] = int($value/$factor-$offset);
|
||||
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
$ret = OWXMULTI_SetValues($hash,@a);
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
@ -1028,8 +1037,6 @@ sub OWXMULTI_SetValues($@) {
|
||||
my $key = $a[1];
|
||||
my $value = $a[2];
|
||||
|
||||
OWX_Reset($master);
|
||||
|
||||
#-- issue the match ROM command \x55 and the write scratchpad command \x4E,
|
||||
# followed by the write EEPROM command \x48
|
||||
#
|
||||
@ -1046,6 +1053,7 @@ sub OWXMULTI_SetValues($@) {
|
||||
}
|
||||
#-- synchronous mode
|
||||
} else {
|
||||
OWX_Reset($master);
|
||||
my $res=OWX_Complex($master,$owx_dev,$select,0);
|
||||
if( $res eq 0 ){
|
||||
return "OWXMULTI: Device $owx_dev not accessible";
|
||||
|
@ -241,12 +241,13 @@ sub OWSWITCH_Define ($$) {
|
||||
$hash->{OW_FAMILY} = $fam;
|
||||
$hash->{PRESENT} = 0;
|
||||
$hash->{INTERVAL} = $interval;
|
||||
$hash->{ASYNC} = 0; #-- false for now
|
||||
|
||||
#-- Couple to I/O device
|
||||
AssignIoPort($hash);
|
||||
if( !defined($hash->{IODev}->{NAME}) || !defined($hash->{IODev}) ){
|
||||
if( !defined($hash->{IODev}) or !defined($hash->{IODev}->{NAME}) ){
|
||||
return "OWSWITCH: Warning, no 1-Wire I/O device found for $name.";
|
||||
} else {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0; #-- false for now
|
||||
}
|
||||
|
||||
$main::modules{OWSWITCH}{defptr}{$id} = $hash;
|
||||
@ -290,7 +291,14 @@ sub OWSWITCH_Attr(@) {
|
||||
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "OWSWITCH_GetValues", $hash, 1);
|
||||
}
|
||||
last;
|
||||
}
|
||||
};
|
||||
$key eq "IODev" and do {
|
||||
AssignIoPort($hash,$value);
|
||||
if( defined($hash->{IODev}) ) {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0;
|
||||
}
|
||||
last;
|
||||
};
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
@ -479,7 +487,7 @@ sub OWSWITCH_Get($@) {
|
||||
if( !defined($fnd) );
|
||||
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
$ret = OWXSWITCH_GetState($hash);
|
||||
#ASYNC OWXSWITCH_AwaitGetState($hash);
|
||||
#-- OWFS interface
|
||||
@ -497,7 +505,7 @@ sub OWSWITCH_Get($@) {
|
||||
return "OWSWITCH: Get needs no parameter when reading gpio"
|
||||
if( int(@a)==1 );
|
||||
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
$ret = OWXSWITCH_GetState($hash);
|
||||
#ASYNC OWXSWITCH_AwaitGetState($hash);
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
@ -539,7 +547,7 @@ sub OWSWITCH_GetValues($) {
|
||||
|
||||
#-- Get readings according to interface type
|
||||
my $interface= $hash->{IODev}->{TYPE};
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
#-- max 3 tries
|
||||
for(my $try=0; $try<3; $try++){
|
||||
$ret = OWXSWITCH_GetState($hash);
|
||||
@ -698,7 +706,7 @@ sub OWSWITCH_Set($@) {
|
||||
}
|
||||
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
$ret1 = OWXSWITCH_GetState($hash);
|
||||
$value = 0;
|
||||
#-- vax or val ?
|
||||
@ -740,7 +748,7 @@ sub OWSWITCH_Set($@) {
|
||||
return "OWSWITCH: Set with wrong value for gpio port, must be 0 <= gpio <= ".((1 << $cnumber{$attr{$name}{"model"}})-1)
|
||||
if( ! ((int($value) >= 0) && (int($value) <= ((1 << $cnumber{$attr{$name}{"model"}})-1 ))) );
|
||||
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
$ret = OWXSWITCH_SetState($hash,int($value));
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
$ret = OWFSSWITCH_SetState($hash,int($value));
|
||||
@ -921,6 +929,8 @@ sub OWFSSWITCH_SetState($$) {
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub OWXSWITCH_BinValues($$$$$$$$); #define prototype for recursive call;
|
||||
|
||||
sub OWXSWITCH_BinValues($$$$$$$$) {
|
||||
my ($hash, $context, $success, $reset, $owx_dev, $command, $numread, $res) = @_;
|
||||
|
||||
@ -993,8 +1003,7 @@ sub OWXSWITCH_BinValues($$$$$$$$) {
|
||||
my $select=sprintf("\x55\x07\x00%c",$statneu);
|
||||
#-- asynchronous mode
|
||||
if( $hash->{ASYNC} ){
|
||||
if (OWX_Execute( $master, "setstateds2406.2.".$value, 1, $owx_dev, $select, 2, undef )) {
|
||||
OWX_Reset($master);
|
||||
if (OWX_Execute( $master, "setstate.ds2406.2.".$value, 1, $owx_dev, $select, 2, undef )) {
|
||||
return undef;
|
||||
} else {
|
||||
return "device $owx_dev not accessible in writing";
|
||||
@ -1066,13 +1075,13 @@ sub OWXSWITCH_AwaitGetState($) {
|
||||
if ($master and $owx_dev) {
|
||||
#-- family = 12 => DS2406
|
||||
if( $family eq "12" ) {
|
||||
return OWX_AwaitExecuteResponse( $master, "getstateds2406", $owx_dev );
|
||||
return OWX_AwaitExecuteResponse( $master, "getstate.ds2406", $owx_dev );
|
||||
#-- family = 29 => DS2408
|
||||
} elsif( $family eq "29" ) {
|
||||
return OWX_AwaitExecuteResponse( $master, "getstateds2408", $owx_dev );
|
||||
return OWX_AwaitExecuteResponse( $master, "getstate.ds2408", $owx_dev );
|
||||
#-- family = 3A => DS2413
|
||||
} elsif( $family eq "3A" ) {
|
||||
return OWX_AwaitExecuteResponse( $master, "getstateds2413", $owx_dev );
|
||||
return OWX_AwaitExecuteResponse( $master, "getstate.ds2413", $owx_dev );
|
||||
}
|
||||
}
|
||||
return undef;
|
||||
@ -1113,9 +1122,8 @@ sub OWXSWITCH_GetState($) {
|
||||
$select=sprintf("\xF5\xDD\xFF");
|
||||
#-- asynchronous mode
|
||||
if( $hash->{ASYNC} ){
|
||||
if (OWX_Execute( $master, "getstateds2406", 1, $owx_dev, $select, 4, undef )) {
|
||||
OWX_Reset($master);
|
||||
return undef;
|
||||
if (OWX_Execute( $master, "getstate.ds2406", 1, $owx_dev, $select, 4, undef )) {
|
||||
return undef;
|
||||
} else {
|
||||
return "not accessible in reading";
|
||||
}
|
||||
@ -1139,9 +1147,8 @@ sub OWXSWITCH_GetState($) {
|
||||
$select=sprintf("\xF0\x88\x00");
|
||||
#-- asynchronous mode
|
||||
if( $hash->{ASYNC} ){
|
||||
if (OWX_Execute( $master, "getstateds2408", 1, $owx_dev, $select, 10, undef )) {
|
||||
OWX_Reset($master);
|
||||
return undef;
|
||||
if (OWX_Execute( $master, "getstate.ds2408", 1, $owx_dev, $select, 10, undef )) {
|
||||
return undef;
|
||||
} else {
|
||||
return "not accessible in reading";
|
||||
}
|
||||
@ -1164,9 +1171,8 @@ sub OWXSWITCH_GetState($) {
|
||||
#-- reading 9 + 1 + 2 data bytes = 12 bytes
|
||||
#-- asynchronous mode
|
||||
if( $hash->{ASYNC} ){
|
||||
if (OWX_Execute( $master, "getstateds2413", 1, $owx_dev, "\xF5", 2, undef )) {
|
||||
OWX_Reset($master);
|
||||
return undef;
|
||||
if (OWX_Execute( $master, "getstate.ds2413", 1, $owx_dev, "\xF5", 2, undef )) {
|
||||
return undef;
|
||||
} else {
|
||||
return "not accessible in reading";
|
||||
}
|
||||
@ -1222,7 +1228,7 @@ sub OWXSWITCH_SetState($$) {
|
||||
#-- reading 9 + 3 + 1 data bytes + 2 CRC bytes = 15 bytes
|
||||
#-- asynchronous mode
|
||||
if( $hash->{ASYNC} ){
|
||||
if (OWX_Execute( $master, "setstateds2406.1.".$value, 1, $owx_dev, "\xAA\x07\x00", 3, undef )) {
|
||||
if (OWX_Execute( $master, "setstate.ds2406.1.".$value, 1, $owx_dev, "\xAA\x07\x00", 3, undef )) {
|
||||
return undef;
|
||||
} else {
|
||||
return "not accessible in writing";
|
||||
@ -1246,10 +1252,9 @@ sub OWXSWITCH_SetState($$) {
|
||||
$select=sprintf("\x5A%c%c",$value,255-$value);
|
||||
#-- asynchronous mode
|
||||
if( $hash->{ASYNC} ){
|
||||
if (OWX_Execute( $master, "setstateds2408", 1, $owx_dev, $select, 1, undef )) {
|
||||
OWX_Reset($master);
|
||||
return undef;
|
||||
} else {
|
||||
if (OWX_Execute( $master, "setstate.ds2408", 1, $owx_dev, $select, 1, undef )) {
|
||||
return undef;
|
||||
} else {
|
||||
return "device $owx_dev not accessible in writing";
|
||||
}
|
||||
#-- synchronous mode
|
||||
@ -1270,10 +1275,9 @@ sub OWXSWITCH_SetState($$) {
|
||||
$select=sprintf("\x5A%c%c",252+$value,3-$value);
|
||||
#-- asynchronous mode
|
||||
if( $hash->{ASYNC} ){
|
||||
if (OWX_Execute( $master, "setstateds2413", 1, $owx_dev, $select, 1, undef )) {
|
||||
OWX_Reset($master);
|
||||
return undef;
|
||||
} else {
|
||||
if (OWX_Execute( $master, "setstate.ds2413", 1, $owx_dev, $select, 1, undef )) {
|
||||
return undef;
|
||||
} else {
|
||||
return "device $owx_dev not accessible in writing";
|
||||
}
|
||||
#-- synchronous mode
|
||||
|
@ -225,18 +225,20 @@ sub OWTHERM_Define ($$) {
|
||||
$hash->{ROM_ID} = "$fam.$id.$crc";
|
||||
$hash->{INTERVAL} = $interval;
|
||||
$hash->{ERRCOUNT} = 0;
|
||||
$hash->{ASYNC} = 0; #-- false for now
|
||||
|
||||
#-- temperature globals - always the raw values from/for the device
|
||||
$hash->{owg_temp} = "";
|
||||
$hash->{owg_th} = "";
|
||||
$hash->{owg_tl} = "";
|
||||
|
||||
#-- Couple to I/O device, exit if not possible
|
||||
#-- Couple to I/O device
|
||||
AssignIoPort($hash);
|
||||
if( !defined($hash->{IODev}->{NAME}) || !defined($hash->{IODev}) ){
|
||||
if( !defined($hash->{IODev}) or !defined($hash->{IODev}->{NAME}) ){
|
||||
return "OWTHERM: Warning, no 1-Wire I/O device found for $name.";
|
||||
} else {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0; #-- false for now
|
||||
}
|
||||
|
||||
$modules{OWTHERM}{defptr}{$id} = $hash;
|
||||
#--
|
||||
readingsSingleUpdate($hash,"state","defined",1);
|
||||
@ -276,20 +278,28 @@ sub OWTHERM_Attr(@) {
|
||||
RemoveInternalTimer($hash);
|
||||
InternalTimer(gettimeofday()+$hash->{INTERVAL}, "OWTHERM_GetValues", $hash, 1);
|
||||
}
|
||||
last;
|
||||
};
|
||||
#-- resolution modified at runtime
|
||||
$key eq "resolution" and do {
|
||||
last;
|
||||
};
|
||||
#-- resolution modified at runtime
|
||||
$key eq "resolution" and do {
|
||||
$hash->{owg_cf} = $value;
|
||||
last;
|
||||
};
|
||||
#-- alarm settings modified at runtime
|
||||
$key =~ m/(.*)(Low|High)/ and do {
|
||||
#-- safeguard against uninitialized devices
|
||||
return undef
|
||||
if( $hash->{READINGS}{"state"}{VAL} eq "defined" );
|
||||
$ret = OWTHERM_Set($hash,($name,$key,$value));
|
||||
};
|
||||
};
|
||||
#-- alarm settings modified at runtime
|
||||
$key =~ m/(.*)(Low|High)/ and do {
|
||||
#-- safeguard against uninitialized devices
|
||||
return undef
|
||||
if( $hash->{READINGS}{"state"}{VAL} eq "defined" );
|
||||
$ret = OWTHERM_Set($hash,($name,$key,$value));
|
||||
last;
|
||||
};
|
||||
$key eq "IODev" and do {
|
||||
AssignIoPort($hash,$value);
|
||||
if( defined($hash->{IODev}) ) {
|
||||
$hash->{ASYNC} = $hash->{IODev}->{TYPE} eq "OWX_ASYNC" ? 1 : 0;
|
||||
}
|
||||
last;
|
||||
};
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
@ -411,7 +421,7 @@ sub OWTHERM_Get($@) {
|
||||
#-- get present
|
||||
if($a[1] eq "present" ) {
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
#-- hash of the busmaster
|
||||
my $master = $hash->{IODev};
|
||||
$value = OWX_Verify($master,$hash->{ROM_ID});
|
||||
@ -434,7 +444,7 @@ sub OWTHERM_Get($@) {
|
||||
}
|
||||
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
#-- not different from getting all values ..
|
||||
$ret = OWXTHERM_GetValues($hash);
|
||||
#ASYNC: NEED TO WAIT UNTIL DATA IS THERE
|
||||
@ -489,7 +499,7 @@ sub OWTHERM_GetValues($@) {
|
||||
|
||||
#-- Get values according to interface type
|
||||
my $interface= $hash->{IODev}->{TYPE};
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
#-- max 3 tries
|
||||
for(my $try=0; $try<3; $try++){
|
||||
$ret = OWXTHERM_GetValues($hash);
|
||||
@ -558,7 +568,7 @@ sub OWTHERM_InitializeDevice($) {
|
||||
$hash->{tempf}{factor} = $factor;
|
||||
|
||||
#-- Check if temperature conversion is consistent
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
if( defined($attr{$name}{tempConv}) && ( $attr{$name}{tempConv} eq "onkick") ){
|
||||
if( !(defined($attr{$hash->{IODev}->{NAME}}{dokick})) ||
|
||||
( defined($attr{$hash->{IODev}->{NAME}}{dokick}) && ($attr{$hash->{IODev}->{NAME}}{dokick} eq "0") )){
|
||||
@ -591,7 +601,7 @@ sub OWTHERM_InitializeDevice($) {
|
||||
|
||||
#-- put into device
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
$ret = OWXTHERM_SetValues($hash,$args);
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
@ -681,7 +691,7 @@ sub OWTHERM_Set($@) {
|
||||
}
|
||||
#-- put into device
|
||||
#-- OWX interface
|
||||
if( $interface eq "OWX" ){
|
||||
if( $interface =~ /^OWX/ ){
|
||||
$ret = OWXTHERM_SetValues($hash,$args);
|
||||
#-- OWFS interface
|
||||
}elsif( $interface eq "OWServer" ){
|
||||
@ -1010,8 +1020,6 @@ sub OWXTHERM_SetValues($$) {
|
||||
#-- resolution is defined in bits 5+6 of configuration register
|
||||
my $cfg = defined $hash->{owg_cf} ? (($hash->{owg_cf}-9) << 5) | 0x1f : 0x7f;
|
||||
|
||||
OWX_Reset($master);
|
||||
|
||||
#-- issue the match ROM command \x55 and the write scratchpad command \x4E,
|
||||
# followed by 3 bytes of data (alarm_temp_high, alarm_temp_low, config)
|
||||
# config-byte of 0x7F means 12 bit resolution (750ms convert time)
|
||||
@ -1027,6 +1035,7 @@ sub OWXTHERM_SetValues($$) {
|
||||
OWX_Execute($master,"setvalues",1,$owx_dev,$select,3,undef);
|
||||
#-- synchronous mode
|
||||
}else{
|
||||
OWX_Reset($master);
|
||||
my $res=OWX_Complex($master,$owx_dev,$select,3);
|
||||
if( $res eq 0 ){
|
||||
return "OWXTHERM: Device $owx_dev not accessible";
|
||||
|
Loading…
x
Reference in New Issue
Block a user