-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: introduce a sensor abstraction #474
base: main
Are you sure you want to change the base?
Conversation
#[derive(Debug, Copy, Clone, PartialEq)] | ||
#[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
pub struct Value { | ||
value: i32, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we downsize this to an i24
(?) so we can losslessly convert it to an f32
?
/// [Acceleration *g*](https://en.wikipedia.org/wiki/G-force#Unit_and_measurement). | ||
AccelG, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given this isn't a SenML unit, should we remove it and ask sensor drivers to convert it to m/s² instead?
Some initial comments based on the docs Bikeshedding:
Does it make sense to include the sensor range in a same way the accuracy is provided? I think this can be valuable with gas sensors and accelerometers, to know when the measurement is out of (or close to) the max range.
I think a set of (gated) helpers to convert to floats is useful, even if it just to make printing measurements easier. On the API side, the only question I have so far is whether it is easy enough to zip a set of |
👍 To be clear, that would mean in the case of 3-axis accelerometers we'd have three samples, part of one reading.
Currently a 3-axis accelerometer + magnetometer (like the LSM303AGR on the micro:bit V2) would return six The plan was to expand that
That's indeed something I haven't considered yet; I'll look into how useful this could be and whether we can do that while keeping memory usage under control, thanks for the suggestion!
👍 I don't this needs to be part of this first PR, as I expect the helpers to be purely additive.
It sure is! There's even a pointer to that already in the docs of |
Exactly!
(Don't forget the 9 axis IMU's, those include The way I interpreted the current
Agreed, and this can all be added later, don't want to introduce too much feature creep here. |
Description
This is the first step in providing a sensor abstraction/API whose goal is to provide consistent access to sensor drivers and their readings, abstracting over implementation details of specific sensor devices. It is a (partial) implementation of RFC #201 (handling of thresholds and sensor interrupts will come later and is expected to be relatively orthogonal).
The main change is the introduction of a
riot-rs-sensors
crate, which is re-exported inriot-rs
as thesensors
module, which is feature-gated behind thesensors
Cargo feature. Until this API and the first sensor drivers are landed, this feature is considered experimental/unstable and breaking changes will therefore not be reflected on the version number of theriot-rs
crate.Issues/PRs references
Partial implementation of RFC #201.
Open Questions
serde::Serialize
on the relevant items?Value
+ReadingAxis
+Accuracy
which would return floats taking into account everything required to make sense of the reading (in particular the scaling value)?Reading
trait was initially introduced when it was thought it would be possible to return different concrete types fromSensor::wait_for_reading()
(it now always return aValues
); should the trait be removed and its methods implemented onValues
itself, slightly simplifying the API (it is not impossible that Rust would allow returning different concrete types fromSensor::wait_for_reading()
in the far future)?Value
and theAccuracy
types, in an attempt to keep it close to its associated implementation. Should we instead group (some of) it in the top-level module?Future work
The following steps would be:
How to review this PR
I think this PR is better reviewed by generating the rustdoc docs locally and starting from there, before glancing at the implementation.
TODO
Category
,Label
, andMeasurementUnit
enums should be expanded with more variants, even though these can (and will) be expanded later.Change checklist