Skip to content

Instantly share code, notes, and snippets.

@mikevb3
Created November 4, 2022 01:45
Show Gist options
  • Save mikevb3/3fe0ff13ab25f803430e11213bf03c04 to your computer and use it in GitHub Desktop.
Save mikevb3/3fe0ff13ab25f803430e11213bf03c04 to your computer and use it in GitHub Desktop.
Parse an APEM joystick input on python
# Sample APEM joystick parsing with hidapi
import hid
def button_parse(raw_data):
"""
:param input_list: tuple of bitmaps
:return: button
"""
a = 1 if raw_data[4] & 2 == 2 else 0
b = 1 if raw_data[4] & 4 == 4 else 0
c = 1 if raw_data[4] & 8 == 8 else 0
d = 1 if raw_data[4] & 16 == 16 else 0
z = 1 if raw_data[4] & 1 == 1 else 0
return a, b, c, d, z
def cursor_parse(input_list):
# here you can get the raw bit, or a simpler bit
x_raw = input_list[0]
x = input_list[1]
y_raw = input_list[2]
y = input_list[3]
return x, y
device = hid.device()
device.open(vendor_id, product_id)
device.set_nonblocking(True)
# this is a bitmap, you need to check your device and look for the inputs
# in my joystick test case i have 5 buttons and one X, Y pad.
while True:
raw_data = device.read(64)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment