Re: [PATCH 2/4] iio: pressure: Add scale value for channels

From: Andy Shevchenko
Date: Mon Mar 04 2024 - 06:43:10 EST


On Sun, Mar 03, 2024 at 05:52:58PM +0100, Vasileios Amoiridis wrote:
> Add extra IIO_CHAN_INFO_SCALE in order to be able to have the scales
> for the values in userspace. Can be used for triggered buffers.

..


> + case IIO_CHAN_INFO_SCALE:
> + switch (chan->type) {
> + case IIO_HUMIDITYRELATIVE:
> + if (!strcmp(indio_dev->name, "bme280")) {
> + *val = 1000;
> + *val2 = 1024;
> + ret = IIO_VAL_FRACTIONAL;
> + } else {
> + ret = -EINVAL;
> + }

No, just make these int arrays part of chip_info, then

case IIO_HUMIDITYRELATIVE:
if (chip_info->hrel) {
*val = chip_info->hrel[0];
*val2 = chip_info->hrel[1];
ret = IIO_VAL_FRACTIONAL;
} else {
ret = -EINVAL;
}

> + break;
> + case IIO_PRESSURE:
> + if ((!strcmp(indio_dev->name, "bmp085")) ||
> + (!strcmp(indio_dev->name, "bmp180")) ||
> + (!strcmp(indio_dev->name, "bmp181"))) {
> + *val = 1;
> + *val2 = 1000;
> + ret = IIO_VAL_FRACTIONAL;
> + } else if ((!strcmp(indio_dev->name, "bmp280")) ||
> + (!strcmp(indio_dev->name, "bme280"))) {
> + *val = 1;
> + *val2 = 256000;
> + ret = IIO_VAL_FRACTIONAL;
> + } else if (!strcmp(indio_dev->name, "bmp380")) {
> + *val = 1;
> + *val2 = 100000;
> + ret = IIO_VAL_FRACTIONAL;
> + } else if (!strcmp(indio_dev->name, "bmp580")) {
> + *val = 1;
> + *val2 = 64000;
> + ret = IIO_VAL_FRACTIONAL;
> + } else {
> + ret = -EINVAL;
> + }
> + break;

Ditto.

> + case IIO_TEMP:
> + if ((!strcmp(indio_dev->name, "bmp085")) ||
> + (!strcmp(indio_dev->name, "bmp180")) ||
> + (!strcmp(indio_dev->name, "bmp181"))) {
> + *val = 100;
> + *val2 = 1;
> + ret = IIO_VAL_FRACTIONAL;
> + } else if ((!strcmp(indio_dev->name, "bmp280")) ||
> + (!strcmp(indio_dev->name, "bme280"))) {
> + *val = 10;
> + *val2 = 1;
> + ret = IIO_VAL_FRACTIONAL;
> + } else if (!strcmp(indio_dev->name, "bmp380")) {
> + *val = 10;
> + *val2 = 1;
> + ret = IIO_VAL_FRACTIONAL;
> + } else if (!strcmp(indio_dev->name, "bmp580")) {
> + *val = 1000;
> + *val2 = 16;
> + ret = IIO_VAL_FRACTIONAL_LOG2;
> + } else {
> + ret = -EINVAL;
> + }
> + break;

Ditto.

> + default:
> + ret = -EINVAL;
> + break;
> + }
> + break;

--
With Best Regards,
Andy Shevchenko