2018-09-17 05:49:14 +02:00
|
|
|
import logging
|
|
|
|
|
HID: Support Consumer (media) keys
What a short title for such a massive diff.
This (heavily squashed) commit adds support for Consumer keys such as
volume keys, media play/pause/stop, etc. by exposing four HID devices
over a single USB lane (as opposed to just exposing a keyboard). This
heavily refactors how HIDHelper works due to the new reporting
structure.
Many of the media keys were changed (mostly Keycodes.Media section), but
many (especially anything regarding Application keys) haven't been
touched yet - thus many keycodes may still be wrong. Probably worth
updating those soon, but I didn't get around to it yet. The definitive
list I refered to was
http://www.freebsddiary.org/APC/usb_hid_usages.php, which is basically
copy-pasta from the official USB HID spec at
https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
(warning: massive PDF, not light reading).
The only known regression this introduces is that instead of 6KRO as the
USB spec usually supports, we can now only have 5KRO (maybe even 4KRO),
for reasons I have yet to fully debug - this seems to be related to the
report having to include the device descriptor _and_ not supporting a
full 8 bytes as it used to. For now I'm willing to accept this, but it
definitely will be great to squash that bug.
This adds descriptor support for MOUSE and SYSCONTROL devices, as of yet
unimplemented.
2018-09-30 00:46:17 +02:00
|
|
|
from pyb import USB_HID, delay, hid_keyboard
|
2018-09-17 05:49:14 +02:00
|
|
|
|
HID: Support Consumer (media) keys
What a short title for such a massive diff.
This (heavily squashed) commit adds support for Consumer keys such as
volume keys, media play/pause/stop, etc. by exposing four HID devices
over a single USB lane (as opposed to just exposing a keyboard). This
heavily refactors how HIDHelper works due to the new reporting
structure.
Many of the media keys were changed (mostly Keycodes.Media section), but
many (especially anything regarding Application keys) haven't been
touched yet - thus many keycodes may still be wrong. Probably worth
updating those soon, but I didn't get around to it yet. The definitive
list I refered to was
http://www.freebsddiary.org/APC/usb_hid_usages.php, which is basically
copy-pasta from the official USB HID spec at
https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
(warning: massive PDF, not light reading).
The only known regression this introduces is that instead of 6KRO as the
USB spec usually supports, we can now only have 5KRO (maybe even 4KRO),
for reasons I have yet to fully debug - this seems to be related to the
report having to include the device descriptor _and_ not supporting a
full 8 bytes as it used to. For now I'm willing to accept this, but it
definitely will be great to squash that bug.
This adds descriptor support for MOUSE and SYSCONTROL devices, as of yet
unimplemented.
2018-09-30 00:46:17 +02:00
|
|
|
from kmk.common.consts import HID_REPORT_STRUCTURE, HIDReportTypes
|
2018-09-23 06:49:58 +02:00
|
|
|
from kmk.common.event_defs import HID_REPORT_EVENT
|
HID: Support Consumer (media) keys
What a short title for such a massive diff.
This (heavily squashed) commit adds support for Consumer keys such as
volume keys, media play/pause/stop, etc. by exposing four HID devices
over a single USB lane (as opposed to just exposing a keyboard). This
heavily refactors how HIDHelper works due to the new reporting
structure.
Many of the media keys were changed (mostly Keycodes.Media section), but
many (especially anything regarding Application keys) haven't been
touched yet - thus many keycodes may still be wrong. Probably worth
updating those soon, but I didn't get around to it yet. The definitive
list I refered to was
http://www.freebsddiary.org/APC/usb_hid_usages.php, which is basically
copy-pasta from the official USB HID spec at
https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
(warning: massive PDF, not light reading).
The only known regression this introduces is that instead of 6KRO as the
USB spec usually supports, we can now only have 5KRO (maybe even 4KRO),
for reasons I have yet to fully debug - this seems to be related to the
report having to include the device descriptor _and_ not supporting a
full 8 bytes as it used to. For now I'm willing to accept this, but it
definitely will be great to squash that bug.
This adds descriptor support for MOUSE and SYSCONTROL devices, as of yet
unimplemented.
2018-09-30 00:46:17 +02:00
|
|
|
from kmk.common.keycodes import (FIRST_KMK_INTERNAL_KEYCODE, ConsumerKeycode,
|
2018-10-01 06:14:30 +02:00
|
|
|
ModifierKeycode)
|
2018-10-01 09:31:45 +02:00
|
|
|
from kmk.common.macros import KMKMacro
|
HID: Support Consumer (media) keys
What a short title for such a massive diff.
This (heavily squashed) commit adds support for Consumer keys such as
volume keys, media play/pause/stop, etc. by exposing four HID devices
over a single USB lane (as opposed to just exposing a keyboard). This
heavily refactors how HIDHelper works due to the new reporting
structure.
Many of the media keys were changed (mostly Keycodes.Media section), but
many (especially anything regarding Application keys) haven't been
touched yet - thus many keycodes may still be wrong. Probably worth
updating those soon, but I didn't get around to it yet. The definitive
list I refered to was
http://www.freebsddiary.org/APC/usb_hid_usages.php, which is basically
copy-pasta from the official USB HID spec at
https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
(warning: massive PDF, not light reading).
The only known regression this introduces is that instead of 6KRO as the
USB spec usually supports, we can now only have 5KRO (maybe even 4KRO),
for reasons I have yet to fully debug - this seems to be related to the
report having to include the device descriptor _and_ not supporting a
full 8 bytes as it used to. For now I'm willing to accept this, but it
definitely will be great to squash that bug.
This adds descriptor support for MOUSE and SYSCONTROL devices, as of yet
unimplemented.
2018-09-30 00:46:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
def generate_pyb_hid_descriptor():
|
|
|
|
existing_keyboard = list(hid_keyboard)
|
|
|
|
existing_keyboard[-1] = HID_REPORT_STRUCTURE
|
|
|
|
return tuple(existing_keyboard)
|
2018-09-17 05:49:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
class HIDHelper:
|
2018-09-17 08:20:16 +02:00
|
|
|
def __init__(self, store, log_level=logging.NOTSET):
|
2018-09-17 05:49:14 +02:00
|
|
|
self.logger = logging.getLogger(__name__)
|
|
|
|
self.logger.setLevel(log_level)
|
|
|
|
|
2018-09-17 08:20:16 +02:00
|
|
|
self.store = store
|
|
|
|
self.store.subscribe(
|
|
|
|
lambda state, action: self._subscription(state, action),
|
|
|
|
)
|
|
|
|
|
2018-09-17 05:49:14 +02:00
|
|
|
self._hid = USB_HID()
|
HID: Support Consumer (media) keys
What a short title for such a massive diff.
This (heavily squashed) commit adds support for Consumer keys such as
volume keys, media play/pause/stop, etc. by exposing four HID devices
over a single USB lane (as opposed to just exposing a keyboard). This
heavily refactors how HIDHelper works due to the new reporting
structure.
Many of the media keys were changed (mostly Keycodes.Media section), but
many (especially anything regarding Application keys) haven't been
touched yet - thus many keycodes may still be wrong. Probably worth
updating those soon, but I didn't get around to it yet. The definitive
list I refered to was
http://www.freebsddiary.org/APC/usb_hid_usages.php, which is basically
copy-pasta from the official USB HID spec at
https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
(warning: massive PDF, not light reading).
The only known regression this introduces is that instead of 6KRO as the
USB spec usually supports, we can now only have 5KRO (maybe even 4KRO),
for reasons I have yet to fully debug - this seems to be related to the
report having to include the device descriptor _and_ not supporting a
full 8 bytes as it used to. For now I'm willing to accept this, but it
definitely will be great to squash that bug.
This adds descriptor support for MOUSE and SYSCONTROL devices, as of yet
unimplemented.
2018-09-30 00:46:17 +02:00
|
|
|
|
|
|
|
# For some bizarre reason this can no longer be 8, it'll just fail to
|
|
|
|
# send anything. This is almost certainly a bug in the report descriptor
|
|
|
|
# sent over in the boot process. For now the sacrifice is that we only
|
|
|
|
# support 5KRO until I figure this out, rather than the 6KRO HID defines.
|
|
|
|
self._evt = bytearray(7)
|
|
|
|
self.report_device = memoryview(self._evt)[0:1]
|
|
|
|
|
|
|
|
# Landmine alert for HIDReportTypes.KEYBOARD: byte index 1 of this view
|
|
|
|
# is "reserved" and evidently (mostly?) unused. However, other modes (or
|
|
|
|
# at least consumer, so far) will use this byte, which is the main reason
|
|
|
|
# this view exists. For KEYBOARD, use report_mods and report_non_mods
|
|
|
|
self.report_keys = memoryview(self._evt)[1:]
|
|
|
|
|
|
|
|
self.report_mods = memoryview(self._evt)[1:2]
|
|
|
|
self.report_non_mods = memoryview(self._evt)[3:]
|
2018-09-17 05:49:14 +02:00
|
|
|
|
2018-09-17 08:20:16 +02:00
|
|
|
def _subscription(self, state, action):
|
2018-10-01 07:50:04 +02:00
|
|
|
if action[0] == HID_REPORT_EVENT:
|
2018-09-23 06:49:58 +02:00
|
|
|
self.clear_all()
|
|
|
|
|
HID: Support Consumer (media) keys
What a short title for such a massive diff.
This (heavily squashed) commit adds support for Consumer keys such as
volume keys, media play/pause/stop, etc. by exposing four HID devices
over a single USB lane (as opposed to just exposing a keyboard). This
heavily refactors how HIDHelper works due to the new reporting
structure.
Many of the media keys were changed (mostly Keycodes.Media section), but
many (especially anything regarding Application keys) haven't been
touched yet - thus many keycodes may still be wrong. Probably worth
updating those soon, but I didn't get around to it yet. The definitive
list I refered to was
http://www.freebsddiary.org/APC/usb_hid_usages.php, which is basically
copy-pasta from the official USB HID spec at
https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
(warning: massive PDF, not light reading).
The only known regression this introduces is that instead of 6KRO as the
USB spec usually supports, we can now only have 5KRO (maybe even 4KRO),
for reasons I have yet to fully debug - this seems to be related to the
report having to include the device descriptor _and_ not supporting a
full 8 bytes as it used to. For now I'm willing to accept this, but it
definitely will be great to squash that bug.
This adds descriptor support for MOUSE and SYSCONTROL devices, as of yet
unimplemented.
2018-09-30 00:46:17 +02:00
|
|
|
consumer_key = None
|
2018-09-23 06:49:58 +02:00
|
|
|
for key in state.keys_pressed:
|
HID: Support Consumer (media) keys
What a short title for such a massive diff.
This (heavily squashed) commit adds support for Consumer keys such as
volume keys, media play/pause/stop, etc. by exposing four HID devices
over a single USB lane (as opposed to just exposing a keyboard). This
heavily refactors how HIDHelper works due to the new reporting
structure.
Many of the media keys were changed (mostly Keycodes.Media section), but
many (especially anything regarding Application keys) haven't been
touched yet - thus many keycodes may still be wrong. Probably worth
updating those soon, but I didn't get around to it yet. The definitive
list I refered to was
http://www.freebsddiary.org/APC/usb_hid_usages.php, which is basically
copy-pasta from the official USB HID spec at
https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
(warning: massive PDF, not light reading).
The only known regression this introduces is that instead of 6KRO as the
USB spec usually supports, we can now only have 5KRO (maybe even 4KRO),
for reasons I have yet to fully debug - this seems to be related to the
report having to include the device descriptor _and_ not supporting a
full 8 bytes as it used to. For now I'm willing to accept this, but it
definitely will be great to squash that bug.
This adds descriptor support for MOUSE and SYSCONTROL devices, as of yet
unimplemented.
2018-09-30 00:46:17 +02:00
|
|
|
if isinstance(key, ConsumerKeycode):
|
|
|
|
consumer_key = key
|
|
|
|
break
|
|
|
|
|
|
|
|
reporting_device = self.report_device[0]
|
|
|
|
needed_reporting_device = HIDReportTypes.KEYBOARD
|
|
|
|
|
|
|
|
if consumer_key:
|
|
|
|
needed_reporting_device = HIDReportTypes.CONSUMER
|
|
|
|
|
|
|
|
if reporting_device != needed_reporting_device:
|
|
|
|
# If we are about to change reporting devices, release
|
|
|
|
# all keys and close our proverbial tab on the existing
|
|
|
|
# device, or keys will get stuck (mostly when releasing
|
|
|
|
# media/consumer keys)
|
|
|
|
self.send()
|
|
|
|
|
|
|
|
self.report_device[0] = needed_reporting_device
|
|
|
|
|
|
|
|
if consumer_key:
|
|
|
|
self.add_key(consumer_key)
|
|
|
|
else:
|
|
|
|
for key in state.keys_pressed:
|
2018-10-01 09:31:45 +02:00
|
|
|
if isinstance(key, KMKMacro) or key.code >= FIRST_KMK_INTERNAL_KEYCODE:
|
HID: Support Consumer (media) keys
What a short title for such a massive diff.
This (heavily squashed) commit adds support for Consumer keys such as
volume keys, media play/pause/stop, etc. by exposing four HID devices
over a single USB lane (as opposed to just exposing a keyboard). This
heavily refactors how HIDHelper works due to the new reporting
structure.
Many of the media keys were changed (mostly Keycodes.Media section), but
many (especially anything regarding Application keys) haven't been
touched yet - thus many keycodes may still be wrong. Probably worth
updating those soon, but I didn't get around to it yet. The definitive
list I refered to was
http://www.freebsddiary.org/APC/usb_hid_usages.php, which is basically
copy-pasta from the official USB HID spec at
https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
(warning: massive PDF, not light reading).
The only known regression this introduces is that instead of 6KRO as the
USB spec usually supports, we can now only have 5KRO (maybe even 4KRO),
for reasons I have yet to fully debug - this seems to be related to the
report having to include the device descriptor _and_ not supporting a
full 8 bytes as it used to. For now I'm willing to accept this, but it
definitely will be great to squash that bug.
This adds descriptor support for MOUSE and SYSCONTROL devices, as of yet
unimplemented.
2018-09-30 00:46:17 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
if isinstance(key, ModifierKeycode):
|
|
|
|
self.add_modifier(key)
|
|
|
|
else:
|
|
|
|
self.add_key(key)
|
|
|
|
|
|
|
|
if key.has_modifiers:
|
|
|
|
for mod in key.has_modifiers:
|
|
|
|
self.add_modifier(mod)
|
2018-09-23 14:19:57 +02:00
|
|
|
|
2018-09-23 06:49:58 +02:00
|
|
|
self.send()
|
2018-09-17 08:20:16 +02:00
|
|
|
|
2018-09-17 05:49:14 +02:00
|
|
|
def send(self):
|
|
|
|
self.logger.debug('Sending HID report: {}'.format(self._evt))
|
|
|
|
self._hid.send(self._evt)
|
|
|
|
|
2018-10-01 03:03:43 +02:00
|
|
|
# Without this delay, events get clobbered and you'll likely end up with
|
|
|
|
# a string like `heloooooooooooooooo` rather than `hello`. This number
|
|
|
|
# may be able to be shrunken down. It may also make sense to use
|
|
|
|
# time.sleep_us or time.sleep_ms or time.sleep (platform dependent)
|
|
|
|
# on non-Pyboards.
|
|
|
|
#
|
|
|
|
# It'd be real awesome if pyb.USB_HID.send/recv would support
|
|
|
|
# uselect.poll or uselect.select to more safely determine when
|
|
|
|
# it is safe to write to the host again...
|
2018-10-01 09:31:45 +02:00
|
|
|
delay(5)
|
2018-10-01 03:03:43 +02:00
|
|
|
|
2018-09-17 05:49:14 +02:00
|
|
|
return self
|
|
|
|
|
|
|
|
def clear_all(self):
|
HID: Support Consumer (media) keys
What a short title for such a massive diff.
This (heavily squashed) commit adds support for Consumer keys such as
volume keys, media play/pause/stop, etc. by exposing four HID devices
over a single USB lane (as opposed to just exposing a keyboard). This
heavily refactors how HIDHelper works due to the new reporting
structure.
Many of the media keys were changed (mostly Keycodes.Media section), but
many (especially anything regarding Application keys) haven't been
touched yet - thus many keycodes may still be wrong. Probably worth
updating those soon, but I didn't get around to it yet. The definitive
list I refered to was
http://www.freebsddiary.org/APC/usb_hid_usages.php, which is basically
copy-pasta from the official USB HID spec at
https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
(warning: massive PDF, not light reading).
The only known regression this introduces is that instead of 6KRO as the
USB spec usually supports, we can now only have 5KRO (maybe even 4KRO),
for reasons I have yet to fully debug - this seems to be related to the
report having to include the device descriptor _and_ not supporting a
full 8 bytes as it used to. For now I'm willing to accept this, but it
definitely will be great to squash that bug.
This adds descriptor support for MOUSE and SYSCONTROL devices, as of yet
unimplemented.
2018-09-30 00:46:17 +02:00
|
|
|
for idx, _ in enumerate(self.report_keys):
|
|
|
|
self.report_keys[idx] = 0x00
|
|
|
|
|
2018-09-17 05:49:14 +02:00
|
|
|
return self
|
|
|
|
|
|
|
|
def clear_non_modifiers(self):
|
HID: Support Consumer (media) keys
What a short title for such a massive diff.
This (heavily squashed) commit adds support for Consumer keys such as
volume keys, media play/pause/stop, etc. by exposing four HID devices
over a single USB lane (as opposed to just exposing a keyboard). This
heavily refactors how HIDHelper works due to the new reporting
structure.
Many of the media keys were changed (mostly Keycodes.Media section), but
many (especially anything regarding Application keys) haven't been
touched yet - thus many keycodes may still be wrong. Probably worth
updating those soon, but I didn't get around to it yet. The definitive
list I refered to was
http://www.freebsddiary.org/APC/usb_hid_usages.php, which is basically
copy-pasta from the official USB HID spec at
https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
(warning: massive PDF, not light reading).
The only known regression this introduces is that instead of 6KRO as the
USB spec usually supports, we can now only have 5KRO (maybe even 4KRO),
for reasons I have yet to fully debug - this seems to be related to the
report having to include the device descriptor _and_ not supporting a
full 8 bytes as it used to. For now I'm willing to accept this, but it
definitely will be great to squash that bug.
This adds descriptor support for MOUSE and SYSCONTROL devices, as of yet
unimplemented.
2018-09-30 00:46:17 +02:00
|
|
|
for idx, _ in enumerate(self.report_non_mods):
|
|
|
|
self.report_non_mods[idx] = 0x00
|
2018-09-17 05:49:14 +02:00
|
|
|
|
|
|
|
return self
|
|
|
|
|
2018-09-17 08:20:16 +02:00
|
|
|
def add_modifier(self, modifier):
|
2018-09-23 14:19:57 +02:00
|
|
|
if isinstance(modifier, ModifierKeycode):
|
HID: Support Consumer (media) keys
What a short title for such a massive diff.
This (heavily squashed) commit adds support for Consumer keys such as
volume keys, media play/pause/stop, etc. by exposing four HID devices
over a single USB lane (as opposed to just exposing a keyboard). This
heavily refactors how HIDHelper works due to the new reporting
structure.
Many of the media keys were changed (mostly Keycodes.Media section), but
many (especially anything regarding Application keys) haven't been
touched yet - thus many keycodes may still be wrong. Probably worth
updating those soon, but I didn't get around to it yet. The definitive
list I refered to was
http://www.freebsddiary.org/APC/usb_hid_usages.php, which is basically
copy-pasta from the official USB HID spec at
https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
(warning: massive PDF, not light reading).
The only known regression this introduces is that instead of 6KRO as the
USB spec usually supports, we can now only have 5KRO (maybe even 4KRO),
for reasons I have yet to fully debug - this seems to be related to the
report having to include the device descriptor _and_ not supporting a
full 8 bytes as it used to. For now I'm willing to accept this, but it
definitely will be great to squash that bug.
This adds descriptor support for MOUSE and SYSCONTROL devices, as of yet
unimplemented.
2018-09-30 00:46:17 +02:00
|
|
|
self.report_mods[0] |= modifier.code
|
2018-09-23 14:19:57 +02:00
|
|
|
else:
|
HID: Support Consumer (media) keys
What a short title for such a massive diff.
This (heavily squashed) commit adds support for Consumer keys such as
volume keys, media play/pause/stop, etc. by exposing four HID devices
over a single USB lane (as opposed to just exposing a keyboard). This
heavily refactors how HIDHelper works due to the new reporting
structure.
Many of the media keys were changed (mostly Keycodes.Media section), but
many (especially anything regarding Application keys) haven't been
touched yet - thus many keycodes may still be wrong. Probably worth
updating those soon, but I didn't get around to it yet. The definitive
list I refered to was
http://www.freebsddiary.org/APC/usb_hid_usages.php, which is basically
copy-pasta from the official USB HID spec at
https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
(warning: massive PDF, not light reading).
The only known regression this introduces is that instead of 6KRO as the
USB spec usually supports, we can now only have 5KRO (maybe even 4KRO),
for reasons I have yet to fully debug - this seems to be related to the
report having to include the device descriptor _and_ not supporting a
full 8 bytes as it used to. For now I'm willing to accept this, but it
definitely will be great to squash that bug.
This adds descriptor support for MOUSE and SYSCONTROL devices, as of yet
unimplemented.
2018-09-30 00:46:17 +02:00
|
|
|
self.report_mods[0] |= modifier
|
2018-09-17 08:20:16 +02:00
|
|
|
|
2018-09-23 14:19:57 +02:00
|
|
|
return self
|
2018-09-17 08:20:16 +02:00
|
|
|
|
|
|
|
def remove_modifier(self, modifier):
|
2018-09-23 14:19:57 +02:00
|
|
|
if isinstance(modifier, ModifierKeycode):
|
HID: Support Consumer (media) keys
What a short title for such a massive diff.
This (heavily squashed) commit adds support for Consumer keys such as
volume keys, media play/pause/stop, etc. by exposing four HID devices
over a single USB lane (as opposed to just exposing a keyboard). This
heavily refactors how HIDHelper works due to the new reporting
structure.
Many of the media keys were changed (mostly Keycodes.Media section), but
many (especially anything regarding Application keys) haven't been
touched yet - thus many keycodes may still be wrong. Probably worth
updating those soon, but I didn't get around to it yet. The definitive
list I refered to was
http://www.freebsddiary.org/APC/usb_hid_usages.php, which is basically
copy-pasta from the official USB HID spec at
https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
(warning: massive PDF, not light reading).
The only known regression this introduces is that instead of 6KRO as the
USB spec usually supports, we can now only have 5KRO (maybe even 4KRO),
for reasons I have yet to fully debug - this seems to be related to the
report having to include the device descriptor _and_ not supporting a
full 8 bytes as it used to. For now I'm willing to accept this, but it
definitely will be great to squash that bug.
This adds descriptor support for MOUSE and SYSCONTROL devices, as of yet
unimplemented.
2018-09-30 00:46:17 +02:00
|
|
|
self.report_mods[0] ^= modifier.code
|
2018-09-23 14:19:57 +02:00
|
|
|
else:
|
HID: Support Consumer (media) keys
What a short title for such a massive diff.
This (heavily squashed) commit adds support for Consumer keys such as
volume keys, media play/pause/stop, etc. by exposing four HID devices
over a single USB lane (as opposed to just exposing a keyboard). This
heavily refactors how HIDHelper works due to the new reporting
structure.
Many of the media keys were changed (mostly Keycodes.Media section), but
many (especially anything regarding Application keys) haven't been
touched yet - thus many keycodes may still be wrong. Probably worth
updating those soon, but I didn't get around to it yet. The definitive
list I refered to was
http://www.freebsddiary.org/APC/usb_hid_usages.php, which is basically
copy-pasta from the official USB HID spec at
https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
(warning: massive PDF, not light reading).
The only known regression this introduces is that instead of 6KRO as the
USB spec usually supports, we can now only have 5KRO (maybe even 4KRO),
for reasons I have yet to fully debug - this seems to be related to the
report having to include the device descriptor _and_ not supporting a
full 8 bytes as it used to. For now I'm willing to accept this, but it
definitely will be great to squash that bug.
This adds descriptor support for MOUSE and SYSCONTROL devices, as of yet
unimplemented.
2018-09-30 00:46:17 +02:00
|
|
|
self.report_mods[0] ^= modifier
|
2018-09-17 05:49:14 +02:00
|
|
|
|
2018-09-23 14:19:57 +02:00
|
|
|
return self
|
2018-09-17 05:49:14 +02:00
|
|
|
|
|
|
|
def add_key(self, key):
|
2018-09-17 08:30:52 +02:00
|
|
|
# Try to find the first empty slot in the key report, and fill it
|
|
|
|
placed = False
|
HID: Support Consumer (media) keys
What a short title for such a massive diff.
This (heavily squashed) commit adds support for Consumer keys such as
volume keys, media play/pause/stop, etc. by exposing four HID devices
over a single USB lane (as opposed to just exposing a keyboard). This
heavily refactors how HIDHelper works due to the new reporting
structure.
Many of the media keys were changed (mostly Keycodes.Media section), but
many (especially anything regarding Application keys) haven't been
touched yet - thus many keycodes may still be wrong. Probably worth
updating those soon, but I didn't get around to it yet. The definitive
list I refered to was
http://www.freebsddiary.org/APC/usb_hid_usages.php, which is basically
copy-pasta from the official USB HID spec at
https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
(warning: massive PDF, not light reading).
The only known regression this introduces is that instead of 6KRO as the
USB spec usually supports, we can now only have 5KRO (maybe even 4KRO),
for reasons I have yet to fully debug - this seems to be related to the
report having to include the device descriptor _and_ not supporting a
full 8 bytes as it used to. For now I'm willing to accept this, but it
definitely will be great to squash that bug.
This adds descriptor support for MOUSE and SYSCONTROL devices, as of yet
unimplemented.
2018-09-30 00:46:17 +02:00
|
|
|
|
|
|
|
where_to_place = self.report_non_mods
|
|
|
|
|
|
|
|
if self.report_device[0] == HIDReportTypes.CONSUMER:
|
|
|
|
where_to_place = self.report_keys
|
|
|
|
|
|
|
|
for idx, _ in enumerate(where_to_place):
|
|
|
|
if where_to_place[idx] == 0x00:
|
|
|
|
where_to_place[idx] = key.code
|
2018-09-17 08:30:52 +02:00
|
|
|
placed = True
|
|
|
|
break
|
2018-09-17 08:20:16 +02:00
|
|
|
|
2018-09-17 08:30:52 +02:00
|
|
|
if not placed:
|
|
|
|
self.logger.warning('Out of space in HID report, could not add key')
|
2018-09-17 08:20:16 +02:00
|
|
|
|
2018-09-17 08:30:52 +02:00
|
|
|
return self
|
2018-09-17 08:20:16 +02:00
|
|
|
|
|
|
|
def remove_key(self, key):
|
2018-09-17 08:30:52 +02:00
|
|
|
removed = False
|
HID: Support Consumer (media) keys
What a short title for such a massive diff.
This (heavily squashed) commit adds support for Consumer keys such as
volume keys, media play/pause/stop, etc. by exposing four HID devices
over a single USB lane (as opposed to just exposing a keyboard). This
heavily refactors how HIDHelper works due to the new reporting
structure.
Many of the media keys were changed (mostly Keycodes.Media section), but
many (especially anything regarding Application keys) haven't been
touched yet - thus many keycodes may still be wrong. Probably worth
updating those soon, but I didn't get around to it yet. The definitive
list I refered to was
http://www.freebsddiary.org/APC/usb_hid_usages.php, which is basically
copy-pasta from the official USB HID spec at
https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
(warning: massive PDF, not light reading).
The only known regression this introduces is that instead of 6KRO as the
USB spec usually supports, we can now only have 5KRO (maybe even 4KRO),
for reasons I have yet to fully debug - this seems to be related to the
report having to include the device descriptor _and_ not supporting a
full 8 bytes as it used to. For now I'm willing to accept this, but it
definitely will be great to squash that bug.
This adds descriptor support for MOUSE and SYSCONTROL devices, as of yet
unimplemented.
2018-09-30 00:46:17 +02:00
|
|
|
|
|
|
|
where_to_place = self.report_non_mods
|
|
|
|
|
|
|
|
if self.report_device[0] == HIDReportTypes.CONSUMER:
|
|
|
|
where_to_place = self.report_keys
|
|
|
|
|
|
|
|
for idx, _ in enumerate(where_to_place):
|
|
|
|
if where_to_place[idx] == key.code:
|
|
|
|
where_to_place[idx] = 0x00
|
2018-09-17 08:30:52 +02:00
|
|
|
removed = True
|
2018-09-17 05:49:14 +02:00
|
|
|
|
2018-09-17 08:30:52 +02:00
|
|
|
if not removed:
|
|
|
|
self.logger.warning('Tried to remove key that was not added')
|
2018-09-17 05:49:14 +02:00
|
|
|
|
2018-09-17 08:30:52 +02:00
|
|
|
return self
|