This commit is contained in:
Robin Appelman 2024-02-23 22:53:44 +01:00
commit a90361ac60
2 changed files with 1 additions and 37 deletions

View file

@ -3,6 +3,7 @@ name = "hlk_ld6002"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
description = "A library for interfacing with the HLK-LD6002 respiratory and heartbeat radar module" description = "A library for interfacing with the HLK-LD6002 respiratory and heartbeat radar module"
license = "MIT OR Apache-2.0"
[dependencies] [dependencies]
bytemuck = { version = "1.14.3", features = ["derive"] } bytemuck = { version = "1.14.3", features = ["derive"] }

View file

@ -1,7 +1,6 @@
#![no_std] #![no_std]
use bytemuck::{cast, cast_slice}; use bytemuck::{cast, cast_slice};
use core::sync::atomic::{AtomicU32, Ordering};
use embedded_io::{Error, Read, ReadExactError}; use embedded_io::{Error, Read, ReadExactError};
use embedded_io_async::Read as AsyncRead; use embedded_io_async::Read as AsyncRead;
use num_enum::TryFromPrimitive; use num_enum::TryFromPrimitive;
@ -336,42 +335,6 @@ impl Data {
} }
} }
#[derive(Default, Debug)]
pub struct AtomicData {
respiratory: AtomicU32,
distance: AtomicU32,
heartbeat: AtomicU32,
}
impl AtomicData {
pub fn update(&self, message: MessageBody) {
match message {
MessageBody::Respiratory(rate) => {
self.respiratory.store(rate.to_bits(), Ordering::SeqCst);
}
MessageBody::Distance(Some(distance)) => {
self.distance.store(distance.to_bits(), Ordering::SeqCst);
}
MessageBody::Heartbeat(rate) => {
self.heartbeat.store(rate.to_bits(), Ordering::SeqCst);
}
_ => {}
}
}
pub fn respiratory(&self) -> f32 {
f32::from_bits(self.respiratory.load(Ordering::Relaxed))
}
pub fn distance(&self) -> f32 {
f32::from_bits(self.distance.load(Ordering::Relaxed))
}
pub fn heartbeat(&self) -> f32 {
f32::from_bits(self.heartbeat.load(Ordering::Relaxed))
}
}
fn checksum(data: &[u8]) -> u8 { fn checksum(data: &[u8]) -> u8 {
let mut result = 0; let mut result = 0;
for byte in data { for byte in data {