Fix unsupported packets
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use std::time::Duration;
|
||||
use crate::devices::{ChargingStatus, Color, Device, DeviceError, DeviceEvent, DeviceState};
|
||||
use std::time::Duration;
|
||||
|
||||
// Possible vendor IDs [HP]
|
||||
const VENDOR_IDS: [u16; 1] = [0x03F0];
|
||||
@@ -51,123 +51,140 @@ impl CloudIIWirelessDTS {
|
||||
}
|
||||
|
||||
impl Device for CloudIIWirelessDTS {
|
||||
fn get_charging_packet(&self) -> Vec<u8> {
|
||||
fn get_charging_packet(&self) -> Option<Vec<u8>> {
|
||||
let mut tmp = BASE_PACKET.to_vec();
|
||||
tmp[3] = GET_CHARGING_CMD_ID;
|
||||
tmp
|
||||
Some(tmp)
|
||||
}
|
||||
|
||||
fn get_battery_packet(&self) -> Vec<u8> {
|
||||
fn get_battery_packet(&self) -> Option<Vec<u8>> {
|
||||
let mut tmp = BASE_PACKET.to_vec();
|
||||
tmp[3] = GET_BATTERY_CMD_ID;
|
||||
tmp
|
||||
Some(tmp)
|
||||
}
|
||||
|
||||
fn set_automatic_shut_down_packet(&self, shutdown_after: Duration) -> Vec<u8> {
|
||||
fn set_automatic_shut_down_packet(&self, shutdown_after: Duration) -> Option<Vec<u8>> {
|
||||
let mut tmp = BASE_PACKET.to_vec();
|
||||
tmp[3] = SET_AUTO_SHUTDOWN_CMD_ID;
|
||||
tmp[4] = (shutdown_after.as_secs() / 60) as u8;
|
||||
tmp
|
||||
Some(tmp)
|
||||
}
|
||||
|
||||
fn get_automatic_shut_down_packet(&self) -> Vec<u8> {
|
||||
fn get_automatic_shut_down_packet(&self) -> Option<Vec<u8>> {
|
||||
let mut tmp = BASE_PACKET.to_vec();
|
||||
tmp[3] = GET_AUTO_SHUTDOWN_CMD_ID;
|
||||
tmp
|
||||
Some(tmp)
|
||||
}
|
||||
|
||||
fn get_mute_packet(&self) -> Vec<u8> {
|
||||
fn get_mute_packet(&self) -> Option<Vec<u8>> {
|
||||
let mut tmp = BASE_PACKET.to_vec();
|
||||
tmp[3] = GET_MUTE_CMD_ID;
|
||||
tmp
|
||||
Some(tmp)
|
||||
}
|
||||
|
||||
fn set_mute_packet(&self, mute: bool) -> Vec<u8> {
|
||||
fn set_mute_packet(&self, mute: bool) -> Option<Vec<u8>> {
|
||||
let mut tmp = BASE_PACKET.to_vec();
|
||||
tmp[3] = SET_MUTE_CMD_ID;
|
||||
tmp[4] = mute as u8;
|
||||
tmp
|
||||
Some(tmp)
|
||||
}
|
||||
|
||||
fn get_mic_connected_packet(&self) -> Vec<u8> {
|
||||
fn get_mic_connected_packet(&self) -> Option<Vec<u8>> {
|
||||
let mut tmp = BASE_PACKET.to_vec();
|
||||
tmp[3] = GET_MIC_CONNECTED_CMD_ID;
|
||||
tmp
|
||||
Some(tmp)
|
||||
}
|
||||
|
||||
fn get_pairing_info_packet(&self) -> Vec<u8> {
|
||||
fn get_pairing_info_packet(&self) -> Option<Vec<u8>> {
|
||||
let mut tmp = BASE_PACKET.to_vec();
|
||||
tmp[3] = GET_PAIRING_CMD_ID;
|
||||
tmp
|
||||
Some(tmp)
|
||||
}
|
||||
|
||||
fn get_product_color_packet(&self) -> Vec<u8> {
|
||||
let mut tmp = BASE_PACKET2.to_vec();
|
||||
tmp[2] = GET_PRODUCT_COLOR_CMD_ID;
|
||||
tmp
|
||||
fn get_product_color_packet(&self) -> Option<Vec<u8>> {
|
||||
// let mut tmp = BASE_PACKET2.to_vec();
|
||||
// tmp[2] = GET_PRODUCT_COLOR_CMD_ID;
|
||||
// Some(tmp)
|
||||
// Doesn't work
|
||||
None
|
||||
}
|
||||
|
||||
fn get_side_tone_packet(&self) -> Vec<u8> {
|
||||
fn get_side_tone_packet(&self) -> Option<Vec<u8>> {
|
||||
let mut tmp = BASE_PACKET.to_vec();
|
||||
tmp[3] = GET_SIDE_TONE_ON_CMD_ID;
|
||||
tmp
|
||||
Some(tmp)
|
||||
}
|
||||
|
||||
fn set_side_tone_packet(&self, side_tone_on: bool) -> Vec<u8> {
|
||||
fn set_side_tone_packet(&self, side_tone_on: bool) -> Option<Vec<u8>> {
|
||||
let mut tmp = BASE_PACKET.to_vec();
|
||||
tmp[3] = SET_SIDE_TONE_ON_CMD_ID;
|
||||
tmp[4] = side_tone_on as u8;
|
||||
tmp
|
||||
Some(tmp)
|
||||
}
|
||||
|
||||
fn get_side_tone_volume_packet(&self) -> Vec<u8> {
|
||||
fn get_side_tone_volume_packet(&self) -> Option<Vec<u8>> {
|
||||
let mut tmp = BASE_PACKET.to_vec();
|
||||
tmp[3] = GET_SIDE_TONE_VOLUME_CMD_ID;
|
||||
tmp
|
||||
Some(tmp)
|
||||
}
|
||||
|
||||
fn set_side_tone_volume_packet(&self) -> Vec<u8> {
|
||||
fn set_side_tone_volume_packet(&self) -> Option<Vec<u8>> {
|
||||
let mut tmp = BASE_PACKET.to_vec();
|
||||
tmp[3] = SET_SIDE_TONE_VOLUME_CMD_ID;
|
||||
tmp
|
||||
Some(tmp)
|
||||
}
|
||||
|
||||
fn get_voice_prompt_packet(&self) -> Vec<u8> {
|
||||
let mut tmp = BASE_PACKET2.to_vec();
|
||||
tmp[2] = GET_VOICE_PROMPT_CMD_ID;
|
||||
tmp
|
||||
fn get_voice_prompt_packet(&self) -> Option<Vec<u8>> {
|
||||
// let mut tmp = BASE_PACKET2.to_vec();
|
||||
// tmp[2] = GET_VOICE_PROMPT_CMD_ID;
|
||||
// Some(tmp)
|
||||
// Doesn't work
|
||||
None
|
||||
}
|
||||
|
||||
fn set_voice_prompt_packet(&self, enable: bool) -> Vec<u8> {
|
||||
fn set_voice_prompt_packet(&self, enable: bool) -> Option<Vec<u8>> {
|
||||
let mut tmp = BASE_PACKET2.to_vec();
|
||||
tmp[2] = SET_VOICE_PROMPT_CMD_ID;
|
||||
tmp
|
||||
Some(tmp)
|
||||
}
|
||||
|
||||
fn get_wireless_connected_status_packet(&self) -> Vec<u8> {
|
||||
fn get_wireless_connected_status_packet(&self) -> Option<Vec<u8>> {
|
||||
let mut tmp = BASE_PACKET.to_vec();
|
||||
tmp[3] = GET_WIRELESS_STATUS_CMD_ID;
|
||||
tmp
|
||||
Some(tmp)
|
||||
}
|
||||
|
||||
fn get_event_from_device_response(&self, response: &[u8]) -> Option<DeviceEvent> {
|
||||
match (response[2], response[3], response[4], response[7]) {
|
||||
(_, GET_CHARGING_CMD_ID, status, _) => Some(DeviceEvent::Charging(ChargingStatus::from(status))),
|
||||
(_, GET_MIC_CONNECTED_CMD_ID, status, _) => Some(DeviceEvent::MicConnected(status == 1)),
|
||||
(_, GET_CHARGING_CMD_ID, status, _) => {
|
||||
Some(DeviceEvent::Charging(ChargingStatus::from(status)))
|
||||
}
|
||||
(_, GET_MIC_CONNECTED_CMD_ID, status, _) => {
|
||||
Some(DeviceEvent::MicConnected(status == 1))
|
||||
}
|
||||
(_, GET_BATTERY_CMD_ID, _, level) => Some(DeviceEvent::BatterLevel(level)),
|
||||
(_, GET_AUTO_SHUTDOWN_CMD_ID, time, _) => Some(DeviceEvent::AutomaticShutdownAfter(Duration::from_secs(time as u64 * 60))),
|
||||
(_, GET_AUTO_SHUTDOWN_CMD_ID, time, _) => Some(DeviceEvent::AutomaticShutdownAfter(
|
||||
Duration::from_secs(time as u64 * 60),
|
||||
)),
|
||||
(_, GET_MUTE_CMD_ID, status, _) => Some(DeviceEvent::Muted(status == 1)),
|
||||
(_, GET_PAIRING_CMD_ID, status, _) => Some(DeviceEvent::PairingInfo(status)),
|
||||
(_, GET_SIDE_TONE_ON_CMD_ID, status, _) => Some(DeviceEvent::SideToneOn(status == 1)),
|
||||
(_, GET_SIDE_TONE_VOLUME_CMD_ID, status, _) => Some(DeviceEvent::SideToneVolume(status)),
|
||||
(_, GET_WIRELESS_STATUS_CMD_ID, status, _) => Some(DeviceEvent::WirelessConnected(status == 1 || status == 4)),
|
||||
(_, GET_SIDE_TONE_VOLUME_CMD_ID, status, _) => {
|
||||
Some(DeviceEvent::SideToneVolume(status))
|
||||
}
|
||||
(_, GET_WIRELESS_STATUS_CMD_ID, status, _) => {
|
||||
Some(DeviceEvent::WirelessConnected(status == 1 || status == 4))
|
||||
}
|
||||
(GET_VOICE_PROMPT_CMD_ID, status, _, _) => Some(DeviceEvent::VoicePrompt(status == 1)),
|
||||
(GET_PRODUCT_COLOR_CMD_ID, status, _, _) => Some(DeviceEvent::ProductColor(Color::from(status))),
|
||||
_ => None
|
||||
(GET_PRODUCT_COLOR_CMD_ID, status, _, _) => {
|
||||
Some(DeviceEvent::ProductColor(Color::from(status)))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_device_state(&mut self) -> &mut DeviceState {
|
||||
&mut self.state
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -210,22 +210,22 @@ impl From<u8> for ChargingStatus {
|
||||
}
|
||||
|
||||
pub trait Device {
|
||||
fn get_charging_packet(&self) -> Vec<u8>;
|
||||
fn get_battery_packet(&self) -> Vec<u8>;
|
||||
fn set_automatic_shut_down_packet(&self, shutdown_after: Duration) -> Vec<u8>;
|
||||
fn get_automatic_shut_down_packet(&self) -> Vec<u8>;
|
||||
fn get_mute_packet(&self) -> Vec<u8>;
|
||||
fn set_mute_packet(&self, mute: bool) -> Vec<u8>;
|
||||
fn get_mic_connected_packet(&self) -> Vec<u8>;
|
||||
fn get_pairing_info_packet(&self) -> Vec<u8>;
|
||||
fn get_product_color_packet(&self) -> Vec<u8>;
|
||||
fn get_side_tone_packet(&self) -> Vec<u8>;
|
||||
fn set_side_tone_packet(&self, side_tone_on: bool) -> Vec<u8>;
|
||||
fn get_side_tone_volume_packet(&self) -> Vec<u8>;
|
||||
fn set_side_tone_volume_packet(&self) -> Vec<u8>;
|
||||
fn get_voice_prompt_packet(&self) -> Vec<u8>;
|
||||
fn set_voice_prompt_packet(&self, enable: bool) -> Vec<u8>;
|
||||
fn get_wireless_connected_status_packet(&self) -> Vec<u8>;
|
||||
fn get_charging_packet(&self) -> Option<Vec<u8>>;
|
||||
fn get_battery_packet(&self) -> Option<Vec<u8>>;
|
||||
fn set_automatic_shut_down_packet(&self, shutdown_after: Duration) -> Option<Vec<u8>>;
|
||||
fn get_automatic_shut_down_packet(&self) -> Option<Vec<u8>>;
|
||||
fn get_mute_packet(&self) -> Option<Vec<u8>>;
|
||||
fn set_mute_packet(&self, mute: bool) -> Option<Vec<u8>>;
|
||||
fn get_mic_connected_packet(&self) -> Option<Vec<u8>>;
|
||||
fn get_pairing_info_packet(&self) -> Option<Vec<u8>>;
|
||||
fn get_product_color_packet(&self) -> Option<Vec<u8>>;
|
||||
fn get_side_tone_packet(&self) -> Option<Vec<u8>>;
|
||||
fn set_side_tone_packet(&self, side_tone_on: bool) -> Option<Vec<u8>>;
|
||||
fn get_side_tone_volume_packet(&self) -> Option<Vec<u8>>;
|
||||
fn set_side_tone_volume_packet(&self) -> Option<Vec<u8>>;
|
||||
fn get_voice_prompt_packet(&self) -> Option<Vec<u8>>;
|
||||
fn set_voice_prompt_packet(&self, enable: bool) -> Option<Vec<u8>>;
|
||||
fn get_wireless_connected_status_packet(&self) -> Option<Vec<u8>>;
|
||||
fn get_event_from_device_response(&self, response: &[u8]) -> Option<DeviceEvent>;
|
||||
fn get_device_state(&mut self) -> &mut DeviceState;
|
||||
|
||||
@@ -253,21 +253,23 @@ pub trait Device {
|
||||
self.get_mute_packet(),
|
||||
self.get_mic_connected_packet(),
|
||||
self.get_pairing_info_packet(),
|
||||
// self.get_product_color_packet(),
|
||||
self.get_product_color_packet(),
|
||||
self.get_side_tone_packet(),
|
||||
self.get_side_tone_volume_packet(),
|
||||
// self.get_voice_prompt_packet(),
|
||||
self.get_voice_prompt_packet(),
|
||||
];
|
||||
|
||||
let mut responded = false;
|
||||
for packet in packets {
|
||||
self.get_device_state().hid_device.write(&packet)?;
|
||||
if let Some(event) = self.wait_for_updates(Duration::from_secs(1)) {
|
||||
self.get_device_state().update_self_with_event(&event);
|
||||
responded = true;
|
||||
}
|
||||
if !self.get_device_state().connected.map_or(true, |c| c) {
|
||||
break;
|
||||
if let Some(packet) = packet {
|
||||
self.get_device_state().hid_device.write(&packet)?;
|
||||
if let Some(event) = self.wait_for_updates(Duration::from_secs(1)) {
|
||||
self.get_device_state().update_self_with_event(&event);
|
||||
responded = true;
|
||||
}
|
||||
if !self.get_device_state().connected.map_or(true, |c| c) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user