Align everything to Headset_protocol.md (Copilot)
This commit is contained in:
@@ -171,54 +171,86 @@ impl Device for CloudIIWireless {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
println!("Received packet: {:?}", response);
|
println!("Received packet: {:?}", response);
|
||||||
match (
|
|
||||||
response[0],
|
// Most responses are Report ID 11 (0x0B) with structure: [11, 0, 187, cmd_id, ...]
|
||||||
response[3],
|
// Some responses are Report ID 10 (0x0A) for DSP/surround status
|
||||||
response[4],
|
match response[0] {
|
||||||
response[7],
|
11 if response[2] == 187 => {
|
||||||
response[12],
|
// Standard response format: [11, 0, 187, cmd_id, data...]
|
||||||
response[14],
|
match response[3] {
|
||||||
) {
|
CONNECTION_STATUS_RESPONSE_ID => {
|
||||||
(11, CONNECTION_STATUS_RESPONSE_ID, status, _, _, _) => {
|
let status = response[4];
|
||||||
let flag = status == 1 || status == 4;
|
let connected = status == 1 || status == 4;
|
||||||
if status == 2 {
|
if status == 2 {
|
||||||
println!("pairing");
|
println!("Pairing mode");
|
||||||
|
}
|
||||||
|
println!("Connected: {}", connected);
|
||||||
|
Some(vec![DeviceEvent::WirelessConnected(connected)])
|
||||||
|
}
|
||||||
|
GET_BATTERY_CMD_ID => {
|
||||||
|
// Battery level is at byte 7, not byte 4
|
||||||
|
let level = response[7];
|
||||||
|
println!("Battery Level: {}%", level);
|
||||||
|
Some(vec![DeviceEvent::BatterLevel(level)])
|
||||||
|
}
|
||||||
|
GET_CHARGING_CMD_ID => {
|
||||||
|
let status = response[4];
|
||||||
|
println!(
|
||||||
|
"Charging status: {} ({:?})",
|
||||||
|
status,
|
||||||
|
ChargingStatus::from(status)
|
||||||
|
);
|
||||||
|
Some(vec![DeviceEvent::Charging(ChargingStatus::from(status))])
|
||||||
|
}
|
||||||
|
MUTE_RESPONSE_ID => {
|
||||||
|
let muted = response[4] == 1;
|
||||||
|
println!("Microphone muted: {}", muted);
|
||||||
|
Some(vec![DeviceEvent::Muted(muted)])
|
||||||
|
}
|
||||||
|
FIRMWARE_VERSION_RESPONSE_ID => {
|
||||||
|
println!(
|
||||||
|
"Firmware version: {}.{}.{}.{}",
|
||||||
|
response[4], response[5], response[6], response[7]
|
||||||
|
);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
SET_SIDE_TONE_ON_CMD_ID => {
|
||||||
|
// Response format: [11, 0, 187, 25, status, ...]
|
||||||
|
// where status: 1 = enabled, 0 = disabled
|
||||||
|
let enabled = response[4] == 1;
|
||||||
|
println!("Sidetone enabled: {}", enabled);
|
||||||
|
Some(vec![DeviceEvent::SideToneOn(enabled)])
|
||||||
|
}
|
||||||
|
GET_AUTO_SHUTDOWN_CMD_ID => {
|
||||||
|
let minutes = response[4];
|
||||||
|
println!("Auto shutdown after: {} minutes", minutes);
|
||||||
|
Some(vec![DeviceEvent::AutomaticShutdownAfter(
|
||||||
|
Duration::from_secs(minutes as u64 * 60),
|
||||||
|
)])
|
||||||
|
}
|
||||||
|
9 | 29 => {
|
||||||
|
// Commands 9 and 29 are seen during initialization but purpose unclear
|
||||||
|
println!("Initialization response (cmd {})", response[3]);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
println!("Unknown command response: cmd_id={}", response[3]);
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
println!("Connected {flag}");
|
|
||||||
Some(vec![DeviceEvent::WirelessConnected(flag)])
|
|
||||||
}
|
}
|
||||||
(11, GET_BATTERY_CMD_ID, _, level, _, _) => {
|
10 => {
|
||||||
println!("Battery Level {level}");
|
// DSP/Surround sound status response: [10, 0, dsp_status, ...]
|
||||||
Some(vec![DeviceEvent::BatterLevel(level)])
|
let dsp_status = response[2];
|
||||||
}
|
let surround_enabled = (dsp_status & 2) == 2;
|
||||||
(11, GET_CHARGING_CMD_ID, status, _, _, _) => {
|
println!(
|
||||||
println!("Charging {status} {:?}", ChargingStatus::from(status));
|
"Surround sound enabled: {} (dsp_status=0x{:02X})",
|
||||||
Some(vec![DeviceEvent::Charging(ChargingStatus::from(status))])
|
surround_enabled, dsp_status
|
||||||
}
|
);
|
||||||
(11, MUTE_RESPONSE_ID, status, _, _, _) => {
|
Some(vec![DeviceEvent::SurroundSound(surround_enabled)])
|
||||||
println!("Muted {status} {:?}", ChargingStatus::from(status));
|
|
||||||
Some(vec![DeviceEvent::Muted(status == 1)])
|
|
||||||
}
|
|
||||||
(11, FIRMWARE_VERSION_RESPONSE_ID, ..) => {
|
|
||||||
print!("Firmware version update");
|
|
||||||
None
|
|
||||||
}
|
|
||||||
(11, SET_SIDE_TONE_ON_CMD_ID, status, ..) => {
|
|
||||||
print!("Side tone on {status}");
|
|
||||||
Some(vec![DeviceEvent::SideToneOn(status != 1)])
|
|
||||||
}
|
|
||||||
(11, GET_AUTO_SHUTDOWN_CMD_ID, shutdown, _, _, _) => {
|
|
||||||
println!("Shutdown time {shutdown}");
|
|
||||||
Some(vec![DeviceEvent::AutomaticShutdownAfter(
|
|
||||||
Duration::from_secs(shutdown as u64 * 60),
|
|
||||||
)])
|
|
||||||
}
|
|
||||||
(10, surround, _, _, _, _) => {
|
|
||||||
println!("Surround sound {}", surround);
|
|
||||||
Some(vec![DeviceEvent::SurroundSound((surround & 2) == 2)])
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
println!("Unknown device event: {:?}", response);
|
println!("Unknown response format: report_id={}", response[0]);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user