Repository: pwr-Solaar/Solaar

Issue:
Support for K810
Hi!! :)

**Information**
- Solaar version 1.1.1.1
- Distribution: Fedora
- Kernel version: Linux 5.15.18-200.fc35.x86_64 x86_64 GNU/Linux
- Output of `solaar show` for the target device (if applicable):


**Describe the solution you'd like**
When pairing a Logitech K810, I'd like it to appear in Solaar, just like the K380 does, so I can at least easily swap the function keys.


**Describe alternatives you've considered**
I use [another project](https://github.com/themech/k810_k811_fkeys) to swap the function keys. It works well, but I'd rather have that functionnality built in Solaar which I already use for other logitech devices.

**Additional context**
I have both the K810 and the K380 at hand. I wouldn't mind giving technical information and do some testing.



Discussion:
Edit: Oops.  I found the G810, not the K810.  It appears that the K810 is a bluetooth device.  Stay tuned for instructions on getting the information needed to support the K810.
Yep, it's bluetooth! The K810 does have a USB port but it's only for charging as the keyboard has an internal battery (which is annoying and I already had to replace once...). I don't think the USB port registers as a device.
To start the process of support for a Logitech receiver or device:

Make sure the receiver or device is connected and active.

Look at output of `grep -H . /sys/class/hidraw/hidraw*/device/uevent` to find where information about the device is kept.
You are looking for a line like `/sys/class/hidraw/hidrawN/device/uevent:HID_NAME=<NAME>` where `<NAME>` is the name of your receiver or device.

Provide the contents of the file `/sys/class/hidraw/hidrawN/device/uevent` where N was found above.

Also attach contents of the file `/sys/class/hidraw/hidrawN/device/report_descriptor`.  You will have to copy the contents to a file with txt extension before attaching it.
Or, better, install hidrd-convert and provide output of `hidrd-convert -o spec /sys/class/hidraw/hidrawN/device/report_descriptor`

If your device can connect in multiple ways (via a receiver, via a USB cable, via Bluetooth) do this for each way it can connect.

Based on this code in https://github.com/themech/k810_k811_fkeys, it may be that the only problem is that the Bluetooth product IDs are outside of the range that Solaar looks for.
```
#define LOGITECH_VENDOR (__u32)0x046d
#define PRODUCT_K810 (__s16)0xb319
#define PRODUCT_K811 (__s16)0xb317
```
If you have Solaar cloned you could trying changing the line in lib/logitech_receiver/base_usb.py very near the end from
```
        if (product_id >= 0xB012 and product_id <= 0xB0FF or product_id >= 0xB32A and product_id <= 0xB3FF):
```
to
```
        if (product_id >= 0xB012 and product_id <= 0xB0FF or product_id >= 0xB317 and product_id <= 0xB3FF):
```

Then run solaar as `bin/Solaar -ddd` and see whether your keyboard is recognized and there are no errors.
Correct me if I'm wrong, but it looks like "from" and "to" are swapped. 
Yes.  I edited the wrong bit of the message.  The change should be *to* 0xB317.
Ok so here are the files.
[uevent.txt](https://github.com/pwr-Solaar/Solaar/files/8279723/uevent.txt)
[report_descriptor.txt](https://github.com/pwr-Solaar/Solaar/files/8279731/report_descriptor.txt)  <-- this one has binary data

hidrd-convert fails:
```
$ hidrd-convert -o spec /sys/class/hidraw/hidraw3/device/report_descriptor
Failed to read input item at offset 319:
invalid item encountered
```

I'll try to run Solaar from the source

hidrd-convert fails for me also.  I wonder what the problem is.
Given that there is a program that sends HID++ commands to the keyboard, it must be an HID++ device so Solaar should pick it up if the product ID range is expanded.
Alright, I made the modification to `base_usb.py` and ran `solaar -ddd`. (I had to run as sudo though)

Solaar recognizes my keyboard, and "Swap Fx function" seems to work well. The backlight option roller never goes away.

![image](https://user-images.githubusercontent.com/5856745/158718766-96f62079-0747-4f27-906a-83d8065a1197.png)

(I still love my M305. I just had to clean the tactile switches inside two times ;) )
I also confirm that nothing shows up in dmesg when I plug the keyboard to a USB port.
The Backlight problem has been seen in another case.  See Issue #1487.

Please provide output of `sudo bin/solaar -ddd show`.

To be able to run Solaar without sudo you need to install the Solaar udev rule as described in the Solaar installation instructions.  Or you can install Solaar using dnf, which will install the rule.
solaar is already installed with dnf.

Here are the results of `sudo bin/solaar -ddd show > debug_output_stdout.txt 2> debug_output_stderr.txt`

[debug_output_stdout.txt](https://github.com/pwr-Solaar/Solaar/files/8279899/debug_output_stdout.txt)
[debug_output_stderr.txt](https://github.com/pwr-Solaar/Solaar/files/8279902/debug_output_stderr.txt)

If the Solaar udev rule is installed, you shouldn't have to use sudo to run Solaar.   Please provide output of `ls -l /dev/hidraw*`.
Here:

```
$ ls -l /dev/hidraw*
crw-rw----+ 1 root root 240, 0 Mar 16 21:05 /dev/hidraw0
crw-rw----+ 1 root root 240, 1 Mar 16 21:05 /dev/hidraw1
crw-rw----+ 1 root root 240, 2 Mar 16 21:05 /dev/hidraw2
crw-rw----+ 1 root root 240, 3 Mar 16 21:05 /dev/hidraw3
```

I meant I have to run the repo binary with sudo. The dnf installed version runs fine without sudo. I don't mind, really, as this is just for testing.
You shouldn't have to run the repo version of Solaar with sudo.   What error do you get if you don't use sudo?
[no_sudo_debug_output_stderr.txt](https://github.com/pwr-Solaar/Solaar/files/8280000/no_sudo_debug_output_stderr.txt)
[no_sudo_debug_output_stdout.txt](https://github.com/pwr-Solaar/Solaar/files/8280001/no_sudo_debug_output_stdout.txt)

That's the same error that you would get running with sudo.   So you don't need to use sudo.
I'm sorry, I just noticed the problem arises when I run solaar without the `show` argument. So `bin/solaar -ddd > no_sudo_no_show_debug_output_stdout.txt 2> no_sudo_no_show_debug_output_stderr.txt`

[no_sudo_no_show_debug_output_stderr.txt](https://github.com/pwr-Solaar/Solaar/files/8280469/no_sudo_no_show_debug_output_stderr.txt)
no_sudo_no_show_debug_output_stdout.txt is empty

Solaar wasn't expecting the value for the backlight that your keyboard produced.   The fix is simple.
I think you are running two Solaar programs.   The second one is trying to communicate with the first one, but the first one is an older version and can't handle the message from the second one.

The solution is to kill the running Solaar and only then run Solaar from your clone of the repo.

Running the second as root means that it doesn't try to communicate with the first one.
Yep! That was it :)

Resolving patch:
diff --git a/lib/logitech_receiver/base_usb.py b/lib/logitech_receiver/base_usb.py
--- a/lib/logitech_receiver/base_usb.py
+++ b/lib/logitech_receiver/base_usb.py
@@ -226,7 +226,7 @@ def other_device_check(bus_id, vendor_id, product_id):
         if (product_id >= 0xC07D and product_id <= 0xC094 or product_id >= 0xC32B and product_id <= 0xC344):
             return _wired_device(product_id, 2)
     elif bus_id == 0x5:  # Bluetooth
-        if (product_id >= 0xB012 and product_id <= 0xB0FF or product_id >= 0xB32A and product_id <= 0xB3FF):
+        if (product_id >= 0xB012 and product_id <= 0xB0FF or product_id >= 0xB317 and product_id <= 0xB3FF):
             return _bt_device(product_id)
 
 
diff --git a/lib/logitech_receiver/settings_templates.py b/lib/logitech_receiver/settings_templates.py
--- a/lib/logitech_receiver/settings_templates.py
+++ b/lib/logitech_receiver/settings_templates.py
@@ -203,7 +203,7 @@ class Backlight(_Setting):
     label = _('Backlight')
     description = _('Set illumination time for keyboard.')
     feature = _F.BACKLIGHT
-    choices_universe = _NamedInts(Off=0, Short=5, Medium=20, Long=60, VeryLong=180)
+    choices_universe = _NamedInts(Off=0, Varying=2, VeryShort=5, Short=10, Medium=20, Long=60, VeryLong=180)
     validator_class = _ChoicesV
     validator_options = {'choices': choices_universe}
 


Test patch: