bledev.hid_gamepad
A gamepad for a bledev.hid.Peripheral, in the shape of Adafruit’s
hid_gamepad.py example (adafruit_hid dropped its own gamepad in 5.0):
import bledev.hid as hid
from bledev.hid_gamepad import Gamepad
per = hid.Peripheral(ble, gamepad=True)
await per.serve()
gp = Gamepad(per.devices)
gp.press_buttons(1, 3)
gp.move_joysticks(x=-127, y=0)
gp.set_hat(2) # east; None is centred
gp.release_all_buttons()
Sixteen buttons numbered 1 to 16, one hat (0 to 7 clockwise from north, or None) and four axes, X, Y, Z and Rz, from -127 to 127. Each call sends the whole report at once, as Adafruit’s example does.
- class bledev.hid_gamepad.Gamepad(devices)[source]
Bases:
objectEmulate a gamepad with sixteen buttons, a hat and four joystick axes.
- move_joysticks(x=None, y=None, z=None, r_z=None)[source]
Set any of the four axes;
Noneleaves an axis where it is.
- set(buttons=None, hat=<object object>, x=None, y=None, z=None, r_z=None)[source]
Change any part of the state in one report:
buttonsas a bit mask (bit 0 is button 1),hatas forset_hat, the axes as formove_joysticks. Anything left out stays as it is.