From 80c36a02a9778e915a08f0c9ee8dbef498b29b29 Mon Sep 17 00:00:00 2001 From: Daniel Pavel Date: Sat, 8 Dec 2012 01:49:59 +0200 Subject: [PATCH] improved notifications detection --- app/solaar_cli.py | 16 +++++++++------- lib/logitech/unifying_receiver/common.py | 10 +++++++++- lib/logitech/unifying_receiver/hidpp10.py | 6 +++--- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/app/solaar_cli.py b/app/solaar_cli.py index a66b1cf3..65d418c1 100644 --- a/app/solaar_cli.py +++ b/app/solaar_cli.py @@ -74,8 +74,9 @@ def _find_device(receiver, name): def _print_receiver(receiver, verbose=False): + paired_count = receiver.count() if not verbose: - print ("-: Unifying Receiver [%s:%s] with %d devices" % (receiver.path, receiver.serial, receiver.count())) + print ("-: Unifying Receiver [%s:%s] with %d devices" % (receiver.path, receiver.serial, paired_count)) return print ("-: Unifying Receiver") @@ -84,21 +85,22 @@ def _print_receiver(receiver, verbose=False): for f in receiver.firmware: print (" %-11s: %s" % (f.kind, f.version)) - print (" Has %d paired device(s)." % receiver.count()) + print (" Has %d paired device(s)." % paired_count) notifications = receiver.request(0x8100) if notifications: notifications = ord(notifications[0:1]) << 16 | ord(notifications[1:2]) << 8 if notifications: from logitech.unifying_receiver import hidpp10 - print (" Enabled notifications: %s." % hidpp10.NOTIFICATION_FLAG.flag_names(notifications)) + print (" Enabled notifications: %06X = %s." % (notifications, ', '.join(hidpp10.NOTIFICATION_FLAG.flag_names(notifications)))) else: print (" All notifications disabled.") - activity = receiver.request(0x83B3) - if activity: - activity = [(d, ord(activity[d - 1:d])) for d in range(1, receiver.max_devices)] - print(" Device activity counters: %s" % ', '.join(('%d=%d' % (d, a)) for d, a in activity if a > 0)) + if paired_count > 0: + activity = receiver.request(0x83B3) + if activity: + activity = [(d, ord(activity[d - 1:d])) for d in range(1, receiver.max_devices)] + print(" Device activity counters: %s" % ', '.join(('%d=%d' % (d, a)) for d, a in activity if a > 0)) def _print_device(dev, verbose=False): diff --git a/lib/logitech/unifying_receiver/common.py b/lib/logitech/unifying_receiver/common.py index 986bf94a..3bf889e3 100644 --- a/lib/logitech/unifying_receiver/common.py +++ b/lib/logitech/unifying_receiver/common.py @@ -83,7 +83,15 @@ class NamedInts(object): self._fallback = None def flag_names(self, value): - return ', '.join(str(self._indexed[k]) for k in self._indexed if k & value == k) + unknown_bits = value + for k in self._indexed: + assert bin(k).count('1') == 1 + if k & value == k: + unknown_bits &= ~k + yield str(self._indexed[k]) + + if unknown_bits: + yield 'unknown:%06X' % unknown_bits def index(self, value): if value in self._values: diff --git a/lib/logitech/unifying_receiver/hidpp10.py b/lib/logitech/unifying_receiver/hidpp10.py index e1731d2e..9912cf19 100644 --- a/lib/logitech/unifying_receiver/hidpp10.py +++ b/lib/logitech/unifying_receiver/hidpp10.py @@ -36,9 +36,9 @@ POWER_SWITCH_LOCATION = _NamedInts( bottom_edge=0x0C) NOTIFICATION_FLAG = _NamedInts( - battery_status=0x00100000, - wireless=0x00000100, - software_present=0x000000800) + battery_status=0x100000, + wireless=0x000100, + software_present=0x0000800) ERROR = _NamedInts( invalid_SubID__command=0x01,