btuuid/appearance/mod.rs
1//! The representation of the external appearance of the device.
2//!
3//! [Bluetooth Assigned Numbers list](https://www.bluetooth.com/wp-content/uploads/Files/Specification/Assigned_Numbers.html#bookmark49)
4
5#[allow(dead_code)]
6mod categories;
7
8pub use categories::*;
9
10use super::BluetoothUuid16;
11
12/// Construct a new appearance value for the GAP Service.
13///
14/// Follow the pattern of the examples below to create new appearance values.
15/// Use UUIDs from the [Bluetooth Assigned Numbers list](https://www.bluetooth.com/wp-content/uploads/Files/Specification/Assigned_Numbers.html#bookmark49).
16///
17/// ## Example
18///
19/// ```rust ignore
20///
21/// const GAMEPAD: BluetoothUuid16 = appearance::from_category(0x00F, 0x040);
22/// const GAMEPAD_BYTES: &[u8; 2] = &GAMEPAD.to_le_bytes();
23/// ```
24pub const fn from_category(category: u8, subcategory: u8) -> BluetoothUuid16 {
25 let uuid = ((category as u16) << 6) | (subcategory as u16);
26 BluetoothUuid16::new(uuid)
27}
28
29#[cfg(test)]
30mod test {
31 use super::*;
32
33 #[test]
34 fn test_appearance() {
35 const CUSTOM_UUID: BluetoothUuid16 = from_category(0x002, 0x007);
36 assert_eq!(u16::from(CUSTOM_UUID), 0x0087);
37 let uuid: u16 = aircraft::LARGE_PASSENGER_AIRCRAFT.into();
38 assert_eq!(uuid, 0x0984);
39 const LABEL_BYTES: [u8; 2] = signage::ELECTRONIC_LABEL.to_le_bytes();
40 assert_eq!(LABEL_BYTES, [0xc2, 0x0a]);
41 const GAMEPAD: BluetoothUuid16 = power_device::GENERIC_POWER_DEVICE;
42 assert_eq!(u16::from(GAMEPAD), 0x780);
43 }
44}