0x1004 · unifiedBattery
现代统一电量功能——一次调用即可读取充电百分比、粗略等级与充电状态,并支持设备主动推送实时更新。
现代的统一电量功能:一次调用即可得到百分比、粗略等级与充电状态,取代了较旧的 0x1000 batteryStatus / 0x1001 batteryVoltage。getBatteryCapabilities 报告设备能测量哪些项;getBatteryInfo 返回充电百分比、一个 BatteryLevel(满 / 良好 / 低 / 危急)以及一个 BatteryStatus(充电中、放电中……)。该功能还会在设备推送时发出实时更新。
OpenLogi 读取它,用于设备轮播与 list 清单中显示的电量百分比和充电状态。
规格: Logitech HID++ 2.0 —— x1004 unifiedBattery。用于: 电量百分比 / 充电状态。
Function reference
The UnifiedBatteryFeature wrapper (0x1004) exposes:
Methods
| Function | HID++ fn | Signature | Returns |
|---|---|---|---|
get_battery_capabilities | 0 | () | BatteryCapabilities |
get_battery_info | 1 | () | BatteryInfo |
listen | event | () | Receiver<BatteryEvent> |
get_battery_capabilities and get_battery_info are async and return Result<…, Hidpp20Error>. listen is synchronous and returns a channel receiver directly.
Types
BatteryCapabilities
Represents the capabilities of this feature and the battery itself.
| Field | Type | Description |
|---|---|---|
reported_levels | HashSet<BatteryLevel> | All BatteryLevel variants the feature supports and reports. |
rechargeable | bool | Whether the battery is rechargeable. |
percentage | bool | Whether the device supports reporting the current charge percentage in BatteryInfo::charging_percentage. |
BatteryInfo
Represents information about the current battery charge.
| Field | Type | Description |
|---|---|---|
charging_percentage | u8 | The current charge of the battery in percent. Always zero if BatteryCapabilities::percentage is false. |
level | BatteryLevel | The current (approximate) level of the battery. |
status | BatteryStatus | The current charging status of the battery. |
BatteryLevel
Represents an approximate level of the battery charge.
| Variant | Value | Description |
|---|---|---|
Critical | 1 | Critical battery level. |
Low | 2 | Low battery level. |
Good | 4 | Good battery level. |
Full | 8 | Full battery level. |
BatteryStatus
Represents the charging status of the battery.
| Variant | Value | Description |
|---|---|---|
Discharging | 0 | Battery is discharging. |
Charging | 1 | Battery is charging. |
ChargingSlow | 2 | Battery is charging slowly. |
Full | 3 | Battery is full. |
Error | 4 | Battery subsystem reported an error. |
Events
UnifiedBatteryFeature implements EmittingFeature<BatteryEvent>. Call listen() to obtain a channel receiver that yields BatteryEvent values pushed by the device.
BatteryEvent
| Variant | Payload | Description |
|---|---|---|
InfoUpdate | BatteryInfo | Emitted whenever the battery information changes. Always enabled. |
Wire format
Both request payloads are 3 zero bytes; the device replies with a 16-byte long-format payload and the crate reads the first few bytes via extend_payload().
get_battery_capabilities (fn 0)
Request: [0x00, 0x00, 0x00] (no parameters)
Response (byte → field):
| Byte | Field | Notes |
|---|---|---|
| 0, bit 0 | reported_levels contains Critical | set if payload[0] & 0x01 != 0 |
| 0, bit 1 | reported_levels contains Low | set if payload[0] & 0x02 != 0 |
| 0, bit 2 | reported_levels contains Good | set if payload[0] & 0x04 != 0 |
| 0, bit 3 | reported_levels contains Full | set if payload[0] & 0x08 != 0 |
| 1, bit 0 | rechargeable | set if payload[1] & 0x01 != 0 |
| 1, bit 1 | percentage | set if payload[1] & 0x02 != 0 |
get_battery_info (fn 1)
Request: [0x00, 0x00, 0x00] (no parameters)
Response (byte → field):
| Byte | Field | Notes |
|---|---|---|
| 0 | charging_percentage | raw u8; zero when BatteryCapabilities::percentage is false |
| 1 | level | BatteryLevel enum value (1 = Critical, 2 = Low, 4 = Good, 8 = Full) |
| 2 | status | BatteryStatus enum value (0 = Discharging … 4 = Error) |
| 3 | (external power source indicator) | not decoded by the crate; see Linux driver notes in source |
InfoUpdate event (fn 0, event sub-id 0)
The device pushes this event unsolicited whenever battery state changes. The crate's message listener parses it identically to get_battery_info:
| Byte | Field | Notes |
|---|---|---|
| 0 | charging_percentage | raw u8 |
| 1 | level | BatteryLevel enum value |
| 2 | status | BatteryStatus enum value |
Usage (Rust)
use hidpp::{
device::Device,
feature::{EmittingFeature, unified_battery::UnifiedBatteryFeature},
};
// device: &mut Device, already created via Device::new(channel, index)
device.enumerate_features().await?;
if let Some(feat) = device.get_feature::<UnifiedBatteryFeature>() {
// Query static capabilities once
let caps = feat.get_battery_capabilities().await?;
println!("rechargeable={}, percentage={}", caps.rechargeable, caps.percentage);
// Poll current state
let info = feat.get_battery_info().await?;
println!("{}% — {:?} / {:?}", info.charging_percentage, info.level, info.status);
// Subscribe to live updates pushed by the device
let rx = feat.listen();
while let Ok(event) = rx.recv().await {
println!("battery event: {:?}", event);
}
}