Nugget
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
psyqo::AdvancedPad Class Reference

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.
 

Detailed Description

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.

Member Enumeration Documentation

◆ Button

Enumerator
Select 
L3 
R3 
Start 
Up 
Right 
Down 
Left 
L2 
R2 
L1 
R1 
Triangle 
Circle 
Cross 
Square 

◆ Pad

enum class psyqo::AdvancedPad::Pad : unsigned
strong
Enumerator
Pad1a 
Pad1b 
Pad1c 
Pad1d 
Pad2a 
Pad2b 
Pad2c 
Pad2d 

◆ PadType

Enumerator
Mouse 
NegCon 
KonamiLightgun 
DigitalPad 
AnalogStick 
NamcoLightGun 
AnalogPad 
Multitap 
JogCon 
FishingCon 
ConfigMode 
None 

◆ PollingMode

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.

Parameters
modeThe polling mode to use.
Enumerator
Normal 
Fast 

Member Function Documentation

◆ getAdc()

uint8_t psyqo::AdvancedPad::getAdc ( Pad  pad,
unsigned int  index 
) const
inline

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)

Parameters
padThe pad to query.
indexThe index of the Analog Input(adc#).
Returns
The state of the Analog Input as an unsigned 8-bit value(0-255).

◆ getHalfword()

uint16_t psyqo::AdvancedPad::getHalfword ( Pad  pad,
unsigned int  index 
) const
inline

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.

Parameters
padThe pad to query.
indexThe index of the halfword.
Returns
The value of the halfword.

◆ getPadType()

uint8_t psyqo::AdvancedPad::getPadType ( Pad  pad) const
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.

Parameters
padThe pad to query.
Returns
The type of the pad.

◆ initialize()

void psyqo::AdvancedPad::initialize ( PollingMode  mode = PollingMode::Normal)

◆ isButtonPressed()

bool psyqo::AdvancedPad::isButtonPressed ( Pad  pad,
Button  button 
) const
inline

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.

Parameters
padThe pad to query.
buttonThe button to query.
Returns
A boolean value indicating whether the button is pressed.

◆ isPadConnected()

bool psyqo::AdvancedPad::isPadConnected ( Pad  pad) const
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.

Parameters
padThe pad to query.
Returns
A boolean value indicating whether the pad is connected.

◆ setOnEvent()

void psyqo::AdvancedPad::setOnEvent ( eastl::function< void(Event)> &&  callback)
inline

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.


The documentation for this class was generated from the following files: