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

Joypad.h

Go to the documentation of this file.
00001 
00004 #ifndef _JOY_MANAGER__
00005 #define _JOY_MANAGER__
00006 
00007 #include <sys/ioctl.h>
00008 #include <linux/ps2/pad.h>
00009 #include <unistd.h>
00010 #include <fcntl.h>
00011 
00012 #include "JoypadConst.h"
00013 
00016 namespace NablaPS2Utils {
00017 
00019 #define JOYPAD_DEV0 "/dev/ps2pad00"
00020 
00021 #define JOYPAD_DEV1 "/dev/ps2pad10"
00022 
00023 static const char * const JoyDev[] = {JOYPAD_DEV0, JOYPAD_DEV1};
00024 
00030 typedef struct _tagAnalogButton {
00031 
00032     float             PressureLevel; 
00033     ButtonState   State;              
00034 } AnalogButton;
00035 
00042 typedef struct _tagPadReadDataType {
00043 
00044     unsigned char           Unused          : 8;
00045     unsigned char           Status          : 2;
00046     unsigned char           AsyStatus       : 2;
00047     unsigned char           Type                : 4;
00048     unsigned short int  DButtons            : 16;
00049     unsigned char           AnalogSRX       : 8;
00050     unsigned char           AnalogSRY       : 8;
00051     unsigned char           AnalogSLX       : 8;
00052     unsigned char           AnalogSLY       : 8;
00053     unsigned char           PadR                : 8;
00054     unsigned char           PadL                : 8;
00055     unsigned char           PadU                : 8;
00056     unsigned char           PadD                : 8;
00057     unsigned char           PadTriangle     : 8;
00058     unsigned char           PadCircle       : 8;
00059     unsigned char           PadCross            : 8;
00060     unsigned char           PadSquare       : 8;
00061     unsigned char           PadL1               : 8;
00062     unsigned char           PadR1               : 8;
00063     unsigned char           PadL2               : 8;
00064     unsigned char           PadR2               : 8;
00065 } PadDataType;
00066 
00075 class JoypadManager {
00076 
00078     int PadHandle;
00080     unsigned char m_PadData[PS2PAD_DATASIZE];
00082     int m_Status;
00084     int m_Type;
00086     bool    m_AnalogLocked;
00088     bool  m_AnalogButtonEnabled;
00090     int m_AStickTreshold;
00091 
00093     void  m_UpdateType();
00095     bool    m_ReadData();
00097     void    m_AnalyzeRead();
00098     
00100     bool m_constActuatorStatus;
00102     unsigned char m_VariableActuatorValue;
00103 
00105     AnalogButton m_Buttons[16];
00107     float            m_AnalogStick[4];
00109     float            m_ReadStickValueX(unsigned char Value);
00111     float            m_ReadStickValueY(unsigned char Value);
00112 public:
00113     
00115     JoypadManager(int PadNumber);
00117     ~JoypadManager();
00119     int  Status();
00121     void WaitUntilBusy();
00123     bool ReadPadData();
00125     const AnalogButton &Button(int Index) {return m_Buttons[Index];}
00127     float AnalogStick(int Index) {return m_AnalogStick[Index];}
00129     void EnableActuators();
00131     bool ActuatorsSupported();
00133     void  SetActuatorConst(bool Status);
00135     void  SetActuatorVariable(unsigned char Value);
00136 
00138     int  GetType();
00140     bool AnalogButtonSupported();
00142     bool SetAnalogMode(bool AMEnable);
00144     bool LockAnalogMode();
00146     bool UnlockAnalogMode();
00147 
00149     bool SetAnalogButtonStatus(bool ABEnable);
00151     void Close();
00152 
00154     operator void*() {return (void *)(Status() == PS2PAD_STAT_READY);}
00155 };
00156 
00157 }; //End Namespace
00158 #endif

Generated on Wed Jan 7 19:11:56 2004 for PS2 Tutorial by doxygen 1.3.4