Nugget
|
An advanced class to access the pads. More...
#include <psyqo/advancedpad.hh>
Classes | |
struct | Event |
Public Types | |
enum class | Pad : unsigned { Pad1a , Pad1b , Pad1c , Pad1d , Pad2a , Pad2b , Pad2c , Pad2d } |
enum | Button { Select = 0 , L3 = 1 , R3 = 2 , Start = 3 , Up = 4 , Right = 5 , Down = 6 , Left = 7 , L2 = 8 , R2 = 9 , L1 = 10 , R1 = 11 , Triangle = 12 , Circle = 13 , Cross = 14 , Square = 15 } |
enum | PadType : uint8_t { Mouse = 0x12 , NegCon = 0x23 , KonamiLightgun = 0x31 , DigitalPad = 0x41 , AnalogStick = 0x53 , NamcoLightGun = 0x63 , AnalogPad = 0x73 , Multitap = 0x80 , JogCon = 0xe3 , FishingCon = 0xe5 , ConfigMode = 0xf3 , None = 0xff } |
enum class | PollingMode { Normal , Fast } |
Initializes the pads. More... | |
Public Member Functions | |
void | initialize (PollingMode mode=PollingMode::Normal) |
void | setOnEvent (eastl::function< void(Event)> &&callback) |
Sets the event callback function. | |
bool | isPadConnected (Pad pad) const |
Returns the state of a pad. | |
bool | isButtonPressed (Pad pad, Button button) const |
Returns the state of a button. | |
uint8_t | getAdc (Pad pad, unsigned int index) const |
Returns the state of an Analog Input. | |
uint16_t | getHalfword (Pad pad, unsigned int index) const |
Returns raw pad data as an unsigned 16-bit value. | |
uint8_t | getPadType (Pad pad) const |
Returns the type of the pad. | |
An advanced class to access the pads.
This class is meant to be used as a singleton, probably in the Application
derived class. It does not use the BIOS' PAD interface. Instead, it uses the SIO interface directly, and can therefore support more device types including multitaps.
|
strong |
enum psyqo::AdvancedPad::PadType : uint8_t |
|
strong |
Initializes the pads.
This method should be called once at the beginning of the program, preferably from the Application::prepare
method. The mode
parameter can be used to indicate whether the ports should be polled one at a time, or both at once. The default is PollingMode::Normal
, which will poll one port per frame. The PollingMode::Fast
mode will poll all ports at once each frame, which can reduce input lag, but will also increase the CPU usage.
mode | The polling mode to use. |
Enumerator | |
---|---|
Normal | |
Fast |
Returns the state of an Analog Input.
See the specific Analog Input functions for details. Indices greater than 3 will return 0. index 0: For analog pads: RightJoyX (00h=Left, 80h=Center, FFh=Right), mouse: X-axis index 1: For analog pads: RightJoyY (00h=Up, 80h=Center, FFh=Down), mouse: Y-axis index 2: For analog pads: LeftJoyX (00h=Left, 80h=Center, FFh=Right) index 3: For analog pads: LeftJoyY (00h=Up, 80h=Center, FFh=Down)
pad | The pad to query. |
index | The index of the Analog Input(adc#). |
Returns raw pad data as an unsigned 16-bit value.
A low level call which returns the halfword value for the requested index of the given pad index. It is recommended to use the higher level functions instead. index 0: pad type << 8 | connected(0 = connected, ffh = disconnected) index 1: button state index 2: analog input 1 << 8 | analog input 0 index 3: analog input 3 << 8 | analog input 2 The index is modulo 4, so it will wrap around if it is greater than 3.
pad | The pad to query. |
index | The index of the halfword. |
|
inline |
Returns the type of the pad.
Known pad types are defined in the PadType enum, returns 0xff if no pad is connected. PadType::Multitap is for internal use only, and should not be returned. Pad connection status should be checked with isPadConnected.
pad | The pad to query. |
void psyqo::AdvancedPad::initialize | ( | PollingMode | mode = PollingMode::Normal | ) |
Returns the state of a button.
Returns the state of a button. The state is a boolean value that is true
if the button is pressed, and false
otherwise.
pad | The pad to query. |
button | The button to query. |
|
inline |
Returns the state of a pad.
Returns the state of a pad. The state is a boolean value that is true
if the pad is connected, and false
otherwise.
pad | The pad to query. |
Sets the event callback function.
The event callback will be called for each pad-related event, such as pad connection / disconnection, or button press / release. The callback will only be called between frames.
Scenes that are calling setOnEvent
during their start
method should call setOnEvent
again in their teardown
method with the nullptr
value in order to unregister the event callback cleanly.
Only one callback can be registered at a time, so setting a new callback will simply remove the previous one.
Careful about what is called from the callback: pushing or popping scenes might call into setOnEvent
as a result, and could end up corrupting memory as a result of the callback being deleted while being executed.