2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-09 14:47:00 +00:00

52_I2C_HDC1008.pm: Fix "temperature" reading (again)

Ouch, my last change from Aug, 1st (r22515) broke update of temperature
reading. Fix and simplify the temperature and humidity reading code -
hopefully finally.


git-svn-id: https://svn.fhem.de/fhem/trunk@22595 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
gernot-h 2020-08-13 19:03:12 +00:00
parent b878aac893
commit e063e44c1b
2 changed files with 7 additions and 24 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.
- bugfix: 52_I2C_HDC1008: fix "temperature" (broken by change from Aug, 1st)
- feature: 49_SSCam: new attribute ptzNoCapPrePat
- feature: 60_Watches: control buttons,new attr hideButtons, controlButtonSize
some more changes according PBP

View File

@ -178,14 +178,13 @@ sub I2C_HDC1008_I2CRec ($$) {
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;
I2C_HDC1008_UpdateTempHum ($hash, $clientmsg->{received}) if $clientmsg->{nbyte} == 4;
}
}
}
}
sub I2C_HDC1008_GetTemp ($$)
sub I2C_HDC1008_UpdateTempHum ($$)
{
my ($hash, $rawdata) = @_;
my $name = $hash->{NAME};
@ -196,33 +195,20 @@ sub I2C_HDC1008_GetTemp ($$)
Log3 $hash, 4, "[$name] I2C_HDC1008_I2CRec invalid temperature raw value: $tempWord";
return undef;
}
my $temperature = (($tempWord /65536.0)*165.0)-40.0;
Log3 $hash, 5, "[$name] I2C_HDC1008_I2CRec calced Temperatur: $temperature";
$temperature = sprintf( '%.' . AttrVal($hash->{NAME}, 'roundTemperatureDecimal', 1) . 'f', $temperature );
}
sub I2C_HDC1008_GetHum ($$)
{
my ($hash, $rawdata) = @_;
my $name = $hash->{NAME};
my @raw = split(" ",$rawdata);
my $humWord = ($raw[2] << 8 | $raw[3]);
if ( ($humWord & 0x3) != 0) {
Log3 $hash, 4, "[$name] I2C_HDC1008_I2CRec invalid humidity raw value: $humWord";
return undef;
}
my $humidity = ($humWord /65536.0)*100.0;
Log3 $hash, 5, "[$name] I2C_HDC1008_I2CRec calced humidity: $humidity";
Log3 $hash, 5, "[$name] I2C_HDC1008_I2CRec calced temp/hum: $temperature $humidity";
my $temperature = ReadingsVal($hash->{NAME} ,"temperature","0");
$humidity = sprintf( '%.' . AttrVal($hash->{NAME}, 'roundHumidityDecimal', 1) . 'f', $humidity );
$temperature = sprintf( '%.' . AttrVal($hash->{NAME}, 'roundTemperatureDecimal', 1) . 'f', $temperature );
$humidity = sprintf( '%.' . AttrVal($hash->{NAME}, 'roundHumidityDecimal', 1) . 'f', $humidity );
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, 'humidity', $humidity);
readingsBulkUpdate($hash, 'temperature', $temperature);
@ -231,11 +217,7 @@ sub I2C_HDC1008_GetHum ($$)
'state',
'T: ' . $temperature . ' H: ' . $humidity
);
readingsEndUpdate($hash, 1);
}
sub I2C_HDC1008_Undef($$)