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

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.