PADStatus

Syntax

#include <cafe/pad.h>

typedef struct PADStatus
{
    u16 button;                 // Or-ed PAD_BUTTON_* and PAD_TRIGGER_* bits
    s8  stickX;                 // -128 <= stickX       <= 127
    s8  stickY;                 // -128 <= stickY       <= 127
    s8  substickX;              // -128 <= substickX    <= 127
    s8  substickY;              // -128 <= substickY    <= 127
    u8  triggerLeft;            //    0 <= triggerLeft  <= 255
    u8  triggerRight;           //    0 <= triggerRight <= 255
    u8  analogA;                //    0 <= analogA      <= 255
    u8  analogB;                //    0 <= analogB      <= 255
    s8  err;                    // one of PAD_ERR_* number
} PADStatus;

#define PAD_MAX_CONTROLLERS     4

#define PAD_BUTTON_LEFT         0x0001
#define PAD_BUTTON_RIGHT        0x0002
#define PAD_BUTTON_DOWN         0x0004
#define PAD_BUTTON_UP           0x0008
#define PAD_TRIGGER_Z           0x0010
#define PAD_BUTTON_Z            PAD_TRIGGER_Z
#define PAD_TRIGGER_R           0x0020
#define PAD_BUTTON_R            PAD_TRIGGER_R
#define PAD_TRIGGER_L           0x0040
#define PAD_BUTTON_L            PAD_TRIGGER_L
#define PAD_BUTTON_A            0x0100
#define PAD_BUTTON_B            0x0200
#define PAD_BUTTON_X            0x0400
#define PAD_BUTTON_Y            0x0800
#define PAD_BUTTON_START        0x1000

#define PAD_ERR_NONE            0
#define PAD_ERR_NO_CONTROLLER   -1
#define PAD_ERR_NOT_READY       -2
#define PAD_ERR_TRANSFER        -3

Elements

button If any button is depressed, the corresponding bit (PAD_BUTTON_* or PAD_TRIGGER_*) is set to 1.
stickX Movement data given in terms of the x-axis of the Control Stick.
stickY Movement data given in terms of the y-axis of the Control Stick.
substickX Movement data given in terms of the x-axis of the C-Stick (sub analog stick).
substickY Movement data given in terms of the y-axis of the C-Stick.
triggerLeft Movement data of the L Button.
triggerRight Movement data of the R Button.
analogA Analog input of the A Button. See note below.
analogB Analog input of the B Button. See note below.
err Controller error code, one of the PAD_ERR_* values in the table below.

Error Codes

PAD_ERR_NONE A Controller is connected to the controller port. The pad status contains valid data.
PAD_ERR_NO_CONTROLLER A Controller is not connected to the controller port. The pad status does not contain valid data (i.e., structure members other than err are all zeroed out.
PAD_ERR_NOT_READY The controller port is still being initialized from previous calls to PADInit. The controller status does not contain valid data (i.e., the structure members other than err are all zeroed out).
NOTE:
The PAD_ERR_NOT_READY state does not continue more than a few video frames except due to programming error.
PAD_ERR_TRANSFER Due to external electrical noise, the prior sampling of Controller data failed.   No valid data is available for the current PADRead (i.e., the structure members other than err are all zeroed out).
NOTE:
It may be suitable to continue using the previous valid controller status if PAD_ERR_TRANSFER is returned (rather than presuming the player might have released controller buttons during PAD_ERR_TRANSFER). The Controller normally recovers from the PAD_ERR_TRANSFER error state within a few frames. Unless the PAD_ERR_NO_CONTROLLER error is returned, the game program should not assume that the Controller has been unplugged.

Description

The PADStatus data structure represents the status of a controller. The table above describes the information that is obtained.

NOTE:
  • The Controller does not support analog input values (analogA/analogB) for the A Button and B Button.
  • PAD_TRIGGER_Z, PAD_TRIGGER_R, PAD_TRIGGER_L will soon be deprecated. Replace with PAD_BUTTON_Z, PAD_BUTTON_R, PAD_BUTTON_L.

See Also

PADInit
PADRead

Revision History

2013-05-08 Automated cleanup pass.
2011-12-19 Added PAD_TRIGGER_Z, PAD_TRIGGER_R, PAD_TRIGGER_L definitions.
2011-02-03 Initial version.


CONFIDENTIAL