Skip to content

Commit

Permalink
device: get min/max axis value from the report descriptor
Browse files Browse the repository at this point in the history
Signed-off-by: Filipe Laíns <[email protected]>
  • Loading branch information
FFY00 committed Mar 18, 2020
1 parent 3d304b1 commit ba96790
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions ratbag_emu/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,18 @@ def send_hid_action(self, endpoint_number: int, action: object) -> None:
endpoint = self.endpoints[endpoint_number]
endpoint.send(endpoint.create_report(action))

def _simulate_action_xy(self, action: Dict[str, Any], packets: List[EventData], report_count: int) -> None:
# FIXME: Read max size from the report descriptor
axis_max = 127
axis_min = -127
def _simulate_action_xy(self, action: Dict[str, Any], endpoint_number: int, packets: List[EventData],
report_count: int) -> None:
endpoint = self.endpoints[endpoint_number]
min = max = {}
for features in endpoint.parsed_rdesc.input_reports.values():
for feature in features:
if feature.usage_name in ['X', 'Y']:
axis = feature.usage_name.lower()
min[axis] = feature.logical_min
max[axis] = feature.logical_max

assert 'x' in min and 'x' in max and 'y' in min and 'y' in max, 'Endpoint does not support XY movement'

# We assume a linear motion
dot_buffer = {}
Expand All @@ -150,6 +158,7 @@ def _simulate_action_xy(self, action: Dict[str, Any], packets: List[EventData],
dot_buffer = self.transform_action(action['data'])

for attr in ['x', 'y']:
axis_max = max[attr]
assert dot_buffer[attr] <= axis_max * report_count
step[attr] = dot_buffer[attr] / report_count

Expand All @@ -160,6 +169,8 @@ def _simulate_action_xy(self, action: Dict[str, Any], packets: List[EventData],
break

for attr in ['x', 'y']:
axis_min = min[attr]
axis_max = max[attr]
dot_buffer[attr] -= step[attr]
diff = int(round(real_dot_buffer[attr] - dot_buffer[attr]))
'''
Expand Down Expand Up @@ -200,7 +211,7 @@ def simulate_action(self, action: Dict[str, Any], type: int = None) -> None:
packets.append(EventData())

if action['type'] == ActionType.XY:
self._simulate_action_xy(action, packets, report_count)
self._simulate_action_xy(action, endpoint, packets, report_count)
elif action['type'] == ActionType.BUTTON:
self._simulate_action_xy(action, packets, report_count)

Expand Down

0 comments on commit ba96790

Please sign in to comment.