From patchwork Sun Feb 11 11:09:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Geyer X-Patchwork-Id: 10211313 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1B56960236 for ; Sun, 11 Feb 2018 11:17:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F03F22638 for ; Sun, 11 Feb 2018 11:17:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 022112625B; Sun, 11 Feb 2018 11:17:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41C1122638 for ; Sun, 11 Feb 2018 11:17:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753073AbeBKLR0 (ORCPT ); Sun, 11 Feb 2018 06:17:26 -0500 Received: from h1.radempa.de ([176.9.142.194]:59025 "EHLO mail.cosmopool.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752987AbeBKLRY (ORCPT ); Sun, 11 Feb 2018 06:17:24 -0500 X-Greylist: delayed 447 seconds by postgrey-1.27 at vger.kernel.org; Sun, 11 Feb 2018 06:17:24 EST Received: from localhost (localhost [127.0.0.1]) by mail.cosmopool.net (Postfix) with ESMTP id 42B19901045; Sun, 11 Feb 2018 12:09:56 +0100 (CET) Received: from mail.cosmopool.net ([127.0.0.1]) by localhost (mail.your-server.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id A57k_gJYHp-Q; Sun, 11 Feb 2018 12:09:54 +0100 (CET) Received: from huygens.ccbib.org (unknown [10.0.10.106]) by mail.cosmopool.net (Postfix) with SMTP id 3732590030D; Sun, 11 Feb 2018 12:09:53 +0100 (CET) Received: by huygens.ccbib.org (sSMTP sendmail emulation); Sun, 11 Feb 2018 11:09:53 +0000 From: Harald Geyer To: Jonathan Cameron Cc: linux-iio@vger.kernel.org, Edward Attfield , Harald Geyer Subject: [PATCH] iio: dht11: Improve detection of sensor type Date: Sun, 11 Feb 2018 11:09:40 +0000 Message-Id: <1518347380-9624-1-git-send-email-harald@ccbib.org> X-Mailer: git-send-email 2.1.4 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The old code was based on a DHT11 datasheet which specifies a measurement range of 20%-90% RH. Turns out the sensor actually reports values outside this range, so we should support it as far as possible. Reported-by: Edward Attfield Signed-off-by: Harald Geyer --- drivers/iio/humidity/dht11.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/humidity/dht11.c b/drivers/iio/humidity/dht11.c index df6bab4..1a9f8f4 100644 --- a/drivers/iio/humidity/dht11.c +++ b/drivers/iio/humidity/dht11.c @@ -159,7 +159,7 @@ static int dht11_decode(struct dht11 *dht11, int offset) } dht11->timestamp = ktime_get_boot_ns(); - if (hum_int < 20) { /* DHT22 */ + if (hum_int < 4) { /* DHT22: 100000 = (3*256+232)*100 */ dht11->temperature = (((temp_int & 0x7f) << 8) + temp_dec) * ((temp_int & 0x80) ? -100 : 100); dht11->humidity = ((hum_int << 8) + hum_dec) * 100;