def find_zedboard_jtag_serials(): return sorted({ dev['ID_SERIAL_SHORT'] for dev in Context().list_devices(ID_VENDOR_ID='0403') if 'DEVLINKS' not in dev } & { dev['ID_SERIAL_SHORT'] for dev in Context().list_devices(ID_MODEL_ID='6014') if 'DEVLINKS' not in dev })
def find_devices(): devices = {'jtag': {}, 'uart': {}} for dev in Context().list_devices(): if 'ID_VENDOR_ID' not in dev or 'ID_MODEL_ID' not in dev: continue if 'DEVLINKS' in dev: if dev['ID_VENDOR_ID'] == '067b' and dev['ID_MODEL_ID'] == '2303': devices['uart'][dev['DEVNAME']] = {'type': 'p2020'} elif dev['ID_VENDOR_ID'] == '04b4' and dev['ID_MODEL_ID'] == '0008': devices['uart'][dev['DEVNAME']] = { 'type': 'zedboard', 'serial': dev['ID_SERIAL_SHORT']} elif dev['ID_VENDOR_ID'] == '0403' and dev['ID_MODEL_ID'] == '6010': if dev['ID_USB_INTERFACE_NUM'] == '01': devices['uart'][dev['DEVNAME']] = { 'type': 'pynq', 'serial': dev['ID_SERIAL_SHORT']} elif dev['ID_VENDOR_ID'] == '0403' and dev['ID_MODEL_ID'] == '6001': devices['uart'][dev['DEVNAME']] = { 'type': 'pmod', 'serial': dev['ID_SERIAL_SHORT']} elif dev['ID_VENDOR_ID'] == '0403' and dev['ID_MODEL_ID'] == '6014': pass elif dev['SUBSYSTEM'] == 'tty': devices['uart'][dev['DEVNAME']] = {'type': 'other'} if 'ID_SERIAL_SHORT' in dev: devices['uart'][dev['DEVNAME']]['serial'] = \ dev['ID_SERIAL_SHORT'] else: if dev['ID_VENDOR_ID'] == '0403' and dev['ID_MODEL_ID'] == '6014': devices['jtag'][dev['ID_SERIAL_SHORT']] = {'type': 'zedboard'} elif dev['ID_VENDOR_ID'] == '0403' and dev['ID_MODEL_ID'] == '6010': devices['jtag'][dev['ID_SERIAL_SHORT']] = {'type': 'pynq'} return devices
def find_zedboard_uart_serials(): return { dev['DEVNAME']: dev['ID_SERIAL_SHORT'] for dev in Context().list_devices(ID_VENDOR_ID='04b4', ID_MODEL_ID='0008') if 'DEVLINKS' in dev }
def __init__(self, player): try: self.player = player # Create a context, create monitor at kernel level, select devices context = Context() monitor = Monitor.from_netlink(context) monitor.filter_by(subsystem='input') self.observer = MonitorObserver(monitor, self.usb_event_callback, name="keyboard") self.observer.start() self.pressed = False # Stores state of press # Check if there is already a keyboard attached for device in context.list_devices(subsystem='input'): if device.get('ID_INPUT_KEYBOARD') == '1': if device.get('DEVNAME') != None: device_name = InputDevice(device.get('DEVNAME')) thread = threading.Thread(target=self.keyboard_event, args=(device_name,), daemon=True) thread.start() continue except Exception as ex: print('Keyboard Control: Error starting: ' + str(ex))
def get_device_info(device_path: os.path) -> Result: """ Tries to figure out what type of device this is :param device_path: os.path to device. :return: Result with Ok or Err """ context = Context() sysname = device_path.basename() for device in context.list_devices(subsystem='block'): if sysname == device.sys_name: # Ok we're a block device device_id = get_uuid(device) media_type = get_media_type(device) capacity = get_size(device) if capacity is None: capacity = 0 fs_type = get_fs_type(device) return Ok( Device(id=device_id, name=sysname, media_type=media_type, capacity=capacity, fs_type=fs_type)) return Err("Unable to find device with name {}".format(device_path))
def run(self): try: try: from pyudev.glib import MonitorObserver def device_event(observer, device): self.sessaoMultiseat.evento_dispositivo( device.action, device.device_path) except: from pyudev.glib import GUDevMonitorObserver as MonitorObserver def device_event(observer, action, device): self.sessaoMultiseat.evento_dispositivo( action, device.device_path) context = Context() monitor = Monitor.from_netlink(context) #monitor.filter_by(subsystem='usb'); observer = MonitorObserver(monitor) observer.connect('device-event', device_event) monitor.start() self.loop.run() except: logging.exception('')
def get_usb_devices(): context = Context() monitor = Monitor.from_netlink(context) monitor.filter_by(subsystem='usb') observer = MonitorObserver(monitor) observer.connect('device-event', device_event) monitor.start() glib.MainLoop().run()
def initialize(): context = Context() monitor = Monitor.from_netlink(context) monitor.filter_by(subsystem='tty') observer = MonitorObserver(monitor, callback=print_device_event, name='monitor-observer') observer.daemon observer.start()
def monitor_bt_headset(**config): context = Context() monitor = Monitor.from_netlink(context) monitor.filter_by('input') while True: led0_headset_off() sys_path, device_node = wait_bt_headset_add(monitor, config['headset_addr']) pa_lo_idx = start_sound_forwarding(device_node=device_node, **config) led0_headset_on() wait_bt_headset_remove(monitor, sys_path) stop_sound_forwarding(pa_lo_idx=pa_lo_idx, **config)
def is_block_device(device_path: str) -> Result: """ Check if a device is a block device :param device_path: str path to the device to check. :return: Result with Ok or Err """ context = Context() sysname = os.path.basename(device_path) for device in context.list_devices(subsystem='block'): if device.sys_name == sysname: return Ok(True) return Err("Unable to find device with name {}".format(device_path))