self.fields = [] for r in self.parsed_rdesc.input_reports.values(): if r.application_name == self.application:
self.fields.extend([f.usage_name for f in r])
def store_axes(self, which, gamepad, data):
amap = self.axes_map[which]
x, y = data
setattr(gamepad, amap["x"].hid, x)
setattr(gamepad, amap["y"].hid, y)
def create_report(
self,
*,
left=(None, None),
right=(None, None),
hat_switch=None,
buttons=None,
reportID=None,
application="Game Pad",
): """ Return an input report for this device.
:param left: a tuple of absolute (x, y) value of the left joypad
where ``None`` is"leave unchanged"
:param right: a tuple of absolute (x, y) value of the right joypad
where ``None`` is"leave unchanged"
:param hat_switch: an absolute angular value of the hat switch
(expressed in 1/8 of circle, 0 being North, 2 East)
where ``None`` is"leave unchanged"
:param buttons: a dict of index/bool for the button states,
where ``None`` is"leave unchanged"
:param reportID: the numeric report ID for this report, if needed
:param application: the application used to report the values """ if buttons isnotNone: for i, b in buttons.items(): if i notin self.buttons: raise InvalidHIDCommunication(
f"button {i} is not part of this {self.application}"
) if b isnotNone:
self._buttons[i] = b
def replace_none_in_tuple(item, default): if item isNone:
item = (None, None)
ifNonein item: if item[0] isNone:
item = (default[0], item[1]) if item[1] isNone:
item = (item[0], default[1])
return item
right = replace_none_in_tuple(right, self.right)
self.right = right
left = replace_none_in_tuple(left, self.left)
self.left = left
if hat_switch isNone:
hat_switch = self.hat_switch else:
self.hat_switch = hat_switch
reportID = reportID or self.default_reportID
gamepad = GamepadData() for i, b in self._buttons.items():
gamepad.__setattr__(f"b{i}", int(b) if b isnotNoneelse 0)
def event(
self, *, left=(None, None), right=(None, None), hat_switch=None, buttons=None
): """
Send an input event on the default report ID.
:param left: a tuple of absolute (x, y) value of the left joypad
where ``None`` is"leave unchanged"
:param right: a tuple of absolute (x, y) value of the right joypad
where ``None`` is"leave unchanged"
:param hat_switch: an absolute angular value of the hat switch
where ``None`` is"leave unchanged"
:param buttons: a dict of index/bool for the button states,
where ``None`` is"leave unchanged" """
r = self.create_report(
left=left, right=right, hat_switch=hat_switch, buttons=buttons
)
self.call_input_event(r) return [r]
def create_report(
self,
*,
left=(None, None),
right=(None, None),
hat_switch=None,
buttons=None,
reportID=None,
application=None,
): """ Return an input report for this device.
:param left: a tuple of absolute (x, y) value of the left joypad
where ``None`` is"leave unchanged"
:param right: a tuple of absolute (x, y) value of the right joypad
where ``None`` is"leave unchanged"
:param hat_switch: an absolute angular value of the hat switch
where ``None`` is"leave unchanged"
:param buttons: a dict of index/bool for the button states,
where ``None`` is"leave unchanged"
:param reportID: the numeric report ID for this report, if needed
:param application: the application for this report, if needed """ if application isNone:
application = "Joystick" return super().create_report(
left=left,
right=right,
hat_switch=hat_switch,
buttons=buttons,
reportID=reportID,
application=application,
)
def store_right_joystick(self, gamepad, data):
gamepad.rudder, gamepad.throttle = data
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.