Add some debug stuff

This commit is contained in:
Lennard Kittner
2025-09-17 12:23:10 +02:00
parent b9028fe287
commit 97ef1d40ad
3 changed files with 27 additions and 7 deletions

View File

@@ -62,6 +62,13 @@ fn main() {
}
};
println!("State before doing anything");
if let Err(error) = device.active_refresh_state() {
eprintln!("{error}");
std::process::exit(1);
};
println!("{}", device.get_device_state());
if let Some(delay) = matches.get_one::<u8>("automatic_shutdown") {
let delay = *delay as u64;
if let Some(packet) =
@@ -127,6 +134,7 @@ fn main() {
std::thread::sleep(Duration::from_secs_f64(0.5));
println!("State after potentially setting some stuff");
if let Err(error) = device.active_refresh_state() {
eprintln!("{error}");
std::process::exit(1);

View File

@@ -155,20 +155,28 @@ impl Device for CloudIIWireless {
}
println!("Received packet: {:?}", response);
match (response[3], response[7], response[12], response[14]) {
(GET_BATTERY_CMD_ID, level, _, _) => Some(vec![DeviceEvent::BatterLevel(level)]),
(GET_BATTERY_CMD_ID, level, _, _) => {
println!("Battery Level {level}");
Some(vec![DeviceEvent::BatterLevel(level)])
}
(GET_CHARGING_CMD_ID, status, _, _) => {
println!("Charging {status} {:?}", ChargingStatus::from(status));
Some(vec![DeviceEvent::Charging(ChargingStatus::from(status))])
}
(GET_AUTO_SHUTDOWN_CMD_ID, shutdown, _, _) => {
println!("Shutdown time {shutdown}");
Some(vec![DeviceEvent::AutomaticShutdownAfter(
Duration::from_secs(shutdown as u64 * 60),
)])
}
(GET_MUTE_CMD_ID, _, surround, other) => Some(vec![
DeviceEvent::SideToneOn((other & 16) != 0),
DeviceEvent::Muted((other & 2) != 0),
DeviceEvent::SurroundSound((surround & 2) != 0),
]),
(GET_MUTE_CMD_ID, _, surround, other) => {
println!("More info {} {}", surround, other);
Some(vec![
DeviceEvent::SideToneOn((other & 16) != 0),
DeviceEvent::Muted((other & 2) != 0),
DeviceEvent::SurroundSound((surround & 2) != 0),
])
}
_ => {
println!("Unknown device event: {:?}", response);
None
@@ -185,6 +193,7 @@ impl Device for CloudIIWireless {
}
fn prepare_write(&mut self) {
println!("Setting input report");
let mut input_report_buffer = [0u8; 64];
input_report_buffer[0] = 6;
self.state

View File

@@ -341,7 +341,7 @@ pub trait Device {
return None;
}
self.get_event_from_device_response(&buf[0..res])
self.get_event_from_device_response(&buf)
}
/// Refreshes the state by querying all available information
@@ -364,6 +364,7 @@ pub trait Device {
let mut responded = false;
for packet in packets.into_iter().flatten() {
self.prepare_write();
println!("writing Packet {packet:?}");
self.get_device_state().hid_device.write(&packet)?;
if let Some(events) = self.wait_for_updates(Duration::from_secs(1)) {
for event in events {
@@ -374,6 +375,8 @@ pub trait Device {
if !self.get_device_state().connected.map_or(true, |c| c) {
break;
}
std::thread::sleep(Duration::from_secs_f64(2.));
println!("waiting 2s before sending the next packet ...");
}
if responded {