2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 16:56:54 +00:00

52_I2C_HDC1008.pm: improve and restructure I2C error handling

The code used to ignore I2C write errors reported by the IODev (e.g.
when triggering a measurement) and just continued. While the subsequent
read should fail if sensor doesn't have values, it sometimes didn't for
me, leading to sporadic reading of 125°C and/or 100% rH. In case of
write errors, just retry current step until it succeeds.



git-svn-id: https://svn.fhem.de/fhem/trunk@16703 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
gernot-h 2018-05-07 20:58:27 +00:00
parent 702257ea23
commit 86a2adc731
2 changed files with 19 additions and 9 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
- change: 52_I2C_HDC1008: improve and restructure I2C error handling
- bugfix: 57_Calendar: fix count for series with exceptions
- bugfix: 72_FB_CALLMONITOR: fix control code entries in phonebook and
reverse search text file

View File

@ -163,12 +163,24 @@ sub I2C_HDC1008_I2CRec ($$) {
my $upper_k = uc $k;
$hash->{$upper_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, "[$name] I2C_HDC1008_I2CRec received: $clientmsg->{type} $clientmsg->{received}";
I2C_HDC1008_GetTemp ($hash, $clientmsg->{received}) if $clientmsg->{type} eq "temp" && $clientmsg->{nbyte} == 2;
I2C_HDC1008_GetHum ($hash, $clientmsg->{received}) if $clientmsg->{type} eq "hum" && $clientmsg->{nbyte} == 2;
if ($clientmsg->{direction} && $clientmsg->{$pname . "_SENDSTAT"}) {
my $sendstat = $clientmsg->{$pname . "_SENDSTAT"};
Log3 $hash, 5, "[$name] I2C_HDC1008_I2CRec $clientmsg->{direction} $sendstat ";
if ( $clientmsg->{$pname . "_SENDSTAT"} eq "Ok") {
if ( $clientmsg->{direction} eq "i2cwrite" ) {
if ($hash->{DEVICE_STATE} eq 'READY') {
$hash->{DEVICE_STATE} = 'CONFIGURING';
} elsif($hash->{DEVICE_STATE} eq 'CONFIGURING') {
$hash->{DEVICE_STATE} = 'MEASURING';
}
}
if ( $clientmsg->{direction} eq "i2cread" && defined($clientmsg->{received}) )
{
Log3 $hash, 5, "[$name] I2C_HDC1008_I2CRec received: $clientmsg->{type} $clientmsg->{received}";
I2C_HDC1008_GetTemp ($hash, $clientmsg->{received}) if $clientmsg->{nbyte} == 4;
I2C_HDC1008_GetHum ($hash, $clientmsg->{received}) if $clientmsg->{nbyte} == 4;
}
}
}
}
@ -315,7 +327,6 @@ sub I2C_HDC1008_UpdateValues($)
reg => 2,
data => $high_byte. " ".$low_byte # Leider fehlt es hier an Doku. Laut Quellcode (00_RPII2C.pm, ab Zeile 369), werden die dezimale Zahlen durch Leerzeichen getrennt, binär gewandelt und zum I2C-Bus geschickt
});
$hash->{DEVICE_STATE} = 'CONFIGURING';
return 15.0/1000; # Sensor braucht bis 15 ms bis er bereit ist
}
elsif($hash->{DEVICE_STATE} eq 'CONFIGURING')
@ -329,8 +340,6 @@ sub I2C_HDC1008_UpdateValues($)
data => (0)
});
$hash->{DEVICE_STATE} = 'MEASURING';
my $tempWait = $I2C_HDC1008_tempParams{$resTempIndex}{delay} +
$I2C_HDC1008_humParams{$resTempIndex}{delay}; # in ns
return $tempWait/1000000.0;