mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-01 13:29:26 +00:00
fc29e62337
git-svn-id: https://svn.fhem.de/fhem/trunk@2441 2b470e98-0d58-463d-a4d8-8e2adae1ed80
189 lines
4.6 KiB
Perl
Executable File
189 lines
4.6 KiB
Perl
Executable File
#############################################
|
|
# $Id$
|
|
package main;
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
sub
|
|
FHT8V_Initialize($)
|
|
{
|
|
my ($hash) = @_;
|
|
|
|
$hash->{DefFn} = "FHT8V_Define";
|
|
$hash->{SetFn} = "FHT8V_Set";
|
|
$hash->{GetFn} = "FHT8V_Get";
|
|
$hash->{AttrList} = "IODev dummy:1,0 ignore:1,0 loglevel:0,1,2,3,4,5,6 ".
|
|
$readingFnAttributes;
|
|
}
|
|
|
|
#############################
|
|
sub
|
|
FHT8V_Define($$)
|
|
{
|
|
my ($hash, $def) = @_;
|
|
my @a = split("[ \t][ \t]*", $def);
|
|
my $n = $a[0];
|
|
|
|
return "wrong syntax: define <name> FHT8V housecode [IODev]" if(@a < 3);
|
|
return "wrong housecode format: specify a 4 digit hex value "
|
|
if(($a[2] !~ m/^[a-f0-9]{4}$/i));
|
|
if(@a > 3) {
|
|
$hash->{IODev} = $defs{$a[3]};
|
|
} else {
|
|
AssignIoPort($hash);
|
|
}
|
|
return "$n: No IODev found" if(!$hash->{IODev});
|
|
return "$n: Wrong IODev, has no FHTID" if(!$hash->{IODev}->{FHTID});
|
|
|
|
#####################
|
|
# Check if the address corresponds to the CUL
|
|
my $ioaddr = hex($hash->{IODev}->{FHTID});
|
|
my $myaddr = hex($a[2]);
|
|
my ($io1, $io0) = (int($ioaddr/255), $ioaddr % 256);
|
|
my ($my1, $my0) = (int($myaddr/255), $myaddr % 256);
|
|
if($my1 < $io1 || $my1 > $io1+7 || $io0 != $my0) {
|
|
my $vals = "";
|
|
for(my $m = 0; $m <= 7; $m++) {
|
|
$vals .= sprintf(" %2x%2x", $io1+$m, $io0);
|
|
}
|
|
return sprintf("Wrong housecode: must be one of$vals");
|
|
}
|
|
|
|
$hash->{addr} = uc($a[2]);
|
|
$hash->{idx} = sprintf("%02X", $my1-$io1);
|
|
$hash->{STATE} = "defined";
|
|
return "";
|
|
}
|
|
|
|
|
|
sub
|
|
FHT8V_Set($@)
|
|
{
|
|
my ($hash, @a) = @_;
|
|
my $n = $hash->{NAME};
|
|
|
|
return "Need a parameter for set" if(@a < 2);
|
|
my $arg = $a[1];
|
|
|
|
if($arg eq "valve" ) {
|
|
return "Set valve needs a numeric parameter between 0 and 100"
|
|
if(@a != 3 || $a[2] !~ m/^\d+$/ || $a[2] < 0 || $a[2] > 100);
|
|
Log GetLogLevel($n,3), "FHT8V set $n $arg $a[2]";
|
|
$hash->{STATE} = sprintf("%d %%", $a[2]);
|
|
IOWrite($hash, "", sprintf("T%s0026%02X", $hash->{addr}, $a[2]*2.55));
|
|
|
|
} elsif ($arg eq "pair" ) {
|
|
Log GetLogLevel($n,3), "FHT8V set $n $arg";
|
|
IOWrite($hash, "", sprintf("T%s002f00", $hash->{addr}));
|
|
|
|
} else {
|
|
return "Unknown argument $a[1], choose one of valve pair"
|
|
|
|
}
|
|
return "";
|
|
|
|
}
|
|
|
|
sub
|
|
FHT8V_Get($@)
|
|
{
|
|
my ($hash, @a) = @_;
|
|
my $n = $hash->{NAME};
|
|
|
|
return "Need a parameter for get" if(@a < 2);
|
|
my $arg = $a[1];
|
|
|
|
if($arg eq "valve" ) {
|
|
my $io = $hash->{IODev};
|
|
my $msg = CallFn($io->{NAME}, "GetFn", $io, (" ", "raw", "T10"));
|
|
my $idx = $hash->{idx};
|
|
return int(hex($1)/2.55) if($msg =~ m/$idx:26(..)/);
|
|
return "N/A";
|
|
|
|
}
|
|
return "Unknown argument $a[1], choose one of valve"
|
|
}
|
|
|
|
|
|
1;
|
|
|
|
=pod
|
|
=begin html
|
|
|
|
<a name="FHT8V"></a>
|
|
<h3>FHT8V</h3>
|
|
<ul>
|
|
Fhem can directly control FHT8V type valves via a <a href="#CUL">CUL</a>
|
|
device without an intermediate FHT. This paragraph documents one of the
|
|
building blocks, the other is the <a href="#PID">PID</a> device.
|
|
<br>
|
|
<br>
|
|
|
|
<a name="FHT8Vdefine"></a>
|
|
<b>Define</b>
|
|
<ul>
|
|
<code>define <name> FHT <housecode> [IODev]</code>
|
|
<br><br>
|
|
|
|
<code><housecode></code> is a four digit hex number,
|
|
and must have the following relation to the housecode of the corresponding CUL
|
|
device:
|
|
<ul>given the CUL housecode as AABB, then this housecode must be
|
|
of the form CCBB, where CC is greater or equal to AA, but less then AA+8.
|
|
</ul>
|
|
This form is chosen so that the CUL can update all FHT8V valve states
|
|
within 2 minutes.
|
|
<br>
|
|
<br>
|
|
<code><IODev></code> must be specified if the last defined CUL device
|
|
is not the one to use. Usually this is done voa the <a
|
|
href="#IODev">IODev</a> attribute, but as the address checked is performed
|
|
at the definition, we must use an exception here.
|
|
<br>
|
|
|
|
Examples:
|
|
<ul>
|
|
<code>define wz FHT8V 3232</code><br>
|
|
</ul>
|
|
</ul>
|
|
<br>
|
|
|
|
<a name="FHT8Vset"></a>
|
|
<b>Set </b>
|
|
<ul>
|
|
<li>set <name> valve <value;><br>
|
|
Set the valve to the given value (in percent, from 0 to 100).
|
|
</li>
|
|
<li>set <name> pair<br>
|
|
Pair the valve with the CUL.
|
|
</li>
|
|
</ul>
|
|
<br>
|
|
|
|
<a name="FHT8Vget"></a>
|
|
<b>Get </b>
|
|
<ul>
|
|
<li>get <name> valve<br>
|
|
Read back the valve position from the CUL FHT buffer, and convert it to percent (from 0 to 100).
|
|
</li>
|
|
</ul>
|
|
<br>
|
|
|
|
<a name="FHT8Vattr"></a>
|
|
<b>Attributes</b>
|
|
<ul>
|
|
<li><a href="#IODev">IODev</a></li>
|
|
<li><a href="#dummy">dummy</a></li>
|
|
<li><a href="#ignore">ignore</a></li>
|
|
<li><a href="#loglevel">loglevel</a></li>
|
|
<li><a href="#eventMap">eventMap</a></li><br>
|
|
<li><a href="#readingFnAttributes">readingFnAttributes</a></li>
|
|
</ul>
|
|
<br>
|
|
</ul>
|
|
|
|
|
|
=end html
|
|
=cut
|