1 //! This library provides helper functions to parse cod.
2
3 struct Class {
4 major: u32,
5 minor: u32,
6 }
7
8 impl Class {
new(cod: u32) -> Class9 fn new(cod: u32) -> Class {
10 Class { major: (cod & 0x1f00) >> 8, minor: (cod & 0xff) }
11 }
12 }
13
is_cod_hid_keyboard(cod: u32) -> bool14 pub fn is_cod_hid_keyboard(cod: u32) -> bool {
15 let c = Class::new(cod);
16 c.major == 0x05 && ((c.minor >> 6) & 0x03) == 0x01
17 }
18
is_cod_hid_combo(cod: u32) -> bool19 pub fn is_cod_hid_combo(cod: u32) -> bool {
20 let c = Class::new(cod);
21 c.major == 0x05 && ((c.minor >> 6) & 0x03) == 0x03
22 }
23
24 #[cfg(test)]
25 mod tests {
26 use crate::cod::{is_cod_hid_combo, is_cod_hid_keyboard};
27
28 #[test]
test_cod()29 fn test_cod() {
30 let keyboard_gamepad_cod = 0x0548;
31 let combo_joystick_cod = 0x05c4;
32 let mouse_cod = 0x0580;
33
34 assert_eq!(is_cod_hid_keyboard(keyboard_gamepad_cod), true);
35 assert_eq!(is_cod_hid_combo(keyboard_gamepad_cod), false);
36 assert_eq!(is_cod_hid_keyboard(combo_joystick_cod), false);
37 assert_eq!(is_cod_hid_combo(combo_joystick_cod), true);
38 assert_eq!(is_cod_hid_keyboard(mouse_cod), false);
39 assert_eq!(is_cod_hid_combo(mouse_cod), false);
40 }
41 }
42