Skip to content

Commit 3473785

Browse files
authored
Merge pull request #19 from LechevSpace/feat/postcard
feat: postcard-experimental feature
2 parents d2d8588 + 79362a6 commit 3473785

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ default = []
1818
defmt-03 = ["dep:defmt"]
1919
serde = ["dep:serde"]
2020
async = ["dep:embedded-hal-async"]
21+
postcard = ["dep:postcard"]
22+
postcard-experimental = ["postcard", "postcard/experimental-derive"]
2123

2224
[dependencies]
2325
embedded-hal = { version = "1" }
@@ -26,3 +28,4 @@ libm = "0.2"
2628

2729
serde = { version = "1", features = ["derive"], default-features = false, optional = true }
2830
defmt = { version = "0.3", optional = true }
31+
postcard = { version = "1", optional = true }

src/accel.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
1919
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
2020
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
21+
#[cfg_attr(feature = "postcard-experimental", derive(postcard::experimental::max_size::MaxSize))]
2122
pub struct Accel {
2223
pub(crate) x: i16,
2324
pub(crate) y: i16,
@@ -95,6 +96,7 @@ impl Accel {
9596
#[derive(Copy, Clone, Debug)]
9697
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
9798
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
99+
#[cfg_attr(feature = "postcard-experimental", derive(postcard::experimental::max_size::MaxSize))]
98100
pub enum AccelFullScale {
99101
/// ±2g range (16384 LSB/g)
100102
G2 = 0,
@@ -134,6 +136,7 @@ impl AccelFullScale {
134136
#[derive(Debug, Clone, Copy)]
135137
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
136138
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
139+
#[cfg_attr(feature = "postcard-experimental", derive(postcard::experimental::max_size::MaxSize))]
137140
pub struct AccelF32 {
138141
/// X-axis acceleration in g-force
139142
x: f32,

src/gravity.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::quaternion::Quaternion;
2424
#[derive(Debug, Copy, Clone)]
2525
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
2626
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
27+
#[cfg_attr(feature = "postcard-experimental", derive(postcard::experimental::max_size::MaxSize))]
2728
pub struct Gravity {
2829
/// Forward/backward tilt component
2930
pub x: f32,

src/gyro.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
1212
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
1313
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
14+
#[cfg_attr(feature = "postcard-experimental", derive(postcard::experimental::max_size::MaxSize))]
1415
pub struct Gyro {
1516
pub(crate) x: i16,
1617
pub(crate) y: i16,
@@ -61,6 +62,12 @@ impl Gyro {
6162
}
6263
}
6364

65+
impl From<Gyro> for [i16; 3] {
66+
fn from(value: Gyro) -> Self {
67+
[value.x, value.y, value.z]
68+
}
69+
}
70+
6471
/// Full-scale range settings for the gyroscope.
6572
///
6673
/// Each setting defines the maximum measurable rotation rate:
@@ -71,6 +78,7 @@ impl Gyro {
7178
#[derive(Copy, Clone, Debug)]
7279
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
7380
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
81+
#[cfg_attr(feature = "postcard-experimental", derive(postcard::experimental::max_size::MaxSize))]
7482
pub enum GyroFullScale {
7583
/// ±250°/s range (131 LSB/°/s)
7684
Deg250 = 0,
@@ -105,6 +113,7 @@ impl GyroFullScale {
105113
#[derive(Copy, Clone, Debug)]
106114
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
107115
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
116+
#[cfg_attr(feature = "postcard-experimental", derive(postcard::experimental::max_size::MaxSize))]
108117
pub struct GyroF32 {
109118
/// Roll rate (°/s)
110119
x: f32,
@@ -131,3 +140,9 @@ impl GyroF32 {
131140
self.z
132141
}
133142
}
143+
144+
impl From<GyroF32> for [f32; 3] {
145+
fn from(value: GyroF32) -> Self {
146+
[value.x, value.y, value.z]
147+
}
148+
}

src/quaternion.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#[derive(Debug, Copy, Clone)]
1717
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
1818
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
19+
#[cfg_attr(feature = "postcard-experimental", derive(postcard::experimental::max_size::MaxSize))]
1920
pub struct Quaternion {
2021
/// Scalar (real) component
2122
pub w: f32,

0 commit comments

Comments
 (0)