hardware/peripherals/sensor/attributes.html · hardware/peripherals/sensor/attributes.rst 공식 원문 ↗

Zephyr 3.7.0 · Hardware · Peripherals · Sensor · Attributes

Sensor Attributes

Scale·sampling frequency·offset·filter·power mode 같은 sensor property를 읽고 변경합니다.

Official pathhardware/peripherals/sensor/attributes.html
Source filehardware/peripherals/sensor/attributes.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

본문 기준: Zephyr 3.7.0 LTS3 · 이후 유지보수 패치는 별도입니다.

Part 1

요약·해설

Immutable·mutable property와 sensor_attr_get/set 사용법을 설명합니다.

Scope

sensor · channel properties

Operations

get · set

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 6165DEE20A059CEFE177F5284DFC3C1D4DB9E2ECF334E94B649C6C08B164F27F
.. _sensor-attribute:

Sensor Attributes
#################

:dfn:`Attributes`, enumerated in :c:enum:`sensor_attribute`, are immutable and
mutable properties of a sensor and its channels.

Attributes allow for obtaining metadata and changing configuration of a sensor.
Common configuration parameters like channel scale, sampling frequency, adjusting
channel offsets, signal filtering, power modes, on chip buffers, and event
handling options are very common. Attributes provide a flexible API for
inspecting and manipulating such device properties.

Attributes are specified using :c:enum:`sensor_attribute` which can be used with
:c:func:`sensor_attr_get` and :c:func:`sensor_attr_set` to get and set a sensors
attributes.

A quick example...

.. code-block:: c

   const struct device *accel_dev = DEVICE_DT_GET(DT_ALIAS(accel0));
   struct sensor_value accel_sample_rate;
   int rc;

   rc = sensor_attr_get(accel_dev, SENSOR_CHAN_ACCEL_XYZ, SENSOR_ATTR_SAMPLING_FREQUENCY, &accel_sample_rate);
   if (rc != 0) {
                printk("Failed to get sampling frequency\n");
   }

   printk("Sample rate for accel %p is %d.06%d\n", accel_dev, accel_sample_rate.val1, accel_sample_rate.val2*1000000);

   accel_sample_rate.val1 = 2000;

   rc = sensor_attr_set(accel_dev, SENSOR_CHAN_ACCEL_XYZ, SENSOR_ATTR_SAMPLING_FREQUENCY, accel_sample_rate);
   if (rc != 0) {
                printk("Failed to set sampling frequency\n");
   }

Part 3

한국어 전문 번역

sensor_attribute enum에 열거된 attribute는 sensor와 그 channel이 가진 immutable·mutable property입니다.

Attribute를 통해 metadata를 얻고 sensor configuration을 변경할 수 있습니다. Channel scale, sampling frequency, channel offset 조정, signal filtering, power mode, on-chip buffer, event handling option 같은 parameter가 흔한 예입니다. Attribute는 이런 device property를 조사하고 조작하는 유연한 API를 제공합니다.

sensor_attribute로 attribute를 지정하고 sensor_attr_get()과 sensor_attr_set()으로 sensor attribute를 가져오거나 설정합니다.

다음은 accelerometer sampling frequency를 읽고 2000으로 변경하는 간단한 예입니다.

const struct device *accel_dev = DEVICE_DT_GET(DT_ALIAS(accel0));
struct sensor_value accel_sample_rate;
int rc;

rc = sensor_attr_get(accel_dev, SENSOR_CHAN_ACCEL_XYZ, SENSOR_ATTR_SAMPLING_FREQUENCY, &accel_sample_rate);
if (rc != 0) {
             printk("Failed to get sampling frequency\n");
}

printk("Sample rate for accel %p is %d.06%d\n", accel_dev, accel_sample_rate.val1, accel_sample_rate.val2*1000000);

accel_sample_rate.val1 = 2000;

rc = sensor_attr_set(accel_dev, SENSOR_CHAN_ACCEL_XYZ, SENSOR_ATTR_SAMPLING_FREQUENCY, accel_sample_rate);
if (rc != 0) {
             printk("Failed to set sampling frequency\n");
}

Source

출처

영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.