Skip to content

Commit 694b857

Browse files
authored
fix(protocol): handle out-of-range battery voltage as unavailable (#516)
Add minimum voltage check in HIDPPDevice::requestBatteryHIDPP to return BATTERY_UNAVAILABLE when measured voltage is below the device's calibrated minimum. This prevents spline interpolation on invalid readings from offline or disconnected headsets. All HID++ battery calibrations store voltages in descending order, so calibration.voltages.back() correctly returns the minimum valid voltage. Affected devices: - Logitech G633/G635/G733/G933/G935 (LOGITECH_G633 calibration) - Logitech G533 (LOGITECH_G533 calibration) - Logitech G535 (LOGITECH_G535 calibration) - Logitech G PRO Series (LOGITECH_GPRO calibration)
1 parent b10c0ed commit 694b857

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

lib/devices/protocols/hidpp_protocol.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ class HIDPPDevice : public HIDDevice {
135135
// Extract voltage from bytes 4 and 5 (big-endian)
136136
uint16_t voltage = (static_cast<uint16_t>(response[4]) << 8) | response[5];
137137

138+
// Check if voltage is below the minimum valid calibrated voltage for the device.
139+
// If the measured voltage is below this threshold, the headset is likely offline or the reading is invalid.
140+
// This check applies to all HID++ devices using this generic battery request method.
141+
if (voltage < calibration.voltages.back()) {
142+
return BatteryResult {
143+
.level_percent = -1,
144+
.status = BATTERY_UNAVAILABLE,
145+
.voltage_mv = static_cast<int>(voltage),
146+
.raw_data = response,
147+
.query_duration = duration
148+
};
149+
}
150+
138151
// Estimate battery percentage using spline interpolation
139152
int level = headsetcontrol::spline_battery_level(
140153
calibration.percentages,

0 commit comments

Comments
 (0)