some code clean-ups

This commit is contained in:
Daniel Pavel 2013-04-28 15:16:45 +02:00
parent a57f3be58d
commit feedbcf581
5 changed files with 12 additions and 15 deletions

View File

@ -371,15 +371,15 @@ def ping(handle, devnumber):
delta = _timestamp() - now
if reply:
report_id, number, data = reply
if number == devnumber:
if data[:2] == request_data[:2] and data[4:5] == request_data[-1:]:
report_id, reply_devnumber, reply_data = reply
if reply_devnumber == devnumber:
if reply_data[:2] == request_data[:2] and reply_data[4:5] == request_data[-1:]:
# HID++ 2.0+ device, currently connected
return ord(data[2:3]) + ord(data[3:4]) / 10.0
return ord(reply_data[2:3]) + ord(reply_data[3:4]) / 10.0
if report_id == 0x10 and data[:1] == b'\x8F' and data[1:3] == request_data[:2]:
assert data[-1:] == b'\x00'
error = ord(data[3:4])
if report_id == 0x10 and reply_data[:1] == b'\x8F' and reply_data[1:3] == request_data[:2]:
assert reply_data[-1:] == b'\x00'
error = ord(reply_data[3:4])
if error == _hidpp10.ERROR.invalid_SubID__command: # a valid reply from a HID++ 1.0 device
return 1.0

View File

@ -17,7 +17,7 @@ class NamedInt(int):
def __new__(cls, value, name):
assert isinstance(name, str) or isinstance(name, unicode)
obj = int.__new__(cls, value)
obj.name = str(name)
obj.name = unicode(name)
return obj
def bytes(self, count=2):
@ -66,8 +66,7 @@ class NamedInts(object):
def _readable_name(n):
if not isinstance(n, str) and not isinstance(n, unicode):
raise TypeError("expected string, got " + type(n))
n = n.replace('__', '/').replace('_', ' ')
return str(n)
return n.replace('__', '/').replace('_', ' ')
values = {k: NamedInt(v, _readable_name(k)) for (k, v) in kwargs.items()}
self.__dict__ = values
@ -75,8 +74,6 @@ class NamedInts(object):
self._indexed = {int(v): v for v in self._values}
self._fallback = None
# print ('%r' % self)
@classmethod
def range(cls, from_value, to_value, name_generator=lambda x: str(x), step=1):
values = {name_generator(x): x for x in range(from_value, to_value + 1, step)}

View File

@ -82,7 +82,7 @@ _D('Touch Mouse M600')
_D('Marathon Mouse M705',
settings=[
_register_smooth_scroll(0x01, true_value=0x40, mask=0x40),
# _register_dpi(0x63, _NamedInts.range(9, 11, lambda x: str(x * 100))),
# _register_dpi(0x63, _NamedInts(**{'100': 10, '300': 30, '350':35, '500':50})),
],
)
_D('Wireless Keyboard K230')

View File

@ -41,7 +41,7 @@ POWER_SWITCH_LOCATION = _NamedInts(
NOTIFICATION_FLAG = _NamedInts(
battery_status=0x100000,
wireless=0x000100,
software_present=0x0000800)
software_present=0x000800)
ERROR = _NamedInts(
invalid_SubID__command=0x01,

View File

@ -25,7 +25,7 @@ del namedtuple
def _ghost(device):
return _GHOST_DEVICE(number=device.number, name=device.name, kind=device.kind, status=None, max_devices=None)
DUMMY = _GHOST_DEVICE(Receiver.number, Receiver.name, None, 'Receiver not found.', Receiver.max_devices)
DUMMY = _GHOST_DEVICE(Receiver.number, 'dialog-error', None, 'Receiver not found.', 6)
#
#