From 73783bb4098679d10a80b2150e221246ef0cb99f Mon Sep 17 00:00:00 2001 From: klauswitt <> Date: Mon, 24 Nov 2014 20:35:23 +0000 Subject: [PATCH] 51_RPI_GPIO: workaround for banana pi added git-svn-id: https://svn.fhem.de/fhem/trunk@7059 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/51_RPI_GPIO.pm | 41 +++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/fhem/FHEM/51_RPI_GPIO.pm b/fhem/FHEM/51_RPI_GPIO.pm index 2ce553a8c..7abbc99f9 100644 --- a/fhem/FHEM/51_RPI_GPIO.pm +++ b/fhem/FHEM/51_RPI_GPIO.pm @@ -102,8 +102,18 @@ sub RPI_GPIO_Define($$) { $counter --; } unless( $counter ) { #abbrechen wenn export fehlgeschlagen - Log3 $hash, 1, "$name: failed to export pin gpio$hash->{RPI_pin}"; - return "$name: failed to export pin gpio$hash->{RPI_pin}"; + #nochmal probieren wenn keine Schreibrechte########## + if ( defined(my $ret = RPI_GPIO_CHECK_GPIO_UTIL($gpioprg)) ) { #Abbbruch da kein gpio utility vorhanden + Log3 $hash, 1, "$name: can't export gpio$hash->{RPI_pin}, no write access to $gpiodir/export and " . $ret; + Log3 $hash, 1, "$name: failed to export pin gpio$hash->{RPI_pin}"; + return "$name: failed to export pin gpio$hash->{RPI_pin}"; + } else { #nutze GPIO Utility? + Log3 $hash, 4, "$name: using gpio utility to export pin (first export failed)"; + RPI_GPIO_exuexpin($hash, "in"); + } + ##################################################### +# Log3 $hash, 1, "$name: failed to export pin gpio$hash->{RPI_pin}"; +# return "$name: failed to export pin gpio$hash->{RPI_pin}"; } $hash->{fhem}{interfaces} = "switch"; @@ -140,10 +150,10 @@ sub RPI_GPIO_Set($@) { if(defined($attr{$name}) && defined($attr{$name}{"direction"})) { my $mt = $attr{$name}{"direction"}; if($mt && $mt eq "output") { - if ($cmd eq 'toggle') { - my $val = RPI_GPIO_fileaccess($hash, "value"); #alten Wert des GPIO direkt auslesen - $cmd = $val eq "0" ? "on" :"off"; - } + #if ($cmd eq 'toggle') { + # my $val = RPI_GPIO_fileaccess($hash, "value"); #alten Wert des GPIO direkt auslesen + # $cmd = $val eq "0" ? "on" :"off"; + #} if ($cmd eq 'on') { RPI_GPIO_fileaccess($hash, "value", "1"); #$hash->{STATE} = 'on'; @@ -160,6 +170,7 @@ sub RPI_GPIO_Set($@) { readingsEndUpdate($hash, 1); } else { my $slist = join(' ', keys %setsoutp); + Log3 $hash, 5, "wird an setextensions gesendet: @a"; return SetExtensions($hash, $slist, @a); } } else { @@ -559,7 +570,7 @@ sub RPI_GPIO_exuexpin($$) { #export, unexport and direction Pin via GPIO utili $dir = ""; } else { $sw = "export"; - $dir = "out" if ( $dir eq "high" || $dir eq "low" ); #auf out zurueck, da gpio tool dies nicht unterstützt + $dir = "out" if ( $dir eq "high" || $dir eq "low" ); #auf out zurueck, da gpio tool dies nicht unterst?tzt $dir = " ".$dir; } if ( defined(my $ret = RPI_GPIO_CHECK_GPIO_UTIL($gpioprg)) ) { @@ -622,7 +633,7 @@ sub RPI_GPIO_inthandling($$) { #start/stop Interrupthandling Raspberry Pi offers direct access to several GPIO via header P1 (and P5 on V2). The Pinout is shown in table under define. With this module you are able to access these GPIO's directly as output or input. For input you can use either polling or interrupt mode
- In addition to the Raspberry Pi, also BBB, Cubie and almost every linux system which provides gpio access in userspace is supported.
+ In addition to the Raspberry Pi, also BBB, Cubie, Banana Pi and almost every linux system which provides gpio access in userspace is supported.
Warning: Never apply any external voltage to an output configured pin! GPIO's internal logic operate with 3,3V. Don't exceed this Voltage!

preliminary:
GPIO Pins accessed by sysfs. The files are located in folder /system/class/gpio and belong to the gpio group (on actual Raspbian distributions since jan 2014).
@@ -631,8 +642,8 @@ sub RPI_GPIO_inthandling($$) { #start/stop Interrupthandling sudo adduser fhem gpio
sudo reboot
- On older Raspbian distributions and if attribute pud_resistor shall be used, aditionally gpio utility from WiringPi - library must be installed to export and change access rights of GPIO's, or to set the internal pullup/down resistor.
+ If attribute pud_resistor shall be used and on older Raspbian distributions, aditionally gpio utility from WiringPi + library must be installed to set the internal pullup/down resistor or export and change access rights of GPIO's (for the second case active_low does not work).
Installation WiringPi:

- Für ältere Raspbian Distributionen und wenn das Attribut pud_resistor verwendet werden soll, muss zusätzlich das gpio Tool der WiringPi - Bibliothek installiert werden, um GPIO's zu exportieren und die korrekten Nutzerrechte zu setzen, bzw. den internen Pullup/down Widerstand zu aktivieren.
+ Wenn das Attribut pud_resistor verwendet werden soll und für ältere Raspbian Distributionen, muss zusätzlich das gpio Tool der WiringPi + Bibliothek installiert werden, um den internen Pullup/down Widerstand zu aktivieren, bzw. GPIO's zu exportieren und die korrekten Nutzerrechte zu setzen (für den zweiten Fall funktioniert das active_low Attribut nicht).
Installation WiringPi: