All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Matt Ranostay <mranostay@gmail.com>
Cc: Narcisa Ana Maria Vasile <narcisaanamaria12@gmail.com>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald <pmeerw@pmeerw.net>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
	Daniel Baluta <daniel.baluta@gmail.com>
Subject: Re: [PATCH] iio: chemical: ccs811: Fix output of IIO_CONCENTRATION channels
Date: Tue, 12 Dec 2017 19:58:43 +0000	[thread overview]
Message-ID: <20171212195843.0442e4aa@archlinux> (raw)
In-Reply-To: <CAKzfze8q7ZVmmwJSNSKiT5_i=kv-bzP=W9+WYy7=ymNfzb0V=A@mail.gmail.com>

On Sun, 10 Dec 2017 13:11:51 -0800
Matt Ranostay <mranostay@gmail.com> wrote:

> On Sun, Dec 10, 2017 at 10:24 AM, Jonathan Cameron <jic23@kernel.org> wrote:
> > 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>  
> 
> Reviewed-by: Matt Ranostay <matt.ranostay@konsulko.com>
Applied to the fixes-togreg branch of iio.git and marked for stable
so hopefully we can avoid too much userspace breakage...

Thanks,

Jonathan
> 
> >> ---
> >> 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?
> >  
> 
> Yes the IIO_CONCENTRATION is suppose to be in ppm/ppb units that are
> converted to percent with the scaling value.
> Basically since someday we may have a sensor that actually with a
> digit on the other the decimal point, but hopefully not really 1.28%
> CO2 since that is well into toxic zone :)
> 
> - Matt
> 
> > 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
> >>  
> >  
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


      reply	other threads:[~2017-12-12 19:58 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
2017-12-10 21:11   ` Matt Ranostay
2017-12-12 19:58     ` Jonathan Cameron [this message]

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=20171212195843.0442e4aa@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.