mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +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:
parent
309d74e78b
commit
d98ee30eb8
@ -129,6 +129,7 @@ sub OWX_Initialize ($) {
|
|||||||
$hash->{UndefFn} = "OWX_Undef";
|
$hash->{UndefFn} = "OWX_Undef";
|
||||||
$hash->{GetFn} = "OWX_Get";
|
$hash->{GetFn} = "OWX_Get";
|
||||||
$hash->{SetFn} = "OWX_Set";
|
$hash->{SetFn} = "OWX_Set";
|
||||||
|
$hash->{NotifyFn} = "OWX_Notify";
|
||||||
$hash->{AttrList}= "loglevel:0,1,2,3,4,5,6 buspower:real,parasitic IODev";
|
$hash->{AttrList}= "loglevel:0,1,2,3,4,5,6 buspower:real,parasitic IODev";
|
||||||
|
|
||||||
#-- Adapt to FRM
|
#-- Adapt to FRM
|
||||||
@ -160,6 +161,8 @@ sub OWX_Define ($$) {
|
|||||||
#-- If this line contains 3 parameters, it is the bus master definition
|
#-- If this line contains 3 parameters, it is the bus master definition
|
||||||
my $dev = $a[2];
|
my $dev = $a[2];
|
||||||
|
|
||||||
|
$hash->{NOTIFYDEV} = "global";
|
||||||
|
|
||||||
#-- Dummy 1-Wire ROM identifier, empty device lists
|
#-- Dummy 1-Wire ROM identifier, empty device lists
|
||||||
$hash->{ROM_ID} = "FF";
|
$hash->{ROM_ID} = "FF";
|
||||||
$hash->{DEVS} = [];
|
$hash->{DEVS} = [];
|
||||||
@ -221,11 +224,19 @@ sub OWX_Define ($$) {
|
|||||||
return $msg." not defined";
|
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
|
#-- Third step: see, if a bus interface is detected
|
||||||
if (!OWX_Detect($hash)){
|
if (!OWX_Detect($hash)){
|
||||||
$hash->{PRESENT} = 0;
|
$hash->{PRESENT} = 0;
|
||||||
readingsSingleUpdate($hash,"state","failed",1);
|
readingsSingleUpdate($hash,"state","failed",1);
|
||||||
# $init_done = 1;
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
#-- Fourth step: discovering devices on the bus
|
#-- Fourth step: discovering devices on the bus
|
||||||
@ -237,18 +248,25 @@ sub OWX_Define ($$) {
|
|||||||
$hash->{followAlarms} = "off";
|
$hash->{followAlarms} = "off";
|
||||||
$hash->{ALARMED} = "no";
|
$hash->{ALARMED} = "no";
|
||||||
|
|
||||||
#-- InternalTimer blocks if init_done is not true
|
|
||||||
my $oid = $init_done;
|
|
||||||
$hash->{PRESENT} = 1;
|
$hash->{PRESENT} = 1;
|
||||||
readingsSingleUpdate($hash,"state","defined",1);
|
readingsSingleUpdate($hash,"state","defined",1);
|
||||||
$init_done = 1;
|
|
||||||
#-- Intiate first alarm detection and eventually conversion in a minute or so
|
#-- Intiate first alarm detection and eventually conversion in a minute or so
|
||||||
InternalTimer(gettimeofday() + $hash->{interval}, "OWX_Kick", $hash,1);
|
InternalTimer(gettimeofday() + $hash->{interval}, "OWX_Kick", $hash,1);
|
||||||
$init_done = $oid;
|
|
||||||
$hash->{STATE} = "Active";
|
$hash->{STATE} = "Active";
|
||||||
return undef;
|
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,
|
# 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)
|
#-- nothing to do for Arduino (already done in FRM)
|
||||||
} elsif($owx_interface eq "firmata") {
|
} elsif($owx_interface eq "firmata") {
|
||||||
my $iodev = $hash->{IODev};
|
eval {
|
||||||
if (defined $iodev and defined $iodev->{FirmataDevice} and defined $iodev->{FD}) {
|
FRM_Client_AssignIOPort($hash);
|
||||||
|
if (defined $hash->{IODev}) {
|
||||||
$ret=1;
|
$ret=1;
|
||||||
$ress .= "Firmata detected in $iodev->{NAME}";
|
$ress .= "Firmata detected in $hash->{IODev}->{NAME}";
|
||||||
} else {
|
} else {
|
||||||
$ret=0;
|
$ret = 0;
|
||||||
$ress .= defined $iodev ? "$iodev->{NAME} is not connected to Firmata" : "not associated to any FRM device";
|
$ress .= "not associated to any FRM device";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if ($@) {
|
||||||
|
$ress .= FRM_Catch($@);
|
||||||
|
$ret = 0;
|
||||||
}
|
}
|
||||||
#-- here we treat the COC/CUNO
|
#-- here we treat the COC/CUNO
|
||||||
} else {
|
} else {
|
||||||
@ -623,7 +647,7 @@ sub OWX_Detect ($) {
|
|||||||
}
|
}
|
||||||
#-- store with OWX device
|
#-- store with OWX device
|
||||||
$hash->{INTERFACE} = $owx_interface;
|
$hash->{INTERFACE} = $owx_interface;
|
||||||
Log 1, $ress;
|
Log3 $hash->{NAME}, 1, $ress;
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -550,6 +550,7 @@ FRM_Client_AssignIOPort($@)
|
|||||||
&& defined( $dev->{IODev} )
|
&& defined( $dev->{IODev} )
|
||||||
&& defined( $dev->{PIN} )
|
&& defined( $dev->{PIN} )
|
||||||
&& $dev->{IODev} == $hash->{IODev}
|
&& $dev->{IODev} == $hash->{IODev}
|
||||||
|
&& defined( $hash->{PIN})
|
||||||
&& grep {$_ == $hash->{PIN}} split(" ",$dev->{PIN}) ) {
|
&& grep {$_ == $hash->{PIN}} split(" ",$dev->{PIN}) ) {
|
||||||
delete $hash->{IODev};
|
delete $hash->{IODev};
|
||||||
delete $attr{$name}{IODev};
|
delete $attr{$name}{IODev};
|
||||||
@ -675,7 +676,8 @@ FRM_OWX_Init($$)
|
|||||||
my ($hash,$args) = @_;
|
my ($hash,$args) = @_;
|
||||||
my $ret = FRM_Init_Pin_Client($hash,$args,PIN_ONEWIRE);
|
my $ret = FRM_Init_Pin_Client($hash,$args,PIN_ONEWIRE);
|
||||||
return $ret if (defined $ret);
|
return $ret if (defined $ret);
|
||||||
my $firmata = $hash->{IODev}->{FirmataDevice};
|
eval {
|
||||||
|
my $firmata = FRM_Client_FirmataDevice($hash);
|
||||||
my $pin = $hash->{PIN};
|
my $pin = $hash->{PIN};
|
||||||
$hash->{FRM_OWX_CORRELATIONID} = 0;
|
$hash->{FRM_OWX_CORRELATIONID} = 0;
|
||||||
$firmata->observe_onewire($pin,\&FRM_OWX_observer,$hash);
|
$firmata->observe_onewire($pin,\&FRM_OWX_observer,$hash);
|
||||||
@ -684,6 +686,8 @@ FRM_OWX_Init($$)
|
|||||||
if ( AttrVal($hash->{NAME},"buspower","") eq "parasitic" ) {
|
if ( AttrVal($hash->{NAME},"buspower","") eq "parasitic" ) {
|
||||||
$firmata->onewire_config($pin,1);
|
$firmata->onewire_config($pin,1);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
return FRM_Catch($@) if ($@);
|
||||||
$hash->{STATE}="Initialized";
|
$hash->{STATE}="Initialized";
|
||||||
InternalTimer(gettimeofday()+10, "OWX_Discover", $hash,0);
|
InternalTimer(gettimeofday()+10, "OWX_Discover", $hash,0);
|
||||||
return undef;
|
return undef;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user