Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

otPS2Controller Class Reference
[PS2 controller library, PS2 controller library]

Library allows you to manage a PS2 controller.

#include <otPS2Controller.h>


Public Types

enum  PSB {
  PSB_SELECT = 0x0001, PSB_L3 = 0x0002, PSB_R3 = 0x0004, PSB_START = 0x0008,
  PSB_PAD_UP = 0x0010, PSB_PAD_RIGHT = 0x0020, PSB_PAD_DOWN = 0x0040, PSB_PAD_LEFT = 0x0080,
  PSB_L2 = 0x0100, PSB_R2 = 0x0200, PSB_L1 = 0x0400, PSB_R1 = 0x0800,
  PSB_GREEN = 0x1000, PSB_RED = 0x2000, PSB_BLUE = 0x4000, PSB_PINK = 0x8000,
  PSB_TRIANGLE = 0x1000, PSB_CIRCLE = 0x2000, PSB_CROSS = 0x4000, PSB_SQUARE = 0x8000
}
enum  Guitar {
  UP_STRUM = 0x0010, DOWN_STRUM = 0x0040, LEFT_STRUM = 0x0080, RIGHT_STRUM = 0x0020,
  STAR_POWER = 0x0100, GREEN_FRET = 0x0200, YELLOW_FRET = 0x1000, RED_FRET = 0x2000,
  BLUE_FRET = 0x4000, ORANGE_FRET = 0x8000, WHAMMY_BAR = 8
}
enum  Stick { PSS_RX = 5, PSS_RY = 6, PSS_LX = 7, PSS_LY = 8 }
enum  PSAB {
  PSAB_PAD_RIGHT = 9, PSAB_PAD_UP = 11, PSAB_PAD_DOWN = 12, PSAB_PAD_LEFT = 10,
  PSAB_L2 = 19, PSAB_R2 = 20, PSAB_L1 = 17, PSAB_R1 = 18,
  PSAB_GREEN = 13, PSAB_RED = 14, PSAB_BLUE = 15, PSAB_PINK = 16,
  PSAB_TRIANGLE = 13, PSAB_CIRCLE = 14, PSAB_CROSS = 15, PSAB_SQUARE = 16
}

Public Member Functions

 otPS2Controller ()
U8 init (setPS2CB attention, setPS2CB command, setPS2CB clock, chkPS2CB data, U8 timer, bool pressures=false, bool rumble=false)
bool button (U16 _button)
U16 buttonData ()
bool buttonState ()
bool buttonState (U16 _button)
bool buttonPressed (U16 _button)
bool buttonReleased (U16 _button)
void readGamepad ()
bool readGamepad (bool motor1, U8 motor2)
void reconfigGamepad ()
void enableRumble ()
bool enablePressures ()
U8 analog (U8 button)
U8 readType ()

Data Fields

enum otPS2Controller::PSB PSB
 These are our button constants.
enum otPS2Controller::Guitar Guitar
 Guitar button constants.
enum otPS2Controller::Stick Stick
 These are stick values.
enum otPS2Controller::PSAB PSAB
 These are analog buttons.


Member Enumeration Documentation

enum otPS2Controller::Guitar
 

Enumeration values:
UP_STRUM 
DOWN_STRUM 
LEFT_STRUM 
RIGHT_STRUM 
STAR_POWER 
GREEN_FRET 
YELLOW_FRET 
RED_FRET 
BLUE_FRET 
ORANGE_FRET 
WHAMMY_BAR 

enum otPS2Controller::PSAB
 

Enumeration values:
PSAB_PAD_RIGHT 
PSAB_PAD_UP 
PSAB_PAD_DOWN 
PSAB_PAD_LEFT 
PSAB_L2 
PSAB_R2 
PSAB_L1 
PSAB_R1 
PSAB_GREEN 
PSAB_RED 
PSAB_BLUE 
PSAB_PINK 
PSAB_TRIANGLE 
PSAB_CIRCLE 
PSAB_CROSS 
PSAB_SQUARE 

enum otPS2Controller::PSB
 

Enumeration values:
PSB_SELECT 
PSB_L3 
PSB_R3 
PSB_START 
PSB_PAD_UP 
PSB_PAD_RIGHT 
PSB_PAD_DOWN 
PSB_PAD_LEFT 
PSB_L2 
PSB_R2 
PSB_L1 
PSB_R1 
PSB_GREEN 
PSB_RED 
PSB_BLUE 
PSB_PINK 
PSB_TRIANGLE 
PSB_CIRCLE 
PSB_CROSS 
PSB_SQUARE 

enum otPS2Controller::Stick
 

Enumeration values:
PSS_RX 
PSS_RY 
PSS_LX 
PSS_LY 


Constructor & Destructor Documentation

otPS2Controller.otPS2Controller (   ) 
 

Create the object.


Member Function Documentation

U8 otPS2Controller.analog (  U8  button  ) 
 

Read related analog value

Parameters:
button Identifier
Returns:
0 to 255 for joystick value

bool otPS2Controller.button (  U16  _button  ) 
 

Check a button state

Parameters:
_button Button identifier
Returns:
True as long as button is pressed

U16 otPS2Controller.buttonData (   ) 
 

Read button code

Returns:
Hardware button code

bool otPS2Controller.buttonPressed (  U16  _button  ) 
 

Check if selected button is pressed

Parameters:
_button Button identifier
Returns:
True if button is off to on

bool otPS2Controller.buttonReleased (  U16  _button  ) 
 

Check if selected button is relesed

Parameters:
_button Button identifier
Returns:
True if button is on to off

bool otPS2Controller.buttonState (  U16  _button  ) 
 

Check a button state

Parameters:
_button Button identifier
Returns:
True if any button changes state (on to off, or off to on)

bool otPS2Controller.buttonState (   ) 
 

Check state of any buttons

Returns:
True if any button changes state (on to off, or off to on)

bool otPS2Controller.enablePressures (   ) 
 

Enable PRESSURES on

void otPS2Controller.enableRumble (   ) 
 

Enable RUMBLE mode

U8 otPS2Controller.init (  setPS2CB  attention,
setPS2CB  command,
setPS2CB  clock,
chkPS2CB  data,
U8  timer,
bool  pressures = false,
bool  rumble = false
) 
 

Init the PS2 hardware and the class

Parameters:
attention Function pointer to set or clear ATTENTION signal see setPS2CB
command Function pointer to set or clear COMMAND signal see setPS2CB
clock Function pointer to set or clear CLOCK signal see setPS2CB
data Function pointer to read DATA signal see chkPS2CB
timer Used timer (see TIMER - Procedure for timer usage) used for timings
pressures If true enable analog reading of push-butttons
rumble If true enable motor rumbling
Returns:
0 = No controller found, 1 = Controller found but not accepting commands, 2 = Controller refusing to enter Pressures mode, may not support it

bool otPS2Controller.readGamepad (  bool  motor1,
U8  motor2
) 
 

Read controller and set large motor to spin at 'vibrate' speed.
You must Read Gamepad to get new values and set vibration values.
If you don't enable the rumble, use readGamepad() with no values.
You should call this at least once a second.

Parameters:
motor1 Small motor on = true, off = false
motor2 Larger motor strenght from 0-255
Returns:
True for analog mode, false Error

void otPS2Controller.readGamepad (   ) 
 

Read controller and set large motor to spin at 0 speed.
You should call this at least once a second.

U8 otPS2Controller.readType (   ) 
 

Read controller type

Returns:
0 = Unknown Controller type found, 1 = DualShock Controller found, 2 = GuitarHero Controller found, 3 = Wireless Sony DualShock Controller found

void otPS2Controller.reconfigGamepad (   ) 
 

Re-init PS2 controller


Field Documentation

enum otPS2Controller::Guitar otPS2Controller.Guitar
 

enum otPS2Controller::PSAB otPS2Controller.PSAB
 

enum otPS2Controller::PSB otPS2Controller.PSB
 

enum otPS2Controller::Stick otPS2Controller.Stick
 


The documentation for this class was generated from the following file: footer
otStudio - Library Reference - (C) 2020-25 Officina Turini, All Rights Reserved
Document built with Doxygen 1.4.0