Skip to content

Commit

Permalink
yapf: adjust style to not indent closing brackets
Browse files Browse the repository at this point in the history
Signed-off-by: Filipe Laíns <lains@archlinux.org>
  • Loading branch information
FFY00 committed Jul 7, 2020
1 parent bbaa144 commit 27c90fa
Show file tree
Hide file tree
Showing 27 changed files with 798 additions and 625 deletions.
6 changes: 4 additions & 2 deletions bin/solaar
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ def init_paths():
sys.path[0].encode(sys.getfilesystemencoding())

except UnicodeError:
sys.stderr.write('ERROR: Solaar cannot recognize encoding of filesystem path, '
'this may happen because non UTF-8 characters in the pathname.\n')
sys.stderr.write(
'ERROR: Solaar cannot recognize encoding of filesystem path, '
'this may happen because non UTF-8 characters in the pathname.\n'
)
sys.exit(1)

prefix = _path.normpath(_path.join(_path.realpath(decoded_path), '..'))
Expand Down
28 changes: 17 additions & 11 deletions lib/hidapi/hidconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ def _print(marker, data, scroll=False):

if interactive and scroll:
# scroll the entire screen above the current line up by 1 line
sys.stdout.write('\033[s' # save cursor position
'\033[S' # scroll up
'\033[A' # cursor up
'\033[L' # insert 1 line
'\033[G') # move cursor to column 1
sys.stdout.write(
'\033[s' # save cursor position
'\033[S' # scroll up
'\033[A' # cursor up
'\033[L' # insert 1 line
'\033[G'
) # move cursor to column 1
sys.stdout.write(s)
if interactive and scroll:
# restore cursor position
Expand Down Expand Up @@ -164,8 +166,10 @@ def _open(args):
if not handle:
sys.exit('!! Failed to open %s, aborting.' % device)

print('.. Opened handle %r, vendor %r product %r serial %r.' %
(handle, _hid.get_manufacturer(handle), _hid.get_product(handle), _hid.get_serial(handle)))
print(
'.. Opened handle %r, vendor %r product %r serial %r.' %
(handle, _hid.get_manufacturer(handle), _hid.get_product(handle), _hid.get_serial(handle))
)
if args.hidpp:
if _hid.get_manufacturer(handle) != b'Logitech':
sys.exit('!! Only Logitech devices support the HID++ protocol.')
Expand All @@ -188,10 +192,12 @@ def _parse_arguments():
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('--history', help='history file (default ~/.hidconsole-history)')
arg_parser.add_argument('--hidpp', action='store_true', help='ensure input data is a valid HID++ request')
arg_parser.add_argument('device',
nargs='?',
help='linux device to connect to (/dev/hidrawX); '
'may be omitted if --hidpp is given, in which case it looks for the first Logitech receiver')
arg_parser.add_argument(
'device',
nargs='?',
help='linux device to connect to (/dev/hidrawX); '
'may be omitted if --hidpp is given, in which case it looks for the first Logitech receiver'
)
return arg_parser.parse_args()


Expand Down
64 changes: 35 additions & 29 deletions lib/hidapi/udev.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,19 @@

native_implementation = 'udev'

DeviceInfo = namedtuple('DeviceInfo', [
'path',
'vendor_id',
'product_id',
'serial',
'release',
'manufacturer',
'product',
'interface',
'driver',
])
DeviceInfo = namedtuple(
'DeviceInfo', [
'path',
'vendor_id',
'product_id',
'serial',
'release',
'manufacturer',
'product',
'interface',
'driver',
]
)
del namedtuple

#
Expand Down Expand Up @@ -121,29 +123,33 @@ def _match(action, device, filter):
return

attrs = usb_device.attributes
d_info = DeviceInfo(path=device.device_node,
vendor_id=vid[-4:],
product_id=pid[-4:],
serial=hid_device.get('HID_UNIQ'),
release=attrs.get('bcdDevice'),
manufacturer=attrs.get('manufacturer'),
product=attrs.get('product'),
interface=usb_interface,
driver=hid_driver_name)
d_info = DeviceInfo(
path=device.device_node,
vendor_id=vid[-4:],
product_id=pid[-4:],
serial=hid_device.get('HID_UNIQ'),
release=attrs.get('bcdDevice'),
manufacturer=attrs.get('manufacturer'),
product=attrs.get('product'),
interface=usb_interface,
driver=hid_driver_name
)
return d_info

elif action == 'remove':
# print (dict(device), dict(usb_device))

d_info = DeviceInfo(path=device.device_node,
vendor_id=vid[-4:],
product_id=pid[-4:],
serial=None,
release=None,
manufacturer=None,
product=None,
interface=None,
driver=None)
d_info = DeviceInfo(
path=device.device_node,
vendor_id=vid[-4:],
product_id=pid[-4:],
serial=None,
release=None,
manufacturer=None,
product=None,
interface=None,
driver=None
)
return d_info


Expand Down
34 changes: 21 additions & 13 deletions lib/logitech_receiver/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,20 +287,22 @@ def make_notification(devnumber, data):

address = ord(data[1:2])
if (
# standard HID++ 1.0 notification, SubId may be 0x40 - 0x7F
# standard HID++ 1.0 notification, SubId may be 0x40 - 0x7F
(sub_id >= 0x40) or # noqa: E131
# custom HID++1.0 battery events, where SubId is 0x07/0x0D
# custom HID++1.0 battery events, where SubId is 0x07/0x0D
(sub_id in (0x07, 0x0D) and len(data) == 5 and data[4:5] == b'\x00') or
# custom HID++1.0 illumination event, where SubId is 0x17
# custom HID++1.0 illumination event, where SubId is 0x17
(sub_id == 0x17 and len(data) == 5) or
# HID++ 2.0 feature notifications have the SoftwareID 0
(address & 0x0F == 0x00)): # noqa: E129
# HID++ 2.0 feature notifications have the SoftwareID 0
(address & 0x0F == 0x00)
): # noqa: E129
return _HIDPP_Notification(devnumber, sub_id, address, data[2:])


_HIDPP_Notification = namedtuple('_HIDPP_Notification', ('devnumber', 'sub_id', 'address', 'data'))
_HIDPP_Notification.__str__ = lambda self: 'Notification(%d,%02X,%02X,%s)' % (self.devnumber, self.sub_id, self.address,
_strhex(self.data))
_HIDPP_Notification.__str__ = lambda self: 'Notification(%d,%02X,%02X,%s)' % (
self.devnumber, self.sub_id, self.address, _strhex(self.data)
)
_HIDPP_Notification.__unicode__ = _HIDPP_Notification.__str__
DJ_NOTIFICATION_LENGTH = _MEDIUM_MESSAGE_SIZE - 4 # to allow easy distinguishing of DJ notifications
del namedtuple
Expand Down Expand Up @@ -374,15 +376,19 @@ def request(handle, devnumber, request_id, *params):
# raise NoSuchDevice(number=devnumber, request=request_id)

if _log.isEnabledFor(_DEBUG):
_log.debug('(%s) device 0x%02X error on request {%04X}: %d = %s', handle, devnumber, request_id, error,
_hidpp10.ERROR[error])
_log.debug(
'(%s) device 0x%02X error on request {%04X}: %d = %s', handle, devnumber, request_id, error,
_hidpp10.ERROR[error]
)
return

if reply_data[:1] == b'\xFF' and reply_data[1:3] == request_data[:2]:
# a HID++ 2.0 feature call returned with an error
error = ord(reply_data[3:4])
_log.error('(%s) device %d error on feature request {%04X}: %d = %s', handle, devnumber, request_id, error,
_hidpp20.ERROR[error])
_log.error(
'(%s) device %d error on feature request {%04X}: %d = %s', handle, devnumber, request_id, error,
_hidpp20.ERROR[error]
)
raise _hidpp20.FeatureCallError(number=devnumber, request=request_id, error=error, params=params)

if reply_data[:2] == request_data[:2]:
Expand Down Expand Up @@ -423,8 +429,10 @@ def request(handle, devnumber, request_id, *params):
# if _log.isEnabledFor(_DEBUG):
# _log.debug("(%s) still waiting for reply, delta %f", handle, delta)

_log.warn('timeout (%0.2f/%0.2f) on device %d request {%04X} params [%s]', delta, timeout, devnumber, request_id,
_strhex(params))
_log.warn(
'timeout (%0.2f/%0.2f) on device %d request {%04X} params [%s]', delta, timeout, devnumber, request_id,
_strhex(params)
)
# raise DeviceUnreachable(number=devnumber, request=request_id)


Expand Down
5 changes: 3 additions & 2 deletions lib/logitech_receiver/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ def __getattr__(self, k):
"""Reprogrammable keys information."""
ReprogrammableKeyInfo = namedtuple('ReprogrammableKeyInfo', ['index', 'key', 'task', 'flags'])

ReprogrammableKeyInfoV4 = namedtuple('ReprogrammableKeyInfoV4',
['index', 'key', 'task', 'flags', 'pos', 'group', 'group_mask', 'remapped'])
ReprogrammableKeyInfoV4 = namedtuple(
'ReprogrammableKeyInfoV4', ['index', 'key', 'task', 'flags', 'pos', 'group', 'group_mask', 'remapped']
)

del namedtuple
85 changes: 48 additions & 37 deletions lib/logitech_receiver/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
#
#

_DeviceDescriptor = namedtuple('_DeviceDescriptor',
('name', 'kind', 'wpid', 'codename', 'protocol', 'registers', 'settings', 'persister'))
_DeviceDescriptor = namedtuple(
'_DeviceDescriptor', ('name', 'kind', 'wpid', 'codename', 'protocol', 'registers', 'settings', 'persister')
)
del namedtuple

DEVICES = {}
Expand All @@ -42,8 +43,10 @@ def _D(name, codename=None, kind=None, wpid=None, protocol=None, registers=None,
assert name

if kind is None:
kind = (_DK.mouse if 'Mouse' in name else _DK.keyboard if 'Keyboard' in name else _DK.numpad if 'Number Pad' in name
else _DK.touchpad if 'Touchpad' in name else _DK.trackball if 'Trackball' in name else None)
kind = (
_DK.mouse if 'Mouse' in name else _DK.keyboard if 'Keyboard' in name else _DK.numpad
if 'Number Pad' in name else _DK.touchpad if 'Touchpad' in name else _DK.trackball if 'Trackball' in name else None
)
assert kind is not None, 'descriptor for %s does not have kind set' % name

# heuristic: the codename is the last word in the device name
Expand All @@ -70,14 +73,16 @@ def _D(name, codename=None, kind=None, wpid=None, protocol=None, registers=None,
elif w[0:1] == '2':
assert kind in (_DK.keyboard, _DK.numpad), '%s has protocol %0.1f, wpid %s' % (name, protocol, w)

device_descriptor = _DeviceDescriptor(name=name,
kind=kind,
wpid=wpid,
codename=codename,
protocol=protocol,
registers=registers,
settings=settings,
persister=persister)
device_descriptor = _DeviceDescriptor(
name=name,
kind=kind,
wpid=wpid,
codename=codename,
protocol=protocol,
registers=registers,
settings=settings,
persister=persister
)

assert codename not in DEVICES, 'duplicate codename in device descriptors: %s' % (DEVICES[codename], )
DEVICES[codename] = device_descriptor
Expand Down Expand Up @@ -293,24 +298,28 @@ def _D(name, codename=None, kind=None, wpid=None, protocol=None, registers=None,

_D('Wireless Mouse M150', protocol=2.0, wpid='4022')
_D('Wireless Mouse M175', protocol=2.0, wpid='4008')
_D('Wireless Mouse M185 new',
codename='M185n',
protocol=4.5,
wpid='4054',
settings=[
_FS.lowres_smooth_scroll(),
_FS.pointer_speed(),
])
_D(
'Wireless Mouse M185 new',
codename='M185n',
protocol=4.5,
wpid='4054',
settings=[
_FS.lowres_smooth_scroll(),
_FS.pointer_speed(),
]
)
# Apparently Logitech uses wpid 4055 for three different mice
# That's not so strange, as M185 is used on both Unifying-ready and non-Unifying-ready mice
_D('Wireless Mouse M185/M235/M310',
codename='M185/M235/M310',
protocol=4.5,
wpid='4055',
settings=[
_FS.lowres_smooth_scroll(),
_FS.pointer_speed(),
])
_D(
'Wireless Mouse M185/M235/M310',
codename='M185/M235/M310',
protocol=4.5,
wpid='4055',
settings=[
_FS.lowres_smooth_scroll(),
_FS.pointer_speed(),
]
)
_D('Wireless Mouse M185', protocol=2.0, wpid='4038')
_D('Wireless Mouse M187', protocol=2.0, wpid='4019')
_D('Wireless Mouse M215', protocol=1.0, wpid='1020')
Expand Down Expand Up @@ -390,15 +399,17 @@ def _D(name, codename=None, kind=None, wpid=None, protocol=None, registers=None,
_RS.side_scroll(),
],
)
_D('Marathon Mouse M705 (M-R0073)',
codename='M705 (M-R0073)',
protocol=4.5,
wpid='406D',
settings=[
_FS.hires_smooth_invert(),
_FS.hires_smooth_resolution(),
_FS.pointer_speed(),
])
_D(
'Marathon Mouse M705 (M-R0073)',
codename='M705 (M-R0073)',
protocol=4.5,
wpid='406D',
settings=[
_FS.hires_smooth_invert(),
_FS.hires_smooth_resolution(),
_FS.pointer_speed(),
]
)
_D('Zone Touch Mouse T400')
_D('Touch Mouse T620', protocol=2.0)
_D('Logitech Cube', kind=_DK.mouse, protocol=2.0)
Expand Down
Loading

0 comments on commit 27c90fa

Please sign in to comment.