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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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






[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux