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: object

Emulate a gamepad with sixteen buttons, a hat and four joystick axes.

press_buttons(*buttons)[source]

Press and hold the given buttons (1 to 16).

release_buttons(*buttons)[source]

Release the given buttons.

release_all_buttons()[source]

Release every button.

click_buttons(*buttons)[source]

Press and release the given buttons.

move_joysticks(x=None, y=None, z=None, r_z=None)[source]

Set any of the four axes; None leaves an axis where it is.

set_hat(direction)[source]

Point the hat: 0 north to 7 north-west, clockwise, or None for centred.

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: buttons as a bit mask (bit 0 is button 1), hat as for set_hat, the axes as for move_joysticks. Anything left out stays as it is.

reset_all()[source]

Release every button, centre the hat and every axis.