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
58impl WirelessDeviceStatusEvent {
59 #[must_use]
65 pub fn decode(function_id: u8, payload: &[u8; 16]) -> Option<Self> {
66 <Self as DecodeEvent>::decode(function_id, payload)
67 }
68}
69
70#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
73#[cfg_attr(feature = "serde", derive(serde::Serialize))]
74#[non_exhaustive]
75pub enum WirelessDeviceStatusEvent {
76 StatusBroadcast(WirelessDeviceStatusBroadcast),
80}
81
82#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
85#[cfg_attr(feature = "serde", derive(serde::Serialize))]
86#[non_exhaustive]
87pub struct WirelessDeviceStatusBroadcast {
88 pub status: WirelessDeviceStatus,
90
91 pub request: WirelessDeviceStatusRequest,
93
94 pub reason: WirelessDeviceStatusReason,
96}
97
98#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, IntoPrimitive, FromPrimitive)]
101#[cfg_attr(feature = "serde", derive(serde::Serialize))]
102#[non_exhaustive]
103#[repr(u8)]
104pub enum WirelessDeviceStatus {
105 Unknown = 0x00,
107 Reconnection = 0x01,
109 #[num_enum(catch_all)]
111 Other(u8),
112}
113
114#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, IntoPrimitive, FromPrimitive)]
117#[cfg_attr(feature = "serde", derive(serde::Serialize))]
118#[non_exhaustive]
119#[repr(u8)]
120pub enum WirelessDeviceStatusRequest {
121 NoRequest = 0x00,
123 SoftwareReconfigurationNeeded = 0x01,
125 #[num_enum(catch_all)]
127 Other(u8),
128}
129
130#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, IntoPrimitive, FromPrimitive)]
133#[cfg_attr(feature = "serde", derive(serde::Serialize))]
134#[non_exhaustive]
135#[repr(u8)]
136pub enum WirelessDeviceStatusReason {
137 Unknown = 0x00,
139 PowerSwitchActivated = 0x01,
141 #[num_enum(catch_all)]
143 Other(u8),
144}