Repository: pwr-Solaar/Solaar

Issue:
Support new device: Logitech G9 Laser Mouse
**Information**
I've basically attached output from the same instructions given in #1457 to support a new device here for the G9. Hope that is sufficient!

- Solaar version (`solaar --version` and `git describe --tags`): 1.1.1
- Distribution: Arch 
- Kernel version (ex. `uname -srmo`): Linux 5.15.13-arch1-1 x86_64 GNU/Linux
- Output of `solaar show` for the target device (if applicable): "Exception: No devices found"

Debug information:
```
$ lsusb | grep G9
Bus 001 Device 002: ID 046d:c048 Logitech, Inc. G9 Laser Mouse
$ sudo lsusb -d 046d:c048 -vv

Bus 001 Device 002: ID 046d:c048 Logitech, Inc. G9 Laser Mouse
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x046d Logitech, Inc.
  idProduct          0xc048 G9 Laser Mouse
  bcdDevice           50.00
  iManufacturer           1 Logitech
  iProduct                2 G9 Laser Mouse
  iSerial                 3 11789148730029
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x003b
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          4 U50.00_B0029
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower               98mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      1 Boot Interface Subclass
      bInterfaceProtocol      2 Mouse
      iInterface              0
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.11
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      67
         Report Descriptors:
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              0
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.11
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength     122
         Report Descriptors:
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0014  1x 20 bytes
        bInterval               1
can't get device qualifier: Resource temporarily unavailable
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x0000
  (Bus Powered)
$ grep -H . /sys/class/hidraw/hidraw*/device/uevent
/sys/class/hidraw/hidraw0/device/uevent:DRIVER=hid-generic
/sys/class/hidraw/hidraw0/device/uevent:HID_ID=0003:0000046D:0000C048
/sys/class/hidraw/hidraw0/device/uevent:HID_NAME=Logitech G9 Laser Mouse
/sys/class/hidraw/hidraw0/device/uevent:HID_PHYS=usb-0000:07:00.1-4/input0
/sys/class/hidraw/hidraw0/device/uevent:HID_UNIQ=11789148730029
/sys/class/hidraw/hidraw0/device/uevent:MODALIAS=hid:b0003g0001v0000046Dp0000C048
/sys/class/hidraw/hidraw1/device/uevent:DRIVER=hid-generic
/sys/class/hidraw/hidraw1/device/uevent:HID_ID=0003:0000046D:0000C048
/sys/class/hidraw/hidraw1/device/uevent:HID_NAME=Logitech G9 Laser Mouse
/sys/class/hidraw/hidraw1/device/uevent:HID_PHYS=usb-0000:07:00.1-4/input1
/sys/class/hidraw/hidraw1/device/uevent:HID_UNIQ=11789148730029
/sys/class/hidraw/hidraw1/device/uevent:MODALIAS=hid:b0003g0001v0000046Dp0000C048
[...snip...]
$ hidrd-convert -o spec /sys/class/hidraw/hidraw0/device/report_descriptor
Usage Page (Desktop),               ; Generic desktop controls (01h)
Usage (Mouse),                      ; Mouse (02h, application collection)
Collection (Application),
    Usage (Pointer),                ; Pointer (01h, physical collection)
    Collection (Physical),
        Usage Page (Button),        ; Button (09h)
        Usage Minimum (01h),
        Usage Maximum (10h),
        Logical Minimum (0),
        Logical Maximum (1),
        Report Count (16),
        Report Size (1),
        Input (Variable),
        Usage Page (Desktop),       ; Generic desktop controls (01h)
        Logical Minimum (-32767),
        Logical Maximum (32767),
        Report Size (16),
        Report Count (2),
        Usage (X),                  ; X (30h, dynamic value)
        Usage (Y),                  ; Y (31h, dynamic value)
        Input (Variable, Relative),
        Logical Minimum (-127),
        Logical Maximum (127),
        Report Size (8),
        Report Count (1),
        Usage (Wheel),              ; Wheel (38h, dynamic value)
        Input (Variable, Relative),
        Usage Page (Consumer),      ; Consumer (0Ch)
        Usage (AC Pan),             ; AC pan (0238h, linear control)
        Report Count (1),
        Input (Variable, Relative),
    End Collection,
End Collection
$ hidrd-convert -o spec /sys/class/hidraw/hidraw1/device/report_descriptor
Usage Page (Desktop),                   ; Generic desktop controls (01h)
Usage (Keyboard),                       ; Keyboard (06h, application collection)
Collection (Application),
    Report ID (1),
    Usage Page (Keyboard),              ; Keyboard/keypad (07h)
    Usage Minimum (KB Leftcontrol),     ; Keyboard left control (E0h, dynamic value)
    Usage Maximum (KB Right GUI),       ; Keyboard right GUI (E7h, dynamic value)
    Logical Minimum (0),
    Logical Maximum (1),
    Report Size (1),
    Report Count (8),
    Input (Variable),
    Report Count (5),
    Report Size (8),
    Logical Minimum (0),
    Logical Maximum (164),
    Usage Page (Keyboard),              ; Keyboard/keypad (07h)
    Usage Minimum (None),               ; No event (00h, selector)
    Usage Maximum (KB ExSel),           ; Keyboard ExSel (A4h, selector)
    Input,
End Collection,
Usage Page (Consumer),                  ; Consumer (0Ch)
Usage (Consumer Control),               ; Consumer control (01h, application collection)
Collection (Application),
    Report ID (3),
    Report Size (16),
    Report Count (2),
    Logical Minimum (1),
    Logical Maximum (652),
    Usage Minimum (Consumer Control),   ; Consumer control (01h, application collection)
    Usage Maximum (AC Send),            ; AC send (028Ch, selector)
    Input,
End Collection,
Usage Page (FF00h),                     ; FF00h, vendor-defined
Usage (01h),
Collection (Application),
    Report ID (16),
    Report Size (8),
    Report Count (6),
    Logical Minimum (0),
    Logical Maximum (255),
    Usage (01h),
    Input,
    Usage (01h),
    Output,
End Collection,
Usage Page (FF00h),                     ; FF00h, vendor-defined
Usage (02h),
Collection (Application),
    Report ID (17),
    Report Size (8),
    Report Count (19),
    Logical Minimum (0),
    Logical Maximum (255),
    Usage (02h),
    Input,
    Usage (02h),
    Output,
End Collection
$
```
</details>


**Is your feature request related to a problem? Please describe.**
It would be nice if my G9 is supported. Not sure if it can be? Thanks a lot for your awesome work so far, hope I can make use of the tool myself in the future! :) :1st_place_medal: 


Discussion:
This device appears to be supportable.  All that should be needed is its description added to descriptors.py  It uses a different USB interface from the one Solaar uses by default.

Resolving patch:
diff --git a/lib/logitech_receiver/descriptors.py b/lib/logitech_receiver/descriptors.py
--- a/lib/logitech_receiver/descriptors.py
+++ b/lib/logitech_receiver/descriptors.py
@@ -29,7 +29,7 @@
 
 _DeviceDescriptor = namedtuple(
     '_DeviceDescriptor',
-    ('name', 'kind', 'wpid', 'codename', 'protocol', 'registers', 'settings', 'persister', 'usbid', 'interface', 'btid')
+    ('name', 'kind', 'wpid', 'codename', 'protocol', 'registers', 'settings', 'usbid', 'interface', 'btid')
 )
 del namedtuple
 
@@ -45,7 +45,6 @@ def _D(
     protocol=None,
     registers=None,
     settings=None,
-    persister=None,
     usbid=None,
     interface=None,
     btid=None,
@@ -84,7 +83,6 @@ def _D(
         protocol=protocol,
         registers=registers,
         settings=settings,
-        persister=persister,
         usbid=usbid,
         interface=interface,
         btid=btid
@@ -441,6 +439,18 @@ class _PerformanceMXDpi(_ST.RegisterDpi):
 _D('Wireless Mouse Pebble M350', protocol=2.0, wpid='4080', codename='Pebble')
 _D('MX Master 3 Wireless Mouse', codename='MX Master 3', protocol=4.5, wpid='4082', btid=0xb023)
 _D('PRO X Wireless', kind='mouse', codename='PRO X', wpid='4093', usbid=0xc094)
+_D(
+    'G9 Laser Mouse',
+    codename='G9',
+    usbid=0xc048,
+    interface=1,
+    protocol=1.0,
+    settings=[
+        _PerformanceMXDpi,
+        _ST.RegisterSmoothScroll,
+        _ST.RegisterSideScroll,
+    ]
+)
 _D('G402 Gaming Mouse', codename='G402', usbid=0xc07e, interface=1)
 _D('G900 Chaos Spectrum Gaming Mouse', codename='G900', usbid=0xc081)
 _D('G403 Gaming Mouse', codename='G403', usbid=0xc082)
diff --git a/lib/logitech_receiver/device.py b/lib/logitech_receiver/device.py
--- a/lib/logitech_receiver/device.py
+++ b/lib/logitech_receiver/device.py
@@ -44,10 +44,7 @@ def __init__(self, receiver, number, link_notification=None, info=None):
 
         if receiver:
             assert number > 0 and number <= receiver.max_devices
-        else:
-            assert number == 0xFF
-        # Device number, 1..6 for unifying devices, 1 otherwise.
-        self.number = number
+        self.number = number  # will be None at this point for directly connected devices
         # 'device active' flag; requires manual management.
         self.online = None
 
@@ -140,8 +137,10 @@ def __init__(self, receiver, number, link_notification=None, info=None):
             self.online = None  # a direct connected device might not be online (as reported by user)
             self.product_id = info.product_id
             self.bluetooth = info.bus_id == 0x0005
-            self.descriptor = _descriptors.get_btid(self.product_id
-                                                    ) if self.bluetooth else _descriptors.get_usbid(self.product_id)
+            self.descriptor = _descriptors.get_btid(self.product_id) if self.bluetooth else \
+                _descriptors.get_usbid(self.product_id)
+            if self.number is None:  # for direct-connected devices get 'number' from descriptor protocol else use 0xFF
+                self.number = 0x00 if self.descriptor and self.descriptor.protocol and self.descriptor.protocol < 2.0 else 0xFF
 
         if self.descriptor:
             self._name = self.descriptor.name
@@ -458,7 +457,7 @@ def open(self, device_info):
         try:
             handle = _base.open_path(device_info.path)
             if handle:
-                return Device(None, 0xFF, info=device_info)
+                return Device(None, None, info=device_info)
         except OSError as e:
             _log.exception('open %s', device_info)
             if e.errno == _errno.EACCES:


Test patch: