Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[package]
name = "accelerometer"
version = "0.12.0" # Also update html_root_url in lib.rs when bumping this
name = "accelerometer"
version = "0.12.0" # Also update html_root_url in lib.rs when bumping this
description = """
Generic, embedded-friendly accelerometer support, including
traits and types for taking readings from 2 or 3-axis
accelerometers and tracking device orientations.
"""
authors = ["Tony Arcieri <[email protected]>"]
license = "Apache-2.0 OR MIT"
repository = "https://github.com/NeoBirth/accelerometer.rs"
readme = "README.md"
edition = "2018"
authors = ["Tony Arcieri <[email protected]>"]
license = "Apache-2.0 OR MIT"
repository = "https://github.com/NeoBirth/accelerometer.rs"
readme = "README.md"
edition = "2018"
rust-version = "1.47"
categories = ["embedded", "hardware-support", "no-std"]
keywords = ["acceleration", "position", "tracking"]
categories = ["embedded", "hardware-support", "no-std"]
keywords = ["acceleration", "position", "tracking"]

[badges]
maintenance = { status = "passively-maintained" }
Expand All @@ -22,6 +22,15 @@ maintenance = { status = "passively-maintained" }
version = "2"
features = ["vector"]

[dependencies.defmt]
version = "0.3.8"
optional = true

[features]
default = ["orientation"]
orientation = []
defmt = ["dep:defmt"]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
36 changes: 36 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,39 @@ where
Self::new_with_cause(ErrorKind::Bus, cause)
}
}

#[cfg_attr(docsrs, doc(cfg(feature = "defmt")))]
#[cfg(feature = "defmt")]
impl<E: Debug + defmt::Format> defmt::Format for Error<E> {
fn format(&self, fmt: defmt::Formatter<'_>) {
// Implemented manually so that the docs.rs marker can be applied.
defmt::write!(
fmt,
"Error {{ kind = {}, cause = {} }}",
self.kind,
self.cause
)
}
}

#[cfg_attr(docsrs, doc(cfg(feature = "defmt")))]
#[cfg(feature = "defmt")]
impl defmt::Format for ErrorKind {
fn format(&self, fmt: defmt::Formatter<'_>) {
// Implemented manually so that the docs.rs marker can be applied.
match self {
ErrorKind::Device => {
defmt::write!(fmt, "Device")
}
ErrorKind::Bus => {
defmt::write!(fmt, "Bus")
}
ErrorKind::Mode => {
defmt::write!(fmt, "Mode")
}
ErrorKind::Param => {
defmt::write!(fmt, "Param")
}
}
}
}
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@
#![forbid(unsafe_code)]
#![warn(missing_docs, rust_2018_idioms, unused_qualifications)]

// Enables the `doc_cfg` feature when the `docsrs` configuration attribute is defined.
#![cfg_attr(docsrs, feature(doc_cfg))]

mod accelerometer;
pub mod error;
#[cfg_attr(docsrs, doc(cfg(feature = "orientation")))]
#[cfg(feature = "orientation")]
pub mod orientation;

Expand Down
31 changes: 31 additions & 0 deletions src/orientation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,34 @@ impl Orientation {
matches!(self, Orientation::PortraitUp | Orientation::PortraitDown)
}
}

#[cfg_attr(docsrs, doc(cfg(feature = "defmt")))]
#[cfg(feature = "defmt")]
impl defmt::Format for Orientation {
fn format(&self, fmt: defmt::Formatter<'_>) {
// Implemented manually so that the docs.rs marker can be applied.
match self {
Orientation::Unknown => {
defmt::write!(fmt, "Unknown")
}
Orientation::PortraitUp => {
defmt::write!(fmt, "PortraitUp")
}
Orientation::PortraitDown => {
defmt::write!(fmt, "PortraitDown")
}
Orientation::LandscapeUp => {
defmt::write!(fmt, "LandscapeUp")
}
Orientation::LandscapeDown => {
defmt::write!(fmt, "LandscapeDown")
}
Orientation::FaceUp => {
defmt::write!(fmt, "FaceUp")
}
Orientation::FaceDown => {
defmt::write!(fmt, "FaceDown")
}
}
}
}
14 changes: 14 additions & 0 deletions src/orientation/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,17 @@ impl Tracker {
self.last_orientation
}
}

#[cfg_attr(docsrs, doc(cfg(feature = "defmt")))]
#[cfg(feature = "defmt")]
impl defmt::Format for Tracker {
fn format(&self, fmt: defmt::Formatter<'_>) {
// Implemented manually so that the docs.rs marker can be applied.
defmt::write!(
fmt,
"Tracker {{ threshold = {}, last_orientation = {} }}",
self.threshold,
self.last_orientation
)
}
}