예제 #1
0
    def find_video_device(self):
        """
        Attempts to automatically detect which video device corresponds to the PureThermal Lepton by searching for the PID and VID.

        Returns
        -------
            int
                device number
        """

        res = None

        if sys.platform.startswith('win32'):
            device_check_path = pkg_resources.resource_filename('flirpy', 'bin/find_cameras.exe')
            device_id = int(subprocess.check_output([device_check_path, "PureThermal"]).decode())

            if device_id >= 0:
                return device_id

        elif sys.platform == "darwin":
            output = subprocess.check_output(["system_profiler", "SPCameraDataType"]).decode()
            devices = [line.strip() for line in output.decode().split("\n") if line.strip().startswith("Model")]

            device_id = 0

            for device in devices:
                if device.contains("VendorID_1E4E") and device.contains("ProductID_0100"):
                    return device_id
            
        else:
            import pyudev

            context = pyudev.Context()
            devices = pyudev.Enumerator(context)

            path = "/sys/class/video4linux/"
            video_devices = [os.path.join(path, device) for device in os.listdir(path)]
            dev = []
            for i, device in enumerate(video_devices):
                udev = pyudev.Devices.from_path(context, device)

                try:
                    vid = udev.get('ID_VENDOR_ID')
                    pid = udev.get('ID_MODEL_ID')

                    if vid == "1E4E" and pid == "0100":
                        dev.append(i)
                except KeyError:
                    pass
            
            # For some reason multiple devices can show up
            for d in dev:
                cam = cv2.VideoCapture(d + cv2.CAP_V4L2)
                data = cam.read()
                if data is not None:
                    res = d
                    break
                cam.release()

        return res
def physical_interfaces():
    """
    Returns a list of pyudev.Device objects for all physical network interfaces
    """
    enumerator = pyudev.Enumerator(udev_context).match_subsystem('net')
    return [
        d for d in enumerator
        if not d.device_path.startswith('/devices/virtual/')
    ]
예제 #3
0
def is_vendor_dell():
    context = pyudev.Context()

    # There should be only one dmi/id device
    for dev in pyudev.Enumerator(context).match_subsystem(
            'dmi').match_sys_name('id'):
        vendor = dev.attributes.get('sys_vendor')
        return re.search('Dell.*', str(vendor)) is not None
    return False
예제 #4
0
 def enumerate(self):
     devices = pyudev.Enumerator(self.context).match_subsystem(subsystem='usb') \
                                              .match_property('DEVTYPE', 'usb_device')
     for device in devices:
         self._send_add(device.properties['ID_VENDOR_ID'],
                        device.properties['ID_MODEL_ID'],
                        device.properties.asint('BUSNUM'),
                        device.properties.asint('DEVNUM'),
                        device.properties['ID_MODEL'])
예제 #5
0
    def is_vendor_dell(self):
        context = pyudev.Context()

        # There should be only one dmi/id device
        dmi = pyudev.Enumerator(context).match_subsystem('dmi')
        dev = list(filter(lambda d: d.sys_name == 'id', dmi))[0]
        vendor = dev.attributes.get('sys_vendor')

        return re.search('Dell.*', str(vendor)) is not None
예제 #6
0
def run():
    config = Config.Config("config.json")

    context = pyudev.Context()

    state = {}
    init_state(state)

    # first we check if there is already a joystick connected
    for device in pyudev.Enumerator(context).match_subsystem("hidraw"):
        if add_input(device, config, state):
            break  # should we break? it only matters if we have 2 connected

    # then we wait for a joystick to be connected
    monitor = pyudev.Monitor.from_netlink(context)
    monitor.filter_by("hidraw")
    for action, device in monitor:
        udev_input(action, device, config, state)
예제 #7
0
def connectBB():
    # returns sys path for balance board using evdev module
    context = pyudev.Context()
    # get list of devices matching devtype = 'balanceboard'
    devices = pyudev.Enumerator(context)
    tst = devices.match_attribute('devtype', 'balanceboard')
    # create empty list to store balance board info
    bboards = []
    # populate list
    for dfg in tst:
        bboards.append(dfg)
    # test how many bboards are connected - should be only one
    if len(bboards) == 0:
        print('No Wii balance boards found')
        return None
    if len(bboards) > 1:
        print('More than one Wii balance boards found: exiting')
        return None
    print('\nBalance board found!\n')
    # return the first in the list
    bb = bboards[0]
    return bb
예제 #8
0
    def find_video_device(self):
        """
        Attempts to automatically detect which video device corresponds to the Boson by searching for the PID and VID.

        Returns
        -------
            int
                device number
        """

        res = None

        if sys.platform.startswith('win32'):
            device_check_path = pkg_resources.resource_filename(
                'flirpy', 'bin/find_cameras.exe')
            device_id = int(
                subprocess.check_output([device_check_path,
                                         "FLIR Video"]).decode())

            if device_id >= 0:
                return device_id

        elif sys.platform == "darwin":
            output = subprocess.check_output(
                ["system_profiler", "SPCameraDataType"]).decode()
            devices = [
                line.strip() for line in output.split("\n")
                if line.strip().startswith("Model")
            ]

            device_id = 0

            for device in devices:
                if device.contains("VendorID_2507") and device.contains(
                        "ProductID_16391"):
                    return device_id

        else:
            import pyudev

            context = pyudev.Context()
            devices = pyudev.Enumerator(context)

            path = "/sys/class/video4linux/"
            video_devices = [
                os.path.join(path, device) for device in os.listdir(path)
            ]
            dev = []
            for device in video_devices:
                udev = pyudev.Devices.from_path(context, device)

                try:
                    vid = udev.properties['ID_VENDOR_ID']
                    pid = udev.properties['ID_MODEL_ID']

                    if vid.lower() == "09cb" and pid.lower() == "4007":
                        dev.append(int(device.split('video')[-1]))
                except KeyError:
                    pass

            # For some reason multiple devices can show up
            # The lower index is often correct, so do a sort first
            if len(dev) > 1:
                for d in sorted(dev):
                    cam = cv2.VideoCapture(d + cv2.CAP_V4L2)
                    data = cam.read()
                    cam.release()

                    # data[1] is the image and should be a numpy array
                    if data[0] == True and data[1] is not None:
                        res = d
                        break
            elif len(dev) == 1:
                res = dev[0]

        return res