minor clean-ups

This commit is contained in:
Daniel Pavel 2013-05-04 17:19:48 +02:00
parent 64c36a1562
commit d7dd9393ff
5 changed files with 30 additions and 4 deletions

View File

@ -59,6 +59,7 @@ def exit():
def _match(action, device, vendor_id=None, product_id=None, interface_number=None, driver=None): def _match(action, device, vendor_id=None, product_id=None, interface_number=None, driver=None):
usb_device = device.find_parent('usb', 'usb_device') usb_device = device.find_parent('usb', 'usb_device')
# print (action, device, "usb:", usb_device)
if not usb_device: if not usb_device:
return return
@ -70,6 +71,7 @@ def _match(action, device, vendor_id=None, product_id=None, interface_number=Non
if action == 'add': if action == 'add':
hid_device = device.find_parent('hid') hid_device = device.find_parent('hid')
# print (action, device, "hid:", usb_device)
if not hid_device: if not hid_device:
return return
hid_driver_name = hid_device['DRIVER'] hid_driver_name = hid_device['DRIVER']
@ -77,6 +79,7 @@ def _match(action, device, vendor_id=None, product_id=None, interface_number=Non
return return
intf_device = device.find_parent('usb', 'usb_interface') intf_device = device.find_parent('usb', 'usb_interface')
# print (action, device, "usb_interface:", usb_device)
if interface_number is None: if interface_number is None:
usb_interface = None if intf_device is None else intf_device.attributes.asint('bInterfaceNumber') usb_interface = None if intf_device is None else intf_device.attributes.asint('bInterfaceNumber')
else: else:

View File

@ -61,7 +61,7 @@ class DeviceUnreachable(_KwException):
# vendor_id, product_id, interface number, driver # vendor_id, product_id, interface number, driver
DEVICE_UNIFYING_RECEIVER = (0x046d, 0xc52b, 2, 'logitech-djreceiver') DEVICE_UNIFYING_RECEIVER = (0x046d, 0xc52b, 2, 'logitech-djreceiver')
DEVICE_UNIFYING_RECEIVER_2 = (0x046d, 0xc532, 2, 'logitech-djreceiver') DEVICE_UNIFYING_RECEIVER_2 = (0x046d, 0xc532, 2, 'logitech-djreceiver')
#DEVICE_NANO_RECEIVER = (0x046d, 0xc526, 1, 'generic-usb') DEVICE_NANO_RECEIVER = (0x046d, 0xc526, 1, 'generic-usb')
def receivers(): def receivers():

View File

@ -214,7 +214,7 @@ class Receiver(object):
serial_reply = self.request(0x83B5, 0x03) serial_reply = self.request(0x83B5, 0x03)
assert serial_reply assert serial_reply
self._serial = _strhex(serial_reply[1:5]) self._serial = _strhex(serial_reply[1:5])
self.max_devices = ord(serial_reply[6:7][0:1]) self.max_devices = ord(serial_reply[6:7])
if self.max_devices == 1: if self.max_devices == 1:
self.name = 'Nano Receiver' self.name = 'Nano Receiver'

View File

@ -87,7 +87,7 @@ def _print_receiver(receiver, verbose=False):
for f in receiver.firmware: for f in receiver.firmware:
print (" %-11s: %s" % (f.kind, f.version)) print (" %-11s: %s" % (f.kind, f.version))
print (" Has", paired_count, "paired device(s).") print (" Has", paired_count, "paired device(s) out of a maximum of", receiver.max_devices)
notification_flags = receiver.request(0x8100) notification_flags = receiver.request(0x8100)
if notification_flags: if notification_flags:
@ -97,7 +97,7 @@ def _print_receiver(receiver, verbose=False):
notification_names = hidpp10.NOTIFICATION_FLAG.flag_names(notification_flags) notification_names = hidpp10.NOTIFICATION_FLAG.flag_names(notification_flags)
print (" Enabled notifications: 0x%06X = %s." % (notification_flags, ', '.join(notification_names))) print (" Enabled notifications: 0x%06X = %s." % (notification_flags, ', '.join(notification_names)))
else: else:
print (" All notifications disabled.") print (" All notifications disabled")
if paired_count > 0: if paired_count > 0:
activity = receiver.request(0x83B3) activity = receiver.request(0x83B3)

23
tools/monitor.py Normal file
View File

@ -0,0 +1,23 @@
#
#
#
from __future__ import absolute_import, division, print_function, unicode_literals
import sys
sys.path += (sys.path[0] + '/../lib',)
import hidapi
from logitech.unifying_receiver.base import DEVICE_UNIFYING_RECEIVER
from logitech.unifying_receiver.base import DEVICE_UNIFYING_RECEIVER_2
from logitech.unifying_receiver.base import DEVICE_NANO_RECEIVER
def print_event(action, device):
print ("~~~~ device [%s] %s" % (action, device))
hidapi.monitor(print_event,
DEVICE_UNIFYING_RECEIVER,
DEVICE_UNIFYING_RECEIVER_2,
DEVICE_NANO_RECEIVER
)