mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-21 01:46:08 +00:00
FRM_IN: fix attribute 'internal-pullup' and 'activeLow' if device is not connected at startup
git-svn-id: https://svn.fhem.de/fhem/trunk@5234 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
0505f3a2d7
commit
f498753fba
@ -567,6 +567,15 @@ sub FRM_Client_FirmataDevice($) {
|
||||
return $iodev->{FirmataDevice};
|
||||
}
|
||||
|
||||
sub FRM_Catch($) {
|
||||
my $exception = shift;
|
||||
if ($exception) {
|
||||
$exception =~ /^(.*)( at.*FHEM.*)$/;
|
||||
return $1;
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
package Firmata_IO;
|
||||
|
||||
sub new {
|
||||
|
@ -59,6 +59,7 @@ FRM_IN_Init($$)
|
||||
}
|
||||
$firmata->observe_digital($pin,\&FRM_IN_observer,$hash);
|
||||
};
|
||||
return FRM_Catch($@) if $@;
|
||||
if (! (defined AttrVal($hash->{NAME},"stateFormat",undef))) {
|
||||
$main::attr{$hash->{NAME}}{"stateFormat"} = "reading";
|
||||
}
|
||||
@ -192,17 +193,21 @@ FRM_IN_Attr($$$$) {
|
||||
last;
|
||||
};
|
||||
$attribute eq "internal-pullup" and do {
|
||||
my $firmata = FRM_Client_FirmataDevice($hash);
|
||||
$firmata->digital_write($pin,$value eq "on" ? 1 : 0);
|
||||
#ignore any errors here, the attribute-value will be applied next time FRM_IN_init() is called.
|
||||
if ($main::init_done) {
|
||||
my $firmata = FRM_Client_FirmataDevice($hash);
|
||||
$firmata->digital_write($pin,$value eq "on" ? 1 : 0);
|
||||
#ignore any errors here, the attribute-value will be applied next time FRM_IN_init() is called.
|
||||
}
|
||||
last;
|
||||
};
|
||||
$attribute eq "activeLow" and do {
|
||||
my $oldval = AttrVal($hash->{NAME},"activeLow","no");
|
||||
if ($oldval ne $value) {
|
||||
$main::attr{$hash->{NAME}}{activeLow} = $value;
|
||||
my $firmata = FRM_Client_FirmataDevice($hash);
|
||||
FRM_IN_observer($pin,undef,$firmata->digital_read($pin),$hash);
|
||||
if ($main::init_done) {
|
||||
my $firmata = FRM_Client_FirmataDevice($hash);
|
||||
FRM_IN_observer($pin,undef,$firmata->digital_read($pin),$hash);
|
||||
}
|
||||
};
|
||||
last;
|
||||
};
|
||||
@ -225,10 +230,9 @@ FRM_IN_Attr($$$$) {
|
||||
}
|
||||
}
|
||||
};
|
||||
if ($@) {
|
||||
$@ =~ /^(.*)( at.*FHEM.*)$/;
|
||||
$hash->{STATE} = "error setting $attribute to $value: ".$1;
|
||||
return "cannot $command attribute $attribute to $value for $name: ".$1;
|
||||
if (my $error = FRM_Catch($@)) {
|
||||
$hash->{STATE} = "error setting $attribute to $value: ".$error;
|
||||
return "cannot $command attribute $attribute to $value for $name: ".$error;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user