libnx  v4.2.2
Data Structures | Macros | Functions
pad.h File Reference

Simple wrapper for the HID Npad API. More...

#include "../types.h"
#include "../services/hid.h"

Go to the source code of this file.

Data Structures

struct  PadState
 Pad state object. More...
 
struct  PadRepeater
 Pad button repeater state object. More...
 

Macros

#define PAD_ANY_ID_MASK   0x1000100FFUL
 Mask including all existing controller IDs.
 
#define padInitialize(_pad, ...)
 Initializes a PadState object to read input from one or more controller input sources. More...
 

Functions

void padConfigureInput (u32 max_players, u32 style_set)
 Configures the input layout supported by the application. More...
 
void padInitializeWithMask (PadState *pad, u64 mask)
 Same as padInitialize, but taking a bitfield of controller IDs directly. More...
 
static void padInitializeAny (PadState *pad)
 Same as padInitialize, but including every single controller input source. More...
 
static void padInitializeDefault (PadState *pad)
 Same as padInitialize, but including HidNpadIdType_No1 and HidNpadIdType_Handheld. More...
 
void padUpdate (PadState *pad)
 Updates pad state by reading from the controller input sources specified during initialization. More...
 
static bool padIsHandheld (const PadState *pad)
 Retrieves whether HidNpadIdType_Handheld is an active input source (i.e. More...
 
static bool padIsNpadActive (const PadState *pad, HidNpadIdType id)
 Retrieves whether the specified controller is an active input source (i.e. More...
 
static u32 padGetStyleSet (const PadState *pad)
 Retrieves the set of input styles supported by the selected controller input sources. More...
 
static u32 padGetAttributes (const PadState *pad)
 Retrieves the set of attributes reported by the system for the selected controller input sources. More...
 
static bool padIsConnected (const PadState *pad)
 Retrieves whether any of the selected controller input sources is connected. More...
 
static u64 padGetButtons (const PadState *pad)
 Retrieves the current set of pressed buttons across all selected controller input sources. More...
 
static u64 padGetButtonsDown (const PadState *pad)
 Retrieves the set of buttons that are newly pressed. More...
 
static u64 padGetButtonsUp (const PadState *pad)
 Retrieves the set of buttons that are newly released. More...
 
static HidAnalogStickState padGetStickPos (const PadState *pad, unsigned i)
 Retrieves the position of an analog stick in a controller. More...
 
static u32 padGetGcTriggerPos (const PadState *pad, unsigned i)
 Retrieves the position of an analog trigger in a GameCube controller. More...
 
static void padRepeaterInitialize (PadRepeater *r, u16 delay, u16 repeat)
 Initializes a PadRepeater object with the specified settings. More...
 
void padRepeaterUpdate (PadRepeater *r, u64 button_mask)
 Updates pad repeat state. More...
 
static u64 padRepeaterGetButtons (const PadRepeater *r)
 Retrieves the set of buttons that are being repeated according to the parameters specified in padRepeaterInitialize. More...
 

Detailed Description

Simple wrapper for the HID Npad API.

Author
fincs

Macro Definition Documentation

◆ padInitialize

#define padInitialize (   _pad,
  ... 
)
Value:
({ \
const HidNpadIdType _pad_ids[] = { __VA_ARGS__ }; \
u64 _pad_mask = 0; \
for (unsigned _pad_i = 0; _pad_i < (sizeof(_pad_ids)/sizeof(_pad_ids[0])); ++_pad_i) \
_pad_mask |= 1UL << (_pad_ids[_pad_i]); \
padInitializeWithMask((_pad), _pad_mask); \
})

Initializes a PadState object to read input from one or more controller input sources.

Parameters
[in]_padPointer to PadState.
Remarks
This is a variadic macro, pass the HidNpadIdType value of each controller to add to the set.

Function Documentation

◆ padConfigureInput()

void padConfigureInput ( u32  max_players,
u32  style_set 
)

Configures the input layout supported by the application.

Parameters
[in]max_playersThe maximum supported number of players (1 to 8).
[in]style_setBitfield of supported controller styles (see HidNpadStyleTag).

◆ padGetAttributes()

static u32 padGetAttributes ( const PadState pad)
inlinestatic

Retrieves the set of attributes reported by the system for the selected controller input sources.

Parameters
[in]padPointer to PadState.
Returns
Bitfield of HidNpadAttribute.
Remarks
padUpdate must have been previously called.

◆ padGetButtons()

static u64 padGetButtons ( const PadState pad)
inlinestatic

Retrieves the current set of pressed buttons across all selected controller input sources.

Parameters
[in]padPointer to PadState.
Returns
Bitfield of HidNpadButton.
Remarks
padUpdate must have been previously called.

◆ padGetButtonsDown()

static u64 padGetButtonsDown ( const PadState pad)
inlinestatic

Retrieves the set of buttons that are newly pressed.

Parameters
[in]padPointer to PadState.
Returns
Bitfield of HidNpadButton.
Remarks
padUpdate must have been previously called.

◆ padGetButtonsUp()

static u64 padGetButtonsUp ( const PadState pad)
inlinestatic

Retrieves the set of buttons that are newly released.

Parameters
[in]padPointer to PadState.
Returns
Bitfield of HidNpadButton.
Remarks
padUpdate must have been previously called.

◆ padGetGcTriggerPos()

static u32 padGetGcTriggerPos ( const PadState pad,
unsigned  i 
)
inlinestatic

Retrieves the position of an analog trigger in a GameCube controller.

Parameters
[in]padPointer to PadState.
[in]iID of the analog trigger to read (0=left, 1=right).
Returns
Analog trigger position (range is 0 to 0x7fff).
Remarks
padUpdate must have been previously called.
HidNpadStyleTag_NpadGc must have been previously configured as a supported style in padConfigureInput for GC trigger data to be readable.

◆ padGetStickPos()

static HidAnalogStickState padGetStickPos ( const PadState pad,
unsigned  i 
)
inlinestatic

Retrieves the position of an analog stick in a controller.

Parameters
[in]padPointer to PadState.
[in]iID of the analog stick to read (0=left, 1=right).
Returns
HidAnalogStickState.
Remarks
padUpdate must have been previously called.

◆ padGetStyleSet()

static u32 padGetStyleSet ( const PadState pad)
inlinestatic

Retrieves the set of input styles supported by the selected controller input sources.

Parameters
[in]padPointer to PadState.
Returns
Bitfield of HidNpadStyleTag.
Remarks
padUpdate must have been previously called.

◆ padInitializeAny()

static void padInitializeAny ( PadState pad)
inlinestatic

Same as padInitialize, but including every single controller input source.

Parameters
[in]padPointer to PadState.
Remarks
Use this function if you want to accept input from any controller.

◆ padInitializeDefault()

static void padInitializeDefault ( PadState pad)
inlinestatic

Same as padInitialize, but including HidNpadIdType_No1 and HidNpadIdType_Handheld.

Parameters
[in]padPointer to PadState.
Remarks
Use this function if you just want to accept input for a single-player application.

◆ padInitializeWithMask()

void padInitializeWithMask ( PadState pad,
u64  mask 
)

Same as padInitialize, but taking a bitfield of controller IDs directly.

Parameters
[in]padPointer to PadState.
[in]maskBitfield of controller IDs (each bit's position indicates a different HidNpadIdType value).

◆ padIsConnected()

static bool padIsConnected ( const PadState pad)
inlinestatic

Retrieves whether any of the selected controller input sources is connected.

Parameters
[in]padPointer to PadState.
Returns
Boolean value.
Remarks
padUpdate must have been previously called.

◆ padIsHandheld()

static bool padIsHandheld ( const PadState pad)
inlinestatic

Retrieves whether HidNpadIdType_Handheld is an active input source (i.e.

it was possible to read from it).

Parameters
[in]padPointer to PadState.
Returns
Boolean value.
Remarks
padUpdate must have been previously called.

◆ padIsNpadActive()

static bool padIsNpadActive ( const PadState pad,
HidNpadIdType  id 
)
inlinestatic

Retrieves whether the specified controller is an active input source (i.e.

it was possible to read from it).

Parameters
[in]padPointer to PadState.
[in]idID of the controller input source (see HidNpadIdType)
Returns
Boolean value.
Remarks
padUpdate must have been previously called.

◆ padRepeaterGetButtons()

static u64 padRepeaterGetButtons ( const PadRepeater r)
inlinestatic

Retrieves the set of buttons that are being repeated according to the parameters specified in padRepeaterInitialize.

Parameters
[in]rPointer to PadRepeater.
Returns
Bitfield of HidNpadButton.
Remarks
It is suggested to bitwise-OR the return value of this function with that of padGetButtonsDown.

◆ padRepeaterInitialize()

static void padRepeaterInitialize ( PadRepeater r,
u16  delay,
u16  repeat 
)
inlinestatic

Initializes a PadRepeater object with the specified settings.

Parameters
[in]rPointer to PadRepeater.
[in]delayNumber of input updates between button presses being first detected and them being considered for repeat.
[in]repeatNumber of input updates between autogenerated repeat button presses.

◆ padRepeaterUpdate()

void padRepeaterUpdate ( PadRepeater r,
u64  button_mask 
)

Updates pad repeat state.

Parameters
[in]rPointer to PadRepeater.
[in]button_maskBitfield of currently pressed HidNpadButton that will be considered for repeat.

◆ padUpdate()

void padUpdate ( PadState pad)

Updates pad state by reading from the controller input sources specified during initialization.

Parameters
[in]padPointer to PadState.
HidNpadIdType
HidNpadIdType
HID controller IDs.
Definition: hid.h:214