From 6e36e33b2263e0dcbfee4682e51786b7db2e63e2 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 26 May 2013 21:43:20 +0200 Subject: [PATCH 1/2] Decouple controls from tasks (programmable keys) They are treated differently in the HID++ 2.0 specification. Observations seem to confirm this difference. For instance, a part of solaar-cli's output: 0: unknown:0022 => Home FN sensitive, is FN, reprogrammable 1: Mail => Mail FN sensitive, is FN, reprogrammable 2: unknown:003E => Search FN sensitive, is FN, reprogrammable --- lib/logitech/unifying_receiver/hidpp20.py | 29 ++--------- .../unifying_receiver/special_keys.py | 51 +++++++++++++++++++ lib/solaar/cli.py | 4 +- 3 files changed, 57 insertions(+), 27 deletions(-) create mode 100644 lib/logitech/unifying_receiver/special_keys.py diff --git a/lib/logitech/unifying_receiver/hidpp20.py b/lib/logitech/unifying_receiver/hidpp20.py index 821fdd76..fd6e29dd 100644 --- a/lib/logitech/unifying_receiver/hidpp20.py +++ b/lib/logitech/unifying_receiver/hidpp20.py @@ -25,6 +25,7 @@ from .common import (FirmwareInfo as _FirmwareInfo, ReprogrammableKeyInfo as _ReprogrammableKeyInfo, KwException as _KwException, NamedInts as _NamedInts) +from . import special_keys # # @@ -82,30 +83,6 @@ BATTERY_STATUS = _NamedInts( invalid_battery=0x05, thermal_error=0x06) -KEY = _NamedInts( - Volume_Up=0x0001, - Volume_Down=0x0002, - Mute=0x0003, - Play__Pause=0x0004, - Next=0x0005, - Previous=0x0006, - Stop=0x0007, - Application_Switcher=0x0008, - Calculator=0x000A, - Mail=0x000E, - Home=0x001A, - Music=0x001D, - Search=0x0029, - Sleep=0x002F) -KEY._fallback = lambda x: 'unknown:%04X' % x - -KEY_FLAG = _NamedInts( - reprogrammable=0x10, - FN_sensitive=0x08, - nonstandard=0x04, - is_FN=0x02, - mse=0x01) - ERROR = _NamedInts( unknown=0x01, invalid_argument=0x02, @@ -285,7 +262,9 @@ class KeysArray(object): keydata = feature_request(self.device, FEATURE.REPROGRAMMABLE_KEYS, 0x10, index) if keydata: key, key_task, flags = _unpack('!HHB', keydata[:5]) - self.keys[index] = _ReprogrammableKeyInfo(index, KEY[key], KEY[key_task], flags) + ctrl_id_text = special_keys.CONTROL[key] + ctrl_task_text = special_keys.TASK[key_task] + self.keys[index] = _ReprogrammableKeyInfo(index, ctrl_id_text, ctrl_task_text, flags) return self.keys[index] diff --git a/lib/logitech/unifying_receiver/special_keys.py b/lib/logitech/unifying_receiver/special_keys.py new file mode 100644 index 00000000..bb2975b3 --- /dev/null +++ b/lib/logitech/unifying_receiver/special_keys.py @@ -0,0 +1,51 @@ +# +# Reprogrammable keys information +# + +from __future__ import absolute_import, division, print_function, unicode_literals + +from .common import NamedInts as _NamedInts + +CONTROL = _NamedInts( + Volume_Up=0x0001, + Volume_Down=0x0002, + Mute=0x0003, + Play__Pause=0x0004, + Next=0x0005, + Previous=0x0006, + Stop=0x0007, + Application_Switcher=0x0008, + Calculator=0x000A, + Mail=0x000E, + Home=0x001A, + Music=0x001D, + Search=0x0029, + Sleep=0x002F, +) +CONTROL._fallback = lambda x: 'unknown:%04X' % x + +TASK = _NamedInts( + Volume_Up=0x0001, + Volume_Down=0x0002, + Mute=0x0003, + Play__Pause=0x0004, + Next=0x0005, + Previous=0x0006, + Stop=0x0007, + Application_Switcher=0x0008, + Calculator=0x000A, + Mail=0x000E, + Home=0x001A, + Music=0x001D, + Search=0x0029, + Sleep=0x002F, +) +TASK._fallback = lambda x: 'unknown:%04X' % x + +KEY_FLAG = _NamedInts( + reprogrammable=0x10, + FN_sensitive=0x08, + nonstandard=0x04, + is_FN=0x02, + mse=0x01 +) diff --git a/lib/solaar/cli.py b/lib/solaar/cli.py index 391f0762..8d1ed3ef 100644 --- a/lib/solaar/cli.py +++ b/lib/solaar/cli.py @@ -132,7 +132,7 @@ def _print_device(dev, verbose=False): if dev.power_switch_location: print (" The power switch is located on the", dev.power_switch_location) - from logitech.unifying_receiver import hidpp10, hidpp20 + from logitech.unifying_receiver import hidpp10, hidpp20, special_keys if p > 0: if dev.features: print (" Supports %d HID++ 2.0 features:" % len(dev.features)) @@ -146,7 +146,7 @@ def _print_device(dev, verbose=False): if dev.keys: print (" Has %d reprogrammable keys:" % len(dev.keys)) for k in dev.keys: - flags = hidpp20.KEY_FLAG.flag_names(k.flags) + flags = special_keys.KEY_FLAG.flag_names(k.flags) print (" %2d: %-20s => %-20s %s" % (k.index, k.key, k.task, ', '.join(flags))) if p > 0: From 28c35633d3a22217af3e64742de7cebb14689f73 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 26 May 2013 22:01:07 +0200 Subject: [PATCH 2/2] Add more tasks for special keys Based on tasks.xml from `%ProgramFiles%\\SetPointP\\tasks.xml`. --- .../unifying_receiver/special_keys.py | 122 +++++++++++++++++- 1 file changed, 119 insertions(+), 3 deletions(-) diff --git a/lib/logitech/unifying_receiver/special_keys.py b/lib/logitech/unifying_receiver/special_keys.py index bb2975b3..0cc6b1e7 100644 --- a/lib/logitech/unifying_receiver/special_keys.py +++ b/lib/logitech/unifying_receiver/special_keys.py @@ -24,21 +24,137 @@ CONTROL = _NamedInts( ) CONTROL._fallback = lambda x: 'unknown:%04X' % x +#