diff --git a/fhem/CHANGED b/fhem/CHANGED index 841177c6f..c39b65c78 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 20_FRM_AD: analog resolution now depending on device capability - change: 93_DbLog: V3.6.5, avoid shutdown problem if database is too slow, extend configCheck with shutdown preparation check, fix logentries if device disabled and db not available diff --git a/fhem/FHEM/20_FRM_AD.pm b/fhem/FHEM/20_FRM_AD.pm index 3eb97bc09..c36acf79c 100755 --- a/fhem/FHEM/20_FRM_AD.pm +++ b/fhem/FHEM/20_FRM_AD.pm @@ -79,9 +79,14 @@ FRM_AD_Init($$) return $ret if (defined $ret); my $firmata = $hash->{IODev}->{FirmataDevice}; my $name = $hash->{NAME}; + my $resolution = 10; + if (defined $firmata->{metadata}{analog_resolutions}) { + $resolution = $firmata->{metadata}{analog_resolutions}{$hash->{PIN}} + } + $hash->{resolution} = $resolution; + $hash->{".max"} = defined $resolution ? (1<<$resolution)-1 : 1024; eval { $firmata->observe_analog($hash->{PIN},\&FRM_AD_observer,$hash); - $main::defs{$name}{resolution}=$firmata->{metadata}{analog_resolutions}{$hash->{PIN}} if (defined $firmata->{metadata}{analog_resolutions}); }; return FRM_Catch($@) if $@; if (! (defined AttrVal($name,"stateFormat",undef))) { @@ -99,28 +104,28 @@ FRM_AD_observer { my ($pin,$old,$new,$hash) = @_; my $name = $hash->{NAME}; - Log3 $name,6,"onAnalogMessage for pin ".$pin.", old: ".(defined $old ? $old : "--").", new: ".(defined $new ? $new : "--"); + Log3 $name,5,"onAnalogMessage for pin ".$pin.", old: ".(defined $old ? $old : "--").", new: ".(defined $new ? $new : "--"); main::readingsBeginUpdate($hash); main::readingsBulkUpdate($hash,"reading",$new,1); my $upperthresholdalarm = ReadingsVal($name,"alarm-upper-threshold","off"); - if ( $new < AttrVal($name,"upper-threshold",1024) ) { - if ( $upperthresholdalarm eq "on" ) { - main::readingsBulkUpdate($hash,"alarm-upper-threshold","off",1); - } - my $lowerthresholdalarm = ReadingsVal($name,"alarm-lower-threshold","off"); - if ( $new > AttrVal($name,"lower-threshold",-1) ) { - if ( $lowerthresholdalarm eq "on" ) { - main::readingsBulkUpdate($hash,"alarm-lower-threshold","off",1); - } - } else { - if ( $lowerthresholdalarm eq "off" ) { - main::readingsBulkUpdate($hash,"alarm-lower-threshold","on",1); - } - } - } else { - if ( $upperthresholdalarm eq "off" ) { - main::readingsBulkUpdate($hash,"alarm-upper-threshold","on",1); - } + if ( $new < AttrVal($name,"upper-threshold",$hash->{".max"}) ) { + if ( $upperthresholdalarm eq "on" ) { + main::readingsBulkUpdate($hash,"alarm-upper-threshold","off",1); + } + my $lowerthresholdalarm = ReadingsVal($name,"alarm-lower-threshold","off"); + if ( $new > AttrVal($name,"lower-threshold",-1) ) { + if ( $lowerthresholdalarm eq "on" ) { + main::readingsBulkUpdate($hash,"alarm-lower-threshold","off",1); + } + } else { + if ( $lowerthresholdalarm eq "off" ) { + main::readingsBulkUpdate($hash,"alarm-lower-threshold","on",1); + } + } + } else { + if ( $upperthresholdalarm eq "off" ) { + main::readingsBulkUpdate($hash,"alarm-upper-threshold","on",1); + } }; main::readingsEndUpdate($hash,1); } @@ -178,6 +183,9 @@ FRM_AD_Attr($$$$) { 2016 jensb o modified sub FRM_AD_Init to catch exceptions and return error message + + 19.01.2018 jensb + o support analog resolution depending on device capability =cut @@ -190,29 +198,33 @@ FRM_AD_Attr($$$$) {

FRM_AD


-
Set

+ Get

+ Attributes
- -
+
+ + + Notes
+ +
=end html =cut