improved notifications detection

This commit is contained in:
Daniel Pavel 2012-12-08 01:49:59 +02:00
parent 4bdfe9b9b8
commit 80c36a02a9
3 changed files with 21 additions and 11 deletions

View File

@ -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):

View File

@ -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:

View File

@ -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,