Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# SPDX-License-Identifier: MIT
''' Represents a real device
:param name: Device name :param info: Bus information (bus, vid, pid) :param rdescs: Array of report descriptors '''
info: Tuple[int, int, int] = (0x03, 0x0001, 0x0001), rdescs: List[List[int]] = [[ # Generic mouse report descriptor 0x05, 0x01, # .Usage Page (Generic Desktop) 0 0x09, 0x02, # .Usage (Mouse) 2 0xa1, 0x01, # .Collection (Application) 4 0x09, 0x02, # ..Usage (Mouse) 6 0xa1, 0x02, # ..Collection (Logical) 8 0x09, 0x01, # ...Usage (Pointer) 10 0xa1, 0x00, # ...Collection (Physical) 12 0x05, 0x09, # ....Usage Page (Button) 14 0x19, 0x01, # ....Usage Minimum (1) 16 0x29, 0x03, # ....Usage Maximum (3) 18 0x15, 0x00, # ....Logical Minimum (0) 20 0x25, 0x01, # ....Logical Maximum (1) 22 0x75, 0x01, # ....Report Size (1) 24 0x95, 0x03, # ....Report Count (3) 26 0x81, 0x02, # ....Input (Data,Var,Abs) 28 0x75, 0x05, # ....Report Size (5) 30 0x95, 0x01, # ....Report Count (1) 32 0x81, 0x03, # ....Input (Cnst,Var,Abs) 34 0x05, 0x01, # ....Usage Page (Generic Desktop) 36 0x09, 0x30, # ....Usage (X) 38 0x09, 0x31, # ....Usage (Y) 40 0x15, 0x81, # ....Logical Minimum (-127) 42 0x25, 0x7f, # ....Logical Maximum (127) 44 0x75, 0x08, # ....Report Size (8) 46 0x95, 0x02, # ....Report Count (2) 48 0x81, 0x06, # ....Input (Data,Var,Rel) 50 0xc0, # ...End Collection 52 0xc0, # ..End Collection 53 0xc0, # .End Collection 54 ]]):
# Find a unique ID for this device assert id != self.id except AssertionError: pass
''' Generates a random name ''' 'mara', 'capybara', 'porcupine', 'paca', 'vole', 'woodrat', 'gerbil', 'shrew', 'hutia', 'beaver', 'squirrel', 'chinchilla', 'rabbit', 'viscacha', 'hare', 'degu', 'gundi', 'acouchy', 'nutria', 'paca', 'hamster', 'zokor', 'chipmunk', 'gopher', 'marmot', 'groundhog', 'suslik', 'agouti', 'blesmol', ]
'sobbing', 'whooping', 'barking', 'yapping', 'howling', 'squawking', 'cheering', 'warbling', 'thundering', 'booming', 'blustering', 'humming', 'crying', 'bawling', 'roaring', 'raging', 'chanting', 'crooning', 'murmuring', 'bellowing', 'wailing', 'weeping', 'screaming', 'yelling', 'yodeling', 'singing', 'honking', 'hooting', 'whispering', 'hollering', ]
return self._rdescs
# Make sure we don't have actuators which will act on the same keys
''' Transforms high-level action according to the actuators
A high-level action will have the x, y values in mm. This values will be converted to pixel by the device actuators (in this case, the sensor/dpi actuator)
:param action: high-level action '''
''' Sends a HID action
We assume there's only one endpoint for each type of action (mouse, keyboard, button, etc.) so we send the action to all endpoints. The endpoint will only act on the action if it supports it.
:param action: HID action ''' # FIXME: global data (0x11)?
''' Simulates action
Translates physical values according to the device properties and converts action into HID reports.
:param action: high-level action :param type: HID report type '''
report_count = 1
# XY movement # We assume a linear motion
''' Initialize pixel_buffer, real_pixel_buffer and step for X and Y
pixel_buffer holds the ammount of pixels left to send (kinda, read below).
We actually have two variables for this, real_pixel_buffer and pixel_buffer. pixel_buffer mimics the user movement and real_pixel_buffer holds true number of pixels left to send. When using high report rates (ex. 1000Hz) we usually don't have a full pixel to send, that's why we need two variables. We subtract the step to pixel_buffer at each iteration, when the difference between pixel_buffer and real_pixel_buffer is equal or higher than 1 pixel we then send a HID report to the device with that difference (int! we send the int part of the difference) and update real_pixel_buffer to include this changes. '''
pixel_buffer[attr])) # FIXME: Read max size from the report descriptor ''' The max is 127, if this happens we need to leave the excess in the buffer for it to be sent in the next report ''' diff = 127 if diff > 0 else -127
# Button elif action['type'] == 'button': for i in range(report_count): if i not in packets: packets[i] = EventData()
setattr(packets[i], 'b{}'.format(action['data']['id']), 1)
nonlocal packets kwargs={'action': packets[i]})
|