drivers: sensor: ccs811: Fix value conversion
The arithmetic performed on the CO2 and VOC measurements is pointless as the units of the sensor already match those of the API, furthermore the multiplication will overflow the u32_t with CO2 or VOC readings greater than 4294 ppm or ppb. This CO2 concentration is achievable by breathing at the sensor. Signed-off-by: Aapo Vienamo <aapo.vienamo@iki.fi>
This commit is contained in:
parent
5ac590a316
commit
0a6f8c1aa2
1 changed files with 5 additions and 8 deletions
|
@ -66,21 +66,18 @@ static int ccs811_channel_get(struct device *dev,
|
||||||
|
|
||||||
switch (chan) {
|
switch (chan) {
|
||||||
case SENSOR_CHAN_CO2:
|
case SENSOR_CHAN_CO2:
|
||||||
uval = drv_data->co2 * 1000000;
|
val->val1 = drv_data->co2;
|
||||||
val->val1 = uval / 1000000;
|
val->val2 = 0;
|
||||||
val->val2 = uval % 1000000;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SENSOR_CHAN_VOC:
|
case SENSOR_CHAN_VOC:
|
||||||
uval = drv_data->voc * 1000000;
|
val->val1 = drv_data->voc;
|
||||||
val->val1 = uval / 1000000;
|
val->val2 = 0;
|
||||||
val->val2 = uval % 1000000;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SENSOR_CHAN_VOLTAGE:
|
case SENSOR_CHAN_VOLTAGE:
|
||||||
/*
|
/*
|
||||||
* Voltage readings are contained in least
|
* Raw ADC readings are contained in least significant 10 bits
|
||||||
* significant 10 bits in volts
|
|
||||||
*/
|
*/
|
||||||
uval = (drv_data->resistance & CCS811_VOLTAGE_MASK)
|
uval = (drv_data->resistance & CCS811_VOLTAGE_MASK)
|
||||||
* CCS811_VOLTAGE_SCALE;
|
* CCS811_VOLTAGE_SCALE;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue