2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-05 17:48:44 +00:00

OWX: do not start before global init is done

Merge branch 'owx_assign_iodev'

git-svn-id: https://svn.fhem.de/fhem/trunk@5267 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
ntruchsess 2014-03-20 20:44:43 +00:00
parent 309d74e78b
commit d98ee30eb8
2 changed files with 50 additions and 22 deletions

View File

@ -129,6 +129,7 @@ sub OWX_Initialize ($) {
$hash->{UndefFn} = "OWX_Undef";
$hash->{GetFn} = "OWX_Get";
$hash->{SetFn} = "OWX_Set";
$hash->{NotifyFn} = "OWX_Notify";
$hash->{AttrList}= "loglevel:0,1,2,3,4,5,6 buspower:real,parasitic IODev";
#-- Adapt to FRM
@ -160,6 +161,8 @@ sub OWX_Define ($$) {
#-- If this line contains 3 parameters, it is the bus master definition
my $dev = $a[2];
$hash->{NOTIFYDEV} = "global";
#-- Dummy 1-Wire ROM identifier, empty device lists
$hash->{ROM_ID} = "FF";
$hash->{DEVS} = [];
@ -221,11 +224,19 @@ sub OWX_Define ($$) {
return $msg." not defined";
}
}
if ($main::init_done) {
return OWX_Start($hash);
}
}
sub OWX_Start ($) {
my ($hash) = @_;
#-- Third step: see, if a bus interface is detected
if (!OWX_Detect($hash)){
$hash->{PRESENT} = 0;
readingsSingleUpdate($hash,"state","failed",1);
# $init_done = 1;
return undef;
}
#-- Fourth step: discovering devices on the bus
@ -237,18 +248,25 @@ sub OWX_Define ($$) {
$hash->{followAlarms} = "off";
$hash->{ALARMED} = "no";
#-- InternalTimer blocks if init_done is not true
my $oid = $init_done;
$hash->{PRESENT} = 1;
readingsSingleUpdate($hash,"state","defined",1);
$init_done = 1;
#-- Intiate first alarm detection and eventually conversion in a minute or so
InternalTimer(gettimeofday() + $hash->{interval}, "OWX_Kick", $hash,1);
$init_done = $oid;
$hash->{STATE} = "Active";
return undef;
}
sub OWX_Notify {
my ($hash,$dev) = @_;
my $name = $hash->{NAME};
my $type = $hash->{TYPE};
if( grep(m/^(INITIALIZED|REREADCFG)$/, @{$dev->{CHANGED}}) ) {
OWX_Start($hash);
} elsif( grep(m/^SAVE$/, @{$dev->{CHANGED}}) ) {
}
}
########################################################################################
#
# OWX_Alarms - Find devices on the 1-Wire bus,
@ -581,13 +599,19 @@ sub OWX_Detect ($) {
}
#-- nothing to do for Arduino (already done in FRM)
} elsif($owx_interface eq "firmata") {
my $iodev = $hash->{IODev};
if (defined $iodev and defined $iodev->{FirmataDevice} and defined $iodev->{FD}) {
$ret=1;
$ress .= "Firmata detected in $iodev->{NAME}";
} else {
$ret=0;
$ress .= defined $iodev ? "$iodev->{NAME} is not connected to Firmata" : "not associated to any FRM device";
eval {
FRM_Client_AssignIOPort($hash);
if (defined $hash->{IODev}) {
$ret=1;
$ress .= "Firmata detected in $hash->{IODev}->{NAME}";
} else {
$ret = 0;
$ress .= "not associated to any FRM device";
}
};
if ($@) {
$ress .= FRM_Catch($@);
$ret = 0;
}
#-- here we treat the COC/CUNO
} else {
@ -623,7 +647,7 @@ sub OWX_Detect ($) {
}
#-- store with OWX device
$hash->{INTERFACE} = $owx_interface;
Log 1, $ress;
Log3 $hash->{NAME}, 1, $ress;
return $ret;
}

View File

@ -550,6 +550,7 @@ FRM_Client_AssignIOPort($@)
&& defined( $dev->{IODev} )
&& defined( $dev->{PIN} )
&& $dev->{IODev} == $hash->{IODev}
&& defined( $hash->{PIN})
&& grep {$_ == $hash->{PIN}} split(" ",$dev->{PIN}) ) {
delete $hash->{IODev};
delete $attr{$name}{IODev};
@ -675,15 +676,18 @@ FRM_OWX_Init($$)
my ($hash,$args) = @_;
my $ret = FRM_Init_Pin_Client($hash,$args,PIN_ONEWIRE);
return $ret if (defined $ret);
my $firmata = $hash->{IODev}->{FirmataDevice};
my $pin = $hash->{PIN};
$hash->{FRM_OWX_CORRELATIONID} = 0;
$firmata->observe_onewire($pin,\&FRM_OWX_observer,$hash);
$hash->{FRM_OWX_REPLIES} = {};
$hash->{DEVS} = [];
if ( AttrVal($hash->{NAME},"buspower","") eq "parasitic" ) {
$firmata->onewire_config($pin,1);
}
eval {
my $firmata = FRM_Client_FirmataDevice($hash);
my $pin = $hash->{PIN};
$hash->{FRM_OWX_CORRELATIONID} = 0;
$firmata->observe_onewire($pin,\&FRM_OWX_observer,$hash);
$hash->{FRM_OWX_REPLIES} = {};
$hash->{DEVS} = [];
if ( AttrVal($hash->{NAME},"buspower","") eq "parasitic" ) {
$firmata->onewire_config($pin,1);
}
};
return FRM_Catch($@) if ($@);
$hash->{STATE}="Initialized";
InternalTimer(gettimeofday()+10, "OWX_Discover", $hash,0);
return undef;