// THIS FILE IS GENERATED, DO NOT EDIT //! A wrapper around the [HID Usage Tables (HUT)](https://usb.org/document-library/hid-usage-tables-15). //! //! In this document and unless stated otherwise, a reference to //! - **"HID Section a.b.c"** refers to the [HID Device Class Definition for HID 1.11](https://www.usb.org/document-library/device-class-definition-hid-111) //! - **"HUT Section a.b.c"** refers to the //! [HID Usage Tables (HUT) version 1.5](https://usb.org/document-library/hid-usage-tables-15) //! //! This module is created through code generation from the HID Usage Tables. //! //! # Terminology //! //! See HID Section 5.5: a HID Usage is a 32 bit value comprising of a 16-bit Usage //! Page (MSB) and a 16-bit Usage ID (LSB) so that: //! //! ``` //! # let usage_page: u32 = 0; //! # let usage_id: u32 = 0; //! let usage: u32 = (usage_page << 16) | usage_id; //! ``` //! Note that the HID encoding requires little endian byte order on the wire. //! //! In this module: //! //! - **"Usage Page"** refers to the 16-bit value. Where the Usage Page is converted //! to or from a 32-bit value the Usage Page is in the upper 16 bits of that value and //! the lower 16 bits are ignored or set to zero. //! ``` //! # let usage: u32 = 0; //! let usage_page: u16 = (usage >> 16) as u16 & 0xffff; //! ``` //! - **"Usage ID"** refers to the 16-bit value. Where the Usage ID is converted to //! or from a 32-bit value the Usage is in the lower 16 bits of that value and //! the upper 16 bits are ignored or set to zero. //! ``` //! # let usage: u32 = 0; //! let usage_id: u16 = (usage & 0xffff) as u16; //! ``` //! - **"Usage"** refers to the 32-bit value comprising a Usage Page and a Usage. //! //! # Converting between types //! //! All defined [Usages](Usage) and [UsagePages](UsagePage) implement [AsUsagePage] and (if applicable) [AsUsage] as //! well as the [`From`](From), [`From`](From), [`TryFrom`](TryFrom), and [`TryFrom`](TryFrom) //! conversions so that: //! ``` //! # use hut::*; //! let usage_page_value: u16 = 0x01; // Generic Desktop //! let usage_id_value: u16 = 0x02; // Mouse //! let usage_value: u32 = ((usage_page_value as u32) << 16) | usage_id_value as u32; //! //! // Create a known Usage from a 32-bit value //! let u: Usage = Usage::try_from(usage_value).unwrap(); //! assert!(matches!(u, Usage::GenericDesktop(GenericDesktop::Mouse))); //! //! // Create a known Usage from the Usage Page and Usage ID values //! let u2 = Usage::new_from_page_and_id(usage_page_value, usage_id_value).unwrap(); //! assert_eq!(u, u2); //! //! // Create a known Usage from an individual Usage Page enum item //! let u3 = Usage::from(GenericDesktop::Mouse); //! assert_eq!(u, u3); //! //! // Create a known Usage from an known Usage Page enum item //! let gd_mouse = GenericDesktop::try_from(usage_id_value).unwrap(); //! let u4 = Usage::from(gd_mouse); //! assert_eq!(u, u4); //! //! // Convert to and fro the Usage either via u32 or the AsUsage trait //! let u = GenericDesktop::Mouse; //! assert_eq!(u32::from(&u), usage_value); //! assert_eq!(u.usage_value(), usage_value); //! //! // Extract the 16-bit Usage ID either via u16 or the AsUsage trait //! assert_eq!(u16::from(&u), usage_id_value); //! assert_eq!(u.usage_id_value(), usage_id_value); //! //! // Extract the Usage Page from the Usage enum value //! let up = u.usage_page(); //! assert!(matches!(up, UsagePage::GenericDesktop)); //! let up: UsagePage = UsagePage::from(&u); //! assert!(matches!(up, UsagePage::GenericDesktop)); //! //! // Get the Usage Page numeric value is via the AsUsagePage //! assert_eq!(u16::from(&up), usage_page_value); //! assert_eq!(up.usage_page_value(), usage_page_value); //! ``` //! //! Naming Usages (e.g. [`GenericDesktop::Mouse`]) above works for Defined Usage //! Pages, Generated Usage Pages (see below) need to be destructured via their //! individual elements: //! ``` //! # use hut::*; //! let usage_page_value: u16 = 0x09; // Button //! let usage_id_value: u16 = 8; // Button number 8 //! let usage_value: u32 = ((usage_page_value as u32) << 16) | usage_id_value as u32; //! //! let u = Usage::try_from(usage_value).unwrap(); //! let button = Usage::Button(Button::Button(8)); //! assert!(matches!(Usage::try_from(usage_value).unwrap(), button)); //! // or via from() or into() //! let button: Usage = Button::Button(8).into(); //! assert!(matches!(Usage::try_from(usage_value).unwrap(), button)); //! ``` //! Once a Usage is created, the [AsUsagePage] and [AsUsage] traits and conversion to and from //! [u16] and [u32] work the same as for a Defined Usage Page. //! //! # Names of Usage Pages and Usage IDs //! //! All defined [Usages](Usage) and [UsagePages](UsagePage) implement `name()` to return a string //! representing that page or usage: //! //! ``` //! # use hut::*; //! let up = UsagePage::GenericDesktop; //! assert_eq!(up.name(), "Generic Desktop"); //! let up = UsagePage::SimulationControls; //! assert_eq!(up.name(), "Simulation Controls"); //! //! let usage = GenericDesktop::Mouse; //! assert_eq!(usage.name(), "Mouse"); //! let usage = SimulationControls::CyclicControl; //! assert_eq!(usage.name(), "Cyclic Control"); //! ``` //! //! # Generated Usage Pages //! //! The HUT differ between "Defined" and "Generated" Usage Pages. The former define Usage ID values //! and their meanings, the latter define a Usage ID range, with the actual Usage ID simply //! referring to "nth thing in this usage page". One example for this is the Button Usage Page //! (0x09) where a Usage ID of 3 means "Button 3". //! //! ``` //! # use hut::*; //! let b = Button::Button(3); //! let o = Ordinal::Ordinal(23); //! ``` //! //! Unlike Defined Usage Pages these Generated Usage Pages need to be destructured in `match` //! statements: //! //! ``` //! # use hut::*; //! let b = Button::Button(3); //! match b { //! Button::Button(b) => println!("Button {b}"), //! _ => {}, //! } //! ``` //! //! The following usage pages are Generated: //! - Usage Page 0x9 - [Button] //! - Usage Page 0xA - [Ordinal] //! - Usage Page 0x10 - [Unicode] //! - Usage Page 0x81 - [MonitorEnumerated] //! //! A further special case of this is the [Unicode] usage page which is not in the HUT //! document and was inserted during code generation. //! //! # Vendor Defined Usage Pages (0xFF00 to 0xFFFF) //! //! [Vendor Defined Usage Pages](VendorDefinedPage) and [VendorUsages](VendorDefinedPage::VendorUsage) are not autogenerated and thus //! follow a different approach: the Usage inside the Usage Page is a simple //! numeric usage that needs to be destructured in `match` statements. //! //! ``` //! # use hut::*; //! let v = Usage::VendorDefinedPage { //! vendor_page: VendorPage::try_from(0xff00 as u16).unwrap(), //! usage: VendorDefinedPage::VendorUsage { usage_id: 0x01 }, //! }; //! match v { //! Usage::VendorDefinedPage { //! vendor_page, //! usage, //! } => println!("Vendor Usage ID {usage}"), //! _ => {}, //! } //! ``` //! //! A notable exception is the [Wacom] (`0xFF0D`) which is technically a //! Vendor-defined page but with defined Usages. Converting from a [UsagePage] //! or [Usage] numeric value will produce the correct or [Wacom] Usage, not a [VendorDefinedPage::VendorUsage]. //! //! # Reserved Usage Pages //! //! [Reserved Usage Pages](ReservedUsagePage) and [ReservedUsages](ReservedUsagePage::ReservedUsage) are //! not autogenerated and thus follow a different approach: the Usage inside the Usage Page is a simple //! numeric usage that needs to be destructured in `match` statements. //! //! Unlike the [Vendor Defined Usage Pages](VendorDefinedPage) a [Reserved Usage Page](ReservedPage) may become //! a defined page in a later version of the HUT standard and thus in a future version of this crate. //! A caller must not rely on a Reserved Usage Page or Reserved Usage to remain so. //! //! The following Usage Pages are reserved as of HUT 1.5 (see HUT Section 3, p15): //! - `0x13`, `0x15-0x1F` //! - `0x21-0x3F` //! - `0x42-0x58` //! - `0x5A-0x7F` //! - `0x83-0x83` //! - `0x86-0x8B` //! - `0x8F-0x8F` //! - `0x93-0xF1CF` //! - `0xF1D1-0xFEFF` //! //! # Renames //! //! For technical reasons, spaces, (` `), dashes (`-`), and slashes (`/`) are //! stripped out of Usage Page and Usage names. The string representation via //! the `Display` trait will have the unmodified value. #![allow(clippy::identity_op, clippy::eq_op, clippy::match_single_binding)] #![no_std] #[cfg(feature = "std")] extern crate std; use core::ops::BitOr; #[cfg(feature = "std")] use std::{fmt, format, string::String, string::ToString}; /// Error raised if conversion between HUT elements fails. #[derive(Debug)] pub enum HutError { /// The usage page value is not known. Usage Pages /// may get added in the future and a future version /// of this crate may not raise this error for the same value. UnknownUsagePage { usage_page: u16 }, /// The usage ID value is not known. Usage IDs /// may get added in the future and a future version /// of this crate may not raise this error for the same value. UnknownUsageId { usage_id: u16 }, /// The value given for a [VendorDefinedPage] is outside the allowed range. InvalidVendorPage { vendor_page: u16 }, /// The value given for a [ReservedUsagePage] is outside the allowed range. InvalidReservedPage { reserved_page: u16 }, /// The 32-bit usage value given cannot be resolved. Usages /// may get added in the future and a future version /// of this crate may not raise this error for the same value. UnknownUsage, } impl core::error::Error for HutError {} impl core::fmt::Display for HutError { fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result { match self { HutError::UnknownUsagePage { usage_page } => { write!(fmt, "Unknown Usage Page {}", usage_page) } HutError::UnknownUsageId { usage_id } => write!(fmt, "Unknown Usage ID {}", usage_id), HutError::InvalidVendorPage { vendor_page } => { write!(fmt, "Invalid Vendor Page {}", vendor_page) } HutError::InvalidReservedPage { reserved_page } => { write!(fmt, "Invalid Reserved Page {}", reserved_page) } HutError::UnknownUsage => write!(fmt, "Unknown Usage"), } } } type Result = core::result::Result; /// A trait to return the Usage and Usage ID as numeric value pub trait AsUsage { /// Returns the 32-bit Usage numeric value of this Usage fn usage_value(&self) -> u32; /// Returns the 16-bit Usage Id numeric value of this Usage fn usage_id_value(&self) -> u16; /// Returns this usage as [Usage] fn usage(&self) -> Usage; } /// A trait to return the Usage Page as numeric value pub trait AsUsagePage { /// Returns the 16-bit Usage Page value fn usage_page_value(&self) -> u16; /// Returns the [UsagePage] fn usage_page(&self) -> UsagePage; } /// A HID UsagePage, see HID Section 5.5. This represents the upper 16 bits in the /// 32-bit Usage. Where a [UsagePage] is converted to or from 32 bit, the /// [UsagePage] value are the upper 16 bits only and the lower 16 bits are /// ignored or set to zero. /// ``` /// # use hut::*; /// let usage = Usage::from(GenericDesktop::Mouse); /// let up: UsagePage = UsagePage::from(&usage); /// assert!(matches!(up, UsagePage::GenericDesktop)); /// ``` /// Note: this enum is generated from the HUT specification. #[allow(non_camel_case_types)] #[derive(Debug)] #[non_exhaustive] pub enum UsagePage { /// Usage Page `0x1`: "Generic Desktop", /// see [GenericDesktop]. GenericDesktop, /// Usage Page `0x2`: "Simulation Controls", /// see [SimulationControls]. SimulationControls, /// Usage Page `0x3`: "VR Controls", /// see [VRControls]. VRControls, /// Usage Page `0x4`: "Sport Controls", /// see [SportControls]. SportControls, /// Usage Page `0x5`: "Game Controls", /// see [GameControls]. GameControls, /// Usage Page `0x6`: "Generic Device Controls", /// see [GenericDeviceControls]. GenericDeviceControls, /// Usage Page `0x7`: "Keyboard/Keypad", /// see [KeyboardKeypad]. KeyboardKeypad, /// Usage Page `0x8`: "LED", /// see [LED]. LED, /// Usage Page `0x9`: "Button", /// see [Button]. Button, /// Usage Page `0xA`: "Ordinal", /// see [Ordinal]. Ordinal, /// Usage Page `0xB`: "Telephony Device", /// see [TelephonyDevice]. TelephonyDevice, /// Usage Page `0xC`: "Consumer", /// see [Consumer]. Consumer, /// Usage Page `0xD`: "Digitizers", /// see [Digitizers]. Digitizers, /// Usage Page `0xE`: "Haptics", /// see [Haptics]. Haptics, /// Usage Page `0xF`: "Physical Input Device", /// see [PhysicalInputDevice]. PhysicalInputDevice, /// Usage Page `0x10`: "Unicode", /// see [Unicode]. Unicode, /// Usage Page `0x11`: "SoC", /// see [SoC]. SoC, /// Usage Page `0x12`: "Eye and Head Trackers", /// see [EyeandHeadTrackers]. EyeandHeadTrackers, /// Usage Page `0x14`: "Auxiliary Display", /// see [AuxiliaryDisplay]. AuxiliaryDisplay, /// Usage Page `0x20`: "Sensors", /// see [Sensors]. Sensors, /// Usage Page `0x40`: "Medical Instrument", /// see [MedicalInstrument]. MedicalInstrument, /// Usage Page `0x41`: "Braille Display", /// see [BrailleDisplay]. BrailleDisplay, /// Usage Page `0x59`: "Lighting And Illumination", /// see [LightingAndIllumination]. LightingAndIllumination, /// Usage Page `0x80`: "Monitor", /// see [Monitor]. Monitor, /// Usage Page `0x81`: "Monitor Enumerated", /// see [MonitorEnumerated]. MonitorEnumerated, /// Usage Page `0x82`: "VESA Virtual Controls", /// see [VESAVirtualControls]. VESAVirtualControls, /// Usage Page `0x84`: "Power", /// see [Power]. Power, /// Usage Page `0x85`: "Battery System", /// see [BatterySystem]. BatterySystem, /// Usage Page `0x8C`: "Barcode Scanner", /// see [BarcodeScanner]. BarcodeScanner, /// Usage Page `0x8D`: "Scales", /// see [Scales]. Scales, /// Usage Page `0x8E`: "Magnetic Stripe Reader", /// see [MagneticStripeReader]. MagneticStripeReader, /// Usage Page `0x90`: "Camera Control", /// see [CameraControl]. CameraControl, /// Usage Page `0x91`: "Arcade", /// see [Arcade]. Arcade, /// Usage Page `0xF1D0`: "FIDO Alliance", /// see [FIDOAlliance]. FIDOAlliance, /// Usage Page `0xFF0D`: "Wacom", /// see [Wacom]. Wacom, /// The Reserved Usage Pages (range: various). See [ReservedUsagePage]. ReservedUsagePage(ReservedPage), /// The Vendor Defined Pages, range `0xFF00 - 0xFFFF`. See [VendorDefinedPage]. VendorDefinedPage(VendorPage), } /// Represents a Reserved Page number value of in the current range of /// reserved values. See [ReservedUsagePage]. /// /// ``` /// # use hut::*; /// // 0x3f is currently reserved /// let vp: ReservedPage = ReservedPage::try_from(0x3f as u16).unwrap(); /// let vp: ReservedPage = ReservedPage::try_from(0x003f1234 as u32).unwrap(); /// /// let usage = Usage::try_from(0x003f1234).unwrap(); /// let up = UsagePage::from(&usage); /// assert!(matches!(up, UsagePage::ReservedUsagePage(_))); /// ``` #[derive(Debug, Clone, Copy, PartialEq, PartialOrd)] pub struct ReservedPage(u16); impl From<&ReservedPage> for ReservedPage { fn from(v: &ReservedPage) -> ReservedPage { ReservedPage(v.0) } } impl From<&ReservedPage> for u16 { fn from(v: &ReservedPage) -> u16 { v.0 } } impl From for u16 { fn from(v: ReservedPage) -> u16 { u16::from(&v) } } impl From<&ReservedPage> for u32 { fn from(v: &ReservedPage) -> u32 { (v.0 as u32) << 16 } } impl From for u32 { fn from(v: ReservedPage) -> u32 { u32::from(&v) } } impl TryFrom for ReservedPage { type Error = HutError; fn try_from(v: u16) -> Result { match v { p @ 0x13 => Ok(ReservedPage(p)), p @ 0x15..=0x1F => Ok(ReservedPage(p)), p @ 0x21..=0x3F => Ok(ReservedPage(p)), p @ 0x42..=0x58 => Ok(ReservedPage(p)), p @ 0x5A..=0x7F => Ok(ReservedPage(p)), p @ 0x83..=0x83 => Ok(ReservedPage(p)), p @ 0x86..=0x8B => Ok(ReservedPage(p)), p @ 0x8F..=0x8F => Ok(ReservedPage(p)), p @ 0x93..=0xF1CF => Ok(ReservedPage(p)), p @ 0xF1D1..=0xFEFF => Ok(ReservedPage(p)), n => Err(HutError::InvalidReservedPage { reserved_page: n }), } } } impl TryFrom for ReservedPage { type Error = HutError; fn try_from(v: u32) -> Result { ReservedPage::try_from((v >> 16) as u16) } } /// Represents a Vendor Defined Page number value of in the range /// `0xFF00..=0xFFFF`. See [VendorDefinedPage]. /// /// ``` /// # use hut::*; /// // The value has to be 0xff00..=0xffff /// let vp: VendorPage = VendorPage::try_from(0xff00 as u16).unwrap(); /// let vp: VendorPage = VendorPage::try_from(0xff001234 as u32).unwrap(); /// /// let usage = Usage::try_from(0xff001234).unwrap(); /// let up = UsagePage::from(&usage); /// assert!(matches!(up, UsagePage::VendorDefinedPage(_))); /// ``` #[derive(Debug, Clone, Copy, PartialEq, PartialOrd)] pub struct VendorPage(u16); impl From<&VendorPage> for VendorPage { fn from(v: &VendorPage) -> VendorPage { VendorPage(v.0) } } impl From<&VendorPage> for u16 { fn from(v: &VendorPage) -> u16 { v.0 } } impl From for u16 { fn from(v: VendorPage) -> u16 { u16::from(&v) } } impl From<&VendorPage> for u32 { fn from(v: &VendorPage) -> u32 { (v.0 as u32) << 16 } } impl From for u32 { fn from(v: VendorPage) -> u32 { u32::from(&v) } } impl TryFrom for VendorPage { type Error = HutError; fn try_from(v: u16) -> Result { match v { p @ 0xff00..=0xffff => Ok(VendorPage(p)), n => Err(HutError::InvalidVendorPage { vendor_page: n }), } } } impl TryFrom for VendorPage { type Error = HutError; fn try_from(v: u32) -> Result { VendorPage::try_from((v >> 16) as u16) } } impl UsagePage { /// Returns the Usage Page for the given Usage Page value. This is the /// 16-bit Usage Page value only, not the full 32-bit Usage. /// ``` /// # use hut::*; /// let usage_value: u16 = 0x1; // GenericDesktop /// let usage_page = UsagePage::from_usage_page_value(usage_value).unwrap(); /// assert!(matches!(UsagePage::GenericDesktop, usage_page)); /// ``` pub fn from_usage_page_value(usage_page: u16) -> Result { UsagePage::try_from(usage_page) } /// Returns the Usage Page for the given Usage numeric value. The Usage Page /// must be in the upper 16 bits of the `usage` value and the lower 16 bits /// are ignored. /// ``` /// # use hut::*; /// let usage_value: u32 = (0x1 << 16) | 0x2; /// let usage = UsagePage::from_usage_value(usage_value).unwrap(); /// assert!(matches!(Usage::from(GenericDesktop::Mouse), usage)); /// ``` pub fn from_usage_value(usage: u32) -> Result { let up: u16 = (usage >> 16) as u16; UsagePage::try_from(up) } /// Returns the 32-bit Usage that is this Usage Page combined with /// the 16 bits Usage ID. /// /// ``` /// # use hut::*; /// let up = UsagePage::GenericDesktop; /// let usage_id_value: u16 = 0x02; // Mouse /// /// let usage = up.to_usage_from_value(usage_id_value).unwrap(); /// assert!(matches!(Usage::from(GenericDesktop::Mouse), usage)); /// ``` pub fn to_usage_from_value(&self, usage: u16) -> Result { let up: u32 = (self.usage_page_value() as u32) << 16; let u: u32 = usage as u32; Usage::try_from(up | u) } /// Return a printable name for this usage page /// ``` /// # use hut::*; /// let up = UsagePage::GenericDesktop; /// assert_eq!(up.name(), "Generic Desktop"); /// ``` #[cfg(feature = "std")] pub fn name(&self) -> String { match self { UsagePage::GenericDesktop => "Generic Desktop".into(), UsagePage::SimulationControls => "Simulation Controls".into(), UsagePage::VRControls => "VR Controls".into(), UsagePage::SportControls => "Sport Controls".into(), UsagePage::GameControls => "Game Controls".into(), UsagePage::GenericDeviceControls => "Generic Device Controls".into(), UsagePage::KeyboardKeypad => "Keyboard/Keypad".into(), UsagePage::LED => "LED".into(), UsagePage::Button => "Button".into(), UsagePage::Ordinal => "Ordinal".into(), UsagePage::TelephonyDevice => "Telephony Device".into(), UsagePage::Consumer => "Consumer".into(), UsagePage::Digitizers => "Digitizers".into(), UsagePage::Haptics => "Haptics".into(), UsagePage::PhysicalInputDevice => "Physical Input Device".into(), UsagePage::Unicode => "Unicode".into(), UsagePage::SoC => "SoC".into(), UsagePage::EyeandHeadTrackers => "Eye and Head Trackers".into(), UsagePage::AuxiliaryDisplay => "Auxiliary Display".into(), UsagePage::Sensors => "Sensors".into(), UsagePage::MedicalInstrument => "Medical Instrument".into(), UsagePage::BrailleDisplay => "Braille Display".into(), UsagePage::LightingAndIllumination => "Lighting And Illumination".into(), UsagePage::Monitor => "Monitor".into(), UsagePage::MonitorEnumerated => "Monitor Enumerated".into(), UsagePage::VESAVirtualControls => "VESA Virtual Controls".into(), UsagePage::Power => "Power".into(), UsagePage::BatterySystem => "Battery System".into(), UsagePage::BarcodeScanner => "Barcode Scanner".into(), UsagePage::Scales => "Scales".into(), UsagePage::MagneticStripeReader => "Magnetic Stripe Reader".into(), UsagePage::CameraControl => "Camera Control".into(), UsagePage::Arcade => "Arcade".into(), UsagePage::FIDOAlliance => "FIDO Alliance".into(), UsagePage::Wacom => "Wacom".into(), UsagePage::ReservedUsagePage(reserved_page) => { format!("Reserved Usage Page {:04X}", u16::from(reserved_page)) } UsagePage::VendorDefinedPage(vendor_page) => { format!("Vendor Defined Page {:04X}", u16::from(vendor_page)) } } } } impl AsUsagePage for UsagePage { /// Returns the 16 bit Usage Page value of this Usage Page /// ``` /// # use hut::*; /// let usage_value: u16 = 0x1; // GenericDesktop /// let usage_page = UsagePage::from_usage_page_value(usage_value).unwrap(); /// assert_eq!(usage_page.usage_page_value(), 0x1); /// ``` fn usage_page_value(&self) -> u16 { u16::from(self) } /// Returns our current [UsagePage] /// ``` /// # use hut::*; /// let usage_value: u16 = 0x1; // GenericDesktop /// let usage_page = UsagePage::from_usage_page_value(usage_value).unwrap(); /// assert!(matches!(usage_page.usage_page(), UsagePage::GenericDesktop)); /// ``` /// There is seldom a need to invoke this function, it is merely /// implemented to meet the [AsUsagePage] requirements. fn usage_page(&self) -> UsagePage { UsagePage::try_from(u16::from(self)).unwrap() } } /// *Usage Page `0x1`: "Generic Desktop"* /// /// **This enum is autogenerated from the HID Usage Tables**. /// ``` /// # use hut::*; /// let u1 = Usage::GenericDesktop(GenericDesktop::Mouse); /// let u2 = Usage::new_from_page_and_id(0x1, 0x2).unwrap(); /// let u3 = Usage::from(GenericDesktop::Mouse); /// let u4: Usage = GenericDesktop::Mouse.into(); /// assert_eq!(u1, u2); /// assert_eq!(u1, u3); /// assert_eq!(u1, u4); /// /// assert!(matches!(u1.usage_page(), UsagePage::GenericDesktop)); /// assert_eq!(0x1, u1.usage_page_value()); /// assert_eq!(0x2, u1.usage_id_value()); /// assert_eq!((0x1 << 16) | 0x2, u1.usage_value()); /// assert_eq!("Mouse", u1.name()); /// ``` /// #[allow(non_camel_case_types)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[non_exhaustive] #[repr(u16)] pub enum GenericDesktop { /// Usage ID `0x1`: "Pointer" Pointer = 0x1, /// Usage ID `0x2`: "Mouse" Mouse = 0x2, /// Usage ID `0x4`: "Joystick" Joystick = 0x4, /// Usage ID `0x5`: "Gamepad" Gamepad = 0x5, /// Usage ID `0x6`: "Keyboard" Keyboard = 0x6, /// Usage ID `0x7`: "Keypad" Keypad = 0x7, /// Usage ID `0x8`: "Multi-axis Controller" MultiaxisController = 0x8, /// Usage ID `0x9`: "Tablet PC System Controls" TabletPCSystemControls = 0x9, /// Usage ID `0xA`: "Water Cooling Device" WaterCoolingDevice = 0xA, /// Usage ID `0xB`: "Computer Chassis Device" ComputerChassisDevice = 0xB, /// Usage ID `0xC`: "Wireless Radio Controls" WirelessRadioControls = 0xC, /// Usage ID `0xD`: "Portable Device Control" PortableDeviceControl = 0xD, /// Usage ID `0xE`: "System Multi-Axis Controller" SystemMultiAxisController = 0xE, /// Usage ID `0xF`: "Spatial Controller" SpatialController = 0xF, /// Usage ID `0x10`: "Assistive Control" AssistiveControl = 0x10, /// Usage ID `0x11`: "Device Dock" DeviceDock = 0x11, /// Usage ID `0x12`: "Dockable Device" DockableDevice = 0x12, /// Usage ID `0x13`: "Call State Management Control" CallStateManagementControl = 0x13, /// Usage ID `0x30`: "X" X = 0x30, /// Usage ID `0x31`: "Y" Y = 0x31, /// Usage ID `0x32`: "Z" Z = 0x32, /// Usage ID `0x33`: "Rx" Rx = 0x33, /// Usage ID `0x34`: "Ry" Ry = 0x34, /// Usage ID `0x35`: "Rz" Rz = 0x35, /// Usage ID `0x36`: "Slider" Slider = 0x36, /// Usage ID `0x37`: "Dial" Dial = 0x37, /// Usage ID `0x38`: "Wheel" Wheel = 0x38, /// Usage ID `0x39`: "Hat Switch" HatSwitch = 0x39, /// Usage ID `0x3A`: "Counted Buffer" CountedBuffer = 0x3A, /// Usage ID `0x3B`: "Byte Count" ByteCount = 0x3B, /// Usage ID `0x3C`: "Motion Wakeup" MotionWakeup = 0x3C, /// Usage ID `0x3D`: "Start" Start = 0x3D, /// Usage ID `0x3E`: "Select" Select = 0x3E, /// Usage ID `0x40`: "Vx" Vx = 0x40, /// Usage ID `0x41`: "Vy" Vy = 0x41, /// Usage ID `0x42`: "Vz" Vz = 0x42, /// Usage ID `0x43`: "Vbrx" Vbrx = 0x43, /// Usage ID `0x44`: "Vbry" Vbry = 0x44, /// Usage ID `0x45`: "Vbrz" Vbrz = 0x45, /// Usage ID `0x46`: "Vno" Vno = 0x46, /// Usage ID `0x47`: "Feature Notification" FeatureNotification = 0x47, /// Usage ID `0x48`: "Resolution Multiplier" ResolutionMultiplier = 0x48, /// Usage ID `0x49`: "Qx" Qx = 0x49, /// Usage ID `0x4A`: "Qy" Qy = 0x4A, /// Usage ID `0x4B`: "Qz" Qz = 0x4B, /// Usage ID `0x4C`: "Qw" Qw = 0x4C, /// Usage ID `0x80`: "System Control" SystemControl = 0x80, /// Usage ID `0x81`: "System Power Down" SystemPowerDown = 0x81, /// Usage ID `0x82`: "System Sleep" SystemSleep = 0x82, /// Usage ID `0x83`: "System Wake Up" SystemWakeUp = 0x83, /// Usage ID `0x84`: "System Context Menu" SystemContextMenu = 0x84, /// Usage ID `0x85`: "System Main Menu" SystemMainMenu = 0x85, /// Usage ID `0x86`: "System App Menu" SystemAppMenu = 0x86, /// Usage ID `0x87`: "System Menu Help" SystemMenuHelp = 0x87, /// Usage ID `0x88`: "System Menu Exit" SystemMenuExit = 0x88, /// Usage ID `0x89`: "System Menu Select" SystemMenuSelect = 0x89, /// Usage ID `0x8A`: "System Menu Right" SystemMenuRight = 0x8A, /// Usage ID `0x8B`: "System Menu Left" SystemMenuLeft = 0x8B, /// Usage ID `0x8C`: "System Menu Up" SystemMenuUp = 0x8C, /// Usage ID `0x8D`: "System Menu Down" SystemMenuDown = 0x8D, /// Usage ID `0x8E`: "System Cold Restart" SystemColdRestart = 0x8E, /// Usage ID `0x8F`: "System Warm Restart" SystemWarmRestart = 0x8F, /// Usage ID `0x90`: "D-pad Up" DpadUp = 0x90, /// Usage ID `0x91`: "D-pad Down" DpadDown = 0x91, /// Usage ID `0x92`: "D-pad Right" DpadRight = 0x92, /// Usage ID `0x93`: "D-pad Left" DpadLeft = 0x93, /// Usage ID `0x94`: "Index Trigger" IndexTrigger = 0x94, /// Usage ID `0x95`: "Palm Trigger" PalmTrigger = 0x95, /// Usage ID `0x96`: "Thumbstick" Thumbstick = 0x96, /// Usage ID `0x97`: "System Function Shift" SystemFunctionShift = 0x97, /// Usage ID `0x98`: "System Function Shift Lock" SystemFunctionShiftLock = 0x98, /// Usage ID `0x99`: "System Function Shift Lock Indicator" SystemFunctionShiftLockIndicator = 0x99, /// Usage ID `0x9A`: "System Dismiss Notification" SystemDismissNotification = 0x9A, /// Usage ID `0x9B`: "System Do Not Disturb" SystemDoNotDisturb = 0x9B, /// Usage ID `0xA0`: "System Dock" SystemDock = 0xA0, /// Usage ID `0xA1`: "System Undock" SystemUndock = 0xA1, /// Usage ID `0xA2`: "System Setup" SystemSetup = 0xA2, /// Usage ID `0xA3`: "System Break" SystemBreak = 0xA3, /// Usage ID `0xA4`: "System Debugger Break" SystemDebuggerBreak = 0xA4, /// Usage ID `0xA5`: "Application Break" ApplicationBreak = 0xA5, /// Usage ID `0xA6`: "Application Debugger Break" ApplicationDebuggerBreak = 0xA6, /// Usage ID `0xA7`: "System Speaker Mute" SystemSpeakerMute = 0xA7, /// Usage ID `0xA8`: "System Hibernate" SystemHibernate = 0xA8, /// Usage ID `0xA9`: "System Microphone Mute" SystemMicrophoneMute = 0xA9, /// Usage ID `0xAA`: "System Accessibility Binding" SystemAccessibilityBinding = 0xAA, /// Usage ID `0xB0`: "System Display Invert" SystemDisplayInvert = 0xB0, /// Usage ID `0xB1`: "System Display Internal" SystemDisplayInternal = 0xB1, /// Usage ID `0xB2`: "System Display External" SystemDisplayExternal = 0xB2, /// Usage ID `0xB3`: "System Display Both" SystemDisplayBoth = 0xB3, /// Usage ID `0xB4`: "System Display Dual" SystemDisplayDual = 0xB4, /// Usage ID `0xB5`: "System Display Toggle Int/Ext Mode" SystemDisplayToggleIntExtMode = 0xB5, /// Usage ID `0xB6`: "System Display Swap Primary/Secondary" SystemDisplaySwapPrimarySecondary = 0xB6, /// Usage ID `0xB7`: "System Display Toggle LCD Autoscale" SystemDisplayToggleLCDAutoscale = 0xB7, /// Usage ID `0xC0`: "Sensor Zone" SensorZone = 0xC0, /// Usage ID `0xC1`: "RPM" RPM = 0xC1, /// Usage ID `0xC2`: "Coolant Level" CoolantLevel = 0xC2, /// Usage ID `0xC3`: "Coolant Critical Level" CoolantCriticalLevel = 0xC3, /// Usage ID `0xC4`: "Coolant Pump" CoolantPump = 0xC4, /// Usage ID `0xC5`: "Chassis Enclosure" ChassisEnclosure = 0xC5, /// Usage ID `0xC6`: "Wireless Radio Button" WirelessRadioButton = 0xC6, /// Usage ID `0xC7`: "Wireless Radio LED" WirelessRadioLED = 0xC7, /// Usage ID `0xC8`: "Wireless Radio Slider Switch" WirelessRadioSliderSwitch = 0xC8, /// Usage ID `0xC9`: "System Display Rotation Lock Button" SystemDisplayRotationLockButton = 0xC9, /// Usage ID `0xCA`: "System Display Rotation Lock Slider Switch" SystemDisplayRotationLockSliderSwitch = 0xCA, /// Usage ID `0xCB`: "Control Enable" ControlEnable = 0xCB, /// Usage ID `0xD0`: "Dockable Device Unique ID" DockableDeviceUniqueID = 0xD0, /// Usage ID `0xD1`: "Dockable Device Vendor ID" DockableDeviceVendorID = 0xD1, /// Usage ID `0xD2`: "Dockable Device Primary Usage Page" DockableDevicePrimaryUsagePage = 0xD2, /// Usage ID `0xD3`: "Dockable Device Primary Usage ID" DockableDevicePrimaryUsageID = 0xD3, /// Usage ID `0xD4`: "Dockable Device Docking State" DockableDeviceDockingState = 0xD4, /// Usage ID `0xD5`: "Dockable Device Display Occlusion" DockableDeviceDisplayOcclusion = 0xD5, /// Usage ID `0xD6`: "Dockable Device Object Type" DockableDeviceObjectType = 0xD6, /// Usage ID `0xE0`: "Call Active LED" CallActiveLED = 0xE0, /// Usage ID `0xE1`: "Call Mute Toggle" CallMuteToggle = 0xE1, /// Usage ID `0xE2`: "Call Mute LED" CallMuteLED = 0xE2, } impl GenericDesktop { #[cfg(feature = "std")] pub fn name(&self) -> String { match self { GenericDesktop::Pointer => "Pointer", GenericDesktop::Mouse => "Mouse", GenericDesktop::Joystick => "Joystick", GenericDesktop::Gamepad => "Gamepad", GenericDesktop::Keyboard => "Keyboard", GenericDesktop::Keypad => "Keypad", GenericDesktop::MultiaxisController => "Multi-axis Controller", GenericDesktop::TabletPCSystemControls => "Tablet PC System Controls", GenericDesktop::WaterCoolingDevice => "Water Cooling Device", GenericDesktop::ComputerChassisDevice => "Computer Chassis Device", GenericDesktop::WirelessRadioControls => "Wireless Radio Controls", GenericDesktop::PortableDeviceControl => "Portable Device Control", GenericDesktop::SystemMultiAxisController => "System Multi-Axis Controller", GenericDesktop::SpatialController => "Spatial Controller", GenericDesktop::AssistiveControl => "Assistive Control", GenericDesktop::DeviceDock => "Device Dock", GenericDesktop::DockableDevice => "Dockable Device", GenericDesktop::CallStateManagementControl => "Call State Management Control", GenericDesktop::X => "X", GenericDesktop::Y => "Y", GenericDesktop::Z => "Z", GenericDesktop::Rx => "Rx", GenericDesktop::Ry => "Ry", GenericDesktop::Rz => "Rz", GenericDesktop::Slider => "Slider", GenericDesktop::Dial => "Dial", GenericDesktop::Wheel => "Wheel", GenericDesktop::HatSwitch => "Hat Switch", GenericDesktop::CountedBuffer => "Counted Buffer", GenericDesktop::ByteCount => "Byte Count", GenericDesktop::MotionWakeup => "Motion Wakeup", GenericDesktop::Start => "Start", GenericDesktop::Select => "Select", GenericDesktop::Vx => "Vx", GenericDesktop::Vy => "Vy", GenericDesktop::Vz => "Vz", GenericDesktop::Vbrx => "Vbrx", GenericDesktop::Vbry => "Vbry", GenericDesktop::Vbrz => "Vbrz", GenericDesktop::Vno => "Vno", GenericDesktop::FeatureNotification => "Feature Notification", GenericDesktop::ResolutionMultiplier => "Resolution Multiplier", GenericDesktop::Qx => "Qx", GenericDesktop::Qy => "Qy", GenericDesktop::Qz => "Qz", GenericDesktop::Qw => "Qw", GenericDesktop::SystemControl => "System Control", GenericDesktop::SystemPowerDown => "System Power Down", GenericDesktop::SystemSleep => "System Sleep", GenericDesktop::SystemWakeUp => "System Wake Up", GenericDesktop::SystemContextMenu => "System Context Menu", GenericDesktop::SystemMainMenu => "System Main Menu", GenericDesktop::SystemAppMenu => "System App Menu", GenericDesktop::SystemMenuHelp => "System Menu Help", GenericDesktop::SystemMenuExit => "System Menu Exit", GenericDesktop::SystemMenuSelect => "System Menu Select", GenericDesktop::SystemMenuRight => "System Menu Right", GenericDesktop::SystemMenuLeft => "System Menu Left", GenericDesktop::SystemMenuUp => "System Menu Up", GenericDesktop::SystemMenuDown => "System Menu Down", GenericDesktop::SystemColdRestart => "System Cold Restart", GenericDesktop::SystemWarmRestart => "System Warm Restart", GenericDesktop::DpadUp => "D-pad Up", GenericDesktop::DpadDown => "D-pad Down", GenericDesktop::DpadRight => "D-pad Right", GenericDesktop::DpadLeft => "D-pad Left", GenericDesktop::IndexTrigger => "Index Trigger", GenericDesktop::PalmTrigger => "Palm Trigger", GenericDesktop::Thumbstick => "Thumbstick", GenericDesktop::SystemFunctionShift => "System Function Shift", GenericDesktop::SystemFunctionShiftLock => "System Function Shift Lock", GenericDesktop::SystemFunctionShiftLockIndicator => { "System Function Shift Lock Indicator" } GenericDesktop::SystemDismissNotification => "System Dismiss Notification", GenericDesktop::SystemDoNotDisturb => "System Do Not Disturb", GenericDesktop::SystemDock => "System Dock", GenericDesktop::SystemUndock => "System Undock", GenericDesktop::SystemSetup => "System Setup", GenericDesktop::SystemBreak => "System Break", GenericDesktop::SystemDebuggerBreak => "System Debugger Break", GenericDesktop::ApplicationBreak => "Application Break", GenericDesktop::ApplicationDebuggerBreak => "Application Debugger Break", GenericDesktop::SystemSpeakerMute => "System Speaker Mute", GenericDesktop::SystemHibernate => "System Hibernate", GenericDesktop::SystemMicrophoneMute => "System Microphone Mute", GenericDesktop::SystemAccessibilityBinding => "System Accessibility Binding", GenericDesktop::SystemDisplayInvert => "System Display Invert", GenericDesktop::SystemDisplayInternal => "System Display Internal", GenericDesktop::SystemDisplayExternal => "System Display External", GenericDesktop::SystemDisplayBoth => "System Display Both", GenericDesktop::SystemDisplayDual => "System Display Dual", GenericDesktop::SystemDisplayToggleIntExtMode => "System Display Toggle Int/Ext Mode", GenericDesktop::SystemDisplaySwapPrimarySecondary => { "System Display Swap Primary/Secondary" } GenericDesktop::SystemDisplayToggleLCDAutoscale => { "System Display Toggle LCD Autoscale" } GenericDesktop::SensorZone => "Sensor Zone", GenericDesktop::RPM => "RPM", GenericDesktop::CoolantLevel => "Coolant Level", GenericDesktop::CoolantCriticalLevel => "Coolant Critical Level", GenericDesktop::CoolantPump => "Coolant Pump", GenericDesktop::ChassisEnclosure => "Chassis Enclosure", GenericDesktop::WirelessRadioButton => "Wireless Radio Button", GenericDesktop::WirelessRadioLED => "Wireless Radio LED", GenericDesktop::WirelessRadioSliderSwitch => "Wireless Radio Slider Switch", GenericDesktop::SystemDisplayRotationLockButton => { "System Display Rotation Lock Button" } GenericDesktop::SystemDisplayRotationLockSliderSwitch => { "System Display Rotation Lock Slider Switch" } GenericDesktop::ControlEnable => "Control Enable", GenericDesktop::DockableDeviceUniqueID => "Dockable Device Unique ID", GenericDesktop::DockableDeviceVendorID => "Dockable Device Vendor ID", GenericDesktop::DockableDevicePrimaryUsagePage => "Dockable Device Primary Usage Page", GenericDesktop::DockableDevicePrimaryUsageID => "Dockable Device Primary Usage ID", GenericDesktop::DockableDeviceDockingState => "Dockable Device Docking State", GenericDesktop::DockableDeviceDisplayOcclusion => "Dockable Device Display Occlusion", GenericDesktop::DockableDeviceObjectType => "Dockable Device Object Type", GenericDesktop::CallActiveLED => "Call Active LED", GenericDesktop::CallMuteToggle => "Call Mute Toggle", GenericDesktop::CallMuteLED => "Call Mute LED", } .into() } } #[cfg(feature = "std")] impl fmt::Display for GenericDesktop { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name()) } } impl AsUsage for GenericDesktop { /// Returns the 32 bit Usage value of this Usage fn usage_value(&self) -> u32 { u32::from(self) } /// Returns the 16 bit Usage ID value of this Usage fn usage_id_value(&self) -> u16 { u16::from(self) } /// Returns this usage as [Usage::GenericDesktop(self)](Usage::GenericDesktop) /// This is a convenience function to avoid having /// to implement `From` for every used type in the caller. /// /// ``` /// # use hut::*; /// let gd_x = GenericDesktop::X; /// let usage = Usage::from(GenericDesktop::X); /// assert!(matches!(gd_x.usage(), usage)); /// ``` fn usage(&self) -> Usage { Usage::from(self) } } impl AsUsagePage for GenericDesktop { /// Returns the 16 bit value of this UsagePage /// /// This value is `0x1` for [GenericDesktop] fn usage_page_value(&self) -> u16 { let up = UsagePage::from(self); u16::from(up) } /// Returns [UsagePage::GenericDesktop]] fn usage_page(&self) -> UsagePage { UsagePage::from(self) } } impl From<&GenericDesktop> for u16 { fn from(genericdesktop: &GenericDesktop) -> u16 { *genericdesktop as u16 } } impl From for u16 { /// Returns the 16bit value of this usage. This is identical /// to [GenericDesktop::usage_page_value()]. fn from(genericdesktop: GenericDesktop) -> u16 { u16::from(&genericdesktop) } } impl From<&GenericDesktop> for u32 { /// Returns the 32 bit value of this usage. This is identical /// to [GenericDesktop::usage_value()]. fn from(genericdesktop: &GenericDesktop) -> u32 { let up = UsagePage::from(genericdesktop); let up = (u16::from(&up) as u32) << 16; let id = u16::from(genericdesktop) as u32; up | id } } impl From<&GenericDesktop> for UsagePage { /// Always returns [UsagePage::GenericDesktop] and is /// identical to [GenericDesktop::usage_page()]. fn from(_: &GenericDesktop) -> UsagePage { UsagePage::GenericDesktop } } impl From for UsagePage { /// Always returns [UsagePage::GenericDesktop] and is /// identical to [GenericDesktop::usage_page()]. fn from(_: GenericDesktop) -> UsagePage { UsagePage::GenericDesktop } } impl From<&GenericDesktop> for Usage { fn from(genericdesktop: &GenericDesktop) -> Usage { Usage::try_from(u32::from(genericdesktop)).unwrap() } } impl From for Usage { fn from(genericdesktop: GenericDesktop) -> Usage { Usage::from(&genericdesktop) } } impl TryFrom for GenericDesktop { type Error = HutError; fn try_from(usage_id: u16) -> Result { match usage_id { 1 => Ok(GenericDesktop::Pointer), 2 => Ok(GenericDesktop::Mouse), 4 => Ok(GenericDesktop::Joystick), 5 => Ok(GenericDesktop::Gamepad), 6 => Ok(GenericDesktop::Keyboard), 7 => Ok(GenericDesktop::Keypad), 8 => Ok(GenericDesktop::MultiaxisController), 9 => Ok(GenericDesktop::TabletPCSystemControls), 10 => Ok(GenericDesktop::WaterCoolingDevice), 11 => Ok(GenericDesktop::ComputerChassisDevice), 12 => Ok(GenericDesktop::WirelessRadioControls), 13 => Ok(GenericDesktop::PortableDeviceControl), 14 => Ok(GenericDesktop::SystemMultiAxisController), 15 => Ok(GenericDesktop::SpatialController), 16 => Ok(GenericDesktop::AssistiveControl), 17 => Ok(GenericDesktop::DeviceDock), 18 => Ok(GenericDesktop::DockableDevice), 19 => Ok(GenericDesktop::CallStateManagementControl), 48 => Ok(GenericDesktop::X), 49 => Ok(GenericDesktop::Y), 50 => Ok(GenericDesktop::Z), 51 => Ok(GenericDesktop::Rx), 52 => Ok(GenericDesktop::Ry), 53 => Ok(GenericDesktop::Rz), 54 => Ok(GenericDesktop::Slider), 55 => Ok(GenericDesktop::Dial), 56 => Ok(GenericDesktop::Wheel), 57 => Ok(GenericDesktop::HatSwitch), 58 => Ok(GenericDesktop::CountedBuffer), 59 => Ok(GenericDesktop::ByteCount), 60 => Ok(GenericDesktop::MotionWakeup), 61 => Ok(GenericDesktop::Start), 62 => Ok(GenericDesktop::Select), 64 => Ok(GenericDesktop::Vx), 65 => Ok(GenericDesktop::Vy), 66 => Ok(GenericDesktop::Vz), 67 => Ok(GenericDesktop::Vbrx), 68 => Ok(GenericDesktop::Vbry), 69 => Ok(GenericDesktop::Vbrz), 70 => Ok(GenericDesktop::Vno), 71 => Ok(GenericDesktop::FeatureNotification), 72 => Ok(GenericDesktop::ResolutionMultiplier), 73 => Ok(GenericDesktop::Qx), 74 => Ok(GenericDesktop::Qy), 75 => Ok(GenericDesktop::Qz), 76 => Ok(GenericDesktop::Qw), 128 => Ok(GenericDesktop::SystemControl), 129 => Ok(GenericDesktop::SystemPowerDown), 130 => Ok(GenericDesktop::SystemSleep), 131 => Ok(GenericDesktop::SystemWakeUp), 132 => Ok(GenericDesktop::SystemContextMenu), 133 => Ok(GenericDesktop::SystemMainMenu), 134 => Ok(GenericDesktop::SystemAppMenu), 135 => Ok(GenericDesktop::SystemMenuHelp), 136 => Ok(GenericDesktop::SystemMenuExit), 137 => Ok(GenericDesktop::SystemMenuSelect), 138 => Ok(GenericDesktop::SystemMenuRight), 139 => Ok(GenericDesktop::SystemMenuLeft), 140 => Ok(GenericDesktop::SystemMenuUp), 141 => Ok(GenericDesktop::SystemMenuDown), 142 => Ok(GenericDesktop::SystemColdRestart), 143 => Ok(GenericDesktop::SystemWarmRestart), 144 => Ok(GenericDesktop::DpadUp), 145 => Ok(GenericDesktop::DpadDown), 146 => Ok(GenericDesktop::DpadRight), 147 => Ok(GenericDesktop::DpadLeft), 148 => Ok(GenericDesktop::IndexTrigger), 149 => Ok(GenericDesktop::PalmTrigger), 150 => Ok(GenericDesktop::Thumbstick), 151 => Ok(GenericDesktop::SystemFunctionShift), 152 => Ok(GenericDesktop::SystemFunctionShiftLock), 153 => Ok(GenericDesktop::SystemFunctionShiftLockIndicator), 154 => Ok(GenericDesktop::SystemDismissNotification), 155 => Ok(GenericDesktop::SystemDoNotDisturb), 160 => Ok(GenericDesktop::SystemDock), 161 => Ok(GenericDesktop::SystemUndock), 162 => Ok(GenericDesktop::SystemSetup), 163 => Ok(GenericDesktop::SystemBreak), 164 => Ok(GenericDesktop::SystemDebuggerBreak), 165 => Ok(GenericDesktop::ApplicationBreak), 166 => Ok(GenericDesktop::ApplicationDebuggerBreak), 167 => Ok(GenericDesktop::SystemSpeakerMute), 168 => Ok(GenericDesktop::SystemHibernate), 169 => Ok(GenericDesktop::SystemMicrophoneMute), 170 => Ok(GenericDesktop::SystemAccessibilityBinding), 176 => Ok(GenericDesktop::SystemDisplayInvert), 177 => Ok(GenericDesktop::SystemDisplayInternal), 178 => Ok(GenericDesktop::SystemDisplayExternal), 179 => Ok(GenericDesktop::SystemDisplayBoth), 180 => Ok(GenericDesktop::SystemDisplayDual), 181 => Ok(GenericDesktop::SystemDisplayToggleIntExtMode), 182 => Ok(GenericDesktop::SystemDisplaySwapPrimarySecondary), 183 => Ok(GenericDesktop::SystemDisplayToggleLCDAutoscale), 192 => Ok(GenericDesktop::SensorZone), 193 => Ok(GenericDesktop::RPM), 194 => Ok(GenericDesktop::CoolantLevel), 195 => Ok(GenericDesktop::CoolantCriticalLevel), 196 => Ok(GenericDesktop::CoolantPump), 197 => Ok(GenericDesktop::ChassisEnclosure), 198 => Ok(GenericDesktop::WirelessRadioButton), 199 => Ok(GenericDesktop::WirelessRadioLED), 200 => Ok(GenericDesktop::WirelessRadioSliderSwitch), 201 => Ok(GenericDesktop::SystemDisplayRotationLockButton), 202 => Ok(GenericDesktop::SystemDisplayRotationLockSliderSwitch), 203 => Ok(GenericDesktop::ControlEnable), 208 => Ok(GenericDesktop::DockableDeviceUniqueID), 209 => Ok(GenericDesktop::DockableDeviceVendorID), 210 => Ok(GenericDesktop::DockableDevicePrimaryUsagePage), 211 => Ok(GenericDesktop::DockableDevicePrimaryUsageID), 212 => Ok(GenericDesktop::DockableDeviceDockingState), 213 => Ok(GenericDesktop::DockableDeviceDisplayOcclusion), 214 => Ok(GenericDesktop::DockableDeviceObjectType), 224 => Ok(GenericDesktop::CallActiveLED), 225 => Ok(GenericDesktop::CallMuteToggle), 226 => Ok(GenericDesktop::CallMuteLED), n => Err(HutError::UnknownUsageId { usage_id: n }), } } } impl BitOr for GenericDesktop { type Output = Usage; /// A convenience function to combine a Usage Page with /// a value. /// /// This function panics if the Usage ID value results in /// an unknown Usage. Where error checking is required, /// use [UsagePage::to_usage_from_value]. fn bitor(self, usage: u16) -> Usage { let up = u16::from(self) as u32; let u = usage as u32; Usage::try_from(up | u).expect("Invalid Usage ID for this Usage Page") } } /// *Usage Page `0x2`: "Simulation Controls"* /// /// **This enum is autogenerated from the HID Usage Tables**. /// ``` /// # use hut::*; /// let u1 = Usage::SimulationControls(SimulationControls::AutomobileSimulationDevice); /// let u2 = Usage::new_from_page_and_id(0x2, 0x2).unwrap(); /// let u3 = Usage::from(SimulationControls::AutomobileSimulationDevice); /// let u4: Usage = SimulationControls::AutomobileSimulationDevice.into(); /// assert_eq!(u1, u2); /// assert_eq!(u1, u3); /// assert_eq!(u1, u4); /// /// assert!(matches!(u1.usage_page(), UsagePage::SimulationControls)); /// assert_eq!(0x2, u1.usage_page_value()); /// assert_eq!(0x2, u1.usage_id_value()); /// assert_eq!((0x2 << 16) | 0x2, u1.usage_value()); /// assert_eq!("Automobile Simulation Device", u1.name()); /// ``` /// #[allow(non_camel_case_types)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[non_exhaustive] #[repr(u16)] pub enum SimulationControls { /// Usage ID `0x1`: "Flight Simulation Device" FlightSimulationDevice = 0x1, /// Usage ID `0x2`: "Automobile Simulation Device" AutomobileSimulationDevice = 0x2, /// Usage ID `0x3`: "Tank Simulation Device" TankSimulationDevice = 0x3, /// Usage ID `0x4`: "Spaceship Simulation Device" SpaceshipSimulationDevice = 0x4, /// Usage ID `0x5`: "Submarine Simulation Device" SubmarineSimulationDevice = 0x5, /// Usage ID `0x6`: "Sailing Simulation Device" SailingSimulationDevice = 0x6, /// Usage ID `0x7`: "Motorcycle Simulation Device" MotorcycleSimulationDevice = 0x7, /// Usage ID `0x8`: "Sports Simulation Device" SportsSimulationDevice = 0x8, /// Usage ID `0x9`: "Airplane Simulation Device" AirplaneSimulationDevice = 0x9, /// Usage ID `0xA`: "Helicopter Simulation Device" HelicopterSimulationDevice = 0xA, /// Usage ID `0xB`: "Magic Carpet Simulation Device" MagicCarpetSimulationDevice = 0xB, /// Usage ID `0xC`: "Bicycle Simulation Device" BicycleSimulationDevice = 0xC, /// Usage ID `0x20`: "Flight Control Stick" FlightControlStick = 0x20, /// Usage ID `0x21`: "Flight Stick" FlightStick = 0x21, /// Usage ID `0x22`: "Cyclic Control" CyclicControl = 0x22, /// Usage ID `0x23`: "Cyclic Trim" CyclicTrim = 0x23, /// Usage ID `0x24`: "Flight Yoke" FlightYoke = 0x24, /// Usage ID `0x25`: "Track Control" TrackControl = 0x25, /// Usage ID `0xB0`: "Aileron" Aileron = 0xB0, /// Usage ID `0xB1`: "Aileron Trim" AileronTrim = 0xB1, /// Usage ID `0xB2`: "Anti-Torque Control" AntiTorqueControl = 0xB2, /// Usage ID `0xB3`: "Autopilot Enable" AutopilotEnable = 0xB3, /// Usage ID `0xB4`: "Chaff Release" ChaffRelease = 0xB4, /// Usage ID `0xB5`: "Collective Control" CollectiveControl = 0xB5, /// Usage ID `0xB6`: "Dive Brake" DiveBrake = 0xB6, /// Usage ID `0xB7`: "Electronic Countermeasures" ElectronicCountermeasures = 0xB7, /// Usage ID `0xB8`: "Elevator" Elevator = 0xB8, /// Usage ID `0xB9`: "Elevator Trim" ElevatorTrim = 0xB9, /// Usage ID `0xBA`: "Rudder" Rudder = 0xBA, /// Usage ID `0xBB`: "Throttle" Throttle = 0xBB, /// Usage ID `0xBC`: "Flight Communications" FlightCommunications = 0xBC, /// Usage ID `0xBD`: "Flare Release" FlareRelease = 0xBD, /// Usage ID `0xBE`: "Landing Gear" LandingGear = 0xBE, /// Usage ID `0xBF`: "Toe Brake" ToeBrake = 0xBF, /// Usage ID `0xC0`: "Trigger" Trigger = 0xC0, /// Usage ID `0xC1`: "Weapons Arm" WeaponsArm = 0xC1, /// Usage ID `0xC2`: "Weapons Select" WeaponsSelect = 0xC2, /// Usage ID `0xC3`: "Wing Flaps" WingFlaps = 0xC3, /// Usage ID `0xC4`: "Accelerator" Accelerator = 0xC4, /// Usage ID `0xC5`: "Brake" Brake = 0xC5, /// Usage ID `0xC6`: "Clutch" Clutch = 0xC6, /// Usage ID `0xC7`: "Shifter" Shifter = 0xC7, /// Usage ID `0xC8`: "Steering" Steering = 0xC8, /// Usage ID `0xC9`: "Turret Direction" TurretDirection = 0xC9, /// Usage ID `0xCA`: "Barrel Elevation" BarrelElevation = 0xCA, /// Usage ID `0xCB`: "Dive Plane" DivePlane = 0xCB, /// Usage ID `0xCC`: "Ballast" Ballast = 0xCC, /// Usage ID `0xCD`: "Bicycle Crank" BicycleCrank = 0xCD, /// Usage ID `0xCE`: "Handle Bars" HandleBars = 0xCE, /// Usage ID `0xCF`: "Front Brake" FrontBrake = 0xCF, /// Usage ID `0xD0`: "Rear Brake" RearBrake = 0xD0, } impl SimulationControls { #[cfg(feature = "std")] pub fn name(&self) -> String { match self { SimulationControls::FlightSimulationDevice => "Flight Simulation Device", SimulationControls::AutomobileSimulationDevice => "Automobile Simulation Device", SimulationControls::TankSimulationDevice => "Tank Simulation Device", SimulationControls::SpaceshipSimulationDevice => "Spaceship Simulation Device", SimulationControls::SubmarineSimulationDevice => "Submarine Simulation Device", SimulationControls::SailingSimulationDevice => "Sailing Simulation Device", SimulationControls::MotorcycleSimulationDevice => "Motorcycle Simulation Device", SimulationControls::SportsSimulationDevice => "Sports Simulation Device", SimulationControls::AirplaneSimulationDevice => "Airplane Simulation Device", SimulationControls::HelicopterSimulationDevice => "Helicopter Simulation Device", SimulationControls::MagicCarpetSimulationDevice => "Magic Carpet Simulation Device", SimulationControls::BicycleSimulationDevice => "Bicycle Simulation Device", SimulationControls::FlightControlStick => "Flight Control Stick", SimulationControls::FlightStick => "Flight Stick", SimulationControls::CyclicControl => "Cyclic Control", SimulationControls::CyclicTrim => "Cyclic Trim", SimulationControls::FlightYoke => "Flight Yoke", SimulationControls::TrackControl => "Track Control", SimulationControls::Aileron => "Aileron", SimulationControls::AileronTrim => "Aileron Trim", SimulationControls::AntiTorqueControl => "Anti-Torque Control", SimulationControls::AutopilotEnable => "Autopilot Enable", SimulationControls::ChaffRelease => "Chaff Release", SimulationControls::CollectiveControl => "Collective Control", SimulationControls::DiveBrake => "Dive Brake", SimulationControls::ElectronicCountermeasures => "Electronic Countermeasures", SimulationControls::Elevator => "Elevator", SimulationControls::ElevatorTrim => "Elevator Trim", SimulationControls::Rudder => "Rudder", SimulationControls::Throttle => "Throttle", SimulationControls::FlightCommunications => "Flight Communications", SimulationControls::FlareRelease => "Flare Release", SimulationControls::LandingGear => "Landing Gear", SimulationControls::ToeBrake => "Toe Brake", SimulationControls::Trigger => "Trigger", SimulationControls::WeaponsArm => "Weapons Arm", SimulationControls::WeaponsSelect => "Weapons Select", SimulationControls::WingFlaps => "Wing Flaps", SimulationControls::Accelerator => "Accelerator", SimulationControls::Brake => "Brake", SimulationControls::Clutch => "Clutch", SimulationControls::Shifter => "Shifter", SimulationControls::Steering => "Steering", SimulationControls::TurretDirection => "Turret Direction", SimulationControls::BarrelElevation => "Barrel Elevation", SimulationControls::DivePlane => "Dive Plane", SimulationControls::Ballast => "Ballast", SimulationControls::BicycleCrank => "Bicycle Crank", SimulationControls::HandleBars => "Handle Bars", SimulationControls::FrontBrake => "Front Brake", SimulationControls::RearBrake => "Rear Brake", } .into() } } #[cfg(feature = "std")] impl fmt::Display for SimulationControls { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name()) } } impl AsUsage for SimulationControls { /// Returns the 32 bit Usage value of this Usage fn usage_value(&self) -> u32 { u32::from(self) } /// Returns the 16 bit Usage ID value of this Usage fn usage_id_value(&self) -> u16 { u16::from(self) } /// Returns this usage as [Usage::SimulationControls(self)](Usage::SimulationControls) /// This is a convenience function to avoid having /// to implement `From` for every used type in the caller. /// /// ``` /// # use hut::*; /// let gd_x = GenericDesktop::X; /// let usage = Usage::from(GenericDesktop::X); /// assert!(matches!(gd_x.usage(), usage)); /// ``` fn usage(&self) -> Usage { Usage::from(self) } } impl AsUsagePage for SimulationControls { /// Returns the 16 bit value of this UsagePage /// /// This value is `0x2` for [SimulationControls] fn usage_page_value(&self) -> u16 { let up = UsagePage::from(self); u16::from(up) } /// Returns [UsagePage::SimulationControls]] fn usage_page(&self) -> UsagePage { UsagePage::from(self) } } impl From<&SimulationControls> for u16 { fn from(simulationcontrols: &SimulationControls) -> u16 { *simulationcontrols as u16 } } impl From for u16 { /// Returns the 16bit value of this usage. This is identical /// to [SimulationControls::usage_page_value()]. fn from(simulationcontrols: SimulationControls) -> u16 { u16::from(&simulationcontrols) } } impl From<&SimulationControls> for u32 { /// Returns the 32 bit value of this usage. This is identical /// to [SimulationControls::usage_value()]. fn from(simulationcontrols: &SimulationControls) -> u32 { let up = UsagePage::from(simulationcontrols); let up = (u16::from(&up) as u32) << 16; let id = u16::from(simulationcontrols) as u32; up | id } } impl From<&SimulationControls> for UsagePage { /// Always returns [UsagePage::SimulationControls] and is /// identical to [SimulationControls::usage_page()]. fn from(_: &SimulationControls) -> UsagePage { UsagePage::SimulationControls } } impl From for UsagePage { /// Always returns [UsagePage::SimulationControls] and is /// identical to [SimulationControls::usage_page()]. fn from(_: SimulationControls) -> UsagePage { UsagePage::SimulationControls } } impl From<&SimulationControls> for Usage { fn from(simulationcontrols: &SimulationControls) -> Usage { Usage::try_from(u32::from(simulationcontrols)).unwrap() } } impl From for Usage { fn from(simulationcontrols: SimulationControls) -> Usage { Usage::from(&simulationcontrols) } } impl TryFrom for SimulationControls { type Error = HutError; fn try_from(usage_id: u16) -> Result { match usage_id { 1 => Ok(SimulationControls::FlightSimulationDevice), 2 => Ok(SimulationControls::AutomobileSimulationDevice), 3 => Ok(SimulationControls::TankSimulationDevice), 4 => Ok(SimulationControls::SpaceshipSimulationDevice), 5 => Ok(SimulationControls::SubmarineSimulationDevice), 6 => Ok(SimulationControls::SailingSimulationDevice), 7 => Ok(SimulationControls::MotorcycleSimulationDevice), 8 => Ok(SimulationControls::SportsSimulationDevice), 9 => Ok(SimulationControls::AirplaneSimulationDevice), 10 => Ok(SimulationControls::HelicopterSimulationDevice), 11 => Ok(SimulationControls::MagicCarpetSimulationDevice), 12 => Ok(SimulationControls::BicycleSimulationDevice), 32 => Ok(SimulationControls::FlightControlStick), 33 => Ok(SimulationControls::FlightStick), 34 => Ok(SimulationControls::CyclicControl), 35 => Ok(SimulationControls::CyclicTrim), 36 => Ok(SimulationControls::FlightYoke), 37 => Ok(SimulationControls::TrackControl), 176 => Ok(SimulationControls::Aileron), 177 => Ok(SimulationControls::AileronTrim), 178 => Ok(SimulationControls::AntiTorqueControl), 179 => Ok(SimulationControls::AutopilotEnable), 180 => Ok(SimulationControls::ChaffRelease), 181 => Ok(SimulationControls::CollectiveControl), 182 => Ok(SimulationControls::DiveBrake), 183 => Ok(SimulationControls::ElectronicCountermeasures), 184 => Ok(SimulationControls::Elevator), 185 => Ok(SimulationControls::ElevatorTrim), 186 => Ok(SimulationControls::Rudder), 187 => Ok(SimulationControls::Throttle), 188 => Ok(SimulationControls::FlightCommunications), 189 => Ok(SimulationControls::FlareRelease), 190 => Ok(SimulationControls::LandingGear), 191 => Ok(SimulationControls::ToeBrake), 192 => Ok(SimulationControls::Trigger), 193 => Ok(SimulationControls::WeaponsArm), 194 => Ok(SimulationControls::WeaponsSelect), 195 => Ok(SimulationControls::WingFlaps), 196 => Ok(SimulationControls::Accelerator), 197 => Ok(SimulationControls::Brake), 198 => Ok(SimulationControls::Clutch), 199 => Ok(SimulationControls::Shifter), 200 => Ok(SimulationControls::Steering), 201 => Ok(SimulationControls::TurretDirection), 202 => Ok(SimulationControls::BarrelElevation), 203 => Ok(SimulationControls::DivePlane), 204 => Ok(SimulationControls::Ballast), 205 => Ok(SimulationControls::BicycleCrank), 206 => Ok(SimulationControls::HandleBars), 207 => Ok(SimulationControls::FrontBrake), 208 => Ok(SimulationControls::RearBrake), n => Err(HutError::UnknownUsageId { usage_id: n }), } } } impl BitOr for SimulationControls { type Output = Usage; /// A convenience function to combine a Usage Page with /// a value. /// /// This function panics if the Usage ID value results in /// an unknown Usage. Where error checking is required, /// use [UsagePage::to_usage_from_value]. fn bitor(self, usage: u16) -> Usage { let up = u16::from(self) as u32; let u = usage as u32; Usage::try_from(up | u).expect("Invalid Usage ID for this Usage Page") } } /// *Usage Page `0x3`: "VR Controls"* /// /// **This enum is autogenerated from the HID Usage Tables**. /// ``` /// # use hut::*; /// let u1 = Usage::VRControls(VRControls::BodySuit); /// let u2 = Usage::new_from_page_and_id(0x3, 0x2).unwrap(); /// let u3 = Usage::from(VRControls::BodySuit); /// let u4: Usage = VRControls::BodySuit.into(); /// assert_eq!(u1, u2); /// assert_eq!(u1, u3); /// assert_eq!(u1, u4); /// /// assert!(matches!(u1.usage_page(), UsagePage::VRControls)); /// assert_eq!(0x3, u1.usage_page_value()); /// assert_eq!(0x2, u1.usage_id_value()); /// assert_eq!((0x3 << 16) | 0x2, u1.usage_value()); /// assert_eq!("Body Suit", u1.name()); /// ``` /// #[allow(non_camel_case_types)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[non_exhaustive] #[repr(u16)] pub enum VRControls { /// Usage ID `0x1`: "Belt" Belt = 0x1, /// Usage ID `0x2`: "Body Suit" BodySuit = 0x2, /// Usage ID `0x3`: "Flexor" Flexor = 0x3, /// Usage ID `0x4`: "Glove" Glove = 0x4, /// Usage ID `0x5`: "Head Tracker" HeadTracker = 0x5, /// Usage ID `0x6`: "Head Mounted Display" HeadMountedDisplay = 0x6, /// Usage ID `0x7`: "Hand Tracker" HandTracker = 0x7, /// Usage ID `0x8`: "Oculometer" Oculometer = 0x8, /// Usage ID `0x9`: "Vest" Vest = 0x9, /// Usage ID `0xA`: "Animatronic Device" AnimatronicDevice = 0xA, /// Usage ID `0x20`: "Stereo Enable" StereoEnable = 0x20, /// Usage ID `0x21`: "Display Enable" DisplayEnable = 0x21, } impl VRControls { #[cfg(feature = "std")] pub fn name(&self) -> String { match self { VRControls::Belt => "Belt", VRControls::BodySuit => "Body Suit", VRControls::Flexor => "Flexor", VRControls::Glove => "Glove", VRControls::HeadTracker => "Head Tracker", VRControls::HeadMountedDisplay => "Head Mounted Display", VRControls::HandTracker => "Hand Tracker", VRControls::Oculometer => "Oculometer", VRControls::Vest => "Vest", VRControls::AnimatronicDevice => "Animatronic Device", VRControls::StereoEnable => "Stereo Enable", VRControls::DisplayEnable => "Display Enable", } .into() } } #[cfg(feature = "std")] impl fmt::Display for VRControls { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name()) } } impl AsUsage for VRControls { /// Returns the 32 bit Usage value of this Usage fn usage_value(&self) -> u32 { u32::from(self) } /// Returns the 16 bit Usage ID value of this Usage fn usage_id_value(&self) -> u16 { u16::from(self) } /// Returns this usage as [Usage::VRControls(self)](Usage::VRControls) /// This is a convenience function to avoid having /// to implement `From` for every used type in the caller. /// /// ``` /// # use hut::*; /// let gd_x = GenericDesktop::X; /// let usage = Usage::from(GenericDesktop::X); /// assert!(matches!(gd_x.usage(), usage)); /// ``` fn usage(&self) -> Usage { Usage::from(self) } } impl AsUsagePage for VRControls { /// Returns the 16 bit value of this UsagePage /// /// This value is `0x3` for [VRControls] fn usage_page_value(&self) -> u16 { let up = UsagePage::from(self); u16::from(up) } /// Returns [UsagePage::VRControls]] fn usage_page(&self) -> UsagePage { UsagePage::from(self) } } impl From<&VRControls> for u16 { fn from(vrcontrols: &VRControls) -> u16 { *vrcontrols as u16 } } impl From for u16 { /// Returns the 16bit value of this usage. This is identical /// to [VRControls::usage_page_value()]. fn from(vrcontrols: VRControls) -> u16 { u16::from(&vrcontrols) } } impl From<&VRControls> for u32 { /// Returns the 32 bit value of this usage. This is identical /// to [VRControls::usage_value()]. fn from(vrcontrols: &VRControls) -> u32 { let up = UsagePage::from(vrcontrols); let up = (u16::from(&up) as u32) << 16; let id = u16::from(vrcontrols) as u32; up | id } } impl From<&VRControls> for UsagePage { /// Always returns [UsagePage::VRControls] and is /// identical to [VRControls::usage_page()]. fn from(_: &VRControls) -> UsagePage { UsagePage::VRControls } } impl From for UsagePage { /// Always returns [UsagePage::VRControls] and is /// identical to [VRControls::usage_page()]. fn from(_: VRControls) -> UsagePage { UsagePage::VRControls } } impl From<&VRControls> for Usage { fn from(vrcontrols: &VRControls) -> Usage { Usage::try_from(u32::from(vrcontrols)).unwrap() } } impl From for Usage { fn from(vrcontrols: VRControls) -> Usage { Usage::from(&vrcontrols) } } impl TryFrom for VRControls { type Error = HutError; fn try_from(usage_id: u16) -> Result { match usage_id { 1 => Ok(VRControls::Belt), 2 => Ok(VRControls::BodySuit), 3 => Ok(VRControls::Flexor), 4 => Ok(VRControls::Glove), 5 => Ok(VRControls::HeadTracker), 6 => Ok(VRControls::HeadMountedDisplay), 7 => Ok(VRControls::HandTracker), 8 => Ok(VRControls::Oculometer), 9 => Ok(VRControls::Vest), 10 => Ok(VRControls::AnimatronicDevice), 32 => Ok(VRControls::StereoEnable), 33 => Ok(VRControls::DisplayEnable), n => Err(HutError::UnknownUsageId { usage_id: n }), } } } impl BitOr for VRControls { type Output = Usage; /// A convenience function to combine a Usage Page with /// a value. /// /// This function panics if the Usage ID value results in /// an unknown Usage. Where error checking is required, /// use [UsagePage::to_usage_from_value]. fn bitor(self, usage: u16) -> Usage { let up = u16::from(self) as u32; let u = usage as u32; Usage::try_from(up | u).expect("Invalid Usage ID for this Usage Page") } } /// *Usage Page `0x4`: "Sport Controls"* /// /// **This enum is autogenerated from the HID Usage Tables**. /// ``` /// # use hut::*; /// let u1 = Usage::SportControls(SportControls::GolfClub); /// let u2 = Usage::new_from_page_and_id(0x4, 0x2).unwrap(); /// let u3 = Usage::from(SportControls::GolfClub); /// let u4: Usage = SportControls::GolfClub.into(); /// assert_eq!(u1, u2); /// assert_eq!(u1, u3); /// assert_eq!(u1, u4); /// /// assert!(matches!(u1.usage_page(), UsagePage::SportControls)); /// assert_eq!(0x4, u1.usage_page_value()); /// assert_eq!(0x2, u1.usage_id_value()); /// assert_eq!((0x4 << 16) | 0x2, u1.usage_value()); /// assert_eq!("Golf Club", u1.name()); /// ``` /// #[allow(non_camel_case_types)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[non_exhaustive] #[repr(u16)] pub enum SportControls { /// Usage ID `0x1`: "Baseball Bat" BaseballBat = 0x1, /// Usage ID `0x2`: "Golf Club" GolfClub = 0x2, /// Usage ID `0x3`: "Rowing Machine" RowingMachine = 0x3, /// Usage ID `0x4`: "Treadmill" Treadmill = 0x4, /// Usage ID `0x30`: "Oar" Oar = 0x30, /// Usage ID `0x31`: "Slope" Slope = 0x31, /// Usage ID `0x32`: "Rate" Rate = 0x32, /// Usage ID `0x33`: "Stick Speed" StickSpeed = 0x33, /// Usage ID `0x34`: "Stick Face Angle" StickFaceAngle = 0x34, /// Usage ID `0x35`: "Stick Heel/Toe" StickHeelToe = 0x35, /// Usage ID `0x36`: "Stick Follow Through" StickFollowThrough = 0x36, /// Usage ID `0x37`: "Stick Tempo" StickTempo = 0x37, /// Usage ID `0x38`: "Stick Type" StickType = 0x38, /// Usage ID `0x39`: "Stick Height" StickHeight = 0x39, /// Usage ID `0x50`: "Putter" Putter = 0x50, /// Usage ID `0x51`: "1 Iron" OneIron = 0x51, /// Usage ID `0x52`: "2 Iron" TwoIron = 0x52, /// Usage ID `0x53`: "3 Iron" ThreeIron = 0x53, /// Usage ID `0x54`: "4 Iron" FourIron = 0x54, /// Usage ID `0x55`: "5 Iron" FiveIron = 0x55, /// Usage ID `0x56`: "6 Iron" SixIron = 0x56, /// Usage ID `0x57`: "7 Iron" SevenIron = 0x57, /// Usage ID `0x58`: "8 Iron" EightIron = 0x58, /// Usage ID `0x59`: "9 Iron" NineIron = 0x59, /// Usage ID `0x5A`: "10 Iron" One0Iron = 0x5A, /// Usage ID `0x5B`: "11 Iron" One1Iron = 0x5B, /// Usage ID `0x5C`: "Sand Wedge" SandWedge = 0x5C, /// Usage ID `0x5D`: "Loft Wedge" LoftWedge = 0x5D, /// Usage ID `0x5E`: "Power Wedge" PowerWedge = 0x5E, /// Usage ID `0x5F`: "1 Wood" OneWood = 0x5F, /// Usage ID `0x60`: "3 Wood" ThreeWood = 0x60, /// Usage ID `0x61`: "5 Wood" FiveWood = 0x61, /// Usage ID `0x62`: "7 Wood" SevenWood = 0x62, /// Usage ID `0x63`: "9 Wood" NineWood = 0x63, } impl SportControls { #[cfg(feature = "std")] pub fn name(&self) -> String { match self { SportControls::BaseballBat => "Baseball Bat", SportControls::GolfClub => "Golf Club", SportControls::RowingMachine => "Rowing Machine", SportControls::Treadmill => "Treadmill", SportControls::Oar => "Oar", SportControls::Slope => "Slope", SportControls::Rate => "Rate", SportControls::StickSpeed => "Stick Speed", SportControls::StickFaceAngle => "Stick Face Angle", SportControls::StickHeelToe => "Stick Heel/Toe", SportControls::StickFollowThrough => "Stick Follow Through", SportControls::StickTempo => "Stick Tempo", SportControls::StickType => "Stick Type", SportControls::StickHeight => "Stick Height", SportControls::Putter => "Putter", SportControls::OneIron => "1 Iron", SportControls::TwoIron => "2 Iron", SportControls::ThreeIron => "3 Iron", SportControls::FourIron => "4 Iron", SportControls::FiveIron => "5 Iron", SportControls::SixIron => "6 Iron", SportControls::SevenIron => "7 Iron", SportControls::EightIron => "8 Iron", SportControls::NineIron => "9 Iron", SportControls::One0Iron => "10 Iron", SportControls::One1Iron => "11 Iron", SportControls::SandWedge => "Sand Wedge", SportControls::LoftWedge => "Loft Wedge", SportControls::PowerWedge => "Power Wedge", SportControls::OneWood => "1 Wood", SportControls::ThreeWood => "3 Wood", SportControls::FiveWood => "5 Wood", SportControls::SevenWood => "7 Wood", SportControls::NineWood => "9 Wood", } .into() } } #[cfg(feature = "std")] impl fmt::Display for SportControls { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name()) } } impl AsUsage for SportControls { /// Returns the 32 bit Usage value of this Usage fn usage_value(&self) -> u32 { u32::from(self) } /// Returns the 16 bit Usage ID value of this Usage fn usage_id_value(&self) -> u16 { u16::from(self) } /// Returns this usage as [Usage::SportControls(self)](Usage::SportControls) /// This is a convenience function to avoid having /// to implement `From` for every used type in the caller. /// /// ``` /// # use hut::*; /// let gd_x = GenericDesktop::X; /// let usage = Usage::from(GenericDesktop::X); /// assert!(matches!(gd_x.usage(), usage)); /// ``` fn usage(&self) -> Usage { Usage::from(self) } } impl AsUsagePage for SportControls { /// Returns the 16 bit value of this UsagePage /// /// This value is `0x4` for [SportControls] fn usage_page_value(&self) -> u16 { let up = UsagePage::from(self); u16::from(up) } /// Returns [UsagePage::SportControls]] fn usage_page(&self) -> UsagePage { UsagePage::from(self) } } impl From<&SportControls> for u16 { fn from(sportcontrols: &SportControls) -> u16 { *sportcontrols as u16 } } impl From for u16 { /// Returns the 16bit value of this usage. This is identical /// to [SportControls::usage_page_value()]. fn from(sportcontrols: SportControls) -> u16 { u16::from(&sportcontrols) } } impl From<&SportControls> for u32 { /// Returns the 32 bit value of this usage. This is identical /// to [SportControls::usage_value()]. fn from(sportcontrols: &SportControls) -> u32 { let up = UsagePage::from(sportcontrols); let up = (u16::from(&up) as u32) << 16; let id = u16::from(sportcontrols) as u32; up | id } } impl From<&SportControls> for UsagePage { /// Always returns [UsagePage::SportControls] and is /// identical to [SportControls::usage_page()]. fn from(_: &SportControls) -> UsagePage { UsagePage::SportControls } } impl From for UsagePage { /// Always returns [UsagePage::SportControls] and is /// identical to [SportControls::usage_page()]. fn from(_: SportControls) -> UsagePage { UsagePage::SportControls } } impl From<&SportControls> for Usage { fn from(sportcontrols: &SportControls) -> Usage { Usage::try_from(u32::from(sportcontrols)).unwrap() } } impl From for Usage { fn from(sportcontrols: SportControls) -> Usage { Usage::from(&sportcontrols) } } impl TryFrom for SportControls { type Error = HutError; fn try_from(usage_id: u16) -> Result { match usage_id { 1 => Ok(SportControls::BaseballBat), 2 => Ok(SportControls::GolfClub), 3 => Ok(SportControls::RowingMachine), 4 => Ok(SportControls::Treadmill), 48 => Ok(SportControls::Oar), 49 => Ok(SportControls::Slope), 50 => Ok(SportControls::Rate), 51 => Ok(SportControls::StickSpeed), 52 => Ok(SportControls::StickFaceAngle), 53 => Ok(SportControls::StickHeelToe), 54 => Ok(SportControls::StickFollowThrough), 55 => Ok(SportControls::StickTempo), 56 => Ok(SportControls::StickType), 57 => Ok(SportControls::StickHeight), 80 => Ok(SportControls::Putter), 81 => Ok(SportControls::OneIron), 82 => Ok(SportControls::TwoIron), 83 => Ok(SportControls::ThreeIron), 84 => Ok(SportControls::FourIron), 85 => Ok(SportControls::FiveIron), 86 => Ok(SportControls::SixIron), 87 => Ok(SportControls::SevenIron), 88 => Ok(SportControls::EightIron), 89 => Ok(SportControls::NineIron), 90 => Ok(SportControls::One0Iron), 91 => Ok(SportControls::One1Iron), 92 => Ok(SportControls::SandWedge), 93 => Ok(SportControls::LoftWedge), 94 => Ok(SportControls::PowerWedge), 95 => Ok(SportControls::OneWood), 96 => Ok(SportControls::ThreeWood), 97 => Ok(SportControls::FiveWood), 98 => Ok(SportControls::SevenWood), 99 => Ok(SportControls::NineWood), n => Err(HutError::UnknownUsageId { usage_id: n }), } } } impl BitOr for SportControls { type Output = Usage; /// A convenience function to combine a Usage Page with /// a value. /// /// This function panics if the Usage ID value results in /// an unknown Usage. Where error checking is required, /// use [UsagePage::to_usage_from_value]. fn bitor(self, usage: u16) -> Usage { let up = u16::from(self) as u32; let u = usage as u32; Usage::try_from(up | u).expect("Invalid Usage ID for this Usage Page") } } /// *Usage Page `0x5`: "Game Controls"* /// /// **This enum is autogenerated from the HID Usage Tables**. /// ``` /// # use hut::*; /// let u1 = Usage::GameControls(GameControls::PinballDevice); /// let u2 = Usage::new_from_page_and_id(0x5, 0x2).unwrap(); /// let u3 = Usage::from(GameControls::PinballDevice); /// let u4: Usage = GameControls::PinballDevice.into(); /// assert_eq!(u1, u2); /// assert_eq!(u1, u3); /// assert_eq!(u1, u4); /// /// assert!(matches!(u1.usage_page(), UsagePage::GameControls)); /// assert_eq!(0x5, u1.usage_page_value()); /// assert_eq!(0x2, u1.usage_id_value()); /// assert_eq!((0x5 << 16) | 0x2, u1.usage_value()); /// assert_eq!("Pinball Device", u1.name()); /// ``` /// #[allow(non_camel_case_types)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[non_exhaustive] #[repr(u16)] pub enum GameControls { /// Usage ID `0x1`: "3D Game Controller" ThreeDGameController = 0x1, /// Usage ID `0x2`: "Pinball Device" PinballDevice = 0x2, /// Usage ID `0x3`: "Gun Device" GunDevice = 0x3, /// Usage ID `0x20`: "Point of View" PointofView = 0x20, /// Usage ID `0x21`: "Turn Right/Left" TurnRightLeft = 0x21, /// Usage ID `0x22`: "Pitch Forward/Backward" PitchForwardBackward = 0x22, /// Usage ID `0x23`: "Roll Right/Left" RollRightLeft = 0x23, /// Usage ID `0x24`: "Move Right/Left" MoveRightLeft = 0x24, /// Usage ID `0x25`: "Move Forward/Backward" MoveForwardBackward = 0x25, /// Usage ID `0x26`: "Move Up/Down" MoveUpDown = 0x26, /// Usage ID `0x27`: "Lean Right/Left" LeanRightLeft = 0x27, /// Usage ID `0x28`: "Lean Forward/Backward" LeanForwardBackward = 0x28, /// Usage ID `0x29`: "Height of POV" HeightofPOV = 0x29, /// Usage ID `0x2A`: "Flipper" Flipper = 0x2A, /// Usage ID `0x2B`: "Secondary Flipper" SecondaryFlipper = 0x2B, /// Usage ID `0x2C`: "Bump" Bump = 0x2C, /// Usage ID `0x2D`: "New Game" NewGame = 0x2D, /// Usage ID `0x2E`: "Shoot Ball" ShootBall = 0x2E, /// Usage ID `0x2F`: "Player" Player = 0x2F, /// Usage ID `0x30`: "Gun Bolt" GunBolt = 0x30, /// Usage ID `0x31`: "Gun Clip" GunClip = 0x31, /// Usage ID `0x32`: "Gun Selector" GunSelector = 0x32, /// Usage ID `0x33`: "Gun Single Shot" GunSingleShot = 0x33, /// Usage ID `0x34`: "Gun Burst" GunBurst = 0x34, /// Usage ID `0x35`: "Gun Automatic" GunAutomatic = 0x35, /// Usage ID `0x36`: "Gun Safety" GunSafety = 0x36, /// Usage ID `0x37`: "Gamepad Fire/Jump" GamepadFireJump = 0x37, /// Usage ID `0x39`: "Gamepad Trigger" GamepadTrigger = 0x39, /// Usage ID `0x3A`: "Form-fitting Gamepad" FormfittingGamepad = 0x3A, } impl GameControls { #[cfg(feature = "std")] pub fn name(&self) -> String { match self { GameControls::ThreeDGameController => "3D Game Controller", GameControls::PinballDevice => "Pinball Device", GameControls::GunDevice => "Gun Device", GameControls::PointofView => "Point of View", GameControls::TurnRightLeft => "Turn Right/Left", GameControls::PitchForwardBackward => "Pitch Forward/Backward", GameControls::RollRightLeft => "Roll Right/Left", GameControls::MoveRightLeft => "Move Right/Left", GameControls::MoveForwardBackward => "Move Forward/Backward", GameControls::MoveUpDown => "Move Up/Down", GameControls::LeanRightLeft => "Lean Right/Left", GameControls::LeanForwardBackward => "Lean Forward/Backward", GameControls::HeightofPOV => "Height of POV", GameControls::Flipper => "Flipper", GameControls::SecondaryFlipper => "Secondary Flipper", GameControls::Bump => "Bump", GameControls::NewGame => "New Game", GameControls::ShootBall => "Shoot Ball", GameControls::Player => "Player", GameControls::GunBolt => "Gun Bolt", GameControls::GunClip => "Gun Clip", GameControls::GunSelector => "Gun Selector", GameControls::GunSingleShot => "Gun Single Shot", GameControls::GunBurst => "Gun Burst", GameControls::GunAutomatic => "Gun Automatic", GameControls::GunSafety => "Gun Safety", GameControls::GamepadFireJump => "Gamepad Fire/Jump", GameControls::GamepadTrigger => "Gamepad Trigger", GameControls::FormfittingGamepad => "Form-fitting Gamepad", } .into() } } #[cfg(feature = "std")] impl fmt::Display for GameControls { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name()) } } impl AsUsage for GameControls { /// Returns the 32 bit Usage value of this Usage fn usage_value(&self) -> u32 { u32::from(self) } /// Returns the 16 bit Usage ID value of this Usage fn usage_id_value(&self) -> u16 { u16::from(self) } /// Returns this usage as [Usage::GameControls(self)](Usage::GameControls) /// This is a convenience function to avoid having /// to implement `From` for every used type in the caller. /// /// ``` /// # use hut::*; /// let gd_x = GenericDesktop::X; /// let usage = Usage::from(GenericDesktop::X); /// assert!(matches!(gd_x.usage(), usage)); /// ``` fn usage(&self) -> Usage { Usage::from(self) } } impl AsUsagePage for GameControls { /// Returns the 16 bit value of this UsagePage /// /// This value is `0x5` for [GameControls] fn usage_page_value(&self) -> u16 { let up = UsagePage::from(self); u16::from(up) } /// Returns [UsagePage::GameControls]] fn usage_page(&self) -> UsagePage { UsagePage::from(self) } } impl From<&GameControls> for u16 { fn from(gamecontrols: &GameControls) -> u16 { *gamecontrols as u16 } } impl From for u16 { /// Returns the 16bit value of this usage. This is identical /// to [GameControls::usage_page_value()]. fn from(gamecontrols: GameControls) -> u16 { u16::from(&gamecontrols) } } impl From<&GameControls> for u32 { /// Returns the 32 bit value of this usage. This is identical /// to [GameControls::usage_value()]. fn from(gamecontrols: &GameControls) -> u32 { let up = UsagePage::from(gamecontrols); let up = (u16::from(&up) as u32) << 16; let id = u16::from(gamecontrols) as u32; up | id } } impl From<&GameControls> for UsagePage { /// Always returns [UsagePage::GameControls] and is /// identical to [GameControls::usage_page()]. fn from(_: &GameControls) -> UsagePage { UsagePage::GameControls } } impl From for UsagePage { /// Always returns [UsagePage::GameControls] and is /// identical to [GameControls::usage_page()]. fn from(_: GameControls) -> UsagePage { UsagePage::GameControls } } impl From<&GameControls> for Usage { fn from(gamecontrols: &GameControls) -> Usage { Usage::try_from(u32::from(gamecontrols)).unwrap() } } impl From for Usage { fn from(gamecontrols: GameControls) -> Usage { Usage::from(&gamecontrols) } } impl TryFrom for GameControls { type Error = HutError; fn try_from(usage_id: u16) -> Result { match usage_id { 1 => Ok(GameControls::ThreeDGameController), 2 => Ok(GameControls::PinballDevice), 3 => Ok(GameControls::GunDevice), 32 => Ok(GameControls::PointofView), 33 => Ok(GameControls::TurnRightLeft), 34 => Ok(GameControls::PitchForwardBackward), 35 => Ok(GameControls::RollRightLeft), 36 => Ok(GameControls::MoveRightLeft), 37 => Ok(GameControls::MoveForwardBackward), 38 => Ok(GameControls::MoveUpDown), 39 => Ok(GameControls::LeanRightLeft), 40 => Ok(GameControls::LeanForwardBackward), 41 => Ok(GameControls::HeightofPOV), 42 => Ok(GameControls::Flipper), 43 => Ok(GameControls::SecondaryFlipper), 44 => Ok(GameControls::Bump), 45 => Ok(GameControls::NewGame), 46 => Ok(GameControls::ShootBall), 47 => Ok(GameControls::Player), 48 => Ok(GameControls::GunBolt), 49 => Ok(GameControls::GunClip), 50 => Ok(GameControls::GunSelector), 51 => Ok(GameControls::GunSingleShot), 52 => Ok(GameControls::GunBurst), 53 => Ok(GameControls::GunAutomatic), 54 => Ok(GameControls::GunSafety), 55 => Ok(GameControls::GamepadFireJump), 57 => Ok(GameControls::GamepadTrigger), 58 => Ok(GameControls::FormfittingGamepad), n => Err(HutError::UnknownUsageId { usage_id: n }), } } } impl BitOr for GameControls { type Output = Usage; /// A convenience function to combine a Usage Page with /// a value. /// /// This function panics if the Usage ID value results in /// an unknown Usage. Where error checking is required, /// use [UsagePage::to_usage_from_value]. fn bitor(self, usage: u16) -> Usage { let up = u16::from(self) as u32; let u = usage as u32; Usage::try_from(up | u).expect("Invalid Usage ID for this Usage Page") } } /// *Usage Page `0x6`: "Generic Device Controls"* /// /// **This enum is autogenerated from the HID Usage Tables**. /// ``` /// # use hut::*; /// let u1 = Usage::GenericDeviceControls(GenericDeviceControls::BatteryStrength); /// let u2 = Usage::new_from_page_and_id(0x6, 0x20).unwrap(); /// let u3 = Usage::from(GenericDeviceControls::BatteryStrength); /// let u4: Usage = GenericDeviceControls::BatteryStrength.into(); /// assert_eq!(u1, u2); /// assert_eq!(u1, u3); /// assert_eq!(u1, u4); /// /// assert!(matches!(u1.usage_page(), UsagePage::GenericDeviceControls)); /// assert_eq!(0x6, u1.usage_page_value()); /// assert_eq!(0x20, u1.usage_id_value()); /// assert_eq!((0x6 << 16) | 0x20, u1.usage_value()); /// assert_eq!("Battery Strength", u1.name()); /// ``` /// #[allow(non_camel_case_types)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[non_exhaustive] #[repr(u16)] pub enum GenericDeviceControls { /// Usage ID `0x1`: "Background/Nonuser Controls" BackgroundNonuserControls = 0x1, /// Usage ID `0x20`: "Battery Strength" BatteryStrength = 0x20, /// Usage ID `0x21`: "Wireless Channel" WirelessChannel = 0x21, /// Usage ID `0x22`: "Wireless ID" WirelessID = 0x22, /// Usage ID `0x23`: "Discover Wireless Control" DiscoverWirelessControl = 0x23, /// Usage ID `0x24`: "Security Code Character Entered" SecurityCodeCharacterEntered = 0x24, /// Usage ID `0x25`: "Security Code Character Erased" SecurityCodeCharacterErased = 0x25, /// Usage ID `0x26`: "Security Code Cleared" SecurityCodeCleared = 0x26, /// Usage ID `0x27`: "Sequence ID" SequenceID = 0x27, /// Usage ID `0x28`: "Sequence ID Reset" SequenceIDReset = 0x28, /// Usage ID `0x29`: "RF Signal Strength" RFSignalStrength = 0x29, /// Usage ID `0x2A`: "Software Version" SoftwareVersion = 0x2A, /// Usage ID `0x2B`: "Protocol Version" ProtocolVersion = 0x2B, /// Usage ID `0x2C`: "Hardware Version" HardwareVersion = 0x2C, /// Usage ID `0x2D`: "Major" Major = 0x2D, /// Usage ID `0x2E`: "Minor" Minor = 0x2E, /// Usage ID `0x2F`: "Revision" Revision = 0x2F, /// Usage ID `0x30`: "Handedness" Handedness = 0x30, /// Usage ID `0x31`: "Either Hand" EitherHand = 0x31, /// Usage ID `0x32`: "Left Hand" LeftHand = 0x32, /// Usage ID `0x33`: "Right Hand" RightHand = 0x33, /// Usage ID `0x34`: "Both Hands" BothHands = 0x34, /// Usage ID `0x40`: "Grip Pose Offset" GripPoseOffset = 0x40, /// Usage ID `0x41`: "Pointer Pose Offset" PointerPoseOffset = 0x41, } impl GenericDeviceControls { #[cfg(feature = "std")] pub fn name(&self) -> String { match self { GenericDeviceControls::BackgroundNonuserControls => "Background/Nonuser Controls", GenericDeviceControls::BatteryStrength => "Battery Strength", GenericDeviceControls::WirelessChannel => "Wireless Channel", GenericDeviceControls::WirelessID => "Wireless ID", GenericDeviceControls::DiscoverWirelessControl => "Discover Wireless Control", GenericDeviceControls::SecurityCodeCharacterEntered => { "Security Code Character Entered" } GenericDeviceControls::SecurityCodeCharacterErased => "Security Code Character Erased", GenericDeviceControls::SecurityCodeCleared => "Security Code Cleared", GenericDeviceControls::SequenceID => "Sequence ID", GenericDeviceControls::SequenceIDReset => "Sequence ID Reset", GenericDeviceControls::RFSignalStrength => "RF Signal Strength", GenericDeviceControls::SoftwareVersion => "Software Version", GenericDeviceControls::ProtocolVersion => "Protocol Version", GenericDeviceControls::HardwareVersion => "Hardware Version", GenericDeviceControls::Major => "Major", GenericDeviceControls::Minor => "Minor", GenericDeviceControls::Revision => "Revision", GenericDeviceControls::Handedness => "Handedness", GenericDeviceControls::EitherHand => "Either Hand", GenericDeviceControls::LeftHand => "Left Hand", GenericDeviceControls::RightHand => "Right Hand", GenericDeviceControls::BothHands => "Both Hands", GenericDeviceControls::GripPoseOffset => "Grip Pose Offset", GenericDeviceControls::PointerPoseOffset => "Pointer Pose Offset", } .into() } } #[cfg(feature = "std")] impl fmt::Display for GenericDeviceControls { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name()) } } impl AsUsage for GenericDeviceControls { /// Returns the 32 bit Usage value of this Usage fn usage_value(&self) -> u32 { u32::from(self) } /// Returns the 16 bit Usage ID value of this Usage fn usage_id_value(&self) -> u16 { u16::from(self) } /// Returns this usage as [Usage::GenericDeviceControls(self)](Usage::GenericDeviceControls) /// This is a convenience function to avoid having /// to implement `From` for every used type in the caller. /// /// ``` /// # use hut::*; /// let gd_x = GenericDesktop::X; /// let usage = Usage::from(GenericDesktop::X); /// assert!(matches!(gd_x.usage(), usage)); /// ``` fn usage(&self) -> Usage { Usage::from(self) } } impl AsUsagePage for GenericDeviceControls { /// Returns the 16 bit value of this UsagePage /// /// This value is `0x6` for [GenericDeviceControls] fn usage_page_value(&self) -> u16 { let up = UsagePage::from(self); u16::from(up) } /// Returns [UsagePage::GenericDeviceControls]] fn usage_page(&self) -> UsagePage { UsagePage::from(self) } } impl From<&GenericDeviceControls> for u16 { fn from(genericdevicecontrols: &GenericDeviceControls) -> u16 { *genericdevicecontrols as u16 } } impl From for u16 { /// Returns the 16bit value of this usage. This is identical /// to [GenericDeviceControls::usage_page_value()]. fn from(genericdevicecontrols: GenericDeviceControls) -> u16 { u16::from(&genericdevicecontrols) } } impl From<&GenericDeviceControls> for u32 { /// Returns the 32 bit value of this usage. This is identical /// to [GenericDeviceControls::usage_value()]. fn from(genericdevicecontrols: &GenericDeviceControls) -> u32 { let up = UsagePage::from(genericdevicecontrols); let up = (u16::from(&up) as u32) << 16; let id = u16::from(genericdevicecontrols) as u32; up | id } } impl From<&GenericDeviceControls> for UsagePage { /// Always returns [UsagePage::GenericDeviceControls] and is /// identical to [GenericDeviceControls::usage_page()]. fn from(_: &GenericDeviceControls) -> UsagePage { UsagePage::GenericDeviceControls } } impl From for UsagePage { /// Always returns [UsagePage::GenericDeviceControls] and is /// identical to [GenericDeviceControls::usage_page()]. fn from(_: GenericDeviceControls) -> UsagePage { UsagePage::GenericDeviceControls } } impl From<&GenericDeviceControls> for Usage { fn from(genericdevicecontrols: &GenericDeviceControls) -> Usage { Usage::try_from(u32::from(genericdevicecontrols)).unwrap() } } impl From for Usage { fn from(genericdevicecontrols: GenericDeviceControls) -> Usage { Usage::from(&genericdevicecontrols) } } impl TryFrom for GenericDeviceControls { type Error = HutError; fn try_from(usage_id: u16) -> Result { match usage_id { 1 => Ok(GenericDeviceControls::BackgroundNonuserControls), 32 => Ok(GenericDeviceControls::BatteryStrength), 33 => Ok(GenericDeviceControls::WirelessChannel), 34 => Ok(GenericDeviceControls::WirelessID), 35 => Ok(GenericDeviceControls::DiscoverWirelessControl), 36 => Ok(GenericDeviceControls::SecurityCodeCharacterEntered), 37 => Ok(GenericDeviceControls::SecurityCodeCharacterErased), 38 => Ok(GenericDeviceControls::SecurityCodeCleared), 39 => Ok(GenericDeviceControls::SequenceID), 40 => Ok(GenericDeviceControls::SequenceIDReset), 41 => Ok(GenericDeviceControls::RFSignalStrength), 42 => Ok(GenericDeviceControls::SoftwareVersion), 43 => Ok(GenericDeviceControls::ProtocolVersion), 44 => Ok(GenericDeviceControls::HardwareVersion), 45 => Ok(GenericDeviceControls::Major), 46 => Ok(GenericDeviceControls::Minor), 47 => Ok(GenericDeviceControls::Revision), 48 => Ok(GenericDeviceControls::Handedness), 49 => Ok(GenericDeviceControls::EitherHand), 50 => Ok(GenericDeviceControls::LeftHand), 51 => Ok(GenericDeviceControls::RightHand), 52 => Ok(GenericDeviceControls::BothHands), 64 => Ok(GenericDeviceControls::GripPoseOffset), 65 => Ok(GenericDeviceControls::PointerPoseOffset), n => Err(HutError::UnknownUsageId { usage_id: n }), } } } impl BitOr for GenericDeviceControls { type Output = Usage; /// A convenience function to combine a Usage Page with /// a value. /// /// This function panics if the Usage ID value results in /// an unknown Usage. Where error checking is required, /// use [UsagePage::to_usage_from_value]. fn bitor(self, usage: u16) -> Usage { let up = u16::from(self) as u32; let u = usage as u32; Usage::try_from(up | u).expect("Invalid Usage ID for this Usage Page") } } /// *Usage Page `0x7`: "Keyboard/Keypad"* /// /// **This enum is autogenerated from the HID Usage Tables**. /// ``` /// # use hut::*; /// let u1 = Usage::KeyboardKeypad(KeyboardKeypad::POSTFail); /// let u2 = Usage::new_from_page_and_id(0x7, 0x2).unwrap(); /// let u3 = Usage::from(KeyboardKeypad::POSTFail); /// let u4: Usage = KeyboardKeypad::POSTFail.into(); /// assert_eq!(u1, u2); /// assert_eq!(u1, u3); /// assert_eq!(u1, u4); /// /// assert!(matches!(u1.usage_page(), UsagePage::KeyboardKeypad)); /// assert_eq!(0x7, u1.usage_page_value()); /// assert_eq!(0x2, u1.usage_id_value()); /// assert_eq!((0x7 << 16) | 0x2, u1.usage_value()); /// assert_eq!("POSTFail", u1.name()); /// ``` /// #[allow(non_camel_case_types)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[non_exhaustive] #[repr(u16)] pub enum KeyboardKeypad { /// Usage ID `0x1`: "ErrorRollOver" ErrorRollOver = 0x1, /// Usage ID `0x2`: "POSTFail" POSTFail = 0x2, /// Usage ID `0x3`: "ErrorUndefined" ErrorUndefined = 0x3, /// Usage ID `0x4`: "Keyboard A" KeyboardA = 0x4, /// Usage ID `0x5`: "Keyboard B" KeyboardB = 0x5, /// Usage ID `0x6`: "Keyboard C" KeyboardC = 0x6, /// Usage ID `0x7`: "Keyboard D" KeyboardD = 0x7, /// Usage ID `0x8`: "Keyboard E" KeyboardE = 0x8, /// Usage ID `0x9`: "Keyboard F" KeyboardF = 0x9, /// Usage ID `0xA`: "Keyboard G" KeyboardG = 0xA, /// Usage ID `0xB`: "Keyboard H" KeyboardH = 0xB, /// Usage ID `0xC`: "Keyboard I" KeyboardI = 0xC, /// Usage ID `0xD`: "Keyboard J" KeyboardJ = 0xD, /// Usage ID `0xE`: "Keyboard K" KeyboardK = 0xE, /// Usage ID `0xF`: "Keyboard L" KeyboardL = 0xF, /// Usage ID `0x10`: "Keyboard M" KeyboardM = 0x10, /// Usage ID `0x11`: "Keyboard N" KeyboardN = 0x11, /// Usage ID `0x12`: "Keyboard O" KeyboardO = 0x12, /// Usage ID `0x13`: "Keyboard P" KeyboardP = 0x13, /// Usage ID `0x14`: "Keyboard Q" KeyboardQ = 0x14, /// Usage ID `0x15`: "Keyboard R" KeyboardR = 0x15, /// Usage ID `0x16`: "Keyboard S" KeyboardS = 0x16, /// Usage ID `0x17`: "Keyboard T" KeyboardT = 0x17, /// Usage ID `0x18`: "Keyboard U" KeyboardU = 0x18, /// Usage ID `0x19`: "Keyboard V" KeyboardV = 0x19, /// Usage ID `0x1A`: "Keyboard W" KeyboardW = 0x1A, /// Usage ID `0x1B`: "Keyboard X" KeyboardX = 0x1B, /// Usage ID `0x1C`: "Keyboard Y" KeyboardY = 0x1C, /// Usage ID `0x1D`: "Keyboard Z" KeyboardZ = 0x1D, /// Usage ID `0x1E`: "Keyboard 1 and Bang" Keyboard1andBang = 0x1E, /// Usage ID `0x1F`: "Keyboard 2 and At" Keyboard2andAt = 0x1F, /// Usage ID `0x20`: "Keyboard 3 and Hash" Keyboard3andHash = 0x20, /// Usage ID `0x21`: "Keyboard 4 and Dollar" Keyboard4andDollar = 0x21, /// Usage ID `0x22`: "Keyboard 5 and Percent" Keyboard5andPercent = 0x22, /// Usage ID `0x23`: "Keyboard 6 and Caret" Keyboard6andCaret = 0x23, /// Usage ID `0x24`: "Keyboard 7 and Ampersand" Keyboard7andAmpersand = 0x24, /// Usage ID `0x25`: "Keyboard 8 and Star" Keyboard8andStar = 0x25, /// Usage ID `0x26`: "Keyboard 9 and Left Bracket" Keyboard9andLeftBracket = 0x26, /// Usage ID `0x27`: "Keyboard 0 and Right Bracket" Keyboard0andRightBracket = 0x27, /// Usage ID `0x28`: "Keyboard Return Enter" KeyboardReturnEnter = 0x28, /// Usage ID `0x29`: "Keyboard Escape" KeyboardEscape = 0x29, /// Usage ID `0x2A`: "Keyboard Delete" KeyboardDelete = 0x2A, /// Usage ID `0x2B`: "Keyboard Tab" KeyboardTab = 0x2B, /// Usage ID `0x2C`: "Keyboard Spacebar" KeyboardSpacebar = 0x2C, /// Usage ID `0x2D`: "Keyboard Dash and Underscore" KeyboardDashandUnderscore = 0x2D, /// Usage ID `0x2E`: "Keyboard Equals and Plus" KeyboardEqualsandPlus = 0x2E, /// Usage ID `0x2F`: "Keyboard Left Brace" KeyboardLeftBrace = 0x2F, /// Usage ID `0x30`: "Keyboard Right Brace" KeyboardRightBrace = 0x30, /// Usage ID `0x31`: "Keyboard Backslash and Pipe" KeyboardBackslashandPipe = 0x31, /// Usage ID `0x32`: "Keyboard Non-US Hash and Tilde" KeyboardNonUSHashandTilde = 0x32, /// Usage ID `0x33`: "Keyboard SemiColon and Colon" KeyboardSemiColonandColon = 0x33, /// Usage ID `0x34`: "Keyboard Left Apos and Double" KeyboardLeftAposandDouble = 0x34, /// Usage ID `0x35`: "Keyboard Grave Accent and Tilde" KeyboardGraveAccentandTilde = 0x35, /// Usage ID `0x36`: "Keyboard Comma and LessThan" KeyboardCommaandLessThan = 0x36, /// Usage ID `0x37`: "Keyboard Period and GreaterThan" KeyboardPeriodandGreaterThan = 0x37, /// Usage ID `0x38`: "Keyboard ForwardSlash and QuestionMark" KeyboardForwardSlashandQuestionMark = 0x38, /// Usage ID `0x39`: "Keyboard Caps Lock" KeyboardCapsLock = 0x39, /// Usage ID `0x3A`: "Keyboard F1" KeyboardF1 = 0x3A, /// Usage ID `0x3B`: "Keyboard F2" KeyboardF2 = 0x3B, /// Usage ID `0x3C`: "Keyboard F3" KeyboardF3 = 0x3C, /// Usage ID `0x3D`: "Keyboard F4" KeyboardF4 = 0x3D, /// Usage ID `0x3E`: "Keyboard F5" KeyboardF5 = 0x3E, /// Usage ID `0x3F`: "Keyboard F6" KeyboardF6 = 0x3F, /// Usage ID `0x40`: "Keyboard F7" KeyboardF7 = 0x40, /// Usage ID `0x41`: "Keyboard F8" KeyboardF8 = 0x41, /// Usage ID `0x42`: "Keyboard F9" KeyboardF9 = 0x42, /// Usage ID `0x43`: "Keyboard F10" KeyboardF10 = 0x43, /// Usage ID `0x44`: "Keyboard F11" KeyboardF11 = 0x44, /// Usage ID `0x45`: "Keyboard F12" KeyboardF12 = 0x45, /// Usage ID `0x46`: "Keyboard PrintScreen" KeyboardPrintScreen = 0x46, /// Usage ID `0x47`: "Keyboard Scroll Lock" KeyboardScrollLock = 0x47, /// Usage ID `0x48`: "Keyboard Pause" KeyboardPause = 0x48, /// Usage ID `0x49`: "Keyboard Insert" KeyboardInsert = 0x49, /// Usage ID `0x4A`: "Keyboard Home" KeyboardHome = 0x4A, /// Usage ID `0x4B`: "Keyboard PageUp" KeyboardPageUp = 0x4B, /// Usage ID `0x4C`: "Keyboard Delete Forward" KeyboardDeleteForward = 0x4C, /// Usage ID `0x4D`: "Keyboard End" KeyboardEnd = 0x4D, /// Usage ID `0x4E`: "Keyboard PageDown" KeyboardPageDown = 0x4E, /// Usage ID `0x4F`: "Keyboard RightArrow" KeyboardRightArrow = 0x4F, /// Usage ID `0x50`: "Keyboard LeftArrow" KeyboardLeftArrow = 0x50, /// Usage ID `0x51`: "Keyboard DownArrow" KeyboardDownArrow = 0x51, /// Usage ID `0x52`: "Keyboard UpArrow" KeyboardUpArrow = 0x52, /// Usage ID `0x53`: "Keypad Num Lock and Clear" KeypadNumLockandClear = 0x53, /// Usage ID `0x54`: "Keypad ForwardSlash" KeypadForwardSlash = 0x54, /// Usage ID `0x55`: "Keypad Star" KeypadStar = 0x55, /// Usage ID `0x56`: "Keypad Dash" KeypadDash = 0x56, /// Usage ID `0x57`: "Keypad Plus" KeypadPlus = 0x57, /// Usage ID `0x58`: "Keypad ENTER" KeypadENTER = 0x58, /// Usage ID `0x59`: "Keypad 1 and End" Keypad1andEnd = 0x59, /// Usage ID `0x5A`: "Keypad 2 and Down Arrow" Keypad2andDownArrow = 0x5A, /// Usage ID `0x5B`: "Keypad 3 and PageDn" Keypad3andPageDn = 0x5B, /// Usage ID `0x5C`: "Keypad 4 and Left Arrow" Keypad4andLeftArrow = 0x5C, /// Usage ID `0x5D`: "Keypad 5" Keypad5 = 0x5D, /// Usage ID `0x5E`: "Keypad 6 and Right Arrow" Keypad6andRightArrow = 0x5E, /// Usage ID `0x5F`: "Keypad 7 and Home" Keypad7andHome = 0x5F, /// Usage ID `0x60`: "Keypad 8 and Up Arrow" Keypad8andUpArrow = 0x60, /// Usage ID `0x61`: "Keypad 9 and PageUp" Keypad9andPageUp = 0x61, /// Usage ID `0x62`: "Keypad 0 and Insert" Keypad0andInsert = 0x62, /// Usage ID `0x63`: "Keypad Period and Delete" KeypadPeriodandDelete = 0x63, /// Usage ID `0x64`: "Keyboard Non-US Backslash and Pipe" KeyboardNonUSBackslashandPipe = 0x64, /// Usage ID `0x65`: "Keyboard Application" KeyboardApplication = 0x65, /// Usage ID `0x66`: "Keyboard Power" KeyboardPower = 0x66, /// Usage ID `0x67`: "Keypad Equals" KeypadEquals = 0x67, /// Usage ID `0x68`: "Keyboard F13" KeyboardF13 = 0x68, /// Usage ID `0x69`: "Keyboard F14" KeyboardF14 = 0x69, /// Usage ID `0x6A`: "Keyboard F15" KeyboardF15 = 0x6A, /// Usage ID `0x6B`: "Keyboard F16" KeyboardF16 = 0x6B, /// Usage ID `0x6C`: "Keyboard F17" KeyboardF17 = 0x6C, /// Usage ID `0x6D`: "Keyboard F18" KeyboardF18 = 0x6D, /// Usage ID `0x6E`: "Keyboard F19" KeyboardF19 = 0x6E, /// Usage ID `0x6F`: "Keyboard F20" KeyboardF20 = 0x6F, /// Usage ID `0x70`: "Keyboard F21" KeyboardF21 = 0x70, /// Usage ID `0x71`: "Keyboard F22" KeyboardF22 = 0x71, /// Usage ID `0x72`: "Keyboard F23" KeyboardF23 = 0x72, /// Usage ID `0x73`: "Keyboard F24" KeyboardF24 = 0x73, /// Usage ID `0x74`: "Keyboard Execute" KeyboardExecute = 0x74, /// Usage ID `0x75`: "Keyboard Help" KeyboardHelp = 0x75, /// Usage ID `0x76`: "Keyboard Menu" KeyboardMenu = 0x76, /// Usage ID `0x77`: "Keyboard Select" KeyboardSelect = 0x77, /// Usage ID `0x78`: "Keyboard Stop" KeyboardStop = 0x78, /// Usage ID `0x79`: "Keyboard Again" KeyboardAgain = 0x79, /// Usage ID `0x7A`: "Keyboard Undo" KeyboardUndo = 0x7A, /// Usage ID `0x7B`: "Keyboard Cut" KeyboardCut = 0x7B, /// Usage ID `0x7C`: "Keyboard Copy" KeyboardCopy = 0x7C, /// Usage ID `0x7D`: "Keyboard Paste" KeyboardPaste = 0x7D, /// Usage ID `0x7E`: "Keyboard Find" KeyboardFind = 0x7E, /// Usage ID `0x7F`: "Keyboard Mute" KeyboardMute = 0x7F, /// Usage ID `0x80`: "Keyboard Volume Up" KeyboardVolumeUp = 0x80, /// Usage ID `0x81`: "Keyboard Volume Down" KeyboardVolumeDown = 0x81, /// Usage ID `0x82`: "Keyboard Locking Caps Lock" KeyboardLockingCapsLock = 0x82, /// Usage ID `0x83`: "Keyboard Locking Num Lock" KeyboardLockingNumLock = 0x83, /// Usage ID `0x84`: "Keyboard Locking Scroll Lock" KeyboardLockingScrollLock = 0x84, /// Usage ID `0x85`: "Keypad Comma" KeypadComma = 0x85, /// Usage ID `0x86`: "Keypad Equal Sign" KeypadEqualSign = 0x86, /// Usage ID `0x87`: "Keyboard International1" KeyboardInternational1 = 0x87, /// Usage ID `0x88`: "Keyboard International2" KeyboardInternational2 = 0x88, /// Usage ID `0x89`: "Keyboard International3" KeyboardInternational3 = 0x89, /// Usage ID `0x8A`: "Keyboard International4" KeyboardInternational4 = 0x8A, /// Usage ID `0x8B`: "Keyboard International5" KeyboardInternational5 = 0x8B, /// Usage ID `0x8C`: "Keyboard International6" KeyboardInternational6 = 0x8C, /// Usage ID `0x8D`: "Keyboard International7" KeyboardInternational7 = 0x8D, /// Usage ID `0x8E`: "Keyboard International8" KeyboardInternational8 = 0x8E, /// Usage ID `0x8F`: "Keyboard International9" KeyboardInternational9 = 0x8F, /// Usage ID `0x90`: "Keyboard LANG1" KeyboardLANG1 = 0x90, /// Usage ID `0x91`: "Keyboard LANG2" KeyboardLANG2 = 0x91, /// Usage ID `0x92`: "Keyboard LANG3" KeyboardLANG3 = 0x92, /// Usage ID `0x93`: "Keyboard LANG4" KeyboardLANG4 = 0x93, /// Usage ID `0x94`: "Keyboard LANG5" KeyboardLANG5 = 0x94, /// Usage ID `0x95`: "Keyboard LANG6" KeyboardLANG6 = 0x95, /// Usage ID `0x96`: "Keyboard LANG7" KeyboardLANG7 = 0x96, /// Usage ID `0x97`: "Keyboard LANG8" KeyboardLANG8 = 0x97, /// Usage ID `0x98`: "Keyboard LANG9" KeyboardLANG9 = 0x98, /// Usage ID `0x99`: "Keyboard Alternate Erase" KeyboardAlternateErase = 0x99, /// Usage ID `0x9A`: "Keyboard SysReq Attention" KeyboardSysReqAttention = 0x9A, /// Usage ID `0x9B`: "Keyboard Cancel" KeyboardCancel = 0x9B, /// Usage ID `0x9C`: "Keyboard Clear" KeyboardClear = 0x9C, /// Usage ID `0x9D`: "Keyboard Prior" KeyboardPrior = 0x9D, /// Usage ID `0x9E`: "Keyboard Return" KeyboardReturn = 0x9E, /// Usage ID `0x9F`: "Keyboard Separator" KeyboardSeparator = 0x9F, /// Usage ID `0xA0`: "Keyboard Out" KeyboardOut = 0xA0, /// Usage ID `0xA1`: "Keyboard Oper" KeyboardOper = 0xA1, /// Usage ID `0xA2`: "Keyboard Clear Again" KeyboardClearAgain = 0xA2, /// Usage ID `0xA3`: "Keyboard CrSel Props" KeyboardCrSelProps = 0xA3, /// Usage ID `0xA4`: "Keyboard ExSel" KeyboardExSel = 0xA4, /// Usage ID `0xB0`: "Keypad Double 0" KeypadDouble0 = 0xB0, /// Usage ID `0xB1`: "Keypad Triple 0" KeypadTriple0 = 0xB1, /// Usage ID `0xB2`: "Thousands Separator" ThousandsSeparator = 0xB2, /// Usage ID `0xB3`: "Decimal Separator" DecimalSeparator = 0xB3, /// Usage ID `0xB4`: "Currency Unit" CurrencyUnit = 0xB4, /// Usage ID `0xB5`: "Currency Sub-unit" CurrencySubunit = 0xB5, /// Usage ID `0xB6`: "Keypad Left Bracket" KeypadLeftBracket = 0xB6, /// Usage ID `0xB7`: "Keypad Right Bracket" KeypadRightBracket = 0xB7, /// Usage ID `0xB8`: "Keypad Left Brace" KeypadLeftBrace = 0xB8, /// Usage ID `0xB9`: "Keypad Right Brace" KeypadRightBrace = 0xB9, /// Usage ID `0xBA`: "Keypad Tab" KeypadTab = 0xBA, /// Usage ID `0xBB`: "Keypad Backspace" KeypadBackspace = 0xBB, /// Usage ID `0xBC`: "Keypad A" KeypadA = 0xBC, /// Usage ID `0xBD`: "Keypad B" KeypadB = 0xBD, /// Usage ID `0xBE`: "Keypad C" KeypadC = 0xBE, /// Usage ID `0xBF`: "Keypad D" KeypadD = 0xBF, /// Usage ID `0xC0`: "Keypad E" KeypadE = 0xC0, /// Usage ID `0xC1`: "Keypad F" KeypadF = 0xC1, /// Usage ID `0xC2`: "Keypad XOR" KeypadXOR = 0xC2, /// Usage ID `0xC3`: "Keypad Caret" KeypadCaret = 0xC3, /// Usage ID `0xC4`: "Keypad Percentage" KeypadPercentage = 0xC4, /// Usage ID `0xC5`: "Keypad Less" KeypadLess = 0xC5, /// Usage ID `0xC6`: "Keypad Greater" KeypadGreater = 0xC6, /// Usage ID `0xC7`: "Keypad Ampersand" KeypadAmpersand = 0xC7, /// Usage ID `0xC8`: "Keypad Double Ampersand" KeypadDoubleAmpersand = 0xC8, /// Usage ID `0xC9`: "Keypad Bar" KeypadBar = 0xC9, /// Usage ID `0xCA`: "Keypad Double Bar" KeypadDoubleBar = 0xCA, /// Usage ID `0xCB`: "Keypad Colon" KeypadColon = 0xCB, /// Usage ID `0xCC`: "Keypad Hash" KeypadHash = 0xCC, /// Usage ID `0xCD`: "Keypad Space" KeypadSpace = 0xCD, /// Usage ID `0xCE`: "Keypad At" KeypadAt = 0xCE, /// Usage ID `0xCF`: "Keypad Bang" KeypadBang = 0xCF, /// Usage ID `0xD0`: "Keypad Memory Store" KeypadMemoryStore = 0xD0, /// Usage ID `0xD1`: "Keypad Memory Recall" KeypadMemoryRecall = 0xD1, /// Usage ID `0xD2`: "Keypad Memory Clear" KeypadMemoryClear = 0xD2, /// Usage ID `0xD3`: "Keypad Memory Add" KeypadMemoryAdd = 0xD3, /// Usage ID `0xD4`: "Keypad Memory Subtract" KeypadMemorySubtract = 0xD4, /// Usage ID `0xD5`: "Keypad Memory Multiply" KeypadMemoryMultiply = 0xD5, /// Usage ID `0xD6`: "Keypad Memory Divide" KeypadMemoryDivide = 0xD6, /// Usage ID `0xD7`: "Keypad Plus Minus" KeypadPlusMinus = 0xD7, /// Usage ID `0xD8`: "Keypad Clear" KeypadClear = 0xD8, /// Usage ID `0xD9`: "Keypad Clear Entry" KeypadClearEntry = 0xD9, /// Usage ID `0xDA`: "Keypad Binary" KeypadBinary = 0xDA, /// Usage ID `0xDB`: "Keypad Octal" KeypadOctal = 0xDB, /// Usage ID `0xDC`: "Keypad Decimal" KeypadDecimal = 0xDC, /// Usage ID `0xDD`: "Keypad Hexadecimal" KeypadHexadecimal = 0xDD, /// Usage ID `0xE0`: "Keyboard LeftControl" KeyboardLeftControl = 0xE0, /// Usage ID `0xE1`: "Keyboard LeftShift" KeyboardLeftShift = 0xE1, /// Usage ID `0xE2`: "Keyboard LeftAlt" KeyboardLeftAlt = 0xE2, /// Usage ID `0xE3`: "Keyboard Left GUI" KeyboardLeftGUI = 0xE3, /// Usage ID `0xE4`: "Keyboard RightControl" KeyboardRightControl = 0xE4, /// Usage ID `0xE5`: "Keyboard RightShift" KeyboardRightShift = 0xE5, /// Usage ID `0xE6`: "Keyboard RightAlt" KeyboardRightAlt = 0xE6, /// Usage ID `0xE7`: "Keyboard Right GUI" KeyboardRightGUI = 0xE7, } impl KeyboardKeypad { #[cfg(feature = "std")] pub fn name(&self) -> String { match self { KeyboardKeypad::ErrorRollOver => "ErrorRollOver", KeyboardKeypad::POSTFail => "POSTFail", KeyboardKeypad::ErrorUndefined => "ErrorUndefined", KeyboardKeypad::KeyboardA => "Keyboard A", KeyboardKeypad::KeyboardB => "Keyboard B", KeyboardKeypad::KeyboardC => "Keyboard C", KeyboardKeypad::KeyboardD => "Keyboard D", KeyboardKeypad::KeyboardE => "Keyboard E", KeyboardKeypad::KeyboardF => "Keyboard F", KeyboardKeypad::KeyboardG => "Keyboard G", KeyboardKeypad::KeyboardH => "Keyboard H", KeyboardKeypad::KeyboardI => "Keyboard I", KeyboardKeypad::KeyboardJ => "Keyboard J", KeyboardKeypad::KeyboardK => "Keyboard K", KeyboardKeypad::KeyboardL => "Keyboard L", KeyboardKeypad::KeyboardM => "Keyboard M", KeyboardKeypad::KeyboardN => "Keyboard N", KeyboardKeypad::KeyboardO => "Keyboard O", KeyboardKeypad::KeyboardP => "Keyboard P", KeyboardKeypad::KeyboardQ => "Keyboard Q", KeyboardKeypad::KeyboardR => "Keyboard R", KeyboardKeypad::KeyboardS => "Keyboard S", KeyboardKeypad::KeyboardT => "Keyboard T", KeyboardKeypad::KeyboardU => "Keyboard U", KeyboardKeypad::KeyboardV => "Keyboard V", KeyboardKeypad::KeyboardW => "Keyboard W", KeyboardKeypad::KeyboardX => "Keyboard X", KeyboardKeypad::KeyboardY => "Keyboard Y", KeyboardKeypad::KeyboardZ => "Keyboard Z", KeyboardKeypad::Keyboard1andBang => "Keyboard 1 and Bang", KeyboardKeypad::Keyboard2andAt => "Keyboard 2 and At", KeyboardKeypad::Keyboard3andHash => "Keyboard 3 and Hash", KeyboardKeypad::Keyboard4andDollar => "Keyboard 4 and Dollar", KeyboardKeypad::Keyboard5andPercent => "Keyboard 5 and Percent", KeyboardKeypad::Keyboard6andCaret => "Keyboard 6 and Caret", KeyboardKeypad::Keyboard7andAmpersand => "Keyboard 7 and Ampersand", KeyboardKeypad::Keyboard8andStar => "Keyboard 8 and Star", KeyboardKeypad::Keyboard9andLeftBracket => "Keyboard 9 and Left Bracket", KeyboardKeypad::Keyboard0andRightBracket => "Keyboard 0 and Right Bracket", KeyboardKeypad::KeyboardReturnEnter => "Keyboard Return Enter", KeyboardKeypad::KeyboardEscape => "Keyboard Escape", KeyboardKeypad::KeyboardDelete => "Keyboard Delete", KeyboardKeypad::KeyboardTab => "Keyboard Tab", KeyboardKeypad::KeyboardSpacebar => "Keyboard Spacebar", KeyboardKeypad::KeyboardDashandUnderscore => "Keyboard Dash and Underscore", KeyboardKeypad::KeyboardEqualsandPlus => "Keyboard Equals and Plus", KeyboardKeypad::KeyboardLeftBrace => "Keyboard Left Brace", KeyboardKeypad::KeyboardRightBrace => "Keyboard Right Brace", KeyboardKeypad::KeyboardBackslashandPipe => "Keyboard Backslash and Pipe", KeyboardKeypad::KeyboardNonUSHashandTilde => "Keyboard Non-US Hash and Tilde", KeyboardKeypad::KeyboardSemiColonandColon => "Keyboard SemiColon and Colon", KeyboardKeypad::KeyboardLeftAposandDouble => "Keyboard Left Apos and Double", KeyboardKeypad::KeyboardGraveAccentandTilde => "Keyboard Grave Accent and Tilde", KeyboardKeypad::KeyboardCommaandLessThan => "Keyboard Comma and LessThan", KeyboardKeypad::KeyboardPeriodandGreaterThan => "Keyboard Period and GreaterThan", KeyboardKeypad::KeyboardForwardSlashandQuestionMark => { "Keyboard ForwardSlash and QuestionMark" } KeyboardKeypad::KeyboardCapsLock => "Keyboard Caps Lock", KeyboardKeypad::KeyboardF1 => "Keyboard F1", KeyboardKeypad::KeyboardF2 => "Keyboard F2", KeyboardKeypad::KeyboardF3 => "Keyboard F3", KeyboardKeypad::KeyboardF4 => "Keyboard F4", KeyboardKeypad::KeyboardF5 => "Keyboard F5", KeyboardKeypad::KeyboardF6 => "Keyboard F6", KeyboardKeypad::KeyboardF7 => "Keyboard F7", KeyboardKeypad::KeyboardF8 => "Keyboard F8", KeyboardKeypad::KeyboardF9 => "Keyboard F9", KeyboardKeypad::KeyboardF10 => "Keyboard F10", KeyboardKeypad::KeyboardF11 => "Keyboard F11", KeyboardKeypad::KeyboardF12 => "Keyboard F12", KeyboardKeypad::KeyboardPrintScreen => "Keyboard PrintScreen", KeyboardKeypad::KeyboardScrollLock => "Keyboard Scroll Lock", KeyboardKeypad::KeyboardPause => "Keyboard Pause", KeyboardKeypad::KeyboardInsert => "Keyboard Insert", KeyboardKeypad::KeyboardHome => "Keyboard Home", KeyboardKeypad::KeyboardPageUp => "Keyboard PageUp", KeyboardKeypad::KeyboardDeleteForward => "Keyboard Delete Forward", KeyboardKeypad::KeyboardEnd => "Keyboard End", KeyboardKeypad::KeyboardPageDown => "Keyboard PageDown", KeyboardKeypad::KeyboardRightArrow => "Keyboard RightArrow", KeyboardKeypad::KeyboardLeftArrow => "Keyboard LeftArrow", KeyboardKeypad::KeyboardDownArrow => "Keyboard DownArrow", KeyboardKeypad::KeyboardUpArrow => "Keyboard UpArrow", KeyboardKeypad::KeypadNumLockandClear => "Keypad Num Lock and Clear", KeyboardKeypad::KeypadForwardSlash => "Keypad ForwardSlash", KeyboardKeypad::KeypadStar => "Keypad Star", KeyboardKeypad::KeypadDash => "Keypad Dash", KeyboardKeypad::KeypadPlus => "Keypad Plus", KeyboardKeypad::KeypadENTER => "Keypad ENTER", KeyboardKeypad::Keypad1andEnd => "Keypad 1 and End", KeyboardKeypad::Keypad2andDownArrow => "Keypad 2 and Down Arrow", KeyboardKeypad::Keypad3andPageDn => "Keypad 3 and PageDn", KeyboardKeypad::Keypad4andLeftArrow => "Keypad 4 and Left Arrow", KeyboardKeypad::Keypad5 => "Keypad 5", KeyboardKeypad::Keypad6andRightArrow => "Keypad 6 and Right Arrow", KeyboardKeypad::Keypad7andHome => "Keypad 7 and Home", KeyboardKeypad::Keypad8andUpArrow => "Keypad 8 and Up Arrow", KeyboardKeypad::Keypad9andPageUp => "Keypad 9 and PageUp", KeyboardKeypad::Keypad0andInsert => "Keypad 0 and Insert", KeyboardKeypad::KeypadPeriodandDelete => "Keypad Period and Delete", KeyboardKeypad::KeyboardNonUSBackslashandPipe => "Keyboard Non-US Backslash and Pipe", KeyboardKeypad::KeyboardApplication => "Keyboard Application", KeyboardKeypad::KeyboardPower => "Keyboard Power", KeyboardKeypad::KeypadEquals => "Keypad Equals", KeyboardKeypad::KeyboardF13 => "Keyboard F13", KeyboardKeypad::KeyboardF14 => "Keyboard F14", KeyboardKeypad::KeyboardF15 => "Keyboard F15", KeyboardKeypad::KeyboardF16 => "Keyboard F16", KeyboardKeypad::KeyboardF17 => "Keyboard F17", KeyboardKeypad::KeyboardF18 => "Keyboard F18", KeyboardKeypad::KeyboardF19 => "Keyboard F19", KeyboardKeypad::KeyboardF20 => "Keyboard F20", KeyboardKeypad::KeyboardF21 => "Keyboard F21", KeyboardKeypad::KeyboardF22 => "Keyboard F22", KeyboardKeypad::KeyboardF23 => "Keyboard F23", KeyboardKeypad::KeyboardF24 => "Keyboard F24", KeyboardKeypad::KeyboardExecute => "Keyboard Execute", KeyboardKeypad::KeyboardHelp => "Keyboard Help", KeyboardKeypad::KeyboardMenu => "Keyboard Menu", KeyboardKeypad::KeyboardSelect => "Keyboard Select", KeyboardKeypad::KeyboardStop => "Keyboard Stop", KeyboardKeypad::KeyboardAgain => "Keyboard Again", KeyboardKeypad::KeyboardUndo => "Keyboard Undo", KeyboardKeypad::KeyboardCut => "Keyboard Cut", KeyboardKeypad::KeyboardCopy => "Keyboard Copy", KeyboardKeypad::KeyboardPaste => "Keyboard Paste", KeyboardKeypad::KeyboardFind => "Keyboard Find", KeyboardKeypad::KeyboardMute => "Keyboard Mute", KeyboardKeypad::KeyboardVolumeUp => "Keyboard Volume Up", KeyboardKeypad::KeyboardVolumeDown => "Keyboard Volume Down", KeyboardKeypad::KeyboardLockingCapsLock => "Keyboard Locking Caps Lock", KeyboardKeypad::KeyboardLockingNumLock => "Keyboard Locking Num Lock", KeyboardKeypad::KeyboardLockingScrollLock => "Keyboard Locking Scroll Lock", KeyboardKeypad::KeypadComma => "Keypad Comma", KeyboardKeypad::KeypadEqualSign => "Keypad Equal Sign", KeyboardKeypad::KeyboardInternational1 => "Keyboard International1", KeyboardKeypad::KeyboardInternational2 => "Keyboard International2", KeyboardKeypad::KeyboardInternational3 => "Keyboard International3", KeyboardKeypad::KeyboardInternational4 => "Keyboard International4", KeyboardKeypad::KeyboardInternational5 => "Keyboard International5", KeyboardKeypad::KeyboardInternational6 => "Keyboard International6", KeyboardKeypad::KeyboardInternational7 => "Keyboard International7", KeyboardKeypad::KeyboardInternational8 => "Keyboard International8", KeyboardKeypad::KeyboardInternational9 => "Keyboard International9", KeyboardKeypad::KeyboardLANG1 => "Keyboard LANG1", KeyboardKeypad::KeyboardLANG2 => "Keyboard LANG2", KeyboardKeypad::KeyboardLANG3 => "Keyboard LANG3", KeyboardKeypad::KeyboardLANG4 => "Keyboard LANG4", KeyboardKeypad::KeyboardLANG5 => "Keyboard LANG5", KeyboardKeypad::KeyboardLANG6 => "Keyboard LANG6", KeyboardKeypad::KeyboardLANG7 => "Keyboard LANG7", KeyboardKeypad::KeyboardLANG8 => "Keyboard LANG8", KeyboardKeypad::KeyboardLANG9 => "Keyboard LANG9", KeyboardKeypad::KeyboardAlternateErase => "Keyboard Alternate Erase", KeyboardKeypad::KeyboardSysReqAttention => "Keyboard SysReq Attention", KeyboardKeypad::KeyboardCancel => "Keyboard Cancel", KeyboardKeypad::KeyboardClear => "Keyboard Clear", KeyboardKeypad::KeyboardPrior => "Keyboard Prior", KeyboardKeypad::KeyboardReturn => "Keyboard Return", KeyboardKeypad::KeyboardSeparator => "Keyboard Separator", KeyboardKeypad::KeyboardOut => "Keyboard Out", KeyboardKeypad::KeyboardOper => "Keyboard Oper", KeyboardKeypad::KeyboardClearAgain => "Keyboard Clear Again", KeyboardKeypad::KeyboardCrSelProps => "Keyboard CrSel Props", KeyboardKeypad::KeyboardExSel => "Keyboard ExSel", KeyboardKeypad::KeypadDouble0 => "Keypad Double 0", KeyboardKeypad::KeypadTriple0 => "Keypad Triple 0", KeyboardKeypad::ThousandsSeparator => "Thousands Separator", KeyboardKeypad::DecimalSeparator => "Decimal Separator", KeyboardKeypad::CurrencyUnit => "Currency Unit", KeyboardKeypad::CurrencySubunit => "Currency Sub-unit", KeyboardKeypad::KeypadLeftBracket => "Keypad Left Bracket", KeyboardKeypad::KeypadRightBracket => "Keypad Right Bracket", KeyboardKeypad::KeypadLeftBrace => "Keypad Left Brace", KeyboardKeypad::KeypadRightBrace => "Keypad Right Brace", KeyboardKeypad::KeypadTab => "Keypad Tab", KeyboardKeypad::KeypadBackspace => "Keypad Backspace", KeyboardKeypad::KeypadA => "Keypad A", KeyboardKeypad::KeypadB => "Keypad B", KeyboardKeypad::KeypadC => "Keypad C", KeyboardKeypad::KeypadD => "Keypad D", KeyboardKeypad::KeypadE => "Keypad E", KeyboardKeypad::KeypadF => "Keypad F", KeyboardKeypad::KeypadXOR => "Keypad XOR", KeyboardKeypad::KeypadCaret => "Keypad Caret", KeyboardKeypad::KeypadPercentage => "Keypad Percentage", KeyboardKeypad::KeypadLess => "Keypad Less", KeyboardKeypad::KeypadGreater => "Keypad Greater", KeyboardKeypad::KeypadAmpersand => "Keypad Ampersand", KeyboardKeypad::KeypadDoubleAmpersand => "Keypad Double Ampersand", KeyboardKeypad::KeypadBar => "Keypad Bar", KeyboardKeypad::KeypadDoubleBar => "Keypad Double Bar", KeyboardKeypad::KeypadColon => "Keypad Colon", KeyboardKeypad::KeypadHash => "Keypad Hash", KeyboardKeypad::KeypadSpace => "Keypad Space", KeyboardKeypad::KeypadAt => "Keypad At", KeyboardKeypad::KeypadBang => "Keypad Bang", KeyboardKeypad::KeypadMemoryStore => "Keypad Memory Store", KeyboardKeypad::KeypadMemoryRecall => "Keypad Memory Recall", KeyboardKeypad::KeypadMemoryClear => "Keypad Memory Clear", KeyboardKeypad::KeypadMemoryAdd => "Keypad Memory Add", KeyboardKeypad::KeypadMemorySubtract => "Keypad Memory Subtract", KeyboardKeypad::KeypadMemoryMultiply => "Keypad Memory Multiply", KeyboardKeypad::KeypadMemoryDivide => "Keypad Memory Divide", KeyboardKeypad::KeypadPlusMinus => "Keypad Plus Minus", KeyboardKeypad::KeypadClear => "Keypad Clear", KeyboardKeypad::KeypadClearEntry => "Keypad Clear Entry", KeyboardKeypad::KeypadBinary => "Keypad Binary", KeyboardKeypad::KeypadOctal => "Keypad Octal", KeyboardKeypad::KeypadDecimal => "Keypad Decimal", KeyboardKeypad::KeypadHexadecimal => "Keypad Hexadecimal", KeyboardKeypad::KeyboardLeftControl => "Keyboard LeftControl", KeyboardKeypad::KeyboardLeftShift => "Keyboard LeftShift", KeyboardKeypad::KeyboardLeftAlt => "Keyboard LeftAlt", KeyboardKeypad::KeyboardLeftGUI => "Keyboard Left GUI", KeyboardKeypad::KeyboardRightControl => "Keyboard RightControl", KeyboardKeypad::KeyboardRightShift => "Keyboard RightShift", KeyboardKeypad::KeyboardRightAlt => "Keyboard RightAlt", KeyboardKeypad::KeyboardRightGUI => "Keyboard Right GUI", } .into() } } #[cfg(feature = "std")] impl fmt::Display for KeyboardKeypad { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name()) } } impl AsUsage for KeyboardKeypad { /// Returns the 32 bit Usage value of this Usage fn usage_value(&self) -> u32 { u32::from(self) } /// Returns the 16 bit Usage ID value of this Usage fn usage_id_value(&self) -> u16 { u16::from(self) } /// Returns this usage as [Usage::KeyboardKeypad(self)](Usage::KeyboardKeypad) /// This is a convenience function to avoid having /// to implement `From` for every used type in the caller. /// /// ``` /// # use hut::*; /// let gd_x = GenericDesktop::X; /// let usage = Usage::from(GenericDesktop::X); /// assert!(matches!(gd_x.usage(), usage)); /// ``` fn usage(&self) -> Usage { Usage::from(self) } } impl AsUsagePage for KeyboardKeypad { /// Returns the 16 bit value of this UsagePage /// /// This value is `0x7` for [KeyboardKeypad] fn usage_page_value(&self) -> u16 { let up = UsagePage::from(self); u16::from(up) } /// Returns [UsagePage::KeyboardKeypad]] fn usage_page(&self) -> UsagePage { UsagePage::from(self) } } impl From<&KeyboardKeypad> for u16 { fn from(keyboardkeypad: &KeyboardKeypad) -> u16 { *keyboardkeypad as u16 } } impl From for u16 { /// Returns the 16bit value of this usage. This is identical /// to [KeyboardKeypad::usage_page_value()]. fn from(keyboardkeypad: KeyboardKeypad) -> u16 { u16::from(&keyboardkeypad) } } impl From<&KeyboardKeypad> for u32 { /// Returns the 32 bit value of this usage. This is identical /// to [KeyboardKeypad::usage_value()]. fn from(keyboardkeypad: &KeyboardKeypad) -> u32 { let up = UsagePage::from(keyboardkeypad); let up = (u16::from(&up) as u32) << 16; let id = u16::from(keyboardkeypad) as u32; up | id } } impl From<&KeyboardKeypad> for UsagePage { /// Always returns [UsagePage::KeyboardKeypad] and is /// identical to [KeyboardKeypad::usage_page()]. fn from(_: &KeyboardKeypad) -> UsagePage { UsagePage::KeyboardKeypad } } impl From for UsagePage { /// Always returns [UsagePage::KeyboardKeypad] and is /// identical to [KeyboardKeypad::usage_page()]. fn from(_: KeyboardKeypad) -> UsagePage { UsagePage::KeyboardKeypad } } impl From<&KeyboardKeypad> for Usage { fn from(keyboardkeypad: &KeyboardKeypad) -> Usage { Usage::try_from(u32::from(keyboardkeypad)).unwrap() } } impl From for Usage { fn from(keyboardkeypad: KeyboardKeypad) -> Usage { Usage::from(&keyboardkeypad) } } impl TryFrom for KeyboardKeypad { type Error = HutError; fn try_from(usage_id: u16) -> Result { match usage_id { 1 => Ok(KeyboardKeypad::ErrorRollOver), 2 => Ok(KeyboardKeypad::POSTFail), 3 => Ok(KeyboardKeypad::ErrorUndefined), 4 => Ok(KeyboardKeypad::KeyboardA), 5 => Ok(KeyboardKeypad::KeyboardB), 6 => Ok(KeyboardKeypad::KeyboardC), 7 => Ok(KeyboardKeypad::KeyboardD), 8 => Ok(KeyboardKeypad::KeyboardE), 9 => Ok(KeyboardKeypad::KeyboardF), 10 => Ok(KeyboardKeypad::KeyboardG), 11 => Ok(KeyboardKeypad::KeyboardH), 12 => Ok(KeyboardKeypad::KeyboardI), 13 => Ok(KeyboardKeypad::KeyboardJ), 14 => Ok(KeyboardKeypad::KeyboardK), 15 => Ok(KeyboardKeypad::KeyboardL), 16 => Ok(KeyboardKeypad::KeyboardM), 17 => Ok(KeyboardKeypad::KeyboardN), 18 => Ok(KeyboardKeypad::KeyboardO), 19 => Ok(KeyboardKeypad::KeyboardP), 20 => Ok(KeyboardKeypad::KeyboardQ), 21 => Ok(KeyboardKeypad::KeyboardR), 22 => Ok(KeyboardKeypad::KeyboardS), 23 => Ok(KeyboardKeypad::KeyboardT), 24 => Ok(KeyboardKeypad::KeyboardU), 25 => Ok(KeyboardKeypad::KeyboardV), 26 => Ok(KeyboardKeypad::KeyboardW), 27 => Ok(KeyboardKeypad::KeyboardX), 28 => Ok(KeyboardKeypad::KeyboardY), 29 => Ok(KeyboardKeypad::KeyboardZ), 30 => Ok(KeyboardKeypad::Keyboard1andBang), 31 => Ok(KeyboardKeypad::Keyboard2andAt), 32 => Ok(KeyboardKeypad::Keyboard3andHash), 33 => Ok(KeyboardKeypad::Keyboard4andDollar), 34 => Ok(KeyboardKeypad::Keyboard5andPercent), 35 => Ok(KeyboardKeypad::Keyboard6andCaret), 36 => Ok(KeyboardKeypad::Keyboard7andAmpersand), 37 => Ok(KeyboardKeypad::Keyboard8andStar), 38 => Ok(KeyboardKeypad::Keyboard9andLeftBracket), 39 => Ok(KeyboardKeypad::Keyboard0andRightBracket), 40 => Ok(KeyboardKeypad::KeyboardReturnEnter), 41 => Ok(KeyboardKeypad::KeyboardEscape), 42 => Ok(KeyboardKeypad::KeyboardDelete), 43 => Ok(KeyboardKeypad::KeyboardTab), 44 => Ok(KeyboardKeypad::KeyboardSpacebar), 45 => Ok(KeyboardKeypad::KeyboardDashandUnderscore), 46 => Ok(KeyboardKeypad::KeyboardEqualsandPlus), 47 => Ok(KeyboardKeypad::KeyboardLeftBrace), 48 => Ok(KeyboardKeypad::KeyboardRightBrace), 49 => Ok(KeyboardKeypad::KeyboardBackslashandPipe), 50 => Ok(KeyboardKeypad::KeyboardNonUSHashandTilde), 51 => Ok(KeyboardKeypad::KeyboardSemiColonandColon), 52 => Ok(KeyboardKeypad::KeyboardLeftAposandDouble), 53 => Ok(KeyboardKeypad::KeyboardGraveAccentandTilde), 54 => Ok(KeyboardKeypad::KeyboardCommaandLessThan), 55 => Ok(KeyboardKeypad::KeyboardPeriodandGreaterThan), 56 => Ok(KeyboardKeypad::KeyboardForwardSlashandQuestionMark), 57 => Ok(KeyboardKeypad::KeyboardCapsLock), 58 => Ok(KeyboardKeypad::KeyboardF1), 59 => Ok(KeyboardKeypad::KeyboardF2), 60 => Ok(KeyboardKeypad::KeyboardF3), 61 => Ok(KeyboardKeypad::KeyboardF4), 62 => Ok(KeyboardKeypad::KeyboardF5), 63 => Ok(KeyboardKeypad::KeyboardF6), 64 => Ok(KeyboardKeypad::KeyboardF7), 65 => Ok(KeyboardKeypad::KeyboardF8), 66 => Ok(KeyboardKeypad::KeyboardF9), 67 => Ok(KeyboardKeypad::KeyboardF10), 68 => Ok(KeyboardKeypad::KeyboardF11), 69 => Ok(KeyboardKeypad::KeyboardF12), 70 => Ok(KeyboardKeypad::KeyboardPrintScreen), 71 => Ok(KeyboardKeypad::KeyboardScrollLock), 72 => Ok(KeyboardKeypad::KeyboardPause), 73 => Ok(KeyboardKeypad::KeyboardInsert), 74 => Ok(KeyboardKeypad::KeyboardHome), 75 => Ok(KeyboardKeypad::KeyboardPageUp), 76 => Ok(KeyboardKeypad::KeyboardDeleteForward), 77 => Ok(KeyboardKeypad::KeyboardEnd), 78 => Ok(KeyboardKeypad::KeyboardPageDown), 79 => Ok(KeyboardKeypad::KeyboardRightArrow), 80 => Ok(KeyboardKeypad::KeyboardLeftArrow), 81 => Ok(KeyboardKeypad::KeyboardDownArrow), 82 => Ok(KeyboardKeypad::KeyboardUpArrow), 83 => Ok(KeyboardKeypad::KeypadNumLockandClear), 84 => Ok(KeyboardKeypad::KeypadForwardSlash), 85 => Ok(KeyboardKeypad::KeypadStar), 86 => Ok(KeyboardKeypad::KeypadDash), 87 => Ok(KeyboardKeypad::KeypadPlus), 88 => Ok(KeyboardKeypad::KeypadENTER), 89 => Ok(KeyboardKeypad::Keypad1andEnd), 90 => Ok(KeyboardKeypad::Keypad2andDownArrow), 91 => Ok(KeyboardKeypad::Keypad3andPageDn), 92 => Ok(KeyboardKeypad::Keypad4andLeftArrow), 93 => Ok(KeyboardKeypad::Keypad5), 94 => Ok(KeyboardKeypad::Keypad6andRightArrow), 95 => Ok(KeyboardKeypad::Keypad7andHome), 96 => Ok(KeyboardKeypad::Keypad8andUpArrow), 97 => Ok(KeyboardKeypad::Keypad9andPageUp), 98 => Ok(KeyboardKeypad::Keypad0andInsert), 99 => Ok(KeyboardKeypad::KeypadPeriodandDelete), 100 => Ok(KeyboardKeypad::KeyboardNonUSBackslashandPipe), 101 => Ok(KeyboardKeypad::KeyboardApplication), 102 => Ok(KeyboardKeypad::KeyboardPower), 103 => Ok(KeyboardKeypad::KeypadEquals), 104 => Ok(KeyboardKeypad::KeyboardF13), 105 => Ok(KeyboardKeypad::KeyboardF14), 106 => Ok(KeyboardKeypad::KeyboardF15), 107 => Ok(KeyboardKeypad::KeyboardF16), 108 => Ok(KeyboardKeypad::KeyboardF17), 109 => Ok(KeyboardKeypad::KeyboardF18), 110 => Ok(KeyboardKeypad::KeyboardF19), 111 => Ok(KeyboardKeypad::KeyboardF20), 112 => Ok(KeyboardKeypad::KeyboardF21), 113 => Ok(KeyboardKeypad::KeyboardF22), 114 => Ok(KeyboardKeypad::KeyboardF23), 115 => Ok(KeyboardKeypad::KeyboardF24), 116 => Ok(KeyboardKeypad::KeyboardExecute), 117 => Ok(KeyboardKeypad::KeyboardHelp), 118 => Ok(KeyboardKeypad::KeyboardMenu), 119 => Ok(KeyboardKeypad::KeyboardSelect), 120 => Ok(KeyboardKeypad::KeyboardStop), 121 => Ok(KeyboardKeypad::KeyboardAgain), 122 => Ok(KeyboardKeypad::KeyboardUndo), 123 => Ok(KeyboardKeypad::KeyboardCut), 124 => Ok(KeyboardKeypad::KeyboardCopy), 125 => Ok(KeyboardKeypad::KeyboardPaste), 126 => Ok(KeyboardKeypad::KeyboardFind), 127 => Ok(KeyboardKeypad::KeyboardMute), 128 => Ok(KeyboardKeypad::KeyboardVolumeUp), 129 => Ok(KeyboardKeypad::KeyboardVolumeDown), 130 => Ok(KeyboardKeypad::KeyboardLockingCapsLock), 131 => Ok(KeyboardKeypad::KeyboardLockingNumLock), 132 => Ok(KeyboardKeypad::KeyboardLockingScrollLock), 133 => Ok(KeyboardKeypad::KeypadComma), 134 => Ok(KeyboardKeypad::KeypadEqualSign), 135 => Ok(KeyboardKeypad::KeyboardInternational1), 136 => Ok(KeyboardKeypad::KeyboardInternational2), 137 => Ok(KeyboardKeypad::KeyboardInternational3), 138 => Ok(KeyboardKeypad::KeyboardInternational4), 139 => Ok(KeyboardKeypad::KeyboardInternational5), 140 => Ok(KeyboardKeypad::KeyboardInternational6), 141 => Ok(KeyboardKeypad::KeyboardInternational7), 142 => Ok(KeyboardKeypad::KeyboardInternational8), 143 => Ok(KeyboardKeypad::KeyboardInternational9), 144 => Ok(KeyboardKeypad::KeyboardLANG1), 145 => Ok(KeyboardKeypad::KeyboardLANG2), 146 => Ok(KeyboardKeypad::KeyboardLANG3), 147 => Ok(KeyboardKeypad::KeyboardLANG4), 148 => Ok(KeyboardKeypad::KeyboardLANG5), 149 => Ok(KeyboardKeypad::KeyboardLANG6), 150 => Ok(KeyboardKeypad::KeyboardLANG7), 151 => Ok(KeyboardKeypad::KeyboardLANG8), 152 => Ok(KeyboardKeypad::KeyboardLANG9), 153 => Ok(KeyboardKeypad::KeyboardAlternateErase), 154 => Ok(KeyboardKeypad::KeyboardSysReqAttention), 155 => Ok(KeyboardKeypad::KeyboardCancel), 156 => Ok(KeyboardKeypad::KeyboardClear), 157 => Ok(KeyboardKeypad::KeyboardPrior), 158 => Ok(KeyboardKeypad::KeyboardReturn), 159 => Ok(KeyboardKeypad::KeyboardSeparator), 160 => Ok(KeyboardKeypad::KeyboardOut), 161 => Ok(KeyboardKeypad::KeyboardOper), 162 => Ok(KeyboardKeypad::KeyboardClearAgain), 163 => Ok(KeyboardKeypad::KeyboardCrSelProps), 164 => Ok(KeyboardKeypad::KeyboardExSel), 176 => Ok(KeyboardKeypad::KeypadDouble0), 177 => Ok(KeyboardKeypad::KeypadTriple0), 178 => Ok(KeyboardKeypad::ThousandsSeparator), 179 => Ok(KeyboardKeypad::DecimalSeparator), 180 => Ok(KeyboardKeypad::CurrencyUnit), 181 => Ok(KeyboardKeypad::CurrencySubunit), 182 => Ok(KeyboardKeypad::KeypadLeftBracket), 183 => Ok(KeyboardKeypad::KeypadRightBracket), 184 => Ok(KeyboardKeypad::KeypadLeftBrace), 185 => Ok(KeyboardKeypad::KeypadRightBrace), 186 => Ok(KeyboardKeypad::KeypadTab), 187 => Ok(KeyboardKeypad::KeypadBackspace), 188 => Ok(KeyboardKeypad::KeypadA), 189 => Ok(KeyboardKeypad::KeypadB), 190 => Ok(KeyboardKeypad::KeypadC), 191 => Ok(KeyboardKeypad::KeypadD), 192 => Ok(KeyboardKeypad::KeypadE), 193 => Ok(KeyboardKeypad::KeypadF), 194 => Ok(KeyboardKeypad::KeypadXOR), 195 => Ok(KeyboardKeypad::KeypadCaret), 196 => Ok(KeyboardKeypad::KeypadPercentage), 197 => Ok(KeyboardKeypad::KeypadLess), 198 => Ok(KeyboardKeypad::KeypadGreater), 199 => Ok(KeyboardKeypad::KeypadAmpersand), 200 => Ok(KeyboardKeypad::KeypadDoubleAmpersand), 201 => Ok(KeyboardKeypad::KeypadBar), 202 => Ok(KeyboardKeypad::KeypadDoubleBar), 203 => Ok(KeyboardKeypad::KeypadColon), 204 => Ok(KeyboardKeypad::KeypadHash), 205 => Ok(KeyboardKeypad::KeypadSpace), 206 => Ok(KeyboardKeypad::KeypadAt), 207 => Ok(KeyboardKeypad::KeypadBang), 208 => Ok(KeyboardKeypad::KeypadMemoryStore), 209 => Ok(KeyboardKeypad::KeypadMemoryRecall), 210 => Ok(KeyboardKeypad::KeypadMemoryClear), 211 => Ok(KeyboardKeypad::KeypadMemoryAdd), 212 => Ok(KeyboardKeypad::KeypadMemorySubtract), 213 => Ok(KeyboardKeypad::KeypadMemoryMultiply), 214 => Ok(KeyboardKeypad::KeypadMemoryDivide), 215 => Ok(KeyboardKeypad::KeypadPlusMinus), 216 => Ok(KeyboardKeypad::KeypadClear), 217 => Ok(KeyboardKeypad::KeypadClearEntry), 218 => Ok(KeyboardKeypad::KeypadBinary), 219 => Ok(KeyboardKeypad::KeypadOctal), 220 => Ok(KeyboardKeypad::KeypadDecimal), 221 => Ok(KeyboardKeypad::KeypadHexadecimal), 224 => Ok(KeyboardKeypad::KeyboardLeftControl), 225 => Ok(KeyboardKeypad::KeyboardLeftShift), 226 => Ok(KeyboardKeypad::KeyboardLeftAlt), 227 => Ok(KeyboardKeypad::KeyboardLeftGUI), 228 => Ok(KeyboardKeypad::KeyboardRightControl), 229 => Ok(KeyboardKeypad::KeyboardRightShift), 230 => Ok(KeyboardKeypad::KeyboardRightAlt), 231 => Ok(KeyboardKeypad::KeyboardRightGUI), n => Err(HutError::UnknownUsageId { usage_id: n }), } } } impl BitOr for KeyboardKeypad { type Output = Usage; /// A convenience function to combine a Usage Page with /// a value. /// /// This function panics if the Usage ID value results in /// an unknown Usage. Where error checking is required, /// use [UsagePage::to_usage_from_value]. fn bitor(self, usage: u16) -> Usage { let up = u16::from(self) as u32; let u = usage as u32; Usage::try_from(up | u).expect("Invalid Usage ID for this Usage Page") } } /// *Usage Page `0x8`: "LED"* /// /// **This enum is autogenerated from the HID Usage Tables**. /// ``` /// # use hut::*; /// let u1 = Usage::LED(LED::CapsLock); /// let u2 = Usage::new_from_page_and_id(0x8, 0x2).unwrap(); /// let u3 = Usage::from(LED::CapsLock); /// let u4: Usage = LED::CapsLock.into(); /// assert_eq!(u1, u2); /// assert_eq!(u1, u3); /// assert_eq!(u1, u4); /// /// assert!(matches!(u1.usage_page(), UsagePage::LED)); /// assert_eq!(0x8, u1.usage_page_value()); /// assert_eq!(0x2, u1.usage_id_value()); /// assert_eq!((0x8 << 16) | 0x2, u1.usage_value()); /// assert_eq!("Caps Lock", u1.name()); /// ``` /// #[allow(non_camel_case_types)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[non_exhaustive] #[repr(u16)] pub enum LED { /// Usage ID `0x1`: "Num Lock" NumLock = 0x1, /// Usage ID `0x2`: "Caps Lock" CapsLock = 0x2, /// Usage ID `0x3`: "Scroll Lock" ScrollLock = 0x3, /// Usage ID `0x4`: "Compose" Compose = 0x4, /// Usage ID `0x5`: "Kana" Kana = 0x5, /// Usage ID `0x6`: "Power" Power = 0x6, /// Usage ID `0x7`: "Shift" Shift = 0x7, /// Usage ID `0x8`: "Do Not Disturb" DoNotDisturb = 0x8, /// Usage ID `0x9`: "Mute" Mute = 0x9, /// Usage ID `0xA`: "Tone Enable" ToneEnable = 0xA, /// Usage ID `0xB`: "High Cut Filter" HighCutFilter = 0xB, /// Usage ID `0xC`: "Low Cut Filter" LowCutFilter = 0xC, /// Usage ID `0xD`: "Equalizer Enable" EqualizerEnable = 0xD, /// Usage ID `0xE`: "Sound Field On" SoundFieldOn = 0xE, /// Usage ID `0xF`: "Surround On" SurroundOn = 0xF, /// Usage ID `0x10`: "Repeat" Repeat = 0x10, /// Usage ID `0x11`: "Stereo" Stereo = 0x11, /// Usage ID `0x12`: "Sampling Rate Detect" SamplingRateDetect = 0x12, /// Usage ID `0x13`: "Spinning" Spinning = 0x13, /// Usage ID `0x14`: "CAV" CAV = 0x14, /// Usage ID `0x15`: "CLV" CLV = 0x15, /// Usage ID `0x16`: "Recording Format Detect" RecordingFormatDetect = 0x16, /// Usage ID `0x17`: "Off-Hook" OffHook = 0x17, /// Usage ID `0x18`: "Ring" Ring = 0x18, /// Usage ID `0x19`: "Message Waiting" MessageWaiting = 0x19, /// Usage ID `0x1A`: "Data Mode" DataMode = 0x1A, /// Usage ID `0x1B`: "Battery Operation" BatteryOperation = 0x1B, /// Usage ID `0x1C`: "Battery OK" BatteryOK = 0x1C, /// Usage ID `0x1D`: "Battery Low" BatteryLow = 0x1D, /// Usage ID `0x1E`: "Speaker" Speaker = 0x1E, /// Usage ID `0x1F`: "Headset" Headset = 0x1F, /// Usage ID `0x20`: "Hold" Hold = 0x20, /// Usage ID `0x21`: "Microphone" Microphone = 0x21, /// Usage ID `0x22`: "Coverage" Coverage = 0x22, /// Usage ID `0x23`: "Night Mode" NightMode = 0x23, /// Usage ID `0x24`: "Send Calls" SendCalls = 0x24, /// Usage ID `0x25`: "Call Pickup" CallPickup = 0x25, /// Usage ID `0x26`: "Conference" Conference = 0x26, /// Usage ID `0x27`: "Stand-by" Standby = 0x27, /// Usage ID `0x28`: "Camera On" CameraOn = 0x28, /// Usage ID `0x29`: "Camera Off" CameraOff = 0x29, /// Usage ID `0x2A`: "On-Line" OnLine = 0x2A, /// Usage ID `0x2B`: "Off-Line" OffLine = 0x2B, /// Usage ID `0x2C`: "Busy" Busy = 0x2C, /// Usage ID `0x2D`: "Ready" Ready = 0x2D, /// Usage ID `0x2E`: "Paper-Out" PaperOut = 0x2E, /// Usage ID `0x2F`: "Paper-Jam" PaperJam = 0x2F, /// Usage ID `0x30`: "Remote" Remote = 0x30, /// Usage ID `0x31`: "Forward" Forward = 0x31, /// Usage ID `0x32`: "Reverse" Reverse = 0x32, /// Usage ID `0x33`: "Stop" Stop = 0x33, /// Usage ID `0x34`: "Rewind" Rewind = 0x34, /// Usage ID `0x35`: "Fast Forward" FastForward = 0x35, /// Usage ID `0x36`: "Play" Play = 0x36, /// Usage ID `0x37`: "Pause" Pause = 0x37, /// Usage ID `0x38`: "Record" Record = 0x38, /// Usage ID `0x39`: "Error" Error = 0x39, /// Usage ID `0x3A`: "Usage Selected Indicator" UsageSelectedIndicator = 0x3A, /// Usage ID `0x3B`: "Usage In Use Indicator" UsageInUseIndicator = 0x3B, /// Usage ID `0x3C`: "Usage Multi Mode Indicator" UsageMultiModeIndicator = 0x3C, /// Usage ID `0x3D`: "Indicator On" IndicatorOn = 0x3D, /// Usage ID `0x3E`: "Indicator Flash" IndicatorFlash = 0x3E, /// Usage ID `0x3F`: "Indicator Slow Blink" IndicatorSlowBlink = 0x3F, /// Usage ID `0x40`: "Indicator Fast Blink" IndicatorFastBlink = 0x40, /// Usage ID `0x41`: "Indicator Off" IndicatorOff = 0x41, /// Usage ID `0x42`: "Flash On Time" FlashOnTime = 0x42, /// Usage ID `0x43`: "Slow Blink On Time" SlowBlinkOnTime = 0x43, /// Usage ID `0x44`: "Slow Blink Off Time" SlowBlinkOffTime = 0x44, /// Usage ID `0x45`: "Fast Blink On Time" FastBlinkOnTime = 0x45, /// Usage ID `0x46`: "Fast Blink Off Time" FastBlinkOffTime = 0x46, /// Usage ID `0x47`: "Usage Indicator Color" UsageIndicatorColor = 0x47, /// Usage ID `0x48`: "Indicator Red" IndicatorRed = 0x48, /// Usage ID `0x49`: "Indicator Green" IndicatorGreen = 0x49, /// Usage ID `0x4A`: "Indicator Amber" IndicatorAmber = 0x4A, /// Usage ID `0x4B`: "Generic Indicator" GenericIndicator = 0x4B, /// Usage ID `0x4C`: "System Suspend" SystemSuspend = 0x4C, /// Usage ID `0x4D`: "External Power Connected" ExternalPowerConnected = 0x4D, /// Usage ID `0x4E`: "Indicator Blue" IndicatorBlue = 0x4E, /// Usage ID `0x4F`: "Indicator Orange" IndicatorOrange = 0x4F, /// Usage ID `0x50`: "Good Status" GoodStatus = 0x50, /// Usage ID `0x51`: "Warning Status" WarningStatus = 0x51, /// Usage ID `0x52`: "RGB LED" RGBLED = 0x52, /// Usage ID `0x53`: "Red LED Channel" RedLEDChannel = 0x53, /// Usage ID `0x54`: "Blue LED Channel" BlueLEDChannel = 0x54, /// Usage ID `0x55`: "Green LED Channel" GreenLEDChannel = 0x55, /// Usage ID `0x56`: "LED Intensity" LEDIntensity = 0x56, /// Usage ID `0x57`: "System Microphone Mute" SystemMicrophoneMute = 0x57, /// Usage ID `0x60`: "Player Indicator" PlayerIndicator = 0x60, /// Usage ID `0x61`: "Player 1" Player1 = 0x61, /// Usage ID `0x62`: "Player 2" Player2 = 0x62, /// Usage ID `0x63`: "Player 3" Player3 = 0x63, /// Usage ID `0x64`: "Player 4" Player4 = 0x64, /// Usage ID `0x65`: "Player 5" Player5 = 0x65, /// Usage ID `0x66`: "Player 6" Player6 = 0x66, /// Usage ID `0x67`: "Player 7" Player7 = 0x67, /// Usage ID `0x68`: "Player 8" Player8 = 0x68, } impl LED { #[cfg(feature = "std")] pub fn name(&self) -> String { match self { LED::NumLock => "Num Lock", LED::CapsLock => "Caps Lock", LED::ScrollLock => "Scroll Lock", LED::Compose => "Compose", LED::Kana => "Kana", LED::Power => "Power", LED::Shift => "Shift", LED::DoNotDisturb => "Do Not Disturb", LED::Mute => "Mute", LED::ToneEnable => "Tone Enable", LED::HighCutFilter => "High Cut Filter", LED::LowCutFilter => "Low Cut Filter", LED::EqualizerEnable => "Equalizer Enable", LED::SoundFieldOn => "Sound Field On", LED::SurroundOn => "Surround On", LED::Repeat => "Repeat", LED::Stereo => "Stereo", LED::SamplingRateDetect => "Sampling Rate Detect", LED::Spinning => "Spinning", LED::CAV => "CAV", LED::CLV => "CLV", LED::RecordingFormatDetect => "Recording Format Detect", LED::OffHook => "Off-Hook", LED::Ring => "Ring", LED::MessageWaiting => "Message Waiting", LED::DataMode => "Data Mode", LED::BatteryOperation => "Battery Operation", LED::BatteryOK => "Battery OK", LED::BatteryLow => "Battery Low", LED::Speaker => "Speaker", LED::Headset => "Headset", LED::Hold => "Hold", LED::Microphone => "Microphone", LED::Coverage => "Coverage", LED::NightMode => "Night Mode", LED::SendCalls => "Send Calls", LED::CallPickup => "Call Pickup", LED::Conference => "Conference", LED::Standby => "Stand-by", LED::CameraOn => "Camera On", LED::CameraOff => "Camera Off", LED::OnLine => "On-Line", LED::OffLine => "Off-Line", LED::Busy => "Busy", LED::Ready => "Ready", LED::PaperOut => "Paper-Out", LED::PaperJam => "Paper-Jam", LED::Remote => "Remote", LED::Forward => "Forward", LED::Reverse => "Reverse", LED::Stop => "Stop", LED::Rewind => "Rewind", LED::FastForward => "Fast Forward", LED::Play => "Play", LED::Pause => "Pause", LED::Record => "Record", LED::Error => "Error", LED::UsageSelectedIndicator => "Usage Selected Indicator", LED::UsageInUseIndicator => "Usage In Use Indicator", LED::UsageMultiModeIndicator => "Usage Multi Mode Indicator", LED::IndicatorOn => "Indicator On", LED::IndicatorFlash => "Indicator Flash", LED::IndicatorSlowBlink => "Indicator Slow Blink", LED::IndicatorFastBlink => "Indicator Fast Blink", LED::IndicatorOff => "Indicator Off", LED::FlashOnTime => "Flash On Time", LED::SlowBlinkOnTime => "Slow Blink On Time", LED::SlowBlinkOffTime => "Slow Blink Off Time", LED::FastBlinkOnTime => "Fast Blink On Time", LED::FastBlinkOffTime => "Fast Blink Off Time", LED::UsageIndicatorColor => "Usage Indicator Color", LED::IndicatorRed => "Indicator Red", LED::IndicatorGreen => "Indicator Green", LED::IndicatorAmber => "Indicator Amber", LED::GenericIndicator => "Generic Indicator", LED::SystemSuspend => "System Suspend", LED::ExternalPowerConnected => "External Power Connected", LED::IndicatorBlue => "Indicator Blue", LED::IndicatorOrange => "Indicator Orange", LED::GoodStatus => "Good Status", LED::WarningStatus => "Warning Status", LED::RGBLED => "RGB LED", LED::RedLEDChannel => "Red LED Channel", LED::BlueLEDChannel => "Blue LED Channel", LED::GreenLEDChannel => "Green LED Channel", LED::LEDIntensity => "LED Intensity", LED::SystemMicrophoneMute => "System Microphone Mute", LED::PlayerIndicator => "Player Indicator", LED::Player1 => "Player 1", LED::Player2 => "Player 2", LED::Player3 => "Player 3", LED::Player4 => "Player 4", LED::Player5 => "Player 5", LED::Player6 => "Player 6", LED::Player7 => "Player 7", LED::Player8 => "Player 8", } .into() } } #[cfg(feature = "std")] impl fmt::Display for LED { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name()) } } impl AsUsage for LED { /// Returns the 32 bit Usage value of this Usage fn usage_value(&self) -> u32 { u32::from(self) } /// Returns the 16 bit Usage ID value of this Usage fn usage_id_value(&self) -> u16 { u16::from(self) } /// Returns this usage as [Usage::LED(self)](Usage::LED) /// This is a convenience function to avoid having /// to implement `From` for every used type in the caller. /// /// ``` /// # use hut::*; /// let gd_x = GenericDesktop::X; /// let usage = Usage::from(GenericDesktop::X); /// assert!(matches!(gd_x.usage(), usage)); /// ``` fn usage(&self) -> Usage { Usage::from(self) } } impl AsUsagePage for LED { /// Returns the 16 bit value of this UsagePage /// /// This value is `0x8` for [LED] fn usage_page_value(&self) -> u16 { let up = UsagePage::from(self); u16::from(up) } /// Returns [UsagePage::LED]] fn usage_page(&self) -> UsagePage { UsagePage::from(self) } } impl From<&LED> for u16 { fn from(led: &LED) -> u16 { *led as u16 } } impl From for u16 { /// Returns the 16bit value of this usage. This is identical /// to [LED::usage_page_value()]. fn from(led: LED) -> u16 { u16::from(&led) } } impl From<&LED> for u32 { /// Returns the 32 bit value of this usage. This is identical /// to [LED::usage_value()]. fn from(led: &LED) -> u32 { let up = UsagePage::from(led); let up = (u16::from(&up) as u32) << 16; let id = u16::from(led) as u32; up | id } } impl From<&LED> for UsagePage { /// Always returns [UsagePage::LED] and is /// identical to [LED::usage_page()]. fn from(_: &LED) -> UsagePage { UsagePage::LED } } impl From for UsagePage { /// Always returns [UsagePage::LED] and is /// identical to [LED::usage_page()]. fn from(_: LED) -> UsagePage { UsagePage::LED } } impl From<&LED> for Usage { fn from(led: &LED) -> Usage { Usage::try_from(u32::from(led)).unwrap() } } impl From for Usage { fn from(led: LED) -> Usage { Usage::from(&led) } } impl TryFrom for LED { type Error = HutError; fn try_from(usage_id: u16) -> Result { match usage_id { 1 => Ok(LED::NumLock), 2 => Ok(LED::CapsLock), 3 => Ok(LED::ScrollLock), 4 => Ok(LED::Compose), 5 => Ok(LED::Kana), 6 => Ok(LED::Power), 7 => Ok(LED::Shift), 8 => Ok(LED::DoNotDisturb), 9 => Ok(LED::Mute), 10 => Ok(LED::ToneEnable), 11 => Ok(LED::HighCutFilter), 12 => Ok(LED::LowCutFilter), 13 => Ok(LED::EqualizerEnable), 14 => Ok(LED::SoundFieldOn), 15 => Ok(LED::SurroundOn), 16 => Ok(LED::Repeat), 17 => Ok(LED::Stereo), 18 => Ok(LED::SamplingRateDetect), 19 => Ok(LED::Spinning), 20 => Ok(LED::CAV), 21 => Ok(LED::CLV), 22 => Ok(LED::RecordingFormatDetect), 23 => Ok(LED::OffHook), 24 => Ok(LED::Ring), 25 => Ok(LED::MessageWaiting), 26 => Ok(LED::DataMode), 27 => Ok(LED::BatteryOperation), 28 => Ok(LED::BatteryOK), 29 => Ok(LED::BatteryLow), 30 => Ok(LED::Speaker), 31 => Ok(LED::Headset), 32 => Ok(LED::Hold), 33 => Ok(LED::Microphone), 34 => Ok(LED::Coverage), 35 => Ok(LED::NightMode), 36 => Ok(LED::SendCalls), 37 => Ok(LED::CallPickup), 38 => Ok(LED::Conference), 39 => Ok(LED::Standby), 40 => Ok(LED::CameraOn), 41 => Ok(LED::CameraOff), 42 => Ok(LED::OnLine), 43 => Ok(LED::OffLine), 44 => Ok(LED::Busy), 45 => Ok(LED::Ready), 46 => Ok(LED::PaperOut), 47 => Ok(LED::PaperJam), 48 => Ok(LED::Remote), 49 => Ok(LED::Forward), 50 => Ok(LED::Reverse), 51 => Ok(LED::Stop), 52 => Ok(LED::Rewind), 53 => Ok(LED::FastForward), 54 => Ok(LED::Play), 55 => Ok(LED::Pause), 56 => Ok(LED::Record), 57 => Ok(LED::Error), 58 => Ok(LED::UsageSelectedIndicator), 59 => Ok(LED::UsageInUseIndicator), 60 => Ok(LED::UsageMultiModeIndicator), 61 => Ok(LED::IndicatorOn), 62 => Ok(LED::IndicatorFlash), 63 => Ok(LED::IndicatorSlowBlink), 64 => Ok(LED::IndicatorFastBlink), 65 => Ok(LED::IndicatorOff), 66 => Ok(LED::FlashOnTime), 67 => Ok(LED::SlowBlinkOnTime), 68 => Ok(LED::SlowBlinkOffTime), 69 => Ok(LED::FastBlinkOnTime), 70 => Ok(LED::FastBlinkOffTime), 71 => Ok(LED::UsageIndicatorColor), 72 => Ok(LED::IndicatorRed), 73 => Ok(LED::IndicatorGreen), 74 => Ok(LED::IndicatorAmber), 75 => Ok(LED::GenericIndicator), 76 => Ok(LED::SystemSuspend), 77 => Ok(LED::ExternalPowerConnected), 78 => Ok(LED::IndicatorBlue), 79 => Ok(LED::IndicatorOrange), 80 => Ok(LED::GoodStatus), 81 => Ok(LED::WarningStatus), 82 => Ok(LED::RGBLED), 83 => Ok(LED::RedLEDChannel), 84 => Ok(LED::BlueLEDChannel), 85 => Ok(LED::GreenLEDChannel), 86 => Ok(LED::LEDIntensity), 87 => Ok(LED::SystemMicrophoneMute), 96 => Ok(LED::PlayerIndicator), 97 => Ok(LED::Player1), 98 => Ok(LED::Player2), 99 => Ok(LED::Player3), 100 => Ok(LED::Player4), 101 => Ok(LED::Player5), 102 => Ok(LED::Player6), 103 => Ok(LED::Player7), 104 => Ok(LED::Player8), n => Err(HutError::UnknownUsageId { usage_id: n }), } } } impl BitOr for LED { type Output = Usage; /// A convenience function to combine a Usage Page with /// a value. /// /// This function panics if the Usage ID value results in /// an unknown Usage. Where error checking is required, /// use [UsagePage::to_usage_from_value]. fn bitor(self, usage: u16) -> Usage { let up = u16::from(self) as u32; let u = usage as u32; Usage::try_from(up | u).expect("Invalid Usage ID for this Usage Page") } } /// *Usage Page `0x9`: "Button"* /// /// **This enum is autogenerated from the HID Usage Tables**. /// /// This Usage Page is generated, not defined, any Usage IDs in this Usage /// Page are simply the button number. /// /// ``` /// # use hut::*; /// let u1 = Usage::Button(Button::Button(3)); /// let u2 = Usage::new_from_page_and_id(0x9, 3).unwrap(); /// let u3 = Usage::from(Button::Button(3)); /// let u4: Usage = Button::Button(3).into(); /// assert_eq!(u1, u2); /// assert_eq!(u1, u3); /// assert_eq!(u1, u4); /// /// assert!(matches!(u1.usage_page(), UsagePage::Button)); /// assert_eq!(0x9, u1.usage_page_value()); /// assert_eq!(3, u1.usage_id_value()); /// assert_eq!((0x9 << 16) | 3, u1.usage_value()); /// assert_eq!("Button 3", u1.name()); /// ``` #[allow(non_camel_case_types)] #[derive(Debug)] #[non_exhaustive] pub enum Button { Button(u16), } impl Button { #[cfg(feature = "std")] pub fn name(&self) -> String { match self { Button::Button(button) => format!("Button {button}"), } } } #[cfg(feature = "std")] impl fmt::Display for Button { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name()) } } impl AsUsage for Button { /// Returns the 32 bit Usage value of this Usage fn usage_value(&self) -> u32 { u32::from(self) } /// Returns the 16 bit Usage ID value of this Usage fn usage_id_value(&self) -> u16 { u16::from(self) } /// Returns this usage as [Usage::Button(self)](Usage::Button) /// This is a convenience function to avoid having /// to implement `From` for every used type in the caller. /// /// ``` /// # use hut::*; /// let gd_x = GenericDesktop::X; /// let usage = Usage::from(GenericDesktop::X); /// assert!(matches!(gd_x.usage(), usage)); /// ``` fn usage(&self) -> Usage { Usage::from(self) } } impl AsUsagePage for Button { /// Returns the 16 bit value of this UsagePage /// /// This value is `0x9` for [Button] fn usage_page_value(&self) -> u16 { let up = UsagePage::from(self); u16::from(up) } /// Returns [UsagePage::Button]] fn usage_page(&self) -> UsagePage { UsagePage::from(self) } } impl From<&Button> for u16 { fn from(button: &Button) -> u16 { match *button { Button::Button(button) => button, } } } impl From