All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: chemical: ccs811: Fix output of IIO_CONCENTRATION channels
@ 2017-12-06 16:57 Narcisa Ana Maria Vasile
  2017-12-10 18:24 ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Narcisa Ana Maria Vasile @ 2017-12-06 16:57 UTC (permalink / raw)
  To: jic23, knaack.h, lars, pmeerw
  Cc: linux-iio, daniel.baluta, Narcisa Ana Maria Vasile

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?

 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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: chemical: ccs811: Fix output of IIO_CONCENTRATION channels
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2017-12-10 18:24 UTC (permalink / raw)
  To: Narcisa Ana Maria Vasile
  Cc: knaack.h, lars, pmeerw, linux-iio, daniel.baluta, mranostay

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
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: chemical: ccs811: Fix output of IIO_CONCENTRATION channels
  2017-12-10 18:24 ` Jonathan Cameron
@ 2017-12-10 21:11   ` Matt Ranostay
  2017-12-12 19:58     ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Matt Ranostay @ 2017-12-10 21:11 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Narcisa Ana Maria Vasile, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald, linux-iio, Daniel Baluta

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>

>> ---
>> 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
>>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: chemical: ccs811: Fix output of IIO_CONCENTRATION channels
  2017-12-10 21:11   ` Matt Ranostay
@ 2017-12-12 19:58     ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2017-12-12 19:58 UTC (permalink / raw)
  To: Matt Ranostay
  Cc: Narcisa Ana Maria Vasile, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald, linux-iio, Daniel Baluta

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-12-12 19:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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.