From 5cc7843fbd8c7818a32d6cdc745db5de47d25d05 Mon Sep 17 00:00:00 2001 From: ntruchsess <> Date: Tue, 2 Apr 2013 09:04:02 +0000 Subject: [PATCH] fire events on AD and I2C readings change. Add Windows USB-handling git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@3018 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/10_FRM.pm | 36 ++++++++++++++++++++++++++++-------- FHEM/20_FRM_AD.pm | 3 +-- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/FHEM/10_FRM.pm b/FHEM/10_FRM.pm index 67859627e..2cf09a6e7 100755 --- a/FHEM/10_FRM.pm +++ b/FHEM/10_FRM.pm @@ -170,6 +170,14 @@ sub FRM_Ready($) { return undef; } return DevIo_OpenDev($hash, 1, "FRM_DoInit") if($hash->{STATE} eq "disconnected"); + + # This is relevant for windows/USB only + my $po = $hash->{USBDev}; + my ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags); + if($po) { + ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags) = $po->status; + } + return ($InBytes && $InBytes>0); } sub FRM_Attr(@) { @@ -430,7 +438,7 @@ sub FRM_i2c_update_device readingsBeginUpdate($hash); $hash->{STATE}="active"; readingsBulkUpdate($hash,"values",join (" ",@values),1); - readingsEndUpdate($hash,undef); + readingsEndUpdate($hash,1); } } @@ -444,14 +452,26 @@ sub FRM_string_observer sub FRM_poll { my ($hash) = @_; - my ($rout, $rin) = ('', ''); - vec($rin, $hash->{FD}, 1) = 1; - my $nfound = select($rout=$rin, undef, undef, 0.1); - my $mfound = vec($rout, $hash->{FD}, 1); - if($mfound) { - $hash->{FirmataDevice}->poll(); + if (defined $hash->{FD}) { + my ($rout, $rin) = ('', ''); + vec($rin, $hash->{FD}, 1) = 1; + my $nfound = select($rout=$rin, undef, undef, 0.1); + my $mfound = vec($rout, $hash->{FD}, 1); + if($mfound) { + $hash->{FirmataDevice}->poll(); + } + return $mfound; + } else { + # This is relevant for windows/USB only + my $po = $hash->{USBDev}; + my ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags); + if($po) { + ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags) = $po->status; + } + if ($InBytes && $InBytes>0) { + $hash->{FirmataDevice}->poll(); + } } - return $mfound; } ######### following is code to be called from OWX: ########## diff --git a/FHEM/20_FRM_AD.pm b/FHEM/20_FRM_AD.pm index e2d93e88a..23ae9403b 100755 --- a/FHEM/20_FRM_AD.pm +++ b/FHEM/20_FRM_AD.pm @@ -72,8 +72,7 @@ FRM_AD_observer main::readingsBulkUpdate($hash,"alarm-upper-threshold","on",1); } }; - main::readingsBulkUpdate($hash,"reading",$new, 1); - main::readingsEndUpdate($hash,0); + main::readingsEndUpdate($hash,1); } sub