From ee838a8e35dfaaa37d58be39defea311e2193b3e Mon Sep 17 00:00:00 2001 From: yoda_gh Date: Thu, 13 Aug 2020 19:03:12 +0000 Subject: [PATCH] 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 --- fhem/CHANGED | 1 + fhem/FHEM/52_I2C_HDC1008.pm | 30 ++++++------------------------ 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index ccc6effbd..dac32e777 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -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 diff --git a/fhem/FHEM/52_I2C_HDC1008.pm b/fhem/FHEM/52_I2C_HDC1008.pm index bab9c0642..892d09861 100644 --- a/fhem/FHEM/52_I2C_HDC1008.pm +++ b/fhem/FHEM/52_I2C_HDC1008.pm @@ -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($$)