From 7fbb0d12757e50f50faefa250acad8387e981e23 Mon Sep 17 00:00:00 2001 From: Peron Date: Sun, 28 Jun 2026 14:49:25 +0800 Subject: [PATCH] fix(hidpp): correct UnifiedBattery (0x1004) charging status codes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The getStatus battery-status byte values 2 and 4 were mislabeled: 2 is the final charging stage (nearly full) and 4 is a below-optimal-speed recharge — not a slow charge and a generic error. Codes 5-7 (invalid battery, thermal error, charging error) were missing entirely. Align BatteryStatus with the Linux hid-logitech-hidpp unified-battery mapping and Solaar, and update map_battery_status: the nearly-full stage maps to Charging and 5-7 map to Error, leaving the core domain enum and GUI unchanged. --- crates/openlogi-hid/src/mappings.rs | 8 ++++++-- .../src/feature/unified_battery/mod.rs | 19 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/crates/openlogi-hid/src/mappings.rs b/crates/openlogi-hid/src/mappings.rs index 18ab81cb..f6f456c5 100644 --- a/crates/openlogi-hid/src/mappings.rs +++ b/crates/openlogi-hid/src/mappings.rs @@ -104,10 +104,14 @@ pub(crate) fn map_battery_level(level: HidppBatteryLevel) -> BatteryLevel { pub(crate) fn map_battery_status(status: HidppBatteryStatus) -> BatteryStatus { match status { HidppBatteryStatus::Discharging => BatteryStatus::Discharging, - HidppBatteryStatus::Charging => BatteryStatus::Charging, + HidppBatteryStatus::Charging | HidppBatteryStatus::ChargingNearlyFull => { + BatteryStatus::Charging + } HidppBatteryStatus::ChargingSlow => BatteryStatus::ChargingSlow, HidppBatteryStatus::Full => BatteryStatus::Full, - HidppBatteryStatus::Error => BatteryStatus::Error, + HidppBatteryStatus::InvalidBattery + | HidppBatteryStatus::ThermalError + | HidppBatteryStatus::ChargingError => BatteryStatus::Error, _ => BatteryStatus::Unknown, } } diff --git a/crates/openlogi-hidpp/src/feature/unified_battery/mod.rs b/crates/openlogi-hidpp/src/feature/unified_battery/mod.rs index 26faf521..c6104129 100755 --- a/crates/openlogi-hidpp/src/feature/unified_battery/mod.rs +++ b/crates/openlogi-hidpp/src/feature/unified_battery/mod.rs @@ -183,7 +183,8 @@ pub enum BatteryLevel { Full = 1 << 3, } -/// Represents the charging status of the battery. +/// Represents the charging status of the battery, as reported in the `0x1004` +/// `getStatus` battery-status byte. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, IntoPrimitive, TryFromPrimitive)] #[cfg_attr(feature = "serde", derive(serde::Serialize))] #[non_exhaustive] @@ -193,12 +194,18 @@ pub enum BatteryStatus { Discharging = 0, /// Battery is charging. Charging = 1, - /// Battery is charging slowly. - ChargingSlow = 2, - /// Battery is full. + /// Battery is charging and in its final stage (nearly full). + ChargingNearlyFull = 2, + /// Battery charge is complete. Full = 3, - /// Battery subsystem reported an error. - Error = 4, + /// Battery is recharging below optimal speed. + ChargingSlow = 4, + /// The battery type is invalid. + InvalidBattery = 5, + /// The battery subsystem reported a thermal error. + ThermalError = 6, + /// The battery subsystem reported a charging error. + ChargingError = 7, } /// Represents an event emitted by the [`UnifiedBatteryFeature`] feature.