use core::fmt;
pub const SOF: u8 = 0xA5;
pub const MAX_PAYLOAD: usize = 512;
pub const PROTO_VER: u8 = 1;
pub const Q_VERSION: u8 = 0;
pub const Q_HEALTH: u8 = 1;
pub const Q_MOUSE_INFO: u8 = 2;
pub const Q_CAPS: u8 = 3;
pub const Q_RATE: u8 = 4;
pub const Q_STATS: u8 = 5;
pub const BTN_LEFT: u8 = 0;
pub const BTN_RIGHT: u8 = 1;
pub const BTN_MIDDLE: u8 = 2;
pub const BTN_SIDE1: u8 = 3;
pub const BTN_SIDE2: u8 = 4;
pub const BTN_COUNT: u8 = 5;
pub const ACT_SOFTREL: u8 = 0;
pub const ACT_PRESS: u8 = 1;
pub const ACT_FORCEREL: u8 = 2;
pub const H_LINK_UP: u8 = 0x01;
pub const H_MOUSE_ATT: u8 = 0x02;
pub const H_CLONE_CFG: u8 = 0x04;
pub const H_INJECT_ON: u8 = 0x08;
pub const H_RATE_CONFIDENT: u8 = 0x10;
pub const MI_HAS_SERIAL: u8 = 0x01;
pub const MI_HAS_BOS: u8 = 0x02;
pub const CAP_X: u8 = 0x01;
pub const CAP_Y: u8 = 0x02;
pub const CAP_WHEEL: u8 = 0x04;
pub const CAP_REPORT_ID: u8 = 0x08;
pub const RATE_CONFIDENT: u8 = 0x01;
pub const LOG_ERROR: u8 = 0;
pub const LOG_WARN: u8 = 1;
pub const LOG_INFO: u8 = 2;
pub const LOG_DEBUG: u8 = 3;
pub const LOG_VERBOSE: u8 = 4;
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FrameType {
Move = 0x01,
Wheel = 0x02,
Button = 0x03,
Reset = 0x04,
Query = 0x05,
Resp = 0x06,
RebootDl = 0x07,
Log = 0x08,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct UnknownFrameType(pub u8);
impl fmt::Display for UnknownFrameType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "unknown frame type 0x{:02X}", self.0)
}
}
impl core::error::Error for UnknownFrameType {}
impl TryFrom<u8> for FrameType {
type Error = UnknownFrameType;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Ok(match value {
0x01 => FrameType::Move,
0x02 => FrameType::Wheel,
0x03 => FrameType::Button,
0x04 => FrameType::Reset,
0x05 => FrameType::Query,
0x06 => FrameType::Resp,
0x07 => FrameType::RebootDl,
0x08 => FrameType::Log,
other => return Err(UnknownFrameType(other)),
})
}
}
impl From<FrameType> for u8 {
fn from(t: FrameType) -> u8 {
t as u8
}
}