ariel_os_sensors/
lib.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//! # Obtaining a sensor reading
29//!
30//! After triggering a measurement with [`Sensor::trigger_measurement()`], a reading can be
31//! obtained using [`Sensor::wait_for_reading()`].
32//! It is additionally necessary to use [`Sensor::reading_channels()`] to make sense of the obtained
33//! reading:
34//!
35//! - [`Sensor::wait_for_reading()`] returns a [`Samples`](sensor::Samples), a data "tuple"
36//!   containing values returned by the sensor driver.
37//! - [`Sensor::reading_channels()`] returns a [`ReadingChannels`](sensor::ReadingChannels) which
38//!   indicates which physical quantity each [`Sample`](sample::Sample) from that tuple corresponds
39//!   to, using a [`Label`].
40//!   For instance, this allows to disambiguate the values provided by a temperature & humidity
41//!   sensor.
42//!
43//! To avoid handling floats, [`Sample`](sample::Sample)s returned by [`Sensor::wait_for_reading()`]
44//! are integers, and a fixed scaling value is provided in
45//! [`ReadingChannel`](sensor::ReadingChannel), for each [`Sample`](sample::Sample) returned.
46//! See [`Sample`](sample::Sample) for more details.
47//!
48//! # For implementors
49//!
50//! Sensor drivers must implement the [`Sensor`] trait.
51//!
52#![no_std]
53#![cfg_attr(nightly, feature(doc_cfg))]
54#![deny(missing_docs)]
55
56mod category;
57mod label;
58mod measurement_unit;
59mod sample;
60pub mod sensor;
61pub mod signal;
62
63pub use category::Category;
64pub use label::Label;
65pub use measurement_unit::MeasurementUnit;
66pub use sample::Reading;
67#[doc(inline)]
68pub use sensor::Sensor;