1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! Decoded `RESP(HEALTH)` flags.
use crate::protocol::opcode::{H_CLONE_CFG, H_INJECT_ON, H_LINK_UP, H_MOUSE_ATT, H_RATE_CONFIDENT};
/// The decoded `RESP(HEALTH)` flags byte.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Health {
/// Inter-chip link to the host chip is up.
pub link_up: bool,
/// A real mouse is attached on the host chip.
pub mouse_attached: bool,
/// The clone has been configured by the game PC.
pub clone_configured: bool,
/// Injection is currently active.
pub injection_active: bool,
/// The native-rate estimator window is full, so the [`Rate`](crate::Rate) value is trustworthy.
pub rate_confident: bool,
}
impl Health {
/// Decode a `RESP(HEALTH)` flags byte.
pub fn from_flags(flags: u8) -> Self {
Health {
link_up: flags & H_LINK_UP != 0,
mouse_attached: flags & H_MOUSE_ATT != 0,
clone_configured: flags & H_CLONE_CFG != 0,
injection_active: flags & H_INJECT_ON != 0,
rate_confident: flags & H_RATE_CONFIDENT != 0,
}
}
/// Re-encode this health view back to its flags byte.
pub fn to_flags(self) -> u8 {
let mut flags = 0u8;
if self.link_up {
flags |= H_LINK_UP;
}
if self.mouse_attached {
flags |= H_MOUSE_ATT;
}
if self.clone_configured {
flags |= H_CLONE_CFG;
}
if self.injection_active {
flags |= H_INJECT_ON;
}
if self.rate_confident {
flags |= H_RATE_CONFIDENT;
}
flags
}
}