hidpp/feature/
wireless_device_status.rs1use std::sync::Arc;
5
6use num_enum::{FromPrimitive, IntoPrimitive};
7
8use crate::{
9 channel::HidppChannel,
10 feature::{CreatableFeature, DecodeEvent, EmittingFeature, EventSource, Feature},
11};
12
13pub struct WirelessDeviceStatusFeature {
15 events: EventSource<WirelessDeviceStatusEvent>,
17}
18
19impl CreatableFeature for WirelessDeviceStatusFeature {
20 const ID: u16 = 0x1d4b;
21 const STARTING_VERSION: u8 = 0;
22
23 fn new(chan: Arc<HidppChannel>, device_index: u8, feature_index: u8) -> Self {
24 Self {
25 events: EventSource::attach(&chan, device_index, feature_index),
26 }
27 }
28}
29
30impl Feature for WirelessDeviceStatusFeature {}
31
32impl EmittingFeature<WirelessDeviceStatusEvent> for WirelessDeviceStatusFeature {
33 fn listen(&self) -> async_channel::Receiver<WirelessDeviceStatusEvent> {
34 self.events.listen()
35 }
36}
37
38impl DecodeEvent for WirelessDeviceStatusEvent {
39 fn decode(sub_id: u8, payload: &[u8; 16]) -> Option<Self> {
40 if sub_id != 0 {
42 return None;
43 }
44
45 Some(WirelessDeviceStatusEvent::StatusBroadcast(
49 WirelessDeviceStatusBroadcast {
50 status: WirelessDeviceStatus::from(payload[0]),
51 request: WirelessDeviceStatusRequest::from(payload[1]),
52 reason: WirelessDeviceStatusReason::from(payload[2]),
53 },
54 ))
55 }
56}
57
58#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
61#[cfg_attr(feature = "serde", derive(serde::Serialize))]
62#[non_exhaustive]
63pub enum WirelessDeviceStatusEvent {
64 StatusBroadcast(WirelessDeviceStatusBroadcast),
68}
69
70#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
73#[cfg_attr(feature = "serde", derive(serde::Serialize))]
74#[non_exhaustive]
75pub struct WirelessDeviceStatusBroadcast {
76 pub status: WirelessDeviceStatus,
78
79 pub request: WirelessDeviceStatusRequest,
81
82 pub reason: WirelessDeviceStatusReason,
84}
85
86#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, IntoPrimitive, FromPrimitive)]
89#[cfg_attr(feature = "serde", derive(serde::Serialize))]
90#[non_exhaustive]
91#[repr(u8)]
92pub enum WirelessDeviceStatus {
93 Unknown = 0x00,
95 Reconnection = 0x01,
97 #[num_enum(catch_all)]
99 Other(u8),
100}
101
102#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, IntoPrimitive, FromPrimitive)]
105#[cfg_attr(feature = "serde", derive(serde::Serialize))]
106#[non_exhaustive]
107#[repr(u8)]
108pub enum WirelessDeviceStatusRequest {
109 NoRequest = 0x00,
111 SoftwareReconfigurationNeeded = 0x01,
113 #[num_enum(catch_all)]
115 Other(u8),
116}
117
118#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, IntoPrimitive, FromPrimitive)]
121#[cfg_attr(feature = "serde", derive(serde::Serialize))]
122#[non_exhaustive]
123#[repr(u8)]
124pub enum WirelessDeviceStatusReason {
125 Unknown = 0x00,
127 PowerSwitchActivated = 0x01,
129 #[num_enum(catch_all)]
131 Other(u8),
132}