Example #1
0
def find_all_devices(do_cache = True):
    global __cached_devices
        
    """
    Get a list of Device objects, one for each supported device that is plugged in.
    There may be more than one device of the same type.
    """
    
    # If we have pydev, we can cache the devices
    if do_cache and have_udev and len(__cached_devices) != 0:
        return __cached_devices
    
    device_map = {}
    
    # Find all supported devices plugged into USB
    for bus in usb.busses():
        for usb_device in bus.devices:
            key =  ( usb_device.idVendor, usb_device.idProduct )
            # Is a supported device
            if not key in device_map:
                device_map[key] = []
            device_map[key].append(usb_device)
    
    # Turn the found USB devices into Device objects
    devices = []
    indices = {}
    
    for device_key in device_map:
        usb_devices = device_map[device_key]
        for usb_device in usb_devices:
            if device_key in device_by_usb_id:     
                device_info = device_by_usb_id[device_key]
                """
                Take the quirk of the G11/G15 into account. This check means that only one of each
                type can exist at a time, but any more is pretty unlikely
                """
                if device_info.model_id == g15driver.MODEL_G15_V1 and not (0x046d, 0xc222) in device_map:
                    # Actually a G11, will be detected with id (0x046d, 0xc225)
                    continue
                elif device_info.model_id == g15driver.MODEL_G11 and (0x046d, 0xc222) in device_map:
                    # Actually a G15v1
                    device_info = device_list[g15driver.MODEL_G15_V1]
                
                """
                Now create the device instance that will be used by the caller
                """
                index = 0 if not device_key in indices else indices[device_key] 
                controls_usb_id = device_info.controls_usb_id_list[device_info.usb_id_list.index(device_key)]
                devices.append(Device(device_key, controls_usb_id, usb_device, index, device_info))
                indices[device_key] = index + 1
            
 
    """
    If the GTK driver is installed, add a virtual device as well
    """
    if g15drivermanager.get_driver_mod("gtk"): 
        devices.append(Device((0x0000, 0x0000), (0x0000, 0x0000), None, 0, device_list['virtual']))
    
    # If we have pydev, we can cache the devices
    if have_udev and do_cache:
        __cached_devices += devices
        
    return devices
Example #2
0
def find_device(models):
    for lg_model in find_all_devices():
        for model in models:
            if lg_model.model_name == model:
                return lg_model
            
def _get_cached_device_by_usb_id(usb_id):
    for c in __cached_devices:
        if c.usb_id == usb_id:
            return c
            
"""
Register all supported models
"""
if g15drivermanager.get_driver_mod("gtk"): 
    DeviceInfo('virtual',               (0x0000, 0x0000),       None,               [],                 0,  ( 0,    0 ),    False,  _("Virtual LCD Window"),                        None)
DeviceInfo(g15driver.MODEL_G11,         (0x046d, 0xc225),       None,               g11_key_layout,     0,  ( 0,    0 ),    True,   _("Logitech G11 Keyboard"),                     g11_action_keys)
DeviceInfo(g15driver.MODEL_G19,         (0x046d, 0xc229),       None,               g19_key_layout,     16, ( 320,  240 ),  True,   _("Logitech G19 Gaming Keyboard"),              g19_action_keys)
DeviceInfo(g15driver.MODEL_G15_V1,      (0x046d, 0xc221),       (0x046d, 0xc222),   g15v1_key_layout,   1,  ( 160,  43 ),   True,   _("Logitech G15 Gaming Keyboard (version 1)"),  g15_action_keys) 
DeviceInfo(g15driver.MODEL_G15_V2,      (0x046d, 0xc227),       None,               g15v2_key_layout,   1,  ( 160,  43 ),   True,   _("Logitech G15 Gaming Keyboard (version 2)"),  g15_action_keys)
DeviceInfo(g15driver.MODEL_G13,         (0x046d, 0xc21c),       None,               g13_key_layout,     1,  ( 160,  43 ),   True,   _("Logitech G13 Advanced Gameboard"),           g15_action_keys)
DeviceInfo(g15driver.MODEL_G510,        [ (0x046d, 0xc22d), 
                                          (0x046d, 0xc22e) ],   None,               g510_key_layout,    1,  ( 160,  43 ),   True,   _("Logitech G510 Keyboard"),                    g15_action_keys)
DeviceInfo(g15driver.MODEL_Z10,         (0x046d, 0x0a07),       None,               z10_key_layout,     1,  ( 160,  43 ),   False,  _("Logitech Z10 Speakers"),                     z10_action_keys)
DeviceInfo(g15driver.MODEL_G110,        (0x046d, 0xc22b),       None,               g110_key_layout,    0,  ( 0,    0 ),    True,   _("Logitech G110 Keyboard"),                    g110_action_keys)
DeviceInfo(g15driver.MODEL_GAMEPANEL,   (0x046d, 0xc251),       None,               g15v1_key_layout,   1,  ( 160,  43 ),   True,   _("Logitech GamePanel"),                        g15_action_keys)
DeviceInfo(g15driver.MODEL_G930,        (0x046d, 0xa1f),        None,               g930_key_layout,    0,  ( 0,  0 ),      True,   _("Logitech G930 Headphones"),                  {})
DeviceInfo(g15driver.MODEL_G35,         (0x046d, 0xa15),        None,               g930_key_layout,    0,  ( 0,  0 ),      True,   _("Logitech G35 Headphones"),                   {})

# When I get hold of an MX5500, I will add Bluetooth detection as well