Modifying Gamepad State
In any function looking to modify the gamepad state, use a pointer to the gamepad. This is absolutely necessary for changing any aspect of gamepad state.
Gamepad *gamepad = Storage::getInstance().GetGamepad();
You can find the appropriate gamepad macros and button masks in headers/gamepad/GamepadState.h
Directional Pad
To modify the gamepad's directional pad (DPad) state, use a bitwise OR assignment and the appropriate GAMEPAD_MASK
enum to set the input as active.
Gamepad *gamepad = Storage::getInstance().GetGamepad();
gamepad->state.dpad |= GAMEPAD_MASK_UP;
gamepad->state.dpad |= GAMEPAD_MASK_DOWN;
gamepad->state.dpad |= GAMEPAD_MASK_LEFT;
gamepad->state.dpad |= GAMEPAD_MASK_RIGHT;
All add-ons need to handle opposing simultaneous cardinal directions within the add-on since they come after standard GPIO inputs has already been SOCD cleaned.
Consider using runSOCDCleaner(SOCDMode mode, uint8_t dpad)
in src/gamepad/GamepadState.cpp
to take incoming DPad inputs and then resolve them at once in the add-on's process()
function.
Buttons
To modify the gamepad's button states, use a bitwise OR assignment and the appropriate GAMEPAD_MASK
enum to set the input as active.
Gamepad *gamepad = Storage::getInstance().GetGamepad();
gamepad->state.buttons |= GAMEPAD_MASK_B1;
gamepad->state.buttons |= GAMEPAD_MASK_B2;
gamepad->state.buttons |= GAMEPAD_MASK_B3;
gamepad->state.buttons |= GAMEPAD_MASK_B4;
gamepad->state.buttons |= GAMEPAD_MASK_L1;
gamepad->state.buttons |= GAMEPAD_MASK_R1;
gamepad->state.buttons |= GAMEPAD_MASK_L2;
gamepad->state.buttons |= GAMEPAD_MASK_R2;
gamepad->state.buttons |= GAMEPAD_MASK_S1;
gamepad->state.buttons |= GAMEPAD_MASK_S2;
gamepad->state.buttons |= GAMEPAD_MASK_L3;
gamepad->state.buttons |= GAMEPAD_MASK_R3;
gamepad->state.buttons |= GAMEPAD_MASK_A1;
gamepad->state.buttons |= GAMEPAD_MASK_A2;
gamepad->state.buttons |= AUX_MASK_FUNCTION;
Joystick
To modify the gamepad's analog joystick state, each joystick's X- and Y-axes must be set to an unsigned integer between 0 and 65535.
GAMEPAD_JOYSTICK_MIN = 0
GAMEPAD_JOYSTICK_MID = 0x7FFF
GAMEPAD_JOYSTICK_MAX = 0xFFFF