fix: BatteryStatus-Mapping empirisch korrigiert
Byte-Zuordnung am echten HS80 verifiziert (Kabel ein/aus): 0x01 = Charging, 0x02 = Discharging, 0x03 = Low, 0x04 = Full Weicht vom ckb-next-Mapping ab. Verbose-Flag zeigt jetzt auch Property-Queries für weitere Diagnose.
This commit is contained in:
parent
812d14b81a
commit
488c4c2631
@ -69,14 +69,16 @@ unterstützt wird oder der Request ungültig war.
|
||||
|
||||
## Battery Status Werte
|
||||
|
||||
Empirisch ermittelt am HS80 RGB Wireless (2026-03-27).
|
||||
Weicht von ckb-next-Quellen ab — dort sind die Werte anders zugeordnet.
|
||||
|
||||
| Wert | Bedeutung |
|
||||
|------|---------------|
|
||||
| 0x00 | Offline |
|
||||
| 0x01 | Entladen |
|
||||
| 0x02 | Niedrig |
|
||||
| 0x03 | Laden |
|
||||
| 0x04 | Laden |
|
||||
| 0x05 | Voll geladen |
|
||||
| 0x01 | Laden |
|
||||
| 0x02 | Entladen |
|
||||
| 0x03 | Niedrig |
|
||||
| 0x04 | Voll geladen |
|
||||
|
||||
## Initialisierungssequenz
|
||||
|
||||
|
||||
@ -14,6 +14,7 @@ use crate::hid;
|
||||
/// und setzt beim Drop automatisch in den Hardware-Modus zurück.
|
||||
pub struct BragiDevice {
|
||||
device: HidDevice,
|
||||
verbose: bool,
|
||||
}
|
||||
|
||||
impl BragiDevice {
|
||||
@ -32,13 +33,14 @@ impl BragiDevice {
|
||||
if verbose {
|
||||
eprintln!("[init] Gerät gefunden und geöffnet");
|
||||
}
|
||||
let bragi = Self { device };
|
||||
bragi.initialize(verbose)?;
|
||||
let bragi = Self { device, verbose };
|
||||
bragi.initialize()?;
|
||||
Ok(bragi)
|
||||
}
|
||||
|
||||
/// Vollständige Bragi-Handshake-Sequenz.
|
||||
fn initialize(&self, verbose: bool) -> Result<()> {
|
||||
fn initialize(&self) -> Result<()> {
|
||||
let verbose = self.verbose;
|
||||
// Phase 1: Receiver initialisieren
|
||||
// Wake-Up: Firmware-Version lesen
|
||||
let packet = protocol::build_get_packet(ENDPOINT_RECEIVER, Property::AppFirmware.id());
|
||||
@ -118,6 +120,10 @@ impl BragiDevice {
|
||||
fn get_headset_property(&self, property: Property) -> Result<BragiResponse> {
|
||||
let packet = protocol::build_get_packet(ENDPOINT_HEADSET, property.id());
|
||||
let raw = hid::send_recv(&self.device, &packet)?;
|
||||
if self.verbose {
|
||||
let hex: Vec<String> = raw.iter().take(10).map(|b| format!("{b:02X}")).collect();
|
||||
eprintln!("[query] GET 0x{:02X} → {}", property.id(), hex.join(" "));
|
||||
}
|
||||
protocol::parse_response(&raw)
|
||||
}
|
||||
|
||||
|
||||
@ -37,13 +37,18 @@ pub enum BatteryStatus {
|
||||
}
|
||||
|
||||
impl BatteryStatus {
|
||||
/// Konvertiert das Status-Byte in einen BatteryStatus.
|
||||
///
|
||||
/// Mapping empirisch ermittelt am HS80 RGB Wireless (2026-03-27):
|
||||
/// 0x00 = Offline, 0x01 = Charging, 0x02 = Discharging,
|
||||
/// 0x03 = Discharging (Low), 0x04 = FullyCharged
|
||||
pub fn from_byte(value: u8) -> Self {
|
||||
match value {
|
||||
0x00 => Self::Offline,
|
||||
0x01 => Self::Discharging,
|
||||
0x02 => Self::Low,
|
||||
0x03 | 0x04 => Self::Charging,
|
||||
0x05 => Self::FullyCharged,
|
||||
0x01 => Self::Charging,
|
||||
0x02 => Self::Discharging,
|
||||
0x03 => Self::Low,
|
||||
0x04 => Self::FullyCharged,
|
||||
other => Self::Unknown(other),
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,25 +4,23 @@
|
||||
use corsairctl::bragi::properties::{battery_promille_to_percent, BatteryStatus, Property};
|
||||
|
||||
#[test]
|
||||
fn battery_status_from_byte_discharging() {
|
||||
assert_eq!(BatteryStatus::from_byte(0x01), BatteryStatus::Discharging);
|
||||
fn battery_status_from_byte_charging() {
|
||||
assert_eq!(BatteryStatus::from_byte(0x01), BatteryStatus::Charging);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn battery_status_from_byte_charging_both_values() {
|
||||
// Sowohl 0x03 als auch 0x04 bedeuten "Charging"
|
||||
assert_eq!(BatteryStatus::from_byte(0x03), BatteryStatus::Charging);
|
||||
assert_eq!(BatteryStatus::from_byte(0x04), BatteryStatus::Charging);
|
||||
fn battery_status_from_byte_discharging() {
|
||||
assert_eq!(BatteryStatus::from_byte(0x02), BatteryStatus::Discharging);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn battery_status_from_byte_all_known_values() {
|
||||
// Empirisch ermittelt am HS80 RGB Wireless
|
||||
assert_eq!(BatteryStatus::from_byte(0x00), BatteryStatus::Offline);
|
||||
assert_eq!(BatteryStatus::from_byte(0x01), BatteryStatus::Discharging);
|
||||
assert_eq!(BatteryStatus::from_byte(0x02), BatteryStatus::Low);
|
||||
assert_eq!(BatteryStatus::from_byte(0x03), BatteryStatus::Charging);
|
||||
assert_eq!(BatteryStatus::from_byte(0x04), BatteryStatus::Charging);
|
||||
assert_eq!(BatteryStatus::from_byte(0x05), BatteryStatus::FullyCharged);
|
||||
assert_eq!(BatteryStatus::from_byte(0x01), BatteryStatus::Charging);
|
||||
assert_eq!(BatteryStatus::from_byte(0x02), BatteryStatus::Discharging);
|
||||
assert_eq!(BatteryStatus::from_byte(0x03), BatteryStatus::Low);
|
||||
assert_eq!(BatteryStatus::from_byte(0x04), BatteryStatus::FullyCharged);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user