Merge pull request #118 from Lekensteyn/fixes
Regression fixes: --hidraw option, python3, hidpp10
This commit is contained in:
commit
ab3a6b50d4
|
@ -210,9 +210,10 @@ class FeaturesArray(object):
|
|||
indices = index.indices(len(self.features))
|
||||
return [self.__getitem__(i) for i in range(*indices)]
|
||||
|
||||
def __contains__(self, value):
|
||||
def __contains__(self, featureId):
|
||||
"""Tests whether the list contains given Feature ID"""
|
||||
if self._check():
|
||||
ivalue = int(value)
|
||||
ivalue = int(featureId)
|
||||
|
||||
may_have = False
|
||||
for f in self.features:
|
||||
|
@ -220,8 +221,6 @@ class FeaturesArray(object):
|
|||
may_have = True
|
||||
elif ivalue == int(f):
|
||||
return True
|
||||
elif ivalue < int(f):
|
||||
break
|
||||
|
||||
if may_have:
|
||||
reply = self.device.request(0x0000, _pack('!H', ivalue))
|
||||
|
@ -231,17 +230,16 @@ class FeaturesArray(object):
|
|||
self.features[index] = FEATURE[ivalue]
|
||||
return True
|
||||
|
||||
def index(self, value):
|
||||
def index(self, featureId):
|
||||
"""Gets the Feature Index for a given Feature ID"""
|
||||
if self._check():
|
||||
may_have = False
|
||||
ivalue = int(value)
|
||||
ivalue = int(featureId)
|
||||
for index, f in enumerate(self.features):
|
||||
if f is None:
|
||||
may_have = True
|
||||
elif ivalue == int(f):
|
||||
return index
|
||||
elif ivalue < int(f):
|
||||
raise ValueError("%r not in list" % value)
|
||||
|
||||
if may_have:
|
||||
reply = self.device.request(0x0000, _pack('!H', ivalue))
|
||||
|
@ -250,7 +248,7 @@ class FeaturesArray(object):
|
|||
self.features[index] = FEATURE[ivalue]
|
||||
return index
|
||||
|
||||
raise ValueError("%r not in list" % value)
|
||||
raise ValueError("%r not in list" % featureId)
|
||||
|
||||
def __iter__(self):
|
||||
if self._check():
|
||||
|
|
|
@ -127,7 +127,7 @@ def _process_hidpp10_custom_notification(device, status, n):
|
|||
status.set_battery_info(charge, status_text)
|
||||
return True
|
||||
|
||||
if n.sub_id == _R.illumination:
|
||||
if n.sub_id == _R.keyboard_illumination:
|
||||
# message layout: 10 ix 17("address") <??> <?> <??> <light level 1=off..5=max>
|
||||
# TODO anything we can do with this?
|
||||
if _log.isEnabledFor(_INFO):
|
||||
|
|
|
@ -76,10 +76,12 @@ _cli_parser, actions = _create_parser()
|
|||
print_help = _cli_parser.print_help
|
||||
|
||||
|
||||
def _receivers():
|
||||
def _receivers(dev_path=None):
|
||||
from logitech_receiver import Receiver
|
||||
from logitech_receiver.base import receivers
|
||||
for dev_info in receivers():
|
||||
if dev_path is not None and dev_path != dev_info.path:
|
||||
continue
|
||||
try:
|
||||
r = Receiver.open(dev_info)
|
||||
if _log.isEnabledFor(_DEBUG):
|
||||
|
@ -130,17 +132,23 @@ def _find_device(receivers, name):
|
|||
raise Exception("no device found matching '%s'" % name)
|
||||
|
||||
|
||||
def run(cli_args=None):
|
||||
def run(cli_args=None, hidraw_path=None):
|
||||
if cli_args:
|
||||
action = cli_args[0]
|
||||
args = _cli_parser.parse_args(cli_args)
|
||||
else:
|
||||
args = _cli_parser.parse_args()
|
||||
# Python 3 has an undocumented 'feature' that breaks parsing empty args
|
||||
# http://bugs.python.org/issue16308
|
||||
if not 'cmd' in args:
|
||||
_cli_parser.print_usage(_sys.stderr)
|
||||
_sys.stderr.write('%s: error: too few arguments\n' % NAME.lower())
|
||||
_sys.exit(2)
|
||||
action = args.action
|
||||
assert action in actions
|
||||
|
||||
try:
|
||||
c = list(_receivers())
|
||||
c = list(_receivers(hidraw_path))
|
||||
if not c:
|
||||
raise Exception('Logitech receiver not found')
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@ def _parse_arguments():
|
|||
arg_parser = argparse.ArgumentParser(prog=NAME.lower())
|
||||
arg_parser.add_argument('-d', '--debug', action='count', default=0,
|
||||
help='print logging messages, for debugging purposes (may be repeated for extra verbosity)')
|
||||
arg_parser.add_argument('-D', '--hidraw', action='store', dest='hidraw_path', metavar='PATH',
|
||||
help='unifying receiver to use; the first detected receiver if unspecified. Example: /dev/hidraw2')
|
||||
arg_parser.add_argument('--restart-on-wake-up', action='store_true',
|
||||
help='restart Solaar on sleep wake-up (experimental)')
|
||||
arg_parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__)
|
||||
|
@ -81,7 +83,7 @@ def main():
|
|||
|
||||
args = _parse_arguments()
|
||||
if not args: return
|
||||
if args.action: return _cli.run(args.action)
|
||||
if args.action: return _cli.run(args.action, args.hidraw_path)
|
||||
|
||||
_require('gi.repository', 'python-gi')
|
||||
_require('gi.repository.Gtk', 'gir1.2-gtk-3.0')
|
||||
|
|
Loading…
Reference in New Issue