示例#1
0
 def find_devices(self,
                  vendor=None,
                  product=None,
                  bus=None,
                  address=None,
                  usb_port=None,
                  **kwargs):
     """ Find compatible regular USB devices."""
     drivers = sorted(find_all_subclasses(UsbDriver),
                      key=lambda x: x.__name__)
     LOGGER.debug('searching %s (drivers=[%s])', self.__class__.__name__,
                  ', '.join(map(lambda x: x.__name__, drivers)))
     for handle in PyUsbDevice.enumerate(vendor, product):
         if bus and handle.bus != bus:
             continue
         if address and handle.address != address:
             continue
         if usb_port and handle.port != usb_port:
             continue
         LOGGER.debug('probing drivers for device %s:%s',
                      hex(handle.vendor_id), hex(handle.product_id))
         for drv in drivers:
             yield from drv.probe(handle,
                                  vendor=vendor,
                                  product=product,
                                  **kwargs)
示例#2
0
        def find_devices(self, bus=None, usb_port=None, **kwargs):
            """Find compatible SMBus devices."""

            if usb_port:
                # a usb_port filter implies an USB bus
                return

            devices = self._i2c_root.joinpath('devices')
            if not devices.exists():
                _LOGGER.debug('skipping %s, %s not available',
                              self.__class__.__name__, devices)
                return

            drivers = sorted(find_all_subclasses(SmbusDriver),
                             key=lambda x: (x.__module__, x.__name__))

            _LOGGER.debug('searching %s (%s)', self.__class__.__name__,
                          ', '.join(map(lambda x: x.__name__, drivers)))

            for i2c_dev in devices.iterdir():
                try:
                    i2c_bus = LinuxI2cBus(i2c_dev)
                except ValueError as err:
                    _LOGGER.debug('ignoring %s, %s', i2c_dev.name, err)
                    continue

                if bus and bus != i2c_bus.name:
                    continue

                _LOGGER.debug('found I²C bus %s', i2c_bus.name)
                yield from i2c_bus.find_devices(drivers, **kwargs)
示例#3
0
 def find_devices(self,
                  vendor=None,
                  product=None,
                  bus=None,
                  address=None,
                  usb_port=None,
                  **kwargs):
     """Find compatible HID devices."""
     handles = HidapiDevice.enumerate(hid, vendor, product)
     drivers = sorted(find_all_subclasses(UsbHidDriver),
                      key=lambda x: (x.__module__, x.__name__))
     _LOGGER.debug('searching %s (%s)', self.__class__.__name__,
                   ', '.join(map(lambda x: x.__name__, drivers)))
     for handle in handles:
         if bus and handle.bus != bus:
             continue
         if address and handle.address != address:
             continue
         if usb_port and handle.port != usb_port:
             continue
         _LOGGER.debug('found HID device %04x:%04x', handle.vendor_id,
                       handle.product_id)
         for drv in drivers:
             yield from drv.probe(handle,
                                  vendor=vendor,
                                  product=product,
                                  **kwargs)
示例#4
0
def find_liquidctl_devices(pick=None, **kwargs):
    """Find devices and instantiate corresponding liquidctl drivers.

    Probes all buses and drivers that have been loaded at the time of the call
    and yields driver instances.

    Filter conditions can be passed through to the buses and drivers via
    `**kwargs`.  A driver instance will be yielded for each compatible device
    that matches the supplied filter conditions.

    If `pick` is passed, only the driver instance for the `(pick + 1)`-th
    matched device will be yielded.
    """
    buses = sorted(find_all_subclasses(BaseBus),
                   key=lambda x: (x.__module__, x.__name__))
    num = 0
    for bus_cls in buses:
        for dev in bus_cls().find_devices(**kwargs):
            if pick is not None:
                if num == pick:
                    yield dev
                    return
                num += 1
            else:
                yield dev
示例#5
0
    def find_devices(self,
                     vendor=None,
                     product=None,
                     hid=None,
                     bus=None,
                     address=None,
                     usb_port=None,
                     **kwargs):
        """Find compatible USB HID devices.

        Both hidapi and PyUSB backends are supported.  On Mac and Linux the
        default is to use hidapi; on all other platforms it is PyUSB.

        The choice of API for HID can be overiden with `hid`:

         - `hid='usb'`: use PyUSB (libusb-1.0, libusb-0.1 or OpenUSB)
         - `hid='hid'`: use hidapi (backend depends on hidapi build options)
         - `hid='hidraw'`: specifically try to use hidraw (Linux; depends on
           hidapi build options)
        """

        if not hid:
            if sys.platform.startswith('linux'):
                hid = 'hidraw'
            elif sys.platform == 'darwin':
                hid = 'hid'
            else:
                hid = 'usb'

        api = globals()[hid]
        if hid.startswith('hid'):
            handles = HidapiDevice.enumerate(api, vendor, product)
        else:
            handles = PyUsbHid.enumerate(vendor, product)

        drivers = sorted(find_all_subclasses(UsbHidDriver),
                         key=lambda x: x.__name__)
        LOGGER.debug('searching %s (api=%s, drivers=[%s])',
                     self.__class__.__name__, api.__name__,
                     ', '.join(map(lambda x: x.__name__, drivers)))
        for handle in handles:
            if bus and handle.bus != bus:
                continue
            if address and handle.address != address:
                continue
            if usb_port and handle.port != usb_port:
                continue
            LOGGER.debug('probing drivers for device %s:%s',
                         hex(handle.vendor_id), hex(handle.product_id))
            for drv in drivers:
                yield from drv.probe(handle,
                                     vendor=vendor,
                                     product=product,
                                     **kwargs)
示例#6
0
 def find_devices(self,
                  vendor=None,
                  product=None,
                  bus=None,
                  address=None,
                  usb_port=None,
                  **kwargs):
     """Find compatible HID devices."""
     handles = HidapiDevice.enumerate(hid, vendor, product)
     drivers = sorted(find_all_subclasses(UsbHidDriver),
                      key=lambda x: x.__name__)
     _LOGGER.debug('searching %s', self.__class__.__name__)
     _LOGGER.debug('%s drivers: %s', self.__class__.__name__,
                   ', '.join(map(lambda x: x.__name__, drivers)))
     for handle in handles:
         if bus and handle.bus != bus:
             continue
         if address and handle.address != address:
             continue
         if usb_port and handle.port != usb_port:
             continue
         # each handle is a HIDAPI hid_device, and that can either mean one
         # entire HID interface, or one interface ⨯ usage page ⨯ usage id
         # product, depending on the platform and backend; but, for brevity,
         # refer them simply as "HID devices"
         if 'usage' in handle.hidinfo and 'usage_page' in handle.hidinfo:
             _LOGGER.debug(
                 'HID device: %04x:%04x (usage_page=%#06x usage=%#06x)',
                 handle.vendor_id,
                 handle.product_id,
                 handle.hidinfo['usage_page'],
                 handle.hidinfo['usage'],
             )
         else:
             _LOGGER.debug(
                 'HID device: %04x:%04x (usage n/a)',
                 handle.vendor_id,
                 handle.product_id,
             )
         for drv in drivers:
             yield from drv.probe(handle,
                                  vendor=vendor,
                                  product=product,
                                  **kwargs)
示例#7
0
        RUN{builtin}="kmod load i2c-dev"
'''

print(cleandoc(HEADER))

print()
print()
print(cleandoc(MANUAL_RULES))

print()
print()
print(f'# Section: NVIDIA graphics cards')

nvidia_devs = {}

for driver in find_all_subclasses(_NvidiaI2CDriver):
    for did, sdid, description in driver._MATCHES:
        ids = (driver._VENDOR, did, sdid)
        if ids in nvidia_devs:
            nvidia_devs[ids].append(description)
            nvidia_devs[ids].sort()
        else:
            nvidia_devs[ids] = [description]

nvidia_devs = [(svid, did, sdid, description)
               for (svid, did, sdid), description in nvidia_devs.items()]
nvidia_devs.sort(key=lambda x: x[3][0])

for svid, did, sdid, descriptions in nvidia_devs:
    print()
    for desc in descriptions: