1.. _sensor-attribute: 2 3Sensor Attributes 4################# 5 6:dfn:`Attributes`, enumerated in :c:enum:`sensor_attribute`, are immutable and 7mutable properties of a sensor and its channels. 8 9Attributes allow for obtaining metadata and changing configuration of a sensor. 10Common configuration parameters like channel scale, sampling frequency, adjusting 11channel offsets, signal filtering, power modes, on chip buffers, and event 12handling options are very common. Attributes provide a flexible API for 13inspecting and manipulating such device properties. 14 15Attributes are specified using :c:enum:`sensor_attribute` which can be used with 16:c:func:`sensor_attr_get` and :c:func:`sensor_attr_set` to get and set a sensors 17attributes. 18 19A quick example... 20 21.. code-block:: c 22 23 const struct device *accel_dev = DEVICE_DT_GET(DT_ALIAS(accel0)); 24 struct sensor_value accel_sample_rate; 25 int rc; 26 27 rc = sensor_attr_get(accel_dev, SENSOR_CHAN_ACCEL_XYZ, SENSOR_ATTR_SAMPLING_FREQUENCY, &accel_sample_rate); 28 if (rc != 0) { 29 printk("Failed to get sampling frequency\n"); 30 } 31 32 printk("Sample rate for accel %p is %d.06%d\n", accel_dev, accel_sample_rate.val1, accel_sample_rate.val2*1000000); 33 34 accel_sample_rate.val1 = 2000; 35 36 rc = sensor_attr_set(accel_dev, SENSOR_CHAN_ACCEL_XYZ, SENSOR_ATTR_SAMPLING_FREQUENCY, accel_sample_rate); 37 if (rc != 0) { 38 printk("Failed to set sampling frequency\n"); 39 } 40