Main Page | Namespace List | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

NablaPS2Utils::JoypadManager Class Reference

This class is a Pad manager, helping the user to access pad ioctl function and reading data. More...

#include <Joypad.h>

Collaboration diagram for NablaPS2Utils::JoypadManager:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 JoypadManager (int PadNumber)
 Constructor needs only the ID of the pad to use (0, 1).

 ~JoypadManager ()
 Destructor of the class.

int Status ()
 Used to read the status of the pad.

void WaitUntilBusy ()
 Wait till joypad is busy.

bool ReadPadData ()
 Used to make joypad read joy data.

const AnalogButtonButton (int Index)
 Used to access button status.

float AnalogStick (int Index)
 Used to access AnalogStick status.

void EnableActuators ()
 Enable use of DualShock Actuators.

bool ActuatorsSupported ()
 Check for presence of the two actuators.

void SetActuatorConst (bool Status)
 Enable disable constant actuator.

void SetActuatorVariable (unsigned char Value)
 Enable disable constant actuator.

int GetType ()
 Get type of the controller.

bool AnalogButtonSupported ()
 Ask for supporting of analog button.

bool SetAnalogMode (bool AMEnable)
 Force analog or digital mode of the pad.

bool LockAnalogMode ()
 Lock analog mode of the pad.

bool UnlockAnalogMode ()
 Unlock previus locked pad.

bool SetAnalogButtonStatus (bool ABEnable)
 Enable or disable Analog button retrieval.

void Close ()
 Close the handle to the pad.

 operator void * ()
 Providing conversion to void *, to use the class in if () test.


Private Member Functions

void m_UpdateType ()
 Used to read Pad Type.

bool m_ReadData ()
 Function used to read data into internal char array.

void m_AnalyzeRead ()
 Function used to analyze data read.

float m_ReadStickValueX (unsigned char Value)
 This read normalized thresholded value of the stick.

float m_ReadStickValueY (unsigned char Value)
 This read normalized thresholded value of the stick.


Private Attributes

int PadHandle
 Internal handle to joypad device file.

unsigned char m_PadData [PS2PAD_DATASIZE]
 Internal array used to read data from pad.

int m_Status
 Internal status flag.

int m_Type
 Type of controller.

bool m_AnalogLocked
 Tells if the pad is locked in analog mode.

bool m_AnalogButtonEnabled
 Status of Analog pressing buttons.

int m_AStickTreshold
 Represent treshold level for analog stick.

bool m_constActuatorStatus
 Status of const actuator.

unsigned char m_VariableActuatorValue
 Status of VariableIntensity actuator.

AnalogButton m_Buttons [16]
 These represent all button of the pad, to avoid confusion AnalogButton is used.

float m_AnalogStick [4]
 This array contains normalized value for position of analog stick.


Detailed Description

Array m_Buttons contains all digital and analog buttons as well as digital pad, that is nothing more that a four button stick. Structure for analog button is used even for digital ones but this is done for sake of simplicity.

Definition at line 75 of file Joypad.h.


Constructor & Destructor Documentation

NablaPS2Utils::JoypadManager::JoypadManager int  JoypadNumber  ) 
 

Constructor simply open file of selected joypad, remember to check if all went good. Since this first version of the class was tested only with DualShock all other JoyPad are discharded. Remember that even DualShock JoyPad is recognized as PS2PAD_TYPE_DIGITAL if analog mode is not enabled.

Parameters:
JoypadNumber 0 mean left port pad and 1 means right port pad

Definition at line 16 of file Joypad.cpp.

NablaPS2Utils::JoypadManager::~JoypadManager  ) 
 

Cleanup routine: 1)try to unlock the pad, routine UnlockAnalogMode automatically check for locked pad. 2)Invoke Close() function that release the handle to the pad device

Definition at line 40 of file Joypad.cpp.


Member Function Documentation

bool NablaPS2Utils::JoypadManager::ActuatorsSupported  ) 
 

Remember to change this functions if some other type of controller is used

Definition at line 211 of file Joypad.cpp.

bool NablaPS2Utils::JoypadManager::AnalogButtonSupported  ) 
 

Before setting buttons state to analog mode there is the need to check for their support.

Returns:
True if the pad supports analog buttons, false otherwise

Definition at line 178 of file Joypad.cpp.

void NablaPS2Utils::JoypadManager::Close  ) 
 

Simply close the handle to device.

Definition at line 293 of file Joypad.cpp.

void NablaPS2Utils::JoypadManager::EnableActuators  ) 
 

Remember that it is possible also to check if actuators are supported by the pad.

Definition at line 192 of file Joypad.cpp.

bool NablaPS2Utils::JoypadManager::LockAnalogMode  ) 
 

Remember that if the pad is set to analog mode there is the need to unlock the pad before exiting the class if not the pad will remain lock. Unlocking of the pad is done automatically in the distructor of the class.

Definition at line 148 of file Joypad.cpp.

void NablaPS2Utils::JoypadManager::m_AnalyzeRead  )  [private]
 

This function do the real work and set all button value into Buttons internal structure as well to set analog stick position. It is called after data is read into internal array.

Definition at line 366 of file Joypad.cpp.

bool NablaPS2Utils::JoypadManager::m_ReadData  )  [private]
 

Before actually read the data status is checked, rememeber that checking status do also a busy loop to check if both handle to joypad is good and joypad is not in busy state.

Definition at line 306 of file Joypad.cpp.

float NablaPS2Utils::JoypadManager::m_ReadStickValueX unsigned char  Value  )  [private]
 

Unbias position of the pad, use threshold to zero value of digital stick if value is less than threshold and finally normalize value to float range -1, 1.

Parameters:
Value Value to be normalized

Definition at line 329 of file Joypad.cpp.

float NablaPS2Utils::JoypadManager::m_ReadStickValueY unsigned char  Value  )  [private]
 

Unbias position of the pad, use threshold to zero value of digital stick if value is less than threshold and finally normalize value to float range -1, 1.

Parameters:
Value Value to be normalized

Definition at line 347 of file Joypad.cpp.

void NablaPS2Utils::JoypadManager::m_UpdateType  )  [private]
 

Update type of the pad, remember that pad can be init in digital mode and then switched to analog mode, so there is the need to recheck type of the pad whenever its state can change

Definition at line 51 of file Joypad.cpp.

bool NablaPS2Utils::JoypadManager::ReadPadData  ) 
 

Call internal function m_ReadData that does not only read pad data with read() but update also internal structures to change status of the buttons.

Returns:
Status of reading data, rememeber that read() function can fail.

Definition at line 106 of file Joypad.cpp.

void NablaPS2Utils::JoypadManager::SetActuatorConst bool  Status  ) 
 

It is important to remember that is not possibile to handle the two actuators independently, so to set only the constant actuator value of variable actuators must be stored and set, if not actuator vibrations will be stopped

Returns:
Status Boolean value to Enable/Disable the constant actuator

Definition at line 232 of file Joypad.cpp.

void NablaPS2Utils::JoypadManager::SetActuatorVariable unsigned char  Value  ) 
 

Same consideration as for JoypadManager::SetActuatorConst() function will apply

Parameters:
Value Intensity of the vibration in range [0,255]

Definition at line 257 of file Joypad.cpp.

bool NablaPS2Utils::JoypadManager::SetAnalogButtonStatus bool  ABEnable  ) 
 

Enable or disable Analog button status

Returns:
Result of the operation, the function returns true if operation is successful or false if the status of the pad is not ready

Definition at line 276 of file Joypad.cpp.

bool NablaPS2Utils::JoypadManager::SetAnalogMode bool  AMEnable  ) 
 

Since analog mode mantains all functionality of digital mode there is no need in making a SetDigitalMode or a SetMode function. Only SetAnalogMode is useful.

Parameters:
AMEnable If true enable analog mode, but if set to fase disable analog mode effectively activating digital mode.
Returns:
status of the operation.

Definition at line 127 of file Joypad.cpp.

int NablaPS2Utils::JoypadManager::Status  ) 
 

Check the status of the pad, remember to check also if the handle to the file is correct. If file handle is not valid then it is sufficient to return PS2PAD_STAT_ERROR so the user know that some error occurred. This function will not return until status of the pad is busy

Returns:
Status of the pad

Definition at line 67 of file Joypad.cpp.

bool NablaPS2Utils::JoypadManager::UnlockAnalogMode  ) 
 

This function does not change the mode of the pad, it is used only to unlock a previously locked analog mode.

Definition at line 162 of file Joypad.cpp.

void NablaPS2Utils::JoypadManager::WaitUntilBusy  ) 
 

This is a simple routine that cycle until status of the pad is ready.

Definition at line 88 of file Joypad.cpp.


The documentation for this class was generated from the following files:
Generated on Wed Jan 7 19:12:21 2004 for PS2 Tutorial by doxygen 1.3.4