mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 16:56:54 +00:00
20_FRM_AD.pm: analog resolution depending on device capability (Forum #81815)
git-svn-id: https://svn.fhem.de/fhem/trunk@15932 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
5b31decf28
commit
78f921e6d9
@ -1,5 +1,6 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# 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.
|
# 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,
|
- change: 93_DbLog: V3.6.5, avoid shutdown problem if database is too slow,
|
||||||
extend configCheck with shutdown preparation check,
|
extend configCheck with shutdown preparation check,
|
||||||
fix logentries if device disabled and db not available
|
fix logentries if device disabled and db not available
|
||||||
|
@ -79,9 +79,14 @@ FRM_AD_Init($$)
|
|||||||
return $ret if (defined $ret);
|
return $ret if (defined $ret);
|
||||||
my $firmata = $hash->{IODev}->{FirmataDevice};
|
my $firmata = $hash->{IODev}->{FirmataDevice};
|
||||||
my $name = $hash->{NAME};
|
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 {
|
eval {
|
||||||
$firmata->observe_analog($hash->{PIN},\&FRM_AD_observer,$hash);
|
$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 $@;
|
return FRM_Catch($@) if $@;
|
||||||
if (! (defined AttrVal($name,"stateFormat",undef))) {
|
if (! (defined AttrVal($name,"stateFormat",undef))) {
|
||||||
@ -99,11 +104,11 @@ FRM_AD_observer
|
|||||||
{
|
{
|
||||||
my ($pin,$old,$new,$hash) = @_;
|
my ($pin,$old,$new,$hash) = @_;
|
||||||
my $name = $hash->{NAME};
|
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::readingsBeginUpdate($hash);
|
||||||
main::readingsBulkUpdate($hash,"reading",$new,1);
|
main::readingsBulkUpdate($hash,"reading",$new,1);
|
||||||
my $upperthresholdalarm = ReadingsVal($name,"alarm-upper-threshold","off");
|
my $upperthresholdalarm = ReadingsVal($name,"alarm-upper-threshold","off");
|
||||||
if ( $new < AttrVal($name,"upper-threshold",1024) ) {
|
if ( $new < AttrVal($name,"upper-threshold",$hash->{".max"}) ) {
|
||||||
if ( $upperthresholdalarm eq "on" ) {
|
if ( $upperthresholdalarm eq "on" ) {
|
||||||
main::readingsBulkUpdate($hash,"alarm-upper-threshold","off",1);
|
main::readingsBulkUpdate($hash,"alarm-upper-threshold","off",1);
|
||||||
}
|
}
|
||||||
@ -179,6 +184,9 @@ FRM_AD_Attr($$$$) {
|
|||||||
2016 jensb
|
2016 jensb
|
||||||
o modified sub FRM_AD_Init to catch exceptions and return error message
|
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
|
=cut
|
||||||
|
|
||||||
=pod
|
=pod
|
||||||
@ -190,29 +198,33 @@ FRM_AD_Attr($$$$) {
|
|||||||
<a name="FRM_AD"></a>
|
<a name="FRM_AD"></a>
|
||||||
<h3>FRM_AD</h3>
|
<h3>FRM_AD</h3>
|
||||||
<ul>
|
<ul>
|
||||||
represents a pin of an <a href="http://www.arduino.cc">Arduino</a> running <a href="http://www.firmata.org">Firmata</a>
|
This module represents a pin of a <a href="http://www.firmata.org">Firmata device</a>
|
||||||
configured for analog input.<br>
|
that should be configured as an analog input.<br><br>
|
||||||
The value read is stored in reading 'state'. Range is from 0 to 1023 (10 Bit)<br>
|
|
||||||
Requires a defined <a href="#FRM">FRM</a>-device to work.<br><br>
|
Requires a defined <a href="#FRM">FRM</a> device to work. The pin must be listed in the internal reading "<a href="#FRMinternals">analog_pins</a>"<br>
|
||||||
|
of the FRM device (after connecting to the Firmata device) to be used as analog input.<br><br>
|
||||||
|
|
||||||
<a name="FRM_ADdefine"></a>
|
<a name="FRM_ADdefine"></a>
|
||||||
<b>Define</b>
|
<b>Define</b>
|
||||||
<ul>
|
<ul>
|
||||||
<code>define <name> FRM_AD <pin></code> <br>
|
<code>define <name> FRM_AD <pin></code><br><br>
|
||||||
Defines the FRM_AD device. <pin> is the arduino-pin to use.
|
|
||||||
</ul>
|
Defines the FRM_AD device. <pin> is the arduino-pin to use.
|
||||||
|
</ul><br>
|
||||||
|
|
||||||
<br>
|
|
||||||
<a name="FRM_ADset"></a>
|
<a name="FRM_ADset"></a>
|
||||||
<b>Set</b><br>
|
<b>Set</b><br>
|
||||||
<ul>
|
<ul>
|
||||||
N/A<br>
|
N/A<br>
|
||||||
</ul><br>
|
</ul><br>
|
||||||
|
|
||||||
<a name="FRM_ADget"></a>
|
<a name="FRM_ADget"></a>
|
||||||
<b>Get</b><br>
|
<b>Get</b><br>
|
||||||
<ul>
|
<ul>
|
||||||
<li>reading<br>
|
<li>reading<br>
|
||||||
returns the voltage-level read on the arduino-pin. Values range from 0 to 1023.</li>
|
returns the voltage-level equivalent at the arduino-pin. The min value is zero and the max value<br>
|
||||||
|
depends on the Firmata device (see internal reading "<a href="#FRMinternals">analog_resolutions</a>" of the FRM device.<br>
|
||||||
|
For 10 bits resolution the range is 0 to 1023 (also see <a href="http://arduino.cc/en/Reference/AnalogRead">analogRead()</a> for details)<br></li>
|
||||||
<li>alarm-upper-threshold<br>
|
<li>alarm-upper-threshold<br>
|
||||||
returns the current state of 'alarm-upper-threshold'. Values are 'on' and 'off' (Defaults to 'off')<br>
|
returns the current state of 'alarm-upper-threshold'. Values are 'on' and 'off' (Defaults to 'off')<br>
|
||||||
'alarm-upper-threshold' turns 'on' whenever the 'reading' is higher than the attribute 'upper-threshold'<br>
|
'alarm-upper-threshold' turns 'on' whenever the 'reading' is higher than the attribute 'upper-threshold'<br>
|
||||||
@ -224,13 +236,14 @@ FRM_AD_Attr($$$$) {
|
|||||||
<li>state<br>
|
<li>state<br>
|
||||||
returns the 'state' reading</li>
|
returns the 'state' reading</li>
|
||||||
</ul><br>
|
</ul><br>
|
||||||
|
|
||||||
<a name="FRM_ADattr"></a>
|
<a name="FRM_ADattr"></a>
|
||||||
<b>Attributes</b><br>
|
<b>Attributes</b><br>
|
||||||
<ul>
|
<ul>
|
||||||
<li>upper-threshold<br>
|
<li>upper-threshold<br>
|
||||||
sets the 'upper-threshold'. Whenever the 'reading' exceeds this value 'alarm-upper-threshold' is set to 'on'<br>
|
sets the 'upper-threshold'. Whenever the 'reading' exceeds this value 'alarm-upper-threshold' is set to 'on'<br>
|
||||||
As soon 'reading' falls below the 'upper-threshold' 'alarm-upper-threshold' turns 'off' again<br>
|
As soon 'reading' falls below the 'upper-threshold' 'alarm-upper-threshold' turns 'off' again<br>
|
||||||
Defaults to 1024.</li>
|
Defaults to the max pin resolution plus one.</li>
|
||||||
<li>lower-threshold<br>
|
<li>lower-threshold<br>
|
||||||
sets the 'lower-threshold'. Whenever the 'reading' falls below this value 'alarm-lower-threshold' is set to 'on'<br>
|
sets the 'lower-threshold'. Whenever the 'reading' falls below this value 'alarm-lower-threshold' is set to 'on'<br>
|
||||||
As soon 'reading' rises above the 'lower-threshold' 'alarm-lower-threshold' turns 'off' again<br>
|
As soon 'reading' rises above the 'lower-threshold' 'alarm-lower-threshold' turns 'off' again<br>
|
||||||
@ -241,9 +254,17 @@ FRM_AD_Attr($$$$) {
|
|||||||
</li>
|
</li>
|
||||||
<li><a href="#eventMap">eventMap</a><br></li>
|
<li><a href="#eventMap">eventMap</a><br></li>
|
||||||
<li><a href="#readingFnAttributes">readingFnAttributes</a><br></li>
|
<li><a href="#readingFnAttributes">readingFnAttributes</a><br></li>
|
||||||
|
</ul><br>
|
||||||
|
|
||||||
|
<a name="FRM_ADnotes"></a>
|
||||||
|
<b>Notes</b><br>
|
||||||
|
<ul>
|
||||||
|
<li>attribute <i>stateFormat</i><br>
|
||||||
|
In most cases it is a good idea to assign "reading" to the attribute <i>stateFormat</i>. This will show the
|
||||||
|
current value of the pin in the web interface.
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</ul>
|
</ul><br>
|
||||||
<br>
|
|
||||||
|
|
||||||
=end html
|
=end html
|
||||||
=cut
|
=cut
|
||||||
|
Loading…
x
Reference in New Issue
Block a user