20_FRM_OUT.pm: fix "uninitialised" warning when calling FRM_OUT_Set without command (Forum #81815)

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@15928 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jensb 2018-01-19 21:07:42 +00:00
parent acbced894d
commit b9eeb8a186

View File

@ -114,21 +114,25 @@ FRM_OUT_Set($$$)
my ($hash, $name, $cmd, @a) = @_; my ($hash, $name, $cmd, @a) = @_;
my $value; my $value;
my $invert = AttrVal($hash->{NAME},"activeLow", "no"); my $invert = AttrVal($hash->{NAME},"activeLow", "no");
if ($cmd eq "on") { if (defined ($cmd)) {
$value = $invert eq "yes" ? PIN_LOW : PIN_HIGH; if ($cmd eq "on") {
} elsif ($cmd eq "off") { $value = $invert eq "yes" ? PIN_LOW : PIN_HIGH;
$value = $invert eq "yes" ? PIN_HIGH : PIN_LOW; } elsif ($cmd eq "off") {
} else { $value = $invert eq "yes" ? PIN_HIGH : PIN_LOW;
my $list = "on off"; } else {
return SetExtensions($hash, $list, $name, $cmd, @a); my $list = "on off";
} return SetExtensions($hash, $list, $name, $cmd, @a);
eval {
FRM_Client_FirmataDevice($hash)->digital_write($hash->{PIN},$value);
if (AttrVal($hash->{NAME}, "valueMode", "send") ne "receive") {
main::readingsSingleUpdate($hash,"value",$cmd, 1);
} }
}; eval {
return $@; FRM_Client_FirmataDevice($hash)->digital_write($hash->{PIN},$value);
if (AttrVal($hash->{NAME}, "valueMode", "send") ne "receive") {
main::readingsSingleUpdate($hash,"value",$cmd, 1);
}
};
return $@;
} else {
return "no command specified";
}
} }
sub FRM_OUT_State($$$$) sub FRM_OUT_State($$$$)
@ -195,6 +199,8 @@ FRM_OUT_Attr($$$$) {
o create reading "value" in FRM_OUT_Init if missing o create reading "value" in FRM_OUT_Init if missing
02.01.2018 jensb 02.01.2018 jensb
o new attribute "valueMode" to control how "value" reading is updated o new attribute "valueMode" to control how "value" reading is updated
14.01.2018 jensb
o fix "uninitialised" when calling FRM_OUT_Set without command
=cut =cut
@ -207,18 +213,20 @@ FRM_OUT_Attr($$$$) {
<a name="FRM_OUT"></a> <a name="FRM_OUT"></a>
<h3>FRM_OUT</h3> <h3>FRM_OUT</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 digital output.<br> that should be configured as a digital output.<br><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">output_pins</a>"<br>
of the FRM device (after connecting to the Firmata device) to be used as digital output.<br><br>
<a name="FRM_OUTdefine"></a> <a name="FRM_OUTdefine"></a>
<b>Define</b> <b>Define</b>
<ul> <ul>
<code>define &lt;name&gt; FRM_OUT &lt;pin&gt;</code> <br> <code>define &lt;name&gt; FRM_OUT &lt;pin&gt;</code> <br>
Defines the FRM_OUT device. &lt;pin&gt> is the arduino-pin to use. Defines the FRM_OUT device. &lt;pin&gt> is the arduino-pin to use.
</ul> </ul><br>
<br>
<a name="FRM_OUTset"></a> <a name="FRM_OUTset"></a>
<b>Set</b><br> <b>Set</b><br>
<ul> <ul>
@ -226,12 +234,14 @@ FRM_OUT_Attr($$$$) {
</ul> </ul>
<ul> <ul>
<a href="#setExtensions">set extensions</a> are supported<br> <a href="#setExtensions">set extensions</a> are supported<br>
</ul> </ul><br>
<a name="FRM_OUTget"></a> <a name="FRM_OUTget"></a>
<b>Get</b><br> <b>Get</b><br>
<ul> <ul>
N/A N/A
</ul><br> </ul><br>
<a name="FRM_OUTattr"></a> <a name="FRM_OUTattr"></a>
<b>Attributes</b><br> <b>Attributes</b><br>
<ul> <ul>
@ -254,17 +264,27 @@ FRM_OUT_Attr($$$$) {
<li>receive - after receiving</li> <li>receive - after receiving</li>
<li>bidirectional - after sending and receiving</li> <li>bidirectional - after sending and receiving</li>
</ul> </ul>
If you have custom code in your Firmata device that can change the state of an output
you can enable receive or bidirectional mode. For this to work the default Firmata application code must
also be modified in function <em>setPinModeCallback</em>: add <ins>|| mode == OUTPUT</ins>
to the if condition for <em>portConfigInputs[pin / 8] |= (1 << (pin & 7));</em> to enable
reporting the output state as if the pin is an input.
</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> </ul><br>
<a name="FRM_OUTnotes"></a>
<b>Notes</b><br>
<ul>
<li>attribute <i>stateFormat</i><br>
In most cases it is a good idea to assign "value" to the attribute <i>stateFormat</i>. This will show the state
of the pin in the web interface.
</li>
<li>attribute <i>valueMode</i><br>
For modes "receive<" and "bidirectional" to work the default Firmata application code must
be modified in function "<code>setPinModeCallback</code>":<br>
add "<ins> || mode == OUTPUT</ins>" to the if condition for "<code>portConfigInputs[pin / 8] |= (1 << (pin & 7));</code>" to enable<br>
reporting the output state (as if the pin were an input). This is of interest if you have custom code in your Firmata device that can change<br>
the state of an output or you want a feedback from the Firmata device after the output state was changed.
</li>
</ul> </ul>
<br> </ul><br>
=end html =end html
=cut =cut