device: add support for ADC MEASUREMENT battery feature
This commit is contained in:
parent
83eb836177
commit
4c126f417d
|
@ -1310,10 +1310,28 @@ def decipher_battery_voltage(report):
|
|||
return FEATURE.BATTERY_VOLTAGE, charge_lvl, None, status, voltage
|
||||
|
||||
|
||||
def get_adc_measurement(device):
|
||||
try: # this feature call has been known to produce errors so be extra cautious
|
||||
report = feature_request(device, FEATURE.ADC_MEASUREMENT)
|
||||
if report is not None:
|
||||
return decipher_adc_measurement(report)
|
||||
except FeatureCallError:
|
||||
return None
|
||||
|
||||
|
||||
def decipher_adc_measurement(report):
|
||||
# partial implementation - needs mapping to levels
|
||||
adc, flags = _unpack('!HB', report[:3])
|
||||
if flags & 0x01:
|
||||
status = BATTERY_STATUS.recharging if flags & 0x02 else BATTERY_STATUS.discharging
|
||||
return FEATURE.ADC_MEASUREMENT, None, None, status, adc
|
||||
|
||||
|
||||
battery_functions = {
|
||||
FEATURE.BATTERY_STATUS: get_battery_status,
|
||||
FEATURE.BATTERY_VOLTAGE: get_battery_unified,
|
||||
FEATURE.UNIFIED_BATTERY: get_battery_voltage,
|
||||
FEATURE.ADC_MEASUREMENT: get_adc_measurement,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -337,6 +337,13 @@ def _process_feature_notification(device, status, n, feature):
|
|||
else:
|
||||
_log.warn('%s: unknown UNIFIED BATTERY %s', device, n)
|
||||
|
||||
elif feature == _F.ADC_MEASUREMENT:
|
||||
if n.address == 0x00:
|
||||
_ignore, level, next, status, voltage = _hidpp20.decipher_adc_measurement(n.data)
|
||||
status.set_battery_info(level, next, status, voltage)
|
||||
else:
|
||||
_log.warn('%s: unknown ADC MEASUREMENT %s', device, n)
|
||||
|
||||
elif feature == _F.SOLAR_DASHBOARD:
|
||||
if n.data[5:9] == b'GOOD':
|
||||
charge, lux, adc = _unpack('!BHH', n.data[:5])
|
||||
|
|
Loading…
Reference in New Issue