ariel_os/sensors.rs
1//! Provides a sensor abstraction layer.
2//!
3//! # Definitions
4//!
5//! In the context of this abstraction:
6//!
7//! - A *sensor device* is a device measuring one or multiple physical quantities and reporting
8//! them as one or more digital values—we call these values *samples*.
9//! - Sensor devices measuring the same physical quantity are said to be part of the same *sensor
10//! category*.
11//! A sensor device may be part of multiple sensor categories.
12//! - A *measurement* is the physical operation of measuring one or several physical quantities.
13//! - A *reading* is the digital result returned by a sensor device after carrying out a
14//! measurement.
15//! Samples of different physical quantities can therefore be part of the same reading.
16//! - A *sensor driver* refers to a sensor device as exposed by the sensor abstraction layer.
17//! - A *sensor driver instance* is an instance of a sensor driver.
18//!
19//! # Goals
20//!
21//! This abstraction has two main goals:
22//!
23//! - Providing a unified way of accessing the readings from all registered sensor driver instances
24//! in a homogeneous way.
25//! - Making it easy and as transparent as possible to substitute a specific sensor device by a
26//! similar one from the same category.
27//!
28//! # Accessing sensor driver instances
29//!
30//! Registered sensor driver instances can be accessed using
31//! [`REGISTRY::sensors()`](registry::Registry::sensors).
32//! Sensor drivers implement the [`Sensor`] trait, which allows to trigger measurements and obtain
33//! the resulting readings.
34//!
35//! # Obtaining a sensor reading
36//!
37//! After triggering a measurement with [`Sensor::trigger_measurement()`], a reading can be
38//! obtained using [`Sensor::wait_for_reading()`].
39//! [`Sensor::wait_for_reading()`] returns a [`Samples`], a data "tuple" containing values returned
40//! by the sensor driver along with their associated [`ReadingChannel`]s, which identify which
41//! physical quantity the samples are about.
42//! For instance, [`ReadingChannel`]s allow to disambiguate the samples provided by a temperature
43//! &Â humidity sensor.
44//!
45//! To avoid handling floats, [`Sample`]s returned by [`Sensor::wait_for_reading()`]
46//! are integers, and a fixed scaling value is [provided in
47//! `ReadingChannel`][ReadingChannel::scaling] for each [`Sample`]
48//! returned.
49//!
50//! Additionally, [`Sensor::reading_channels()`] returns a [`ReadingChannels`], which lists the
51//! [`ReadingChannel`]s a sensor driver returns, in the same order as [`Samples`].
52//! For instance, this can be used to pre-render a table of readings, without having to trigger
53//! measurements.
54//!
55//! # For implementors
56//!
57//! Sensor drivers must implement the [`Sensor`] trait.
58//!
59//! [`Sample`]: ariel_os_sensors::sensor::Sample
60//! [`Samples`]: ariel_os_sensors::sensor::Samples
61//! [`ReadingChannel`]: ariel_os_sensors::sensor::ReadingChannel
62//! [ReadingChannel::scaling]: ariel_os_sensors::sensor::ReadingChannel::scaling()
63//! [`ReadingChannels`]: ariel_os_sensors::sensor::ReadingChannels
64
65pub use ariel_os_sensors::*;
66#[doc(inline)]
67pub use ariel_os_sensors_registry as registry;
68pub use ariel_os_sensors_registry::{REGISTRY, SENSOR_REFS};