descriptors update (new device K230)

also assume by default all devices have battery info in register 0x0D,
and blacklist them when that's not the case
This commit is contained in:
Daniel Pavel 2012-12-12 21:41:29 +02:00
parent 0ed623caf9
commit 7bb7a092a4
2 changed files with 30 additions and 18 deletions

View File

@ -43,9 +43,9 @@ _D('Wireless Mouse M525')
_D('Wireless Trackball M570') _D('Wireless Trackball M570')
_D('Touch Mouse M600') _D('Touch Mouse M600')
_D('Marathon Mouse M705', _D('Marathon Mouse M705',
registers=_NamedInts(battery=0x0D),
settings=[hidpp10.SmoothScroll_Setting(0x01)], settings=[hidpp10.SmoothScroll_Setting(0x01)],
) )
_D('Wireless Keyboard K230')
_D('Wireless Keyboard K270') _D('Wireless Keyboard K270')
_D('Wireless Keyboard K350') _D('Wireless Keyboard K350')
_D('Wireless Keyboard K360') _D('Wireless Keyboard K360')
@ -55,13 +55,10 @@ _D('Wireless Illuminated Keyboard K800')
_D('Zone Touch Mouse T400') _D('Zone Touch Mouse T400')
_D('Wireless Rechargeable Touchpad T650') _D('Wireless Rechargeable Touchpad T650')
_D('Logitech Cube', kind='mouse') _D('Logitech Cube', kind='mouse')
_D('Anywhere Mouse MX', codename='Anywhere MX', _D('Anywhere Mouse MX', codename='Anywhere MX')
registers=_NamedInts(battery=0x0D),
)
_D('Performance Mouse MX', codename='Performance MX', _D('Performance Mouse MX', codename='Performance MX',
registers=_NamedInts(battery=0x0D),
settings=[ settings=[
hidpp10.MouseDPI_Setting(0x63, _NamedInts(**dict((str(x * 100), 0x80 + x) for x in range(1, 16)))), hidpp10.MouseDPI_Setting(0x63, _NamedInts(**{str(x * 100): (0x80 + x) for x in range(1, 16)})),
], ],
) )

View File

@ -4,8 +4,13 @@
from __future__ import absolute_import, division, print_function, unicode_literals from __future__ import absolute_import, division, print_function, unicode_literals
from logging import getLogger, DEBUG as _DEBUG
_log = getLogger('LUR').getChild('hidpp10')
del getLogger
from .common import (strhex as _strhex, from .common import (strhex as _strhex,
NamedInts as _NamedInts, NamedInts as _NamedInts,
NamedInt as _NamedInt,
FirmwareInfo as _FirmwareInfo) FirmwareInfo as _FirmwareInfo)
from . import settings as _settings from . import settings as _settings
from .hidpp20 import FIRMWARE_KIND from .hidpp20 import FIRMWARE_KIND
@ -119,20 +124,30 @@ class MouseDPI_Setting(_settings.Setting):
# functions # functions
# #
def get_battery(device): def get_register(device, name, default_number=-1):
"""Reads a device's battery level, if provided by the HID++ 1.0 protocol.""" known_register = device.registers[name]
if 'battery' in device.registers: register = known_register or default_number
register = device.registers['battery'] if register > 0:
reply = device.request(0x8100 + (register & 0xFF)) reply = device.request(0x8100 + (register & 0xFF))
if reply: if reply:
charge = ord(reply[:1]) return reply
status = ord(reply[2:3]) & 0xF0
status = ('discharging' if status == 0x30 if not known_register and device.ping():
else 'charging' if status == 0x50 _log.warn("%s: failed to read '%s' from default register 0x%02X, blacklisting", device, name, default_number)
else 'fully charged' if status == 0x90 device.registers[-default_number] = name
else None)
return charge, status
def get_battery(device):
"""Reads a device's battery level, if provided by the HID++ 1.0 protocol."""
reply = get_register(device, 'battery', 0x0D)
if reply:
charge = ord(reply[:1])
status = ord(reply[2:3]) & 0xF0
status = ('discharging' if status == 0x30
else 'charging' if status == 0x50
else 'fully charged' if status == 0x90
else None)
return charge, status
def get_serial(device): def get_serial(device):