mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-21 01:46:08 +00:00
added: new module 55_PIFACE.pm
git-svn-id: https://svn.fhem.de/fhem/trunk@3966 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
74bc61e7ae
commit
7ac5bed514
@ -1,4 +1,5 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||||
|
- feature: new module 55_PIFACE.pm added (betateilchen
|
||||||
- feature: Calendar can read from file and limit number of calendar events
|
- feature: Calendar can read from file and limit number of calendar events
|
||||||
retrieved in get command
|
retrieved in get command
|
||||||
- feature: new module 70_ENIGMA2.pm added (by loredo)
|
- feature: new module 70_ENIGMA2.pm added (by loredo)
|
||||||
|
306
fhem/FHEM/55_PIFACE.pm
Normal file
306
fhem/FHEM/55_PIFACE.pm
Normal file
@ -0,0 +1,306 @@
|
|||||||
|
# $Id:
|
||||||
|
####################################################################################################
|
||||||
|
#
|
||||||
|
# 55_PIFACE.pm
|
||||||
|
#
|
||||||
|
# An FHEM Perl module to control RaspberryPi extension board PiFace
|
||||||
|
#
|
||||||
|
# The PiFace is an add-on board for the Raspberry Pi featuring 8 open-collector outputs,
|
||||||
|
# with 2 relays and 8 inputs (with 4 on-board buttons).
|
||||||
|
# These functions are fairly well fixed in the hardware,
|
||||||
|
# so only the read, write and internal pull-up commands are implemented.
|
||||||
|
#
|
||||||
|
# Please read commandref for details on prerequisits!
|
||||||
|
# Depends on wiringPi library from http://wiringpi.com
|
||||||
|
#
|
||||||
|
# Copyright: betateilchen ®
|
||||||
|
# e-mail: fhem.development@betateilchen.de
|
||||||
|
#
|
||||||
|
# This file is part of fhem.
|
||||||
|
#
|
||||||
|
# Fhem is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Fhem is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with fhem. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
####################################################################################################
|
||||||
|
|
||||||
|
package main;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
sub PIFACE_Define($$);
|
||||||
|
sub PIFACE_Undefine($$);
|
||||||
|
sub PIFACE_Set($@);
|
||||||
|
sub PIFACE_Get($@);
|
||||||
|
|
||||||
|
my $base = 199;
|
||||||
|
|
||||||
|
sub PIFACE_Initialize($){
|
||||||
|
my ($hash) = @_;
|
||||||
|
$hash->{DefFn} = "PIFACE_Define";
|
||||||
|
$hash->{UndefFn} = "PIFACE_Undefine";
|
||||||
|
$hash->{SetFn} = "PIFACE_Set";
|
||||||
|
$hash->{GetFn} = "PIFACE_Get";
|
||||||
|
$hash->{AttrList} = $readingFnAttributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub PIFACE_Define($$){
|
||||||
|
my ($hash, $def) = @_;
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
Log3($name, 3, "PIFACE $name: created");
|
||||||
|
readingsSingleUpdate($hash, "state", "active",1);
|
||||||
|
PI_read_outports($hash);
|
||||||
|
PI_read_inports($hash,0);
|
||||||
|
PI_read_inports($hash,1);
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub PIFACE_Undefine($$){
|
||||||
|
my($hash, $name) = @_;
|
||||||
|
RemoveInternalTimer($hash);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub PIFACE_Set($@){
|
||||||
|
my ($hash, @a) = @_;
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
my $port = $a[1];
|
||||||
|
my $val = $a[2];
|
||||||
|
my ($adr, $cmd, $i, $j, $k);
|
||||||
|
|
||||||
|
my $usage = "Unknown argument $port, choose one of 0 1:0,1 2:0,1 3:0,1 4:0,1 5:0,1 6:0,1 7:0,1 8:0,1 ";
|
||||||
|
return $usage if $port eq "?";
|
||||||
|
|
||||||
|
if ($port ne "0") {
|
||||||
|
$adr = $base + $port;
|
||||||
|
Log3($name, 3, "PIFACE $name: set port $port $val");
|
||||||
|
$cmd = "/usr/local/bin/gpio -p write $adr $val";
|
||||||
|
$cmd = `$cmd`;
|
||||||
|
readingsSingleUpdate($hash, 'out'.$port, $val,1);
|
||||||
|
} else {
|
||||||
|
$adr = $base + 1;
|
||||||
|
Log3($name, 3, "PIFACE $name: set ports $val");
|
||||||
|
readingsBeginUpdate($hash);
|
||||||
|
for($i=0; $i<8; $i++){
|
||||||
|
$j = 2**$i;
|
||||||
|
$k = ($val & $j);
|
||||||
|
$k = ($k) ? 1 : 0;
|
||||||
|
$adr = 1 + $i;
|
||||||
|
Log3($name, 3, "PIFACE $name: set port $adr $k");
|
||||||
|
$adr += $base;
|
||||||
|
$cmd = "/usr/local/bin/gpio -p write $adr $k";
|
||||||
|
$cmd = `$cmd`;
|
||||||
|
$j = $i + 1;
|
||||||
|
readingsBulkUpdate($hash, 'out'.$j, $k);
|
||||||
|
}
|
||||||
|
readingsEndUpdate($hash, 1);
|
||||||
|
}
|
||||||
|
PI_read_outports($hash);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
sub PIFACE_Get($@){
|
||||||
|
my ($hash, @a) = @_;
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
my $port = $a[1];
|
||||||
|
my ($adr, $cmd, $pin, $pull, $val);
|
||||||
|
|
||||||
|
my $usage = "Unknown argument $port, choose one of ".
|
||||||
|
"1:noArg 2:noArg 3:noArg 4:noArg ".
|
||||||
|
"5:noArg 6:noArg 7:noArg 8:noArg ".
|
||||||
|
"11:noArg 12:noArg 13:noArg 14:noArg ".
|
||||||
|
"15:noArg 16:noArg 17:noArg 18:noArg ";
|
||||||
|
return $usage if $port eq "?";
|
||||||
|
|
||||||
|
if($port eq "0"){
|
||||||
|
PI_read_inports($hash,0);
|
||||||
|
PI_read_inports($hash,1);
|
||||||
|
} else {
|
||||||
|
if (length($port) == 2){
|
||||||
|
$pin = $port - 10;
|
||||||
|
$adr = $base + $pin;
|
||||||
|
$cmd = '/usr/local/bin/gpio -p mode '.$adr.' up';
|
||||||
|
$val = `$cmd`;
|
||||||
|
}
|
||||||
|
$cmd = '/usr/local/bin/gpio -p read '.$adr;
|
||||||
|
$val = `$cmd`;
|
||||||
|
readingsSingleUpdate($hash, 'in'.$port, $val, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
sub PI_read_outports($){
|
||||||
|
my ($hash) = @_;
|
||||||
|
|
||||||
|
my $val = '?';
|
||||||
|
my ($cmd, $i, $port);
|
||||||
|
|
||||||
|
readingsBeginUpdate($hash);
|
||||||
|
for($i=1; $i<9; $i++){
|
||||||
|
$port = $base + $i + 8;
|
||||||
|
$cmd = '/usr/local/bin/gpio -p read '.$port;
|
||||||
|
$val = `$cmd`;
|
||||||
|
readingsBulkUpdate($hash, 'out'.$i, $val);
|
||||||
|
}
|
||||||
|
readingsEndUpdate($hash, 1);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sub PI_read_inports($;$){
|
||||||
|
my ($hash,$pull) = @_;
|
||||||
|
|
||||||
|
my $val = '?';
|
||||||
|
my ($cmd, $i, $j, $port);
|
||||||
|
|
||||||
|
readingsBeginUpdate($hash);
|
||||||
|
for($i=1; $i<9; $i++){
|
||||||
|
$port = $base + $i;
|
||||||
|
if($pull eq '1'){
|
||||||
|
$cmd = '/usr/local/bin/gpio -p mode '.$port.' up';
|
||||||
|
$val = `$cmd`;
|
||||||
|
$cmd = '/usr/local/bin/gpio -p read '.$port;
|
||||||
|
$val = `$cmd`;
|
||||||
|
$j = 10 + $i;
|
||||||
|
readingsBulkUpdate($hash, 'in'.$j, $val);
|
||||||
|
} else {
|
||||||
|
$cmd = '/usr/local/bin/gpio -p mode '.$port.' tri';
|
||||||
|
$val = `$cmd`;
|
||||||
|
$cmd = '/usr/local/bin/gpio -p read '.$port;
|
||||||
|
$val = `$cmd`;
|
||||||
|
readingsBulkUpdate($hash, 'in'.$i, $val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
readingsEndUpdate($hash, 1);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
=pod
|
||||||
|
=begin html
|
||||||
|
|
||||||
|
<a name="PIFACE"></a>
|
||||||
|
<h3>PIFACE</h3>
|
||||||
|
<ul>
|
||||||
|
|
||||||
|
<b>Prerequesits</b>
|
||||||
|
<ul>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
Module needs wiringPi tools from <a href=http://wiringpi.com>http://wiringpi.com</a><br/><br/>
|
||||||
|
<code> git clone git://git.drogon.net/wiringPi<br/>
|
||||||
|
cd wiringPi<br/>
|
||||||
|
./build</code>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
<br/><br/>
|
||||||
|
|
||||||
|
<a name="PIFACEdefine"></a>
|
||||||
|
<b>Define</b>
|
||||||
|
<ul>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<code>define <name> PIFACE</code>
|
||||||
|
<br/><br/>
|
||||||
|
This module provides set/get functionality to control ports on RaspberryPi extension board PiFace
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
<br/><br/>
|
||||||
|
|
||||||
|
<a name="PIFACEset"></a>
|
||||||
|
<b>Set-Commands</b><br/>
|
||||||
|
<ul>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<code>set <name> <port> <value></code>
|
||||||
|
<br/><br/>
|
||||||
|
<ul>
|
||||||
|
<li>set single port n to 1 (on) or 0 (off)<br/><br/>
|
||||||
|
Examples:<br/>
|
||||||
|
set <name> 3 1 => set port 3 on<br/>
|
||||||
|
set <name> 5 0 => set port 5 off<br/></li>
|
||||||
|
<br/>
|
||||||
|
<li>set all ports in one command by bitmask<br/><br/>
|
||||||
|
Example:<br/>
|
||||||
|
set <name> 0 255 => set all ports on<br/>
|
||||||
|
set <name> 0 0 => set all ports off<br/>
|
||||||
|
set <name> 0 170 => bitmask(170) = 10101010 => set ports 2 4 6 8 on, ports 1 3 5 7 off<br/>
|
||||||
|
<br/>
|
||||||
|
<ul>
|
||||||
|
<code>port 87654321<br/>
|
||||||
|
bit 10101010</code>
|
||||||
|
</ul></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
<br/><br/>
|
||||||
|
|
||||||
|
<a name="PIFACEget"></a>
|
||||||
|
<b>Get-Commands</b><br/>
|
||||||
|
<ul>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
<code>get <name> <port></code>
|
||||||
|
<br/><br/>
|
||||||
|
<ul>
|
||||||
|
<li>get state of single port with internal pullups <b>off</b><br/><br/>
|
||||||
|
Example:<br/>
|
||||||
|
get <name> 3 => get state of port 3<br/></li>
|
||||||
|
<br/>
|
||||||
|
<li>get state of single port with internal pullups <b>on</b><br/><br/>
|
||||||
|
Add 10 to port number!<br/><br/>
|
||||||
|
Example:<br/>
|
||||||
|
get <name> 15 => get state of port 5<br/></li>
|
||||||
|
<br/>
|
||||||
|
<li>get state of all input ports and update readings<br/><br/>
|
||||||
|
Example:<br/>
|
||||||
|
get <name> 0 => get state of all input ports<br/></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
<br/><br/>
|
||||||
|
|
||||||
|
<a name="PIFACEattr"></a>
|
||||||
|
<b>Attributes</b><br/><br/>
|
||||||
|
<ul>
|
||||||
|
<li><a href="#readingFnAttributes">readingFnAttributes</a></li>
|
||||||
|
</ul>
|
||||||
|
<br/><br/>
|
||||||
|
|
||||||
|
<b>Generated Readings/Events:</b>
|
||||||
|
<br/><br/>
|
||||||
|
<ul>
|
||||||
|
<li><b><out1..out8></b> - state of output port 1..8</li>
|
||||||
|
<li><b><in1..in8></b> - state of input port 1..8 without pullup resistor active</li>
|
||||||
|
<li><b><in11..in18></b> - state of input port 1..8 with pullup resistor active</li>
|
||||||
|
</ul>
|
||||||
|
<br/><br/>
|
||||||
|
|
||||||
|
<b>Author's notes</b><br/><br/>
|
||||||
|
<ul>
|
||||||
|
<li>Relays 1 and 2 have corresponding port 1 and 2</li>
|
||||||
|
<li>Switches 1..4 have corresponding ports 1..4 and must be read with pullups on</li>
|
||||||
|
<br/>
|
||||||
|
<li>Have fun!</li><br/>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
=end html
|
||||||
|
=cut
|
@ -106,6 +106,7 @@ FHEM/49_IPCAM.pm mfr69bs http://forum.fhem.de Sonstiges
|
|||||||
FHEM/50_WS300.pm Dirk http://forum.fhem.de SlowRF
|
FHEM/50_WS300.pm Dirk http://forum.fhem.de SlowRF
|
||||||
FHEM/51_I2C_BMP180.pm Dirk http://forum.fhem.de/ Raspberry Pi
|
FHEM/51_I2C_BMP180.pm Dirk http://forum.fhem.de/ Raspberry Pi
|
||||||
FHEM/55_GDS.pm betateilchen http://forum.fhem.de Unterstützende Dienste
|
FHEM/55_GDS.pm betateilchen http://forum.fhem.de Unterstützende Dienste
|
||||||
|
FHEM/55_PIFACE.pm betateilchen http://forum.fhem.de/ Raspberry Pi
|
||||||
FHEM/56_POKEYS.pm axelberner http://forum.fhem.de Sonstiges
|
FHEM/56_POKEYS.pm axelberner http://forum.fhem.de Sonstiges
|
||||||
FHEM/57_Calendar.pm borisneubert http://forum.fhem.de Sonstiges
|
FHEM/57_Calendar.pm borisneubert http://forum.fhem.de Sonstiges
|
||||||
FHEM/59_HCS.pm mfr69bs http://forum.fhem.de Automatisierung
|
FHEM/59_HCS.pm mfr69bs http://forum.fhem.de Automatisierung
|
||||||
|
Loading…
x
Reference in New Issue
Block a user