36_EleroDrive: support for two sticks

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@15168 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
HCS 2017-10-01 21:45:29 +00:00
parent 4d10a47ca1
commit acb595f825

View File

@ -1,10 +1,5 @@
# $Id$
# ToDo-List
# ---------
# [ ] Move to any position, not only top, bottom, intermediate, ...
package main;
use strict;
@ -51,7 +46,19 @@ sub EleroDrive_Define($$) {
$modules{EleroDrive}{defptr}{$channel} = $hash;
my $ioDev = undef;
my @parts = split("_", $devName);
if(@parts == 3) {
$ioDev = $parts[1];
}
if($ioDev) {
AssignIoPort($hash, $ioDev);
}
else {
AssignIoPort($hash);
}
if(defined($hash->{IODev}->{NAME})) {
Log3 $devName, 4, "$devName: I/O device is " . $hash->{IODev}->{NAME};
}
@ -214,6 +221,24 @@ sub EleroDrive_Parse($$) {
my $name = $hash->{NAME};
my $buffer = $msg;
# aa054d00010102 : channel 1 top
# aa054d00010202 : channel 1 bottom
# aa054d00020102 : channel 2 top
# aa054d00020202 : channel 2 bottom
# aa 05 4d 00 01 01 02
# ----- -- -- -- -- --
# | | | | | |
# | | | | | Checksum
# | | | | State (top, bottom, ...)
# | | | Lower channel bits (1 - 8)
# | | Upper channel bits (9 - 15)
# | 4d = Easy_Ack (answer on Easy_Send or Easy_Info)
# Fix aa 05
# State: 0x01 = top
# 0x02 = bottom
# 0x03 = intermediate
# 0x04 = tilt
# get the channel
my $firstChannels = substr($buffer,6,2);
my $secondChannels = substr($buffer,8,2);
@ -237,7 +262,24 @@ sub EleroDrive_Parse($$) {
}
}
my $rhash = $modules{EleroDrive}{defptr}{$channel};
my $rhash = undef;
foreach my $d (keys %defs) {
my $h = $defs{$d};
my $type = $h->{TYPE};
if($type eq "EleroDrive") {
if (defined($h->{IODev}->{NAME})) {
my $ioDev = $h->{IODev}->{NAME};
my $def = $h->{DEF};
if ($ioDev eq $name && $def eq $channel) {
$rhash = $h;
last;
}
}
}
}
if($rhash) {
my $rname = $rhash->{NAME};
# get status
@ -284,7 +326,6 @@ sub EleroDrive_Parse($$) {
my $newstate = $deviceStati{$statusByte};
my $percentClosed = $percentDefinitions{$statusByte};
if($modules{EleroDrive}{defptr}{$channel}) {
readingsBeginUpdate($rhash);
readingsBulkUpdate($rhash, "state", $newstate);
readingsBulkUpdate($rhash, "position", $newstate);
@ -298,7 +339,7 @@ sub EleroDrive_Parse($$) {
return @list;
}
else {
return "UNDEFINED EleroDrive_$channel EleroDrive $channel";
return "UNDEFINED EleroDrive_" . $name . "_" . $channel . " EleroDrive " . $channel;
}
}
}