steeloxide 0.1.0

A rust library for interacting with SteelSeries devices.
Documentation
// (c) ato
// 
// This is somewhat of a fixed-rate sadly

use crate::error::{MouseError, Result};

#[derive(Debug, Clone, Copy, Default)]
pub struct PollingRate(pub u16);

impl From<u16> for PollingRate {
    fn from(value: u16) -> Self {
        match value {
            0..=125 => Self(125),
            126..=250 => Self(250),
            251..=500 => Self(500),
            501..=1000 => Self(1000),
            _ => Self(125),
        }
    }
}

impl PollingRate {
    pub fn encode(self) -> Result<u8> {
        match self.0 {
            0..=125 => Ok(0x4),
            126..=250 => Ok(0x3),
            251..=500 => Ok(0x2),
            501..=1000 => Ok(0x1),
            _ => Err(MouseError::InvalidPollingRate.into()),
        }
    }
}