Round measures to their significant bits, remove debug statements

This commit is contained in:
Maxime Augier 2024-04-20 12:30:41 +02:00
parent eedf62e304
commit cc63f34e9e

View File

@ -29,11 +29,13 @@ struct Data {
impl Data { impl Data {
fn from_pkt(addr: Address, b: &[u8]) -> Data { fn from_pkt(addr: Address, b: &[u8]) -> Data {
eprintln!("Packet {:?}", b);
let round = |v: f32| (v*100.0).round() / 100.0;
Data { Data {
addr, addr,
temperature: (u16::from_le_bytes([b[2], b[3]]) as f32) * 175.0 / 65535.0 - 45.0, temperature: round((u16::from_le_bytes([b[2], b[3]]) as f32) * 175.0 / 65535.0 - 45.0),
humidity: (u16::from_le_bytes([b[4], b[5]]) as f32) * 100.0 / 65535.0, humidity: round((u16::from_le_bytes([b[4], b[5]]) as f32) * 100.0 / 65535.0),
co2: u16::from_le_bytes([b[6], b[7]]), co2: u16::from_le_bytes([b[6], b[7]]),
} }
} }