Skip to content

Commit

Permalink
Merge pull request #8 from tpoliaw/bitvec_17
Browse files Browse the repository at this point in the history
Update bitvec from v0.16 to v0.17
  • Loading branch information
laptou authored Apr 14, 2020
2 parents c9a7013 + b42501b commit 95b3d68
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ num-traits = "0.2"
num-derive = "0.3"
enumflags2 = "0.6"
bytes = "0.5"
bitvec = "0.16"
bitvec = "0.17"
futures = "0.3"
async-std = { version = "1.4", features = ["attributes"] }

Expand Down
20 changes: 10 additions & 10 deletions src/interface/class.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bitvec::prelude as bv;
use bitvec::prelude::{BitField, Bits};
use bitvec::prelude::{BitField, AsBits};
use bytes::Bytes;
use enumflags2::BitFlags;

Expand Down Expand Up @@ -158,13 +158,13 @@ pub fn from_array(class: [u8; 3]) -> (DeviceClass, ServiceClasses) {
pub fn from_u32(class: u32) -> (DeviceClass, ServiceClasses) {
let service_classes = ServiceClasses::from_bits_truncate(class);

let class_bits = class.bits::<bv::LittleEndian>();
let class_bits = class.bits::<bv::Lsb0>();
let device_class: DeviceClass;

// major device class encoded in bits 8-12
device_class = match class_bits[8..13].load::<u8>().unwrap() {
device_class = match class_bits[8..13].load::<u8>() {
// minor device class in bits 2-7
0b00001 => DeviceClass::Computer(match class_bits[2..8].load::<u8>().unwrap() {
0b00001 => DeviceClass::Computer(match class_bits[2..8].load::<u8>() {
0b000000 => ComputerDeviceClass::Uncategorized,
0b000001 => ComputerDeviceClass::Desktop,
0b000010 => ComputerDeviceClass::Server,
Expand All @@ -175,7 +175,7 @@ pub fn from_u32(class: u32) -> (DeviceClass, ServiceClasses) {
0b000111 => ComputerDeviceClass::Tablet,
_ => ComputerDeviceClass::Unknown,
}),
0b00010 => DeviceClass::Phone(match class_bits[2..8].load::<u8>().unwrap() {
0b00010 => DeviceClass::Phone(match class_bits[2..8].load::<u8>() {
0b000000 => PhoneDeviceClass::Uncategorized,
0b000001 => PhoneDeviceClass::Cellular,
0b000010 => PhoneDeviceClass::Cordless,
Expand All @@ -185,7 +185,7 @@ pub fn from_u32(class: u32) -> (DeviceClass, ServiceClasses) {
_ => PhoneDeviceClass::Unknown,
}),
0b00011 => DeviceClass::AccessPoint(0.),
0b00100 => DeviceClass::AudioVideo(match class_bits[2..8].load::<u8>().unwrap() {
0b00100 => DeviceClass::AudioVideo(match class_bits[2..8].load::<u8>() {
0b000001 => AudioVideoDeviceClass::Headset,
0b000010 => AudioVideoDeviceClass::HandsFree,
0b000011 => AudioVideoDeviceClass::Unknown,
Expand All @@ -209,7 +209,7 @@ pub fn from_u32(class: u32) -> (DeviceClass, ServiceClasses) {
0b00101 => DeviceClass::Peripheral {
keyboard: class_bits[6],
pointer: class_bits[7],
class: match class_bits[2..6].load::<u8>().unwrap() {
class: match class_bits[2..6].load::<u8>() {
0b0000 => PeripheralDeviceClass::Uncategorized,
0b0001 => PeripheralDeviceClass::Joystick,
0b0010 => PeripheralDeviceClass::Gamepad,
Expand All @@ -229,23 +229,23 @@ pub fn from_u32(class: u32) -> (DeviceClass, ServiceClasses) {
scanner: class_bits[6],
printer: class_bits[7],
},
0b00111 => DeviceClass::Wearable(match class_bits[2..8].load::<u8>().unwrap() {
0b00111 => DeviceClass::Wearable(match class_bits[2..8].load::<u8>() {
0b0001 => WearableDeviceClass::Wristwatch,
0b0010 => WearableDeviceClass::Pager,
0b0011 => WearableDeviceClass::Jacket,
0b0100 => WearableDeviceClass::Helmet,
0b0101 => WearableDeviceClass::Glasses,
_ => WearableDeviceClass::Unknown,
}),
0b01000 => DeviceClass::Toy(match class_bits[2..8].load::<u8>().unwrap() {
0b01000 => DeviceClass::Toy(match class_bits[2..8].load::<u8>() {
0b0001 => ToyDeviceClass::Robot,
0b0010 => ToyDeviceClass::Vehicle,
0b0011 => ToyDeviceClass::Doll,
0b0100 => ToyDeviceClass::Controller,
0b0101 => ToyDeviceClass::Game,
_ => ToyDeviceClass::Unknown,
}),
0b01001 => DeviceClass::Health(match class_bits[2..8].load::<u8>().unwrap() {
0b01001 => DeviceClass::Health(match class_bits[2..8].load::<u8>() {
0b000001 => HealthDeviceClass::BloodPressureMeter,
0b000010 => HealthDeviceClass::Thermometer,
0b000011 => HealthDeviceClass::WeightScale,
Expand Down

0 comments on commit 95b3d68

Please sign in to comment.