use std::{any::Any, sync::Arc};
use crate::channel::HidppChannel;
pub mod device_friendly_name;
pub mod device_information;
pub mod device_type_and_name;
pub mod feature_set;
pub mod hires_wheel;
pub mod registry;
pub mod root;
pub mod smartshift;
pub mod thumbwheel;
pub mod unified_battery;
pub mod wireless_device_status;
pub trait Feature: Any + Send + Sync {}
pub trait CreatableFeature: Feature {
const ID: u16;
const STARTING_VERSION: u8;
fn new(chan: Arc<HidppChannel>, device_index: u8, feature_index: u8) -> Self;
}
pub trait EmittingFeature<T>: Feature {
fn listen(&self) -> async_channel::Receiver<T>;
}
#[derive(Clone, Copy, Hash, Debug)]
#[non_exhaustive]
pub struct FeatureType {
pub obsolete: bool,
pub hidden: bool,
pub engineering: bool,
pub manufacturing_deactivatable: bool,
pub compliance_deactivatable: bool,
}
impl From<u8> for FeatureType {
fn from(value: u8) -> Self {
Self {
obsolete: value & (1 << 7) != 0,
hidden: value & (1 << 6) != 0,
engineering: value & (1 << 5) != 0,
manufacturing_deactivatable: value & (1 << 4) != 0,
compliance_deactivatable: value & (1 << 3) != 0,
}
}
}
impl From<FeatureType> for u8 {
fn from(value: FeatureType) -> Self {
let mut raw = 0;
if value.obsolete {
raw |= 1 << 7
}
if value.hidden {
raw |= 1 << 6
}
if value.engineering {
raw |= 1 << 5
}
if value.manufacturing_deactivatable {
raw |= 1 << 4
}
if value.compliance_deactivatable {
raw |= 1 << 3
}
raw
}
}