Repository: pwr-Solaar/Solaar

Issue:
Add support for Fn swap for  K400 Plus
K400 Touch seems to be supported but not K400 Plus, it might be a simple device recognition problem.

```
$ solaar --version
solaar 0.9.2
$ solaar show 3
  3: Wireless Touch Keyboard K400 Plus
     Codename     : K400 Plus
     Kind         : keyboard
     Wireless PID : 404D
     Protocol     : HID++ 4.1
     Polling rate : 8 ms (125Hz)
     Serial number: 43249AE8
        Bootloader: BOT 22.01.B0001
          Firmware: RQK 63.01.B0014
             Other: 
     The power switch is located on the top edge.
     Supports 24 HID++ 2.0 features:
         0: ROOT                   {0000}   
         1: FEATURE SET            {0001}   
         2: DEVICE FW VERSION      {0003}   
         3: DEVICE NAME            {0005}   
         4: WIRELESS DEVICE STATUS {1D4B}   
         5: RESET                  {0020}   
         6: BATTERY STATUS         {1000}   
         7: REPROG CONTROLS V4     {1B04}   
         8: SWAP BUTTON            {2005}   
         9: NEW FN INVERSION       {40A2}   
        10: ENCRYPTION             {4100}   
        11: KEYBOARD DISABLE       {4521}   
        12: TOUCHPAD RAW XY        {6100}   
        13: GESTURE 2              {6501}   
        14: DFUCONTROL 2           {00C1}   
        15: unknown:1811           {1811}   internal, hidden
        16: unknown:1830           {1830}   internal, hidden
        17: unknown:1890           {1890}   internal, hidden
        18: unknown:1DF3           {1DF3}   internal, hidden
        19: unknown:1E00           {1E00}   hidden
        20: unknown:1EB0           {1EB0}   internal, hidden
        21: unknown:1861           {1861}   internal, hidden
        22: unknown:18B0           {18B0}   internal, hidden
        23: unknown:1F11           {1F11}   internal, hidden
     Battery: 90%, discharging.
 $ solaar config 3
solaar: error: no settings for Wireless Touch Keyboard K400 Plus
```


Discussion:
@correaa ,

What version of solaar did you use? Can you try latest master available in this repo? Refer to #282 , they reported it works on latest master. Let me know your result.

Thanks,
@jrbenito , I am using solaar 0.9.2 in Fedora 24. What is the current nominal version? 
I wouldn't know how to replace solaar with the development version and I am afraid to break it. 
@correaa ,

Actually last release is the 0.9.2 but it is outdated. @Lekensteyn is driving a hard work to review open bugs and PRs before we can have a new release. However, you can try use the latest master that seems to have the problem with K400 plus solved as per #282.

If you want to try, close the running instance of Solaar and go to a terminal then type:

```
$ mkdir Solaar
$ git clone https://github.com/pwr/Solaar.git Solaar
$ cd Solaar
$ ./bin/solaar
```

You shall see the solaar gui and your K400 plus might work. If this is works and you want to keep using it, remove solaar rpm package and use your new fresh copy of solaar. 

Out of curiosity, if you want to keep it up to date with the bleeding edge development, just type:

`$ git pull`

on your Solaar directory every week, this will pull every new merge @Lekensteyn  have made.

If you try and it works, please close this ticket. If you have problem please report and if you need assistance drop me a message.

Regards,
Benito
Yes, now it works with the current version pulled from github (thank you for the instructions). The device appears as "Plus" with this info: 

```
Index        : 3
Wireless PID : 404D
Protocol     : HID++ 2.0
Polling rate : 8 ms (125Hz)
Serial       : 43249AE8
  Bootloader : BOT 22.01.B0001
  Firmware   : RQK 63.01.B0014
  Other      : 
```

Also, now there is a "Swap Fx function ON/OFF", which closes the issue. (I hope the changes are pushed to Fedora quickly.)



Hello,

I try to set fn-swap on K400 Plus, but it doesn`t work.

I have code from master:

**git status**
> On branch master
Your branch is up to date with 'origin/master'.
 nothing to commit, working tree clean

Solaar shows, that option is present:

**bin/solaar config 1**
>Wireless Touch Keyboard K400 Plus (K400 Plus) [404D:F35A0546]
>
>Funkcja Swap Fx
> ...
>possible values: on/true/t/yes/y/1 or off/false/f/no/n/0
>fn-swap = True
>
>Disable keys
>Disable specific keyboard keys.
>disable-keyboard-keys = {'1': False, '4': False, '8': False, '16': False}

But when I try to set it, it doesn`t work:

**bin/solaar config 1 fn-swap on**
>solaar: error: Traceback (most recent call last):
  File "/home/marcin/Programy/Solaar/lib/solaar/cli/__init__.py", line 175, in run
    m.run(c, args, _find_receiver, _find_device)
  File "/home/marcin/Programy/Solaar/lib/solaar/cli/config.py", line 74, in run
    raise Exception("no setting '%s' for %s" % (args.setting, dev.name))
Exception: no setting 'fn-swap' for Wireless Touch Keyboard K400 Plus

Please try just showing this feature via:
`bin/solaar config 1 fn-swap`

Also try showing the other settings.

Also try with environment variable LANGUAGE unset to see whether this is a translation problem.

I`ve done:
**unset $LANGUAGE** 
**unset $LANG** 

And then:
**bin/solaar config 1 fn-swap**
> solaar: error: Traceback (most recent call last):
  File "/home/marcin/Programy/Solaar/lib/solaar/cli/__init__.py", line 175, in run
    m.run(c, args, _find_receiver, _find_device)
  File "/home/marcin/Programy/Solaar/lib/solaar/cli/config.py", line 74, in run
    raise Exception("no setting '%s' for %s" % (args.setting, dev.name))
Exception: no setting 'fn-swap' for Wireless Touch Keyboard K400 Plus

**bin/solaar config 1**
> Wireless Touch Keyboard K400 Plus (K400 Plus) [404D:F35A0546]
>
> \# Swap Fx function
> \# When set, the F1..F12 keys will activate their special function, and you must hold the FN key to activate their standard function.  When unset, the F1..F12 keys will activate their standard function, and you must hold the FN key to activate their special function.
> \#   possible values: on/true/t/yes/y/1 or off/false/f/no/n/0
fn-swap = True
> 
> \# Disable keys
> \# Disable specific keyboard keys.
> disable-keyboard-keys = {'1': False, '4': False, '8': False, '16': False}

But calling the other option works:
**bin/solaar config 1 disable-keyboard-keys**

> \# Disable keys
> \# Disable specific keyboard keys.
> disable-keyboard-keys = {'1': False, '4': False, '8': False, '16': False}

I think I see what is going wrong.  Could you post the contents of ~/.config/Solaar/config.json?
Never mind - I'm pretty sure I've found the problem.

Resolving patch:
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
@@ -676,4 +676,6 @@ def check_feature_settings(device, already_known):
 def check_feature_setting(device, setting_name):
     for name, featureId, featureFn, __, __ in _SETTINGS_TABLE:
         if name == setting_name and featureId and featureFn:
-            return check_feature(device, name, featureId, featureFn)
+            feature = check_feature(device, name, featureId, featureFn)
+            if feature:
+                return feature


Test patch: