Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Narcisa Ana Maria Vasile <narcisaanamaria12@gmail.com>
Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net,
	linux-iio@vger.kernel.org, daniel.baluta@gmail.com,
	mranostay@gmail.com
Subject: Re: [PATCH] iio: chemical: ccs811: Fix output of IIO_CONCENTRATION channels
Date: Sun, 10 Dec 2017 18:24:41 +0000	[thread overview]
Message-ID: <20171210182441.5882c372@archlinux> (raw)
In-Reply-To: <1512579478-24601-1-git-send-email-narcisaanamaria12@gmail.com>

On Wed,  6 Dec 2017 18:57:58 +0200
Narcisa Ana Maria Vasile <narcisaanamaria12@gmail.com> wrote:
+CC Matt
> in_concentration_raw should report, according to sysfs-bus-iio documentation,
> a "Raw (unscaled no offset etc.) percentage reading of a substance."
> 
> Modify scale to convert from ppm/ppb to percentage:
> 1 ppm = 0.0001%
> 1 ppb = 0.0000001%
> 
> There is no offset needed to convert the ppm/ppb to percentage,
> so remove offset from IIO_CONCENTRATION (IIO_MOD_CO2) channel.
> 
> Signed-off-by: Narcisa Ana Maria Vasile <narcisaanamaria12@gmail.com>
> ---
> Details:
> The sensors reports data in parts per million for CO2 and parts per
> billion for VOC. The current scaling and offset values were meant to
> convert the ppm/ppb value into a percentage value with respect to
> the sensor's measurement range:
> For example:
>     For eCO2, possible raw values range from 400ppm to 8192ppm.
>     If the value reported is, let's say 500ppm, then, after scaling and
>     offset are applied, the percentage, with reference to the interval
>     [400, 8192] is 1.28%, using this interval mapping formula:
>     (500 - 400) * (100 - 0) / (8192 - 400) + 0. Instead, the value should
>     be 500 * 0.0001 = 0.05% (from ppm to percentage).
> 
> Note:
> In the docs, the in_concentration_raw value is said to be a
> "raw percentage reading of a substance". The raw value from the sensor
> is a ppm/ppb value, not a percentage value. It becomes a percentage value
> after applying a scale. Is this the correct behaviour (after applying scale,
> a percentage value is obtained) or did I misunderstood the docs?

I 'think' you are right on this, but would like some input from
someone more familiar with chemical sensors in general.

Matt, any comment on this?

Thanks,

Jonathan
> 
>  drivers/iio/chemical/ccs811.c | 13 +++----------
>  1 file changed, 3 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/iio/chemical/ccs811.c b/drivers/iio/chemical/ccs811.c
> index 97bce83..fbe2431 100644
> --- a/drivers/iio/chemical/ccs811.c
> +++ b/drivers/iio/chemical/ccs811.c
> @@ -96,7 +96,6 @@ struct ccs811_data {
>  		.channel2 = IIO_MOD_CO2,
>  		.modified = 1,
>  		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> -				      BIT(IIO_CHAN_INFO_OFFSET) |
>  				      BIT(IIO_CHAN_INFO_SCALE),
>  		.scan_index = 0,
>  		.scan_type = {
> @@ -255,24 +254,18 @@ static int ccs811_read_raw(struct iio_dev *indio_dev,
>  			switch (chan->channel2) {
>  			case IIO_MOD_CO2:
>  				*val = 0;
> -				*val2 = 12834;
> +				*val2 = 100;
>  				return IIO_VAL_INT_PLUS_MICRO;
>  			case IIO_MOD_VOC:
>  				*val = 0;
> -				*val2 = 84246;
> -				return IIO_VAL_INT_PLUS_MICRO;
> +				*val2 = 100;
> +				return IIO_VAL_INT_PLUS_NANO;
>  			default:
>  				return -EINVAL;
>  			}
>  		default:
>  			return -EINVAL;
>  		}
> -	case IIO_CHAN_INFO_OFFSET:
> -		if (!(chan->type == IIO_CONCENTRATION &&
> -		      chan->channel2 == IIO_MOD_CO2))
> -			return -EINVAL;
> -		*val = -400;
> -		return IIO_VAL_INT;
>  	default:
>  		return -EINVAL;
>  	}
> --
> 1.9.1
> 


  reply	other threads:[~2017-12-10 18:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-06 16:57 [PATCH] iio: chemical: ccs811: Fix output of IIO_CONCENTRATION channels Narcisa Ana Maria Vasile
2017-12-10 18:24 ` Jonathan Cameron [this message]
2017-12-10 21:11   ` Matt Ranostay
2017-12-12 19:58     ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171210182441.5882c372@archlinux \
    --to=jic23@kernel.org \
    --cc=daniel.baluta@gmail.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=mranostay@gmail.com \
    --cc=narcisaanamaria12@gmail.com \
    --cc=pmeerw@pmeerw.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox