Add second base packet which might work on the older HyperX Cloud 2

This commit is contained in:
Lennard Kittner
2025-03-27 22:01:56 +01:00
parent 50f61a7775
commit ae40be64d4

View File

@@ -1,17 +1,32 @@
use crate::devices::{ChargingStatus, Color, Device, DeviceError, DeviceEvent, DeviceState};
use std::time::Duration;
// Possible vendor IDs [HP]
const VENDOR_IDS: [u16; 1] = [0x03F0];
const HP: u16 = 0x03F0;
const HYPERX: u16 = 0x0696;
const VENDOR_IDS: [u16; 2] = [HP, HYPERX];
// Possible Cloud II Wireless product IDs
const PRODUCT_IDS: [u16; 4] = [0x1718, 0x018B, 0x0D93, 0x0696];
const BASE_PACKET: [u8; 20] = {
const BASE_PACKET_HP: [u8; 20] = {
let mut packet = [0; 20];
(packet[0], packet[1], packet[2]) = (0x06, 0xff, 0xbb);
packet
};
const BASE_PACKET_HYPERX: [u8; 62] = {
let mut packet = [0; 62];
packet[0] = 0x06;
packet[2] = 0x02;
packet[4] = 0x9A;
packet[7] = 0x68;
packet[8] = 0x4A;
packet[9] = 0x8E;
packet[10] = 0x0A;
packet[14] = 0xBB;
packet[15] = 0x01;
packet
};
#[allow(dead_code)]
const BASE_PACKET2: [u8; 20] = {
let mut packet = [0; 20];
@@ -39,66 +54,77 @@ const GET_WIRELESS_STATUS_CMD_ID: u8 = 1;
pub struct CloudIIWirelessDTS {
state: DeviceState,
base_packet: &'static [u8],
}
impl CloudIIWirelessDTS {
pub fn new_from_state(state: DeviceState) -> Self {
CloudIIWirelessDTS { state }
let base_packet = if state.vendor_id == HP {
BASE_PACKET_HP.as_ref()
} else {
BASE_PACKET_HYPERX.as_ref()
};
CloudIIWirelessDTS { state, base_packet }
}
pub fn new() -> Result<Self, DeviceError> {
let state = DeviceState::new(&PRODUCT_IDS, &VENDOR_IDS)?;
Ok(CloudIIWirelessDTS { state })
let base_packet = if state.vendor_id == HP {
BASE_PACKET_HP.as_ref()
} else {
BASE_PACKET_HYPERX.as_ref()
};
Ok(CloudIIWirelessDTS { state, base_packet })
}
}
impl Device for CloudIIWirelessDTS {
fn get_charging_packet(&self) -> Option<Vec<u8>> {
let mut tmp = BASE_PACKET.to_vec();
let mut tmp = self.base_packet.to_vec();
tmp[3] = GET_CHARGING_CMD_ID;
Some(tmp)
}
fn get_battery_packet(&self) -> Option<Vec<u8>> {
let mut tmp = BASE_PACKET.to_vec();
let mut tmp = self.base_packet.to_vec();
tmp[3] = GET_BATTERY_CMD_ID;
Some(tmp)
}
fn set_automatic_shut_down_packet(&self, shutdown_after: Duration) -> Option<Vec<u8>> {
let mut tmp = BASE_PACKET.to_vec();
let mut tmp = self.base_packet.to_vec();
tmp[3] = SET_AUTO_SHUTDOWN_CMD_ID;
tmp[4] = (shutdown_after.as_secs() / 60) as u8;
Some(tmp)
}
fn get_automatic_shut_down_packet(&self) -> Option<Vec<u8>> {
let mut tmp = BASE_PACKET.to_vec();
let mut tmp = self.base_packet.to_vec();
tmp[3] = GET_AUTO_SHUTDOWN_CMD_ID;
Some(tmp)
}
fn get_mute_packet(&self) -> Option<Vec<u8>> {
let mut tmp = BASE_PACKET.to_vec();
let mut tmp = self.base_packet.to_vec();
tmp[3] = GET_MUTE_CMD_ID;
Some(tmp)
}
fn set_mute_packet(&self, mute: bool) -> Option<Vec<u8>> {
let mut tmp = BASE_PACKET.to_vec();
let mut tmp = self.base_packet.to_vec();
tmp[3] = SET_MUTE_CMD_ID;
tmp[4] = mute as u8;
Some(tmp)
}
fn get_mic_connected_packet(&self) -> Option<Vec<u8>> {
let mut tmp = BASE_PACKET.to_vec();
let mut tmp = self.base_packet.to_vec();
tmp[3] = GET_MIC_CONNECTED_CMD_ID;
Some(tmp)
}
fn get_pairing_info_packet(&self) -> Option<Vec<u8>> {
let mut tmp = BASE_PACKET.to_vec();
let mut tmp = self.base_packet.to_vec();
tmp[3] = GET_PAIRING_CMD_ID;
Some(tmp)
}
@@ -112,26 +138,26 @@ impl Device for CloudIIWirelessDTS {
}
fn get_side_tone_packet(&self) -> Option<Vec<u8>> {
let mut tmp = BASE_PACKET.to_vec();
let mut tmp = self.base_packet.to_vec();
tmp[3] = GET_SIDE_TONE_ON_CMD_ID;
Some(tmp)
}
fn set_side_tone_packet(&self, side_tone_on: bool) -> Option<Vec<u8>> {
let mut tmp = BASE_PACKET.to_vec();
let mut tmp = self.base_packet.to_vec();
tmp[3] = SET_SIDE_TONE_ON_CMD_ID;
tmp[4] = side_tone_on as u8;
Some(tmp)
}
fn get_side_tone_volume_packet(&self) -> Option<Vec<u8>> {
let mut tmp = BASE_PACKET.to_vec();
let mut tmp = self.base_packet.to_vec();
tmp[3] = GET_SIDE_TONE_VOLUME_CMD_ID;
Some(tmp)
}
fn set_side_tone_volume_packet(&self, volume: u8) -> Option<Vec<u8>> {
let mut tmp = BASE_PACKET.to_vec();
let mut tmp = self.base_packet.to_vec();
tmp[3] = SET_SIDE_TONE_VOLUME_CMD_ID;
tmp[4] = volume;
Some(tmp)
@@ -154,7 +180,7 @@ impl Device for CloudIIWirelessDTS {
}
fn get_wireless_connected_status_packet(&self) -> Option<Vec<u8>> {
let mut tmp = BASE_PACKET.to_vec();
let mut tmp = self.base_packet.to_vec();
tmp[3] = GET_WIRELESS_STATUS_CMD_ID;
Some(tmp)
}