2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-07 23:09:26 +00:00

52_I2C_SHT21: modified for use with 10_FRM

10_FRM: more logigal devices added
51_RPI_GPIO: better failure log
52_I2C_MCP23008: bufix for poll_interval
52_I2C_MCP23017: bufix for poll_interval
52_I2C_PCA9532: bufix for poll_interval


git-svn-id: https://svn.fhem.de/fhem/trunk@9258 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
klauswitt 2015-09-15 20:45:18 +00:00
parent 2a45ec2da8
commit 15d75dd09a
7 changed files with 61 additions and 33 deletions

View File

@ -23,9 +23,10 @@ my @clients = qw(
I2C_LCD
I2C_DS1307
I2C_PC.*
I2C_MCP23017
I2C_MCP23.*
I2C_BMP180
I2C_SHT21
I2C_TSL2561
);
sub NetzerI2C_Initialize($) {

View File

@ -49,8 +49,10 @@ my @clients = qw(
I2C_LCD
I2C_DS1307
I2C_PC.*
I2C_MCP23017
I2C_MCP23.*
I2C_SHT21
I2C_BMP180
I2C_TSL2561
FRM_LCD
);

View File

@ -80,7 +80,7 @@ sub RPI_GPIO_Define($$) {
#nix tun...ist ja schon da
} elsif (-w "$gpiodir/export") { #gpio export Datei mit schreibrechten?
Log3 $hash, 4, "$name: write access to file $gpiodir/export, use it to export GPIO";
my $exp = IO::File->new("> $gpiodir/export"); #gpio ueber export anlegen
my $exp = IO::File->new("> $gpiodir/export"); #gpio ueber export anlegen
print $exp "$hash->{RPI_pin}";
$exp->close;
} else {
@ -93,28 +93,42 @@ sub RPI_GPIO_Define($$) {
}
}
# wait for Pin export (max 5s)
my $checkpath = qq($gpiodir/gpio$hash->{RPI_pin}/value);
my $counter = 100;
while( $counter ){
last if( -e $checkpath && -w $checkpath );
Time::HiRes::sleep( 0.05 );
$counter --;
}
unless( $counter ) { #abbrechen wenn export fehlgeschlagen
#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");
# wait for Pin export (max 5s)
my $checkpath = qq($gpiodir/gpio$hash->{RPI_pin}/value);
my $counter = 100;
while( $counter ){
last if( -e $checkpath && -w $checkpath );
Time::HiRes::sleep( 0.05 );
$counter --;
}
unless( $counter ) { #abbrechen wenn export fehlgeschlagen
# nochmal probieren wenn keine Schreibrechte auf GPIO Dateien ##########
if ( defined(my $ret = RPI_GPIO_CHECK_GPIO_UTIL($gpioprg)) ) { #Abbbruch da kein gpio utility vorhanden
if ( -e "$gpiodir/export") {
Log3 $hash, 1, "$name: \"$gpiodir/export\" exists and is " . ( ( -w "$gpiodir/export") ? "" : "NOT " ) . "writable";
} else {
Log3 $hash, 1, "$name: gpio$hash->{RPI_pin}/value doesnt exist";
}
#####################################################
# Log3 $hash, 1, "$name: failed to export pin gpio$hash->{RPI_pin}";
# return "$name: failed to export pin gpio$hash->{RPI_pin}";
if(-e "$gpiodir/gpio$hash->{RPI_pin}") {
Log3 $hash, 1, "$name: \"$gpiodir/gpio$hash->{RPI_pin}\" exported but define aborted:";
if ( -e "$gpiodir/gpio$hash->{RPI_pin}/value") {
Log3 $hash, 1, "$name: \"$gpiodir/gpio$hash->{RPI_pin}/value\" exists and is " . ( ( -w "$gpiodir/gpio$hash->{RPI_pin}/value") ? "" : "NOT " ) . "writable";
} else {
Log3 $hash, 1, "$name: \"$gpiodir/gpio$hash->{RPI_pin}/value\" doesnt exist";
}
if ( -e "$gpiodir/gpio$hash->{RPI_pin}/direction") {
Log3 $hash, 1, "$name: \"$gpiodir/gpio$hash->{RPI_pin}/direction\" exists and is " . ( ( -w "$gpiodir/gpio$hash->{RPI_pin}/direction") ? "" : "NOT " ) . "writable";
} else {
Log3 $hash, 1, "$name: \"$gpiodir/gpio$hash->{RPI_pin}/direction\" doesnt exist";
}
Log3 $hash, 1, "$name: second attempt to export gpio$hash->{RPI_pin} failed: " . $ret;
}
return "$name: failed to export pin gpio$hash->{RPI_pin}, see logfile";
} else { #nutze GPIO Utility fuer zweiten Exportversuch
Log3 $hash, 4, "$name: using gpio utility to export pin (first export via $gpiodir/export failed)";
RPI_GPIO_exuexpin($hash, "in");
}
}
$hash->{fhem}{interfaces} = "switch";
return undef;

View File

@ -57,7 +57,7 @@ sub I2C_MCP23008_Initialize($) {
$hash->{SetFn} = "I2C_MCP23008_Set";
$hash->{GetFn} = "I2C_MCP23008_Get";
$hash->{I2CRecFn} = "I2C_MCP23008_I2CRec";
$hash->{AttrList} = "IODev do_not_notify:1,0 ignore:1,0 showtime:1,0".
$hash->{AttrList} = "IODev do_not_notify:1,0 ignore:1,0 showtime:1,0 ".
"poll_interval OnStartup ".
"OutputPorts:multiple-strict,A0,A1,A2,A3,A4,A5,A6,A7 ".
"Pullup:multiple-strict,A0,A1,A2,A3,A4,A5,A6,A7 ".

View File

@ -60,7 +60,7 @@ sub I2C_MCP23017_Initialize($) {
$hash->{SetFn} = "I2C_MCP23017_Set";
$hash->{GetFn} = "I2C_MCP23017_Get";
$hash->{I2CRecFn} = "I2C_MCP23017_I2CRec";
$hash->{AttrList} = "IODev do_not_notify:1,0 ignore:1,0 showtime:1,0".
$hash->{AttrList} = "IODev do_not_notify:1,0 ignore:1,0 showtime:1,0 ".
"poll_interval OnStartup ".
"OutputPorts:multiple-strict,A0,A1,A2,A3,A4,A5,A6,A7,B0,B1,B2,B3,B4,B5,B6,B7 ".
"Pullup:multiple-strict,A0,A1,A2,A3,A4,A5,A6,A7,B0,B1,B2,B3,B4,B5,B6,B7 ".

View File

@ -46,7 +46,7 @@ sub I2C_PCA9532_Initialize($) {
$hash->{SetFn} = "I2C_PCA9532_Set";
$hash->{GetFn} = "I2C_PCA9532_Get";
$hash->{I2CRecFn} = "I2C_PCA9532_I2CRec";
$hash->{AttrList} = "IODev do_not_notify:1,0 ignore:1,0 showtime:1,0".
$hash->{AttrList} = "IODev do_not_notify:1,0 ignore:1,0 showtime:1,0 ".
"poll_interval T0:slider,0,1,255 T1:slider,0,1,255 OnStartup InputPorts ".
"OutputPorts:multiple-strict,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 ".
"$readingFnAttributes";

View File

@ -178,13 +178,24 @@ sub I2C_SHT21_I2CRec ($$) {
while ( my ( $k, $v ) = each %$clientmsg ) { #erzeugen von Internals fuer alle Keys in $clientmsg die mit dem physical Namen beginnen
$hash->{$k} = $v if $k =~ /^$pname/ ;
}
if ($clientmsg->{direction} && $clientmsg->{type} && $clientmsg->{$pname . "_SENDSTAT"} && $clientmsg->{$pname . "_SENDSTAT"} eq "Ok") {
if ( $clientmsg->{direction} eq "i2cread" && defined($clientmsg->{received}) ) {
Log3 $hash, 5, "empfangen: $clientmsg->{received}";
I2C_SHT21_GetTemp ($hash, $clientmsg->{received}) if $clientmsg->{type} eq "temp" && $clientmsg->{nbyte} == 2;
I2C_SHT21_GetHum ($hash, $clientmsg->{received}) if $clientmsg->{type} eq "hum" && $clientmsg->{nbyte} == 2;
}
}
#alte Variante zur Temp Hum Unterscheidung
#if ( $clientmsg->{direction} && $clientmsg->{type} && $clientmsg->{$pname . "_SENDSTAT"} && $clientmsg->{$pname . "_SENDSTAT"} eq "Ok" ) {
# if ( $clientmsg->{direction} eq "i2cread" && defined($clientmsg->{received}) ) {
# Log3 $hash, 5, "empfangen: $clientmsg->{received}";
# I2C_SHT21_GetTemp ($hash, $clientmsg->{received}) if $clientmsg->{type} eq "temp" && $clientmsg->{nbyte} == 2;
# I2C_SHT21_GetHum ($hash, $clientmsg->{received}) if $clientmsg->{type} eq "hum" && $clientmsg->{nbyte} == 2;
# }
#}
# Bit 1 of the two LSBs indicates the measurement type (0: temperature, 1 humidity)
if ( $clientmsg->{direction} && $clientmsg->{$pname . "_SENDSTAT"} && $clientmsg->{$pname . "_SENDSTAT"} eq "Ok" ) {
if ( $clientmsg->{direction} eq "i2cread" && defined($clientmsg->{received}) ) {
Log3 $hash, 5, "empfangen: $clientmsg->{received}";
my @raw = split(" ",$clientmsg->{received});
I2C_SHT21_GetTemp ($hash, $clientmsg->{received}) if !($raw[1] & 2) && $clientmsg->{nbyte} == 2;
I2C_SHT21_GetHum ($hash, $clientmsg->{received}) if ($raw[1] & 2) && $clientmsg->{nbyte} == 2;
}
}
}
sub I2C_SHT21_GetTemp ($$) {