From 04d97b4db6b1dd167489aff56aadc38ca6e48028 Mon Sep 17 00:00:00 2001
From: klauswitt <>
Date: Sat, 11 Jan 2014 15:50:01 +0000
Subject: [PATCH] Reading longpress added
git-svn-id: https://svn.fhem.de/fhem/trunk@4623 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/FHEM/51_RPI_GPIO.pm | 50 ++++++++++++++++++++++++++++++++--------
1 file changed, 41 insertions(+), 9 deletions(-)
diff --git a/fhem/FHEM/51_RPI_GPIO.pm b/fhem/FHEM/51_RPI_GPIO.pm
index 5ed778c01..a2e7658ee 100644
--- a/fhem/FHEM/51_RPI_GPIO.pm
+++ b/fhem/FHEM/51_RPI_GPIO.pm
@@ -149,7 +149,7 @@ if ($cmd eq 'on') {
}
}
-sub RPI_GPIO_State($$$$) {
+sub RPI_GPIO_State($$$$) { #reload readings at FHEM start
my ($hash, $tim, $sname, $sval) = @_;
#Log 1, "$hash->{NAME}: $sname kann auf $sval wiederhergestellt werden $tim";
if ( (AttrVal($hash->{NAME},"restoreOnStartup","on") eq "on") && ($sname ne "STATE") ) {
@@ -285,7 +285,7 @@ sub RPI_GPIO_Attr(@) {
return ($msg) ? $msg : undef;
}
-sub RPI_GPIO_Poll($) {
+sub RPI_GPIO_Poll($) { #for attr poll_intervall -> readout pin value
my ($hash) = @_;
my $name = $hash->{NAME};
updatevalue($hash);
@@ -314,7 +314,7 @@ sub RPI_GPIO_Undef($$) {
return undef;
}
-sub RPI_GPIO_Except($) {
+sub RPI_GPIO_Except($) { #called from main if an interrupt occured
my ($hash) = @_;
#seek($hash->{filehandle},0,0); #an Anfang der Datei springen (ist nötig falls vorher schon etwas gelesen wurde)
#chomp ( my $firstval = $hash->{filehandle}->getline ); #aktuelle Zeile auslesen und Endezeichen entfernen
@@ -363,8 +363,20 @@ sub RPI_GPIO_Except($) {
$valcnt = $hash->{READINGS}{Counter}{VAL} + 1;
#Log 1, "Zähler ist jetzt $valcnt";
}
- }
+ } elsif ($eval eq "both") {
+ if ( $val == 1 ) {
+ my $lngpressInterval = 1;
+ InternalTimer(gettimeofday() + $lngpressInterval, 'longpress', $hash, 0);
+ } else {
+ RemoveInternalTimer('longpress');
+ readingsBeginUpdate($hash);
+ readingsBulkUpdate($hash, 'Longpress', 'off');
+ readingsEndUpdate($hash, 1);
+ }
+ }
+
delete ($hash->{READINGS}{Toggle}) if ($eval ne ("rising" || "falling")); #Reading Toggle löschen wenn kein Wert in Variable
+ delete ($hash->{READINGS}{Longpress}) if ($eval ne "both"); #Reading Longpress löschen wenn edge nicht on both
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, 'Pinlevel', $valalt);
readingsBulkUpdate($hash, 'state', $valst);
@@ -374,7 +386,22 @@ sub RPI_GPIO_Except($) {
#Log 1, "RPIGPIO: Except ausgelöst: $hash->{NAME}, Wert: $val, edge: $eval,vt: $valto, $debounce_time s: $firstval";
}
-sub updatevalue($) {
+sub longpress($) { #for reading longpress
+ my ($hash) = @_;
+ my $name = $hash->{NAME};
+ my $val = fileaccess($hash, "value");
+ if ($val == 1) {
+ readingsBeginUpdate($hash);
+ readingsBulkUpdate($hash, 'Longpress', 'on');
+ readingsEndUpdate($hash, 1);
+ }
+}
+
+sub dblclick($) {
+
+}
+
+sub updatevalue($) { #update value for Input devices
my ($hash) = @_;
my $val = fileaccess($hash, "value");
if ( defined ($val) ) {
@@ -395,7 +422,7 @@ sub updatevalue($) {
}
}
-sub fileaccess($$;$) {
+sub fileaccess($$;$) { #Fileaccess for GPIO base directory
#my ($hash, $fname, $value) = @_;
my ($hash, @args) = @_;
my $fname = $args[0];
@@ -424,7 +451,7 @@ sub fileaccess($$;$) {
}
}
-sub exuexpin($$) {
+sub exuexpin($$) { #export and unexport Pin via GPIO utility
my ($hash, $dir) = @_;
my $sw;
if ($dir eq "unexport") {
@@ -453,7 +480,7 @@ sub exuexpin($$) {
}
-sub inthandling($$) {
+sub inthandling($$) { #start/stop Interrupthandling
my ($hash, $arg) = @_;
my $msg = '';
if ( $arg eq "start") {
@@ -612,7 +639,9 @@ sub inthandling($$) {
can only be used with GPIO configured as input
enables edge detection for GPIO pin
on each interrupt event readings Pinlevel and state will be updated
- Default: none, valid values: none, falling, rising, both
+ Default: none, valid values: none, falling, rising, both
+ For "both" the reading Longpress will be added and set to on as long as kes hold down longer than 1s
+ For "falling" and "rising" the reading Toggle will be added an will be toggled at every interrupt and the reading Counter that increments at every interrupt