Repository: pwr-Solaar/Solaar

Issue:
Ignore K845 wired keyboard
I have a wireless Logitech mouse, which works perfectly on Solaar. But I also have a wired dumb Logitech keyboard with nothing to configure. Every day when I plug in my laptop, Solaar throws error:

> Found a Logitech receiver of device at /dev/hidraw5, but encountered an error connecting to it.
> 
> Try removing the device and plugging it back in or turning it off and then on.

"solaar show" fails on the working wireless mouse when the keyboard is present.

```
> ❯ solaar show
> solaar version 1.1.8
> 
> USB and Bluetooth Devices
> 
> solaar: error: Traceback (most recent call last):
>   File "/usr/share/solaar/lib/logitech_receiver/base.py", line 221, in write
>     _hid.write(int(handle), wdata)
>   File "/usr/share/solaar/lib/hidapi/udev.py", line 373, in write
>     raise OSError(_errno.EIO, 'written %d bytes out of expected %d' % (bytes_written, len(data)))
> OSError: [Errno 5] written 0 bytes out of expected 7
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>   File "/usr/share/solaar/lib/solaar/cli/__init__.py", line 209, in run
>     m.run(c, args, _find_receiver, _find_device)
>   File "/usr/share/solaar/lib/solaar/cli/show.py", line 305, in run
>     _print_device(d, num=dev_num)
>   File "/usr/share/solaar/lib/solaar/cli/show.py", line 85, in _print_device
>     dev.ping()
>   File "/usr/share/solaar/lib/logitech_receiver/device.py", line 455, in ping
>     protocol = _base.ping(self.handle or self.receiver.handle, self.number, long_message=long)
>   File "/usr/share/solaar/lib/logitech_receiver/base.py", line 527, in ping
>     write(ihandle, devnumber, request_data, long_message)
>   File "/usr/share/solaar/lib/logitech_receiver/base.py", line 225, in write
>     raise NoReceiver(reason=reason)
> logitech_receiver.base.NoReceiver: {'reason': OSError(5, 'written 0 bytes out of expected 7')}
```

Unplug the wired keyboard and everything works:

```
> ❯ solaar show
> solaar version 1.1.8
> 
> USB and Bluetooth Devices
> 
>   1: MX Master 3 Wireless Mouse
>      Device path  : /dev/hidraw6
>      USB id       : 046d:B023
>      Codename     : MX Master 3
>      Kind         : mouse
>      Protocol     : HID++ 4.5
>      Serial number: 
>      Model ID:      B02340820000
>      Unit ID:       75A345DA
>         Bootloader: BOT 95.01.B0015
>           Firmware: MPM 19.01.B0015
>              Other: 
>      Supports 31 HID++ 2.0 features:
>          0: ROOT                   {0000} V0     
>          1: FEATURE SET            {0001} V0     
>          2: DEVICE FW VERSION      {0003} V3     
>             Firmware: Bootloader BOT 95.01.B0015 00006A9CA89D
>             Firmware: Firmware MPM 19.01.B0015 B0236A9CA89D
>             Firmware: Other   
>             Unit ID: 75A345DA  Model ID: B02340820000  Transport IDs: {'btleid': 'B023', 'wpid': '4082'}
>          3: DEVICE NAME            {0005} V0     
>             Name: Wireless Mouse MX Master 3
>             Kind: mouse
>          4: WIRELESS DEVICE STATUS {1D4B} V0     
>          5: CONFIG CHANGE          {0020} V0     
>          6: CRYPTO ID              {0021} V1     
>          7: DEVICE FRIENDLY NAME   {0007} V0     
>             Friendly Name: MX Master 3
>          8: BATTERY STATUS         {1000} V1     
>             Battery: 100%, discharging, next level 50%.
>          9: REPROG CONTROLS V4     {1B04} V4     
>             Key/Button Actions (saved): {Left Button:Left Click, Right Button:Right Click, Middle Button:Mouse Middle Button, Back Button:Mouse Back Button, Forward Button:Mouse Forward Button, Mouse Gesture Button:Gesture Button Navigation, Smart Shift:Smart Shift}
>             Key/Button Actions        : {Left Button:Left Click, Right Button:Right Click, Middle Button:Mouse Middle Button, Back Button:Mouse Back Button, Forward Button:Mouse Forward Button, Mouse Gesture Button:Gesture Button Navigation, Smart Shift:Smart Shift}
>             Key/Button Diversion (saved): {Middle Button:Regular, Back Button:Regular, Forward Button:Regular, Mouse Gesture Button:Regular, Smart Shift:Regular}
>             Key/Button Diversion        : {Middle Button:Regular, Back Button:Regular, Forward Button:Regular, Mouse Gesture Button:Regular, Smart Shift:Regular}
>         10: CHANGE HOST            {1814} V1     
>             Change Host        : 1:ubuntu-ROG-Strix-G533QR-G533QR
>         11: XY STATS               {2250} V1     
>         12: ADJUSTABLE DPI         {2201} V1     
>             Sensitivity (DPI) (saved): 1000
>             Sensitivity (DPI)        : 1000
>         13: SMART SHIFT            {2110} V0     
>             Scroll Wheel Ratcheted (saved): Ratcheted
>             Scroll Wheel Ratcheted        : Ratcheted
>             Scroll Wheel Ratchet Speed (saved): 10
>             Scroll Wheel Ratchet Speed        : 10
>         14: HIRES WHEEL            {2121} V1     
>             Multiplier: 15
>             Has invert: Normal wheel motion
>             Has ratchet switch: Normal wheel mode
>             High resolution mode
>             HID notification
>             Scroll Wheel Direction (saved): False
>             Scroll Wheel Direction        : False
>             Scroll Wheel Resolution (saved): True
>             Scroll Wheel Resolution        : True
>             Scroll Wheel Diversion (saved): False
>             Scroll Wheel Diversion        : False
>         15: THUMB WHEEL            {2150} V0     
>             Thumb Wheel Direction (saved): False
>             Thumb Wheel Direction        : False
>             Thumb Wheel Diversion (saved): False
>             Thumb Wheel Diversion        : False
>         16: WHEEL STATS            {2251} V0     
>         17: DFUCONTROL SIGNED      {00C2} V0     
>         18: DEVICE RESET           {1802} V0    internal, hidden 
>         19: unknown:1803           {1803} V0    internal, hidden 
>         20: CONFIG DEVICE PROPS    {1806} V6    internal, hidden 
>         21: unknown:1813           {1813} V0    internal, hidden 
>         22: OOBSTATE               {1805} V0    internal, hidden 
>         23: unknown:1830           {1830} V0    internal, hidden 
>         24: unknown:18A1           {18A1} V0    internal, hidden 
>         25: unknown:1E00           {1E00} V0    hidden 
>         26: unknown:1EB0           {1EB0} V0    internal, hidden 
>         27: unknown:1861           {1861} V0    internal, hidden 
>         28: unknown:9300           {9300} V0    internal, hidden 
>         29: unknown:9001           {9001} V0    internal, hidden 
>         30: unknown:9205           {9205} V0    internal, hidden 
>      Has 8 reprogrammable keys:
>          0: Left Button               , default: Left Click                  => Left Click                
>              mse, analytics key events, pos:0, group:1, group mask:g1
>              reporting: default
>          1: Right Button              , default: Right Click                 => Right Click               
>              mse, analytics key events, pos:0, group:1, group mask:g1
>              reporting: default
>          2: Middle Button             , default: Mouse Middle Button         => Mouse Middle Button       
>              mse, reprogrammable, divertable, raw XY, analytics key events, pos:0, group:3, group mask:g1,g2,g3
>              reporting: default
>          3: Back Button               , default: Mouse Back Button           => Mouse Back Button         
>              mse, reprogrammable, divertable, raw XY, analytics key events, pos:0, group:2, group mask:g1,g2
>              reporting: default
>          4: Forward Button            , default: Mouse Forward Button        => Mouse Forward Button      
>              mse, reprogrammable, divertable, raw XY, analytics key events, pos:0, group:2, group mask:g1,g2
>              reporting: default
>          5: Mouse Gesture Button      , default: Gesture Button Navigation   => Gesture Button Navigation 
>              mse, reprogrammable, divertable, raw XY, analytics key events, pos:0, group:3, group mask:g1,g2,g3
>              reporting: default
>          6: Smart Shift               , default: Smart Shift                 => Smart Shift               
>              mse, reprogrammable, divertable, raw XY, analytics key events, pos:0, group:3, group mask:g1,g2,g3
>              reporting: default
>          7: Virtual Gesture Button    , default: Virtual Gesture Button      => Virtual Gesture Button    
>              divertable, virtual, raw XY, force raw XY, pos:0, group:4, group mask:empty
>              reporting: default
>      Battery: 100%, discharging, next level 50%.
```

Would be nice if Solaar can just ignore this keyboard or provide a way for user to blacklist certain devices.


Keyboard model is K845. https://www.logitech.com/en-us/products/keyboards/k845-mechanical-illuminated.html

Info on the device:

```
> ❯ cat /sys/class/hidraw/hidraw5/device/uevent
> DRIVER=hid-generic
> HID_ID=0003:0000046D:0000C341
> HID_NAME=Logitech Mechanical keyboard Logitech Mechanical keyboard
> HID_PHYS=usb-0000:05:00.3-1.1.1/input2
> HID_UNIQ=KG511U00000A
> MODALIAS=hid:b0003g0001v0000046Dp0000C341

> ❯ sudo lsusb -d 046d:c341 -v
> 
> Bus 001 Device 017: ID 046d:c341 Logitech, Inc. Logitech Mechanical keyboard
> Device Descriptor:
>   bLength                18
>   bDescriptorType         1
>   bcdUSB               2.00
>   bDeviceClass            0 
>   bDeviceSubClass         0 
>   bDeviceProtocol         0 
>   bMaxPacketSize0         8
>   idVendor           0x046d Logitech, Inc.
>   idProduct          0xc341 
>   bcdDevice            1.38
>   iManufacturer           1 Logitech Mechanical keyboard
>   iProduct                2 Logitech Mechanical keyboard
>   iSerial                 3 KG511U00000A
>   bNumConfigurations      1
>   Configuration Descriptor:
>     bLength                 9
>     bDescriptorType         2
>     wTotalLength       0x0054
>     bNumInterfaces          3
>     bConfigurationValue     1
>     iConfiguration          0 
>     bmAttributes         0xa0
>       (Bus Powered)
>       Remote Wakeup
>     MaxPower              250mA
>     Interface Descriptor:
>       bLength                 9
>       bDescriptorType         4
>       bInterfaceNumber        0
>       bAlternateSetting       0
>       bNumEndpoints           1
>       bInterfaceClass         3 Human Interface Device
>       bInterfaceSubClass      1 Boot Interface Subclass
>       bInterfaceProtocol      1 Keyboard
>       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               4
>     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      50
>          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     0x000e  1x 14 bytes
>         bInterval               2
>     Interface Descriptor:
>       bLength                 9
>       bDescriptorType         4
>       bInterfaceNumber        2
>       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      31
>          Report Descriptors: 
>            ** UNAVAILABLE **
>       Endpoint Descriptor:
>         bLength                 7
>         bDescriptorType         5
>         bEndpointAddress     0x83  EP 3 IN
>         bmAttributes            3
>           Transfer Type            Interrupt
```

Thanks


Discussion:
Could you please clone this repository and run `bin/solaar -ddd show` from this repository when the keyboard is connected?  The code for Solaar show has been updated to not terminate on this exception. 

Also run `bin/solaar -ddd` and plug in your laptop as you described above.  You will first have to terminate any running Solaar processes.

In any case this is a bug, as Solaar is supposed to ignore devices that do not implement HID++ commands.

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
@@ -209,6 +209,7 @@ def get_btid(btid):
 _D('G512 RGB Mechanical Gaming Keyboard', codename='G512', usbid=0xc33c, interface=1)
 _D('G815 Mechanical Keyboard', codename='G815', usbid=0xc33f, interface=1)
 _D('diNovo Edge Keyboard', codename='diNovo', protocol=1.0, wpid='C714', settings=[_ST.RegisterFnSwap])
+_D('K845 Mechanical Keyboard', codename='K845', usbid=0xc341, interface=3)
 
 # Mice
 


Test patch: