keydous-bridge 0.1.2

Linux bridge for configuring Keydous keyboards with the official web driver
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum CommandSet {
    Nj98CpV4,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct Capabilities {
    pub display: bool,
    pub rgb: bool,
    pub macros: bool,
    pub hall_effect: bool,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct DeviceProfile {
    pub name: &'static str,
    pub vendor_id: u16,
    pub product_id: u16,
    pub web_profile_id: i32,
    pub usage_page: u16,
    pub usage: u16,
    pub interface_number: i32,
    pub is_wireless: bool,
    pub command_set: CommandSet,
    pub capabilities: Capabilities,
}

pub const NJ98_CP_V4: DeviceProfile = DeviceProfile {
    name: "NJ98-CP V4",
    vendor_id: 0x3151,
    product_id: 0x5030,
    web_profile_id: 3496,
    usage_page: 0xffff,
    usage: 2,
    interface_number: 2,
    is_wireless: false,
    command_set: CommandSet::Nj98CpV4,
    capabilities: Capabilities {
        display: true,
        rgb: true,
        macros: true,
        hall_effect: true,
    },
};

pub const NJ98_CP_V4_24G: DeviceProfile = DeviceProfile {
    name: "NJ98-CP V4 2.4G",
    vendor_id: 0x3151,
    product_id: 0x5038,
    web_profile_id: 3496,
    usage_page: 0xffff,
    usage: 2,
    interface_number: 2,
    is_wireless: true,
    command_set: CommandSet::Nj98CpV4,
    capabilities: Capabilities {
        display: true,
        rgb: true,
        macros: true,
        hall_effect: true,
    },
};

pub const SUPPORTED_PROFILES: &[DeviceProfile] = &[NJ98_CP_V4, NJ98_CP_V4_24G];

#[cfg(test)]
mod tests {
    use std::collections::HashSet;

    use super::SUPPORTED_PROFILES;

    #[test]
    fn supported_profiles_have_unique_hardware_identities() {
        let mut hardware = HashSet::new();
        for profile in SUPPORTED_PROFILES {
            assert!(hardware.insert((
                profile.vendor_id,
                profile.product_id,
                profile.usage_page,
                profile.usage,
                profile.interface_number,
            )));
        }
    }
}