#include <Joypad.h>
Collaboration diagram for NablaPS2Utils::JoypadManager:
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 AnalogButton & | Button (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. |
Definition at line 75 of file Joypad.h.
|
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.
Definition at line 16 of file Joypad.cpp. |
|
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. |
|
Remember to change this functions if some other type of controller is used Definition at line 211 of file Joypad.cpp. |
|
Before setting buttons state to analog mode there is the need to check for their support.
Definition at line 178 of file Joypad.cpp. |
|
Simply close the handle to device. Definition at line 293 of file Joypad.cpp. |
|
Remember that it is possible also to check if actuators are supported by the pad. Definition at line 192 of file Joypad.cpp. |
|
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. |
|
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. |
|
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. |
|
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.
Definition at line 329 of file Joypad.cpp. |
|
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.
Definition at line 347 of file Joypad.cpp. |
|
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. |
|
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.
Definition at line 106 of file Joypad.cpp. |
|
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
Definition at line 232 of file Joypad.cpp. |
|
Same consideration as for JoypadManager::SetActuatorConst() function will apply
Definition at line 257 of file Joypad.cpp. |
|
Enable or disable Analog button status
Definition at line 276 of file Joypad.cpp. |
|
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.
Definition at line 127 of file Joypad.cpp. |
|
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
Definition at line 67 of file Joypad.cpp. |
|
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. |
|
This is a simple routine that cycle until status of the pad is ready. Definition at line 88 of file Joypad.cpp. |