From 93995b90ac19fad0ffda8497e726c8e728d08b3c Mon Sep 17 00:00:00 2001 From: klauswitt Date: Tue, 15 Dec 2015 00:07:00 +0000 Subject: [PATCH] 51_RPI_GPIO: Added possibility to access active_low file 53_GHoma: changed Id to Hex git-svn-id: https://svn.fhem.de/fhem/trunk@10177 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/51_RPI_GPIO.pm | 72 +++++++++++++++++++++++----------------- fhem/FHEM/53_GHoma.pm | 36 +++++++++++--------- 2 files changed, 62 insertions(+), 46 deletions(-) diff --git a/fhem/FHEM/51_RPI_GPIO.pm b/fhem/FHEM/51_RPI_GPIO.pm index ff4bc36a7..3c7083029 100644 --- a/fhem/FHEM/51_RPI_GPIO.pm +++ b/fhem/FHEM/51_RPI_GPIO.pm @@ -36,6 +36,7 @@ sub RPI_GPIO_Initialize($) { " interrupt:none,falling,rising,both" . " toggletostate:no,yes active_low:no,yes" . " debounce_in_ms restoreOnStartup:no,yes,on,off,last" . + " unexportpin:no,yes" . " longpressinterval " . "$readingFnAttributes"; } @@ -353,28 +354,27 @@ sub RPI_GPIO_Attr(@) { $msg = "$hash->{NAME}: debounce_in_ms value to big. Use 0 to 250"; } } - if ($attr eq 'pud_resistor') {#nur fuer Raspberry (ueber gpio utility) - my $pud; - if ( defined(my $ret = RPI_GPIO_CHECK_GPIO_UTIL($gpioprg)) ) { - Log3 $hash, 1, "$hash->{NAME}: unable to change pud resistor:" . $ret; - return "$hash->{NAME}: " . $ret; - } else { - if ( !$val ) { - } elsif ($val eq "off") { - $pud = $gpioprg.' -g mode '.$hash->{RPI_pin}.' tri'; - $pud = `$pud`; - } elsif ($val eq "up") { - $pud = $gpioprg.' -g mode '.$hash->{RPI_pin}.' up'; - $pud = `$pud`; - } elsif ($val eq "down") { - $pud = $gpioprg.' -g mode '.$hash->{RPI_pin}.' down'; - $pud = `$pud`; - } else { - $msg = "$hash->{NAME}: Wrong $attr value. Use off, up or down"; - } - } - } - return ($msg) ? $msg : undef; + if ($attr eq "pud_resistor" && $val) { + if($val =~ /^(off|up|down)$/) { + if(-w "$gpiodir/gpio$hash->{RPI_pin}/pull") { + $val =~ s/off/disable/; + RPI_GPIO_fileaccess($hash, "pull", $val); + } else { #nur fuer Raspberry (ueber gpio utility) + my $pud; + if ( defined(my $ret = RPI_GPIO_CHECK_GPIO_UTIL($gpioprg)) ) { + Log3 $hash, 1, "$hash->{NAME}: unable to change pud resistor:" . $ret; + return "$hash->{NAME}: " . $ret; + } else { + $val =~ s/off/tri/; + $pud = $gpioprg." -g mode ".$hash->{RPI_pin}." ".$val; + $pud = `$pud`; + } + } + } else { + $msg = "$hash->{NAME}: Wrong $attr value. Use off, up or down"; + } + } + return ($msg) ? $msg : undef; } sub RPI_GPIO_Poll($) { #for attr poll_intervall -> readout pin value @@ -397,13 +397,17 @@ sub RPI_GPIO_Undef($$) { delete $selectlist{$hash->{NAME}}; close($hash->{filehandle}); } - if (-w "$gpiodir/unexport") {#unexport Pin alte Version + # to have a chance to externaly setup the GPIOs - + # leave GPIOs untouched if attr unexportpin is set to "no" + if(AttrVal($hash->{NAME},"unexportpin","") ne "no") { + if (-w "$gpiodir/unexport") {#unexport Pin alte Version my $uexp = IO::File->new("> $gpiodir/unexport"); print $uexp "$hash->{RPI_pin}"; $uexp->close; - } else {#alternative unexport Pin: + } else {#alternative unexport Pin: RPI_GPIO_exuexpin($hash, "unexport"); - } + } + } Log3 $hash, 1, "$hash->{NAME}: entfernt"; return undef; } @@ -651,7 +655,7 @@ sub RPI_GPIO_inthandling($$) { #start/stop Interrupthandling 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).
+ 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). It will work even on an Jessie version but NOT if you perform an kerlen update
After execution of following commands, GPIO's are usable whithin PRI_GPIO:

+
Define