Code by B.M.

git-svn-id: https://svn.fhem.de/fhem/trunk@816 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig
2011-01-29 16:41:57 +00:00
parent 0c92b39bfe
commit 68b9f48450
2 changed files with 102 additions and 33 deletions

View File

@@ -17,6 +17,7 @@ LIRC_Initialize($)
# Provider
$hash->{ReadFn} = "LIRC_Read";
$hash->{ReadyFn} = "LIRC_Ready";
$hash->{Clients} = ":LIRC:";
# Consumer
@@ -33,13 +34,14 @@ LIRC_Define($$)
$hash->{STATE} = "Initialized";
$hash->{LircObj}->clean_up() if($hash->{LircObj});
delete $hash->{LircObj};
delete $hash->{FD};
my $name = $a[0];
my $config = $a[2];
Log 3, "LIRC opening LIRC device $config";
Log 3, "LIRC opening $name device $config";
my $lirc = Lirc::Client->new({
prog => 'fhem',
rcfile => "$config",
@@ -53,8 +55,10 @@ LIRC_Define($$)
$select->add( $lirc->sock );
$hash->{LircObj} = $lirc;
$hash->{FD} = $lirc->sock;
$selectlist{"$name.$config"} = $hash;
$hash->{FD} = $lirc->{sock}; # is not working and sets timeout to undefined
$selectlist{"$name"} = $hash; #
$readyfnlist{"$name"} = $hash; # thats why we start polling
$hash->{SelectObj} = $select;
$hash->{DeviceName} = $name;
$hash->{STATE} = "Opened";
@@ -68,7 +72,10 @@ LIRC_Undef($$)
{
my ($hash, $arg) = @_;
$hash->{LircObj}->close() if($hash->{LircObj});
$hash->{LircObj}->clean_up() if($hash->{LircObj});
delete $hash->{LircObj};
delete $hash->{FD};
return undef;
}
@@ -85,11 +92,22 @@ LIRC_Read($)
# an ir event has been received (if you are tracking other filehandles, you need to make sure it is lirc)
my @codes = $lirc->next_codes; # should not block
for my $code (@codes){
Log 3, "LIRC code: $code\n";
Log 3, "LIRC $code toggle";
DoTrigger($code, "toggle");
}
}
}
#####################################
sub
LIRC_Ready($)
{
my ($hash) = @_;
my $select= $hash->{SelectObj};
return $select->can_read(0);
}
1;

View File

@@ -2233,19 +2233,88 @@ A line ending with \ will be concatenated with the next one, so long lines
<ul>
<code>define &lt;name&gt; CUL_HM &lt;6-digit-hex-code&gt;</code>
<br><br>
Try to avoid this command with the <a href="#autocreate">autocreate</a>
module enabled. Now you have two possibilities, both as a set command to
the corresponding CUL device: <a href="#CULset">hmPairForSec</a> and
<a href="#CULset">hmPairSerial</a>.
<br>
If a device was not paired with the CUL, then it won't know its subType,
and therefore won't be able to interpret device messages correctly.
Normally this command is generated by the <a
href="#autocreate">autocreate</a> module, together with the necessary
hmClass and subType attributes. Usually you issue a <a
href="#CULset">hmPairForSec</a> command and press the corresponding button
on the device to be paired, or issue a <a href="#CULset">hmPairSerial</a>
set command if the device is a receiver and you know its serial number.
Autocreate will then create a fhem device and set all necessary attributes.
<br><br>
If you cannot use autocreate, then you have to specify:<br>
<ul>
<li>the &lt;6-digit-hex-code&gt;<br>
which is the hardcoded address of the device (no, you cannot choose
it arbitrarily like for FS20 devices). You may detect it by
inspecting the fhem log.
<li>the hmClass attribute<br>
which is either sender or receiver
<li>the subType attribute<br>
which is one of switch dimmer blindActuator remote sensor swi
pushButton threeStateSensor motionDetector keyMatic winMatic
smokeDetector<br>
Without these attributes fhem won't be able to decode device messages
appropriately.
</ul>
</ul><br>
<a name="CUL_HMset"></a>
<b>Set</b>
<ul>
General commands (available to all hm devices):
Note: devices which are normally send-only (remote/sensor/etc) must be set
into pairing/learning mode in order to receive the following commands.
<br>
<br>
General commands (available to most hm devices):
<ul>
<li>statusRequest<br>
Send a status request to the device.
</li>
<li>reset<br>
Factory reset the device. You need to pair it again to use it with
fhem.
</li>
<li>pair<br>
Pair the device again with its known serialNumber (e.g. after a device
reset). </li>
</ul>
<br>
subType (i.e family) dependent commands:
<ul>
<br>
<li>switch
<ul>
<li>on [forSec] - set the switch on</li>
<li>off - set the switch off</li>
<li>toggle - toggle the switch.</li>
</ul></li>
<br>
<li>dimmer, blindActuator
<ul>
<li>0 - 100 with a resolution of 0.5:<br>
set the dimmer / blindActuator to the given value (in percent).
<li>on / off<br>
this corresponds to 100 or 0 %.
</ul></li>
<br>
<li>4Dis (HM-PB-4DIS-WM)
<ul>
<li>text &lt;btn_no&gt; [on|off] &lt;text1&gt; &lt;text2&gt;<br>
Set the text on the display of the device. To this purpose issue
this set command first (or a number of them), and then choose from
the teach-in menu of the 4Dis the "Central" to transmit the data.
Example:<br>
<ul>
set 4Dis text 1 on On Lamp<br>
set 4Dis text 1 off Kitchen Off<br>
</ul>
</ul></li>
</ul>
<br>
Debugging:
<ul>
<li>raw &lt;data&gt; ...<br>
Only needed for experimentation.
@@ -2259,44 +2328,6 @@ A line ending with \ will be concatenated with the next one, so long lines
++A001F1000012345601080801\
++A001F100001234560106<pre>
</li>
<li>reset<br>
Factory reset the device. You need to pair it again to use it.
</li>
<li>pair<br>
Pair the device again with its known serialNumber
</li>
<li>statusRequest<br>
Send a statusRequest to the device.
</li>
</ul>
subType (i.e family) dependent commands:
<ul>
<li>switch
<ul>
<li>on [forSec] - set the switch on</li>
<li>off - set the switch off</li>
<li>toggle - toggle the switch.</li>
</ul></li>
<li>dimmer, blindActuator
<ul>
<li>0 - 100 with a resolution of 0.5:<br>
set the dimmer / blindActuator to the given value (in percent).
<li>on / off<br>
this corresponds to 100 or 0 %.
</ul></li>
<li>4Dis (HM-PB-4DIS-WM)
<ul>
<li>text &lt;btn_no&gt; [on|off] &lt;text1&gt; &lt;text2&gt;<br>
Set the text on the display of the device. To this purpose issue
this set command first (or a number of them), and then choose from
the teach-in menu of the 4Dis the "Central" to transmit the data.
Example:<br>
<ul>
set 4Dis text 1 on On Lamp<br>
set 4Dis text 1 off Kitchen Off<br>
</ul>
</ul></li>
</ul>
</ul><br>
@@ -3054,12 +3085,32 @@ A line ending with \ will be concatenated with the next one, so long lines
<a name="LIRC"></a>
<h3>LIRC</h3>
<ul>
Can use infrared signals received by an lirc device as toggle events.
<br>
<br>
<a name="LIRCdefine"></a>
<b>Define</b>
<ul>
<code>define &lt;name&gt; LIRC &lt;device&gt;</code>
define &lt;name&gt; LIRC &lt;lircrc_file&gt;<br>
Example:<br>
<ul>
define Lirc LIRC /etc/lirc/lircrc
</ul>
Note: In the lirc configuration file you have to define each possible event.
If you have this configuration
<pre>
begin
prog = fhem
button = pwr
config = IrPower
end</pre>
and you press the pwr button the IrPower toggle event occures at fhem.
<pre>
define IrPower01 notify IrPower set lamp toggle</pre>
turns the lamp on and off.
If you want a faster reaction to keypresses you have to change the
defaultvalue of readytimeout from 5 seconds to e.g. 1 second in fhem.pl
</ul>
<br>