Skip to main content

beyond_lib/protocol/
status.rs

1use deku::prelude::*;
2
3#[derive(Debug, Clone, Copy, DekuSize, DekuRead)]
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[deku(magic = b"\x23", endian = "big")]
6pub struct DeviceStatus {
7    /// Packet size.
8    ///
9    /// The current 0.3 revision of the firmware (versions 0.3.0 to 0.3.18) has
10    /// a packet size of 24 (excluding the ID & size).
11    ///
12    /// Previous firmware revisions are unsupported.
13    #[deku(assert_eq = "24")]
14    pub size: u8,
15    /// Fan speed in RPM.
16    pub fan: u16,
17    /// Distance to the proximity sensor.
18    ///
19    /// Lower number are further away.
20    pub proximity: u16,
21    _unknown1: u16,
22    _unknown2: u16,
23    /// Motherboard temperature in Kelvin.
24    #[deku(endian = "little")]
25    pub t_motherboard: f32,
26    /// Left display temperature in Celsius.
27    #[deku(endian = "little")]
28    pub t_ldisplay: f32,
29    /// Right display temperature in Celsius.
30    #[deku(endian = "little")]
31    pub t_rdisplay: f32,
32    pub brightness: u16,
33    pub state: StateBits,
34}
35
36#[allow(clippy::struct_excessive_bools)]
37#[derive(Debug, Clone, Copy, DekuSize, DekuRead)]
38#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
39#[deku(endian = "endian", ctx = "endian: deku::ctx::Endian")]
40pub struct StateBits {
41    #[deku(bits = "1")]
42    _unknown00: bool,
43    #[deku(bits = "1")]
44    pub ok: bool,
45    #[deku(bits = "1")]
46    pub err: bool,
47    #[deku(bits = "1")]
48    _unknown03: bool,
49    #[deku(bits = "1")]
50    _unknown04: bool,
51    #[deku(bits = "1")]
52    _unknown05: bool,
53    #[deku(bits = "1")]
54    pub ldisplay_ok: bool,
55    #[deku(bits = "1")]
56    pub rdisplay_ok: bool,
57    // ===== //
58    #[deku(bits = "1")]
59    _unknown10: bool,
60    #[deku(bits = "1")]
61    _unknown11: bool,
62    #[deku(bits = "1")]
63    _unknown12: bool,
64    #[deku(bits = "1")]
65    pub connected: bool,
66    #[deku(bits = "1")]
67    pub ready: bool,
68    #[deku(bits = "1")]
69    pub idle: bool,
70    #[deku(bits = "1")]
71    pub proximity: bool,
72    #[deku(bits = "1")]
73    pub displaying: bool,
74}
75
76#[cfg(test)]
77mod tests {
78    use deku::DekuSize;
79
80    use crate::protocol::status::{DeviceStatus, StateBits};
81
82    #[test]
83    // A simple initial check to make sure everything is the correct size
84    fn size() {
85        assert_eq!(DeviceStatus::SIZE_BYTES, Some(24 + 2));
86        assert_eq!(StateBits::SIZE_BITS, 16);
87    }
88}