-
-
Notifications
You must be signed in to change notification settings - Fork 417
Gamepad API
NicoHood edited this page Jun 9, 2022
·
3 revisions
The Gamepad API supports 32 digital buttons, 4 16-bit axes (X, Y, RX, RY), 2 8-bit axes (Z, RZ) and 2 D-Pads/Hat switches.
As usual, there are both single- and multi-report versions of the API.
The single-report version supports up to 4 Gamepads, named Gamepad1, Gamepad2, Gamepad3 and Gamepad4. It will use 1 endpoint for each gamepad.
The multi-report version only suppors a single Gamepad, unsurprisingly named Gamepad.
All objects have the same API, which is straightforward:
-
void begin(void): Initialize the gamepad. It is very important to call this function first on any Arduino type as it will send an initial clean report to the host. -
void end(void): Terminate the gamepad instance. After this function is called, the gamepad can no longer be controlled. -
void write(void): Send the actual report to the host. This function must be called to make any change effective.
-
void press(uint8_t b): Press thebth button [1 .. 32] -
void release(uint8_t b): Release thebth button [1 .. 32] -
void releaseAll(void): Release all buttons -
void buttons(uint32_t b): Set the state of all buttons at once
-
void xAxis(int16_t a): Set the value of the X axis [-32768 .. +32767] -
void yAxis(int16_t a): Set the value of the Y axis [-32768 .. +32767] -
void zAxis(int8_t a): Set the value of the Z axis [-128 .. +127] -
void rxAxis(int16_t a): Set the value of the RX axis [-32768 .. +32767] -
void ryAxis(int16_t a): Set the value of the RY axis [-32768 .. +32767] -
void rzAxis(int8_t a): Set the value of the RZ axis [-128 .. + 127]
-
void dPad1(int8_t d): Set the direction of the first D-Pad.dshould be one of the following constants:GAMEPAD_DPAD_CENTEREDGAMEPAD_DPAD_UPGAMEPAD_DPAD_UP_RIGHTGAMEPAD_DPAD_RIGHTGAMEPAD_DPAD_DOWN_RIGHTGAMEPAD_DPAD_DOWNGAMEPAD_DPAD_DOWN_LEFTGAMEPAD_DPAD_LEFTGAMEPAD_DPAD_UP_LEFT
-
void dPad2(int8_t d): Set the direction of the second D-Pad, see above.
Please refer to the Gamepad example to see the API in action.
Copyright (c) 2014-2015 NicoHood