Add conditional debug printing
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
use crate::devices::{ChargingStatus, Device, DeviceError, DeviceEvent, DeviceState};
|
use crate::{
|
||||||
|
debug_println,
|
||||||
|
devices::{ChargingStatus, Device, DeviceError, DeviceEvent, DeviceState},
|
||||||
|
};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
const HYPERX: u16 = 0x0951;
|
const HYPERX: u16 = 0x0951;
|
||||||
@@ -167,6 +170,7 @@ impl Device for CloudIIWireless {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_event_from_device_response(&self, response: &[u8]) -> Option<Vec<DeviceEvent>> {
|
fn get_event_from_device_response(&self, response: &[u8]) -> Option<Vec<DeviceEvent>> {
|
||||||
|
debug_println!("Read packet: {:?}", response);
|
||||||
if response.len() < 7 {
|
if response.len() < 7 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@@ -181,7 +185,7 @@ impl Device for CloudIIWireless {
|
|||||||
let status = response[4];
|
let status = response[4];
|
||||||
let connected = status == 1 || status == 4;
|
let connected = status == 1 || status == 4;
|
||||||
if status == 2 {
|
if status == 2 {
|
||||||
println!("Pairing mode");
|
debug_println!("Pairing mode");
|
||||||
}
|
}
|
||||||
Some(vec![DeviceEvent::WirelessConnected(connected)])
|
Some(vec![DeviceEvent::WirelessConnected(connected)])
|
||||||
}
|
}
|
||||||
@@ -199,9 +203,12 @@ impl Device for CloudIIWireless {
|
|||||||
Some(vec![DeviceEvent::Muted(muted)])
|
Some(vec![DeviceEvent::Muted(muted)])
|
||||||
}
|
}
|
||||||
FIRMWARE_VERSION_RESPONSE_ID => {
|
FIRMWARE_VERSION_RESPONSE_ID => {
|
||||||
println!(
|
debug_println!(
|
||||||
"Firmware version: {}.{}.{}.{}",
|
"Firmware version: {}.{}.{}.{}",
|
||||||
response[4], response[5], response[6], response[7]
|
response[4],
|
||||||
|
response[5],
|
||||||
|
response[6],
|
||||||
|
response[7]
|
||||||
);
|
);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -220,7 +227,7 @@ impl Device for CloudIIWireless {
|
|||||||
4 => {
|
4 => {
|
||||||
// Command 4: Charge limit or battery management
|
// Command 4: Charge limit or battery management
|
||||||
// This may be sent asynchronously when charging state changes
|
// This may be sent asynchronously when charging state changes
|
||||||
println!(
|
debug_println!(
|
||||||
"Charge limit/battery management response (cmd 4): data={:?}",
|
"Charge limit/battery management response (cmd 4): data={:?}",
|
||||||
&response[4..8]
|
&response[4..8]
|
||||||
);
|
);
|
||||||
@@ -228,11 +235,11 @@ impl Device for CloudIIWireless {
|
|||||||
}
|
}
|
||||||
9 | 29 => {
|
9 | 29 => {
|
||||||
// Commands 9 and 29 are seen during initialization but purpose unclear
|
// Commands 9 and 29 are seen during initialization but purpose unclear
|
||||||
println!("Initialization response (cmd {})", response[3]);
|
debug_println!("Initialization response (cmd {})", response[3]);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
println!("Unknown command response: cmd_id={}", response[3]);
|
debug_println!("Unknown command response: cmd_id={}", response[3]);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -244,7 +251,7 @@ impl Device for CloudIIWireless {
|
|||||||
Some(vec![DeviceEvent::SurroundSound(surround_enabled)])
|
Some(vec![DeviceEvent::SurroundSound(surround_enabled)])
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
println!("Unknown response format: report_id={}", response[0]);
|
debug_println!("Unknown response format: report_id={}", response[0]);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
use crate::devices::{ChargingStatus, Color, Device, DeviceError, DeviceEvent, DeviceState};
|
use crate::{
|
||||||
|
debug_println,
|
||||||
|
devices::{ChargingStatus, Color, Device, DeviceError, DeviceEvent, DeviceState},
|
||||||
|
};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
const HP: u16 = 0x03F0;
|
const HP: u16 = 0x03F0;
|
||||||
@@ -184,6 +187,7 @@ impl Device for CloudIIWirelessDTS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_event_from_device_response(&self, response: &[u8]) -> Option<Vec<DeviceEvent>> {
|
fn get_event_from_device_response(&self, response: &[u8]) -> Option<Vec<DeviceEvent>> {
|
||||||
|
debug_println!("Read packet: {:?}", response);
|
||||||
if response.len() < 7 {
|
if response.len() < 7 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@@ -225,7 +229,7 @@ impl Device for CloudIIWirelessDTS {
|
|||||||
Some(vec![DeviceEvent::ProductColor(Color::from(status))])
|
Some(vec![DeviceEvent::ProductColor(Color::from(status))])
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
println!("Unknown device event: {:?}", response);
|
debug_println!("Unknown device event: {:?}", response);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
use crate::devices::{ChargingStatus, Color, Device, DeviceError, DeviceEvent, DeviceState};
|
use crate::{
|
||||||
|
debug_println,
|
||||||
|
devices::{ChargingStatus, Color, Device, DeviceError, DeviceEvent, DeviceState},
|
||||||
|
};
|
||||||
use std::{time::Duration, vec};
|
use std::{time::Duration, vec};
|
||||||
|
|
||||||
const HP: u16 = 0x03F0;
|
const HP: u16 = 0x03F0;
|
||||||
@@ -177,6 +180,7 @@ impl Device for CloudIIIWireless {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_event_from_device_response(&self, response: &[u8]) -> Option<Vec<DeviceEvent>> {
|
fn get_event_from_device_response(&self, response: &[u8]) -> Option<Vec<DeviceEvent>> {
|
||||||
|
debug_println!("Read packet: {response:?}");
|
||||||
if response[0] != 102 {
|
if response[0] != 102 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@@ -218,7 +222,10 @@ impl Device for CloudIIIWireless {
|
|||||||
}
|
}
|
||||||
Some(vec![DeviceEvent::RequireSIRKReset(flag)])
|
Some(vec![DeviceEvent::RequireSIRKReset(flag)])
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => {
|
||||||
|
debug_println!("Unknown device event: {:?}", response);
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,12 @@ pub mod cloud_ii_wireless;
|
|||||||
pub mod cloud_ii_wireless_dts;
|
pub mod cloud_ii_wireless_dts;
|
||||||
pub mod cloud_iii_wireless;
|
pub mod cloud_iii_wireless;
|
||||||
|
|
||||||
use crate::devices::{
|
use crate::{
|
||||||
|
debug_println,
|
||||||
|
devices::{
|
||||||
cloud_ii_wireless::CloudIIWireless, cloud_ii_wireless_dts::CloudIIWirelessDTS,
|
cloud_ii_wireless::CloudIIWireless, cloud_ii_wireless_dts::CloudIIWirelessDTS,
|
||||||
cloud_iii_wireless::CloudIIIWireless,
|
cloud_iii_wireless::CloudIIIWireless,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use hidapi::{HidApi, HidDevice, HidError};
|
use hidapi::{HidApi, HidDevice, HidError};
|
||||||
use std::{fmt::Display, time::Duration};
|
use std::{fmt::Display, time::Duration};
|
||||||
@@ -506,6 +509,7 @@ pub trait Device {
|
|||||||
let mut responded = false;
|
let mut responded = false;
|
||||||
for packet in packets.into_iter().flatten() {
|
for packet in packets.into_iter().flatten() {
|
||||||
self.prepare_write();
|
self.prepare_write();
|
||||||
|
debug_println!("Write packet: {packet:?}");
|
||||||
self.get_device_state().hid_device.write(&packet)?;
|
self.get_device_state().hid_device.write(&packet)?;
|
||||||
std::thread::sleep(RESPONSE_DELAY);
|
std::thread::sleep(RESPONSE_DELAY);
|
||||||
if let Some(events) = self.wait_for_updates(Duration::from_secs(1)) {
|
if let Some(events) = self.wait_for_updates(Duration::from_secs(1)) {
|
||||||
|
|||||||
@@ -1 +1,9 @@
|
|||||||
pub mod devices;
|
pub mod devices;
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! debug_println {
|
||||||
|
($($args:tt)*) => {
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
println!($($args)*);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user