Module sensors

Module sensors 

Source
Available on crate feature sensors only.
Expand description

Provides a sensor abstraction layer.

§Definitions

In the context of this abstraction:

  • A sensor device is a device measuring one or multiple physical quantities and reporting them as one or more digital values—we call these values samples.
  • Sensor devices measuring the same physical quantity are said to be part of the same sensor category. A sensor device may be part of multiple sensor categories.
  • A measurement is the physical operation of measuring one or several physical quantities.
  • A reading is the digital result returned by a sensor device after carrying out a measurement. Samples of different physical quantities can therefore be part of the same reading.
  • A sensor driver refers to a sensor device as exposed by the sensor abstraction layer.
  • A sensor driver instance is an instance of a sensor driver.

§Goals

This abstraction has two main goals:

  • Providing a unified way of accessing the readings from all registered sensor driver instances in a homogeneous way.
  • Making it easy and as transparent as possible to substitute a specific sensor device by a similar one from the same category.

§Accessing sensor driver instances

Registered sensor driver instances can be accessed using REGISTRY::sensors(). Sensor drivers implement the Sensor trait, which allows to trigger measurements and obtain the resulting readings.

§Obtaining a sensor reading

After triggering a measurement with Sensor::trigger_measurement(), a reading can be obtained using Sensor::wait_for_reading(). Sensor::wait_for_reading() returns a Samples, a data “tuple” containing values returned by the sensor driver along with their associated ReadingChannels, which identify which physical quantity the samples are about. For instance, ReadingChannels allow to disambiguate the samples provided by a temperature & humidity sensor.

To avoid handling floats, Samples returned by Sensor::wait_for_reading() are integers, and a fixed scaling value is provided in ReadingChannel for each Sample returned.

Additionally, Sensor::reading_channels() returns a ReadingChannels, which lists the ReadingChannels a sensor driver returns, in the same order as Samples. For instance, this can be used to pre-render a table of readings, without having to trigger measurements.

§For implementors

Sensor drivers must implement the Sensor trait.

Modules§

registry
Provides a sensor driver instance registry, allowing to register sensor driver instances and access them in a centralized location.
sensor
Provides a Sensor trait abstracting over implementation details of a sensor driver.
signal
This module contains a custom Signal struct meant to be used in the [ariel-os-sensors][ariel-os-sensors] ecosystem.

Enums§

Category
Categories a sensor driver can be part of.
Label
Label of a Sample part of a Samples tuple.
MeasurementUnit
Represents a unit of measurement.

Statics§

REGISTRY
The global registry instance.

Traits§

Reading
Implemented on Samples, returned by Sensor::wait_for_reading().
Sensor
This trait must be implemented by sensor drivers.