Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions facedancer/classes/hid/descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,26 @@

def _hid_item_generator(constant) -> Tuple[int]:
""" Generates a HID descriptor global item entry. """

# See See HID1.1 [6.2.2.1 Items Types and Tags]
size_code_map = {
0: 0b00, # No data
1: 0b01, # 1 byte
2: 0b10, # 2 bytes
4: 0b11, # 4 bytes
}
# Generate a function that creates a item with
# the relevant type...
def hid_item(*octets):
return (constant | len(octets), *octets)
size = len(octets)
if size not in size_code_map:
raise ValueError(
f"HID short item can only have 0, 1, 2 or 4 data bytes, got {size}"
)

size_code = size_code_map[size]
prefix = constant | size_code

return (prefix, *octets)

# ... and return it.
return hid_item
Expand Down