PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PlatformJoystick Class Reference

#include <PlatformJoystick.h>

Inheritance diagram for PlatformJoystick:
PJoystick PJoystick PDevice PEBLObjectBase PDevice PEBLObjectBase

Public Member Functions

 PlatformJoystick (int i)
 The Standard constructor.
 
 PlatformJoystick (const PlatformJoystick &js)
 
virtual ~PlatformJoystick ()
 The Standard destructor.
 
virtual signed int GetHatState (unsigned int hat)
 
virtual Variant GetBallState (unsigned int ball)
 
virtual signed int GetAxisState (unsigned int axis)
 
virtual signed int GetButtonState (unsigned int button)
 
 PlatformJoystick ()
 
 PlatformJoystick (int id)
 
virtual ~PlatformJoystick ()
 
virtual signed int GetHatState (unsigned int hat)
 
virtual Variant GetBallState (unsigned int ball)
 
virtual signed int GetAxisState (unsigned int axis)
 
virtual signed int GetButtonState (unsigned int button)
 
- Public Member Functions inherited from PJoystick
 PJoystick ()
 The Standard constructor.

 
virtual ~PJoystick ()
 The Standard destructor.

 
int GetNumHats ()
 
int GetNumBalls ()
 
int GetNumAxes ()
 
int GetNumButtons ()
 
- Public Member Functions inherited from PDevice
 PDevice ()
 The Standard constructor.
 
virtual ~PDevice ()
 The Standard destructor.
 
virtual PEBL_DEVICE_TYPE GetDeviceType ()
 
virtual int GetState (int iface) const
 
- Public Member Functions inherited from PEBLObjectBase
 PEBLObjectBase ()
 Standard Constructor.
 
 PEBLObjectBase (ComplexDataType cdt)
 Standard Constructor.
 
 PEBLObjectBase (const PEBLObjectBase &pob)
 
virtual ~PEBLObjectBase ()
 Standard Destructor.
 
virtual bool InitializeProperty (std::string name, Variant v)
 
virtual bool SetProperty (std::string name, Variant v)
 
Variant GetProperty (std::string) const
 
virtual ObjectValidationError ValidateProperty (std::string, Variant v) const
 
virtual ObjectValidationError ValidateProperty (std::string) const
 
ComplexDataType GetType ()
 
virtual std::string ObjectName () const
 
virtual std::ostream & PrintProperties (std::ostream &out)
 
virtual Variant GetPropertyList ()
 

Protected Member Functions

virtual std::ostream & SendToStream (std::ostream &out) const
 
virtual std::ostream & SendToStream (std::ostream &out) const
 

Additional Inherited Members

- Protected Attributes inherited from PJoystick
Variant mName
 
int mNumHats
 
int mNumBalls
 
int mNumAxes
 
int mNumButtons
 
bool mIsOpen
 
- Protected Attributes inherited from PEBLObjectBase
ComplexDataType mCDT
 
std::map< std::string, VariantmProperties
 

Detailed Description

Definition at line 37 of file sdl/PlatformJoystick.h.

Constructor & Destructor Documentation

◆ PlatformJoystick() [1/4]

PlatformJoystick::PlatformJoystick ( int  i)

The Standard constructor.

Definition at line 41 of file sdl/PlatformJoystick.cpp.

42{
43 if((SDL_NumJoysticks()>= (index+1)) &
44 (index>=0))
45 {
46 mJoystick = SDL_JoystickOpen(index);
47 mIndex = index;
48 mIsOpen = true;
49
50 }else
51 {
52 PError::SignalFatalError(Variant("Joystick unavailable: ") + Variant(index));
53 }
54
55 //The joystick API has changed a bit:
56#ifdef SDL2_DELETE
57 mName = SDL_JoystickName(mIndex);
58#endif
59
60 mNumHats = SDL_JoystickNumHats(mJoystick);
61 mNumBalls = SDL_JoystickNumBalls(mJoystick);
62 mNumAxes = SDL_JoystickNumAxes(mJoystick);
63 mNumButtons = SDL_JoystickNumButtons(mJoystick);
64
65}
Variant mName
Definition PJoystick.h:68
int mNumButtons
Definition PJoystick.h:72
int mNumHats
Definition PJoystick.h:69
bool mIsOpen
Definition PJoystick.h:74
int mNumAxes
Definition PJoystick.h:71
int mNumBalls
Definition PJoystick.h:70
void SignalFatalError(const std::string &message)

References PJoystick::mIsOpen, PJoystick::mName, PJoystick::mNumAxes, PJoystick::mNumBalls, PJoystick::mNumButtons, PJoystick::mNumHats, and PError::SignalFatalError().

◆ PlatformJoystick() [2/4]

PlatformJoystick::PlatformJoystick ( const PlatformJoystick js)

Definition at line 67 of file sdl/PlatformJoystick.cpp.

68{
69 mJoystick = NULL;
70}
#define NULL
Definition BinReloc.cpp:317

References NULL.

◆ ~PlatformJoystick() [1/2]

PlatformJoystick::~PlatformJoystick ( )
virtual

The Standard destructor.

Definition at line 73 of file sdl/PlatformJoystick.cpp.

74{
75
76 SDL_JoystickClose(mJoystick);
77
78}

◆ PlatformJoystick() [3/4]

PlatformJoystick::PlatformJoystick ( )

Definition at line 4 of file validator/PlatformJoystick.cpp.

4{}

◆ PlatformJoystick() [4/4]

PlatformJoystick::PlatformJoystick ( int  id)

◆ ~PlatformJoystick() [2/2]

virtual PlatformJoystick::~PlatformJoystick ( )
virtual

Member Function Documentation

◆ GetAxisState() [1/2]

signed int PlatformJoystick::GetAxisState ( unsigned int  axis)
virtual

Implements PJoystick.

Definition at line 122 of file sdl/PlatformJoystick.cpp.

123 {
124
125 // if(GetNumAxes()<axis)
126 // {
127 // PError::SignalWarning(Variant("Unavailable joystick axis ")+Variant((int)axis)+Variant(" requested"));
128 // return 0;
129 // }
130
131 SDL_JoystickUpdate();
132 //check to be sure axis exists.
133 return SDL_JoystickGetAxis(mJoystick,axis-1);
134 }

Referenced by PEBLEnvironment::GetJoystickAxisState().

◆ GetAxisState() [2/2]

virtual signed int PlatformJoystick::GetAxisState ( unsigned int  axis)
virtual

Implements PJoystick.

◆ GetBallState() [1/2]

Variant PlatformJoystick::GetBallState ( unsigned int  ball)
virtual

Implements PJoystick.

Definition at line 97 of file sdl/PlatformJoystick.cpp.

98 {
99 if(GetNumBalls()<ball)
100 {
101 PError::SignalWarning(Variant("Unavailable joystick ball ")+Variant((int)ball)+Variant(" requested"));
102 return 0;
103 }
104
105
106 //check to be sure ball exists.
107 SDL_JoystickUpdate();
108 int dx;
109 int dy;
110 SDL_JoystickGetBall(mJoystick,ball-1,&dx,&dy);
111
112 PList * newlist = new PList();
113 newlist->PushBack(Variant(dx));
114 newlist->PushBack(Variant(dy));
116 PComplexData * pcd = new PComplexData(newlist2);
117 return Variant(pcd);
118
119
120 }
int GetNumBalls()
Definition PJoystick.h:53
Definition PList.h:45
void PushBack(const Variant &v)
Definition PList.cpp:149
void SignalWarning(const std::string &message)
Definition PError.cpp:119

References PJoystick::GetNumBalls(), PList::PushBack(), and PError::SignalWarning().

Referenced by PEBLEnvironment::GetJoystickBallState().

◆ GetBallState() [2/2]

virtual Variant PlatformJoystick::GetBallState ( unsigned int  ball)
virtual

Implements PJoystick.

◆ GetButtonState() [1/2]

signed int PlatformJoystick::GetButtonState ( unsigned int  button)
virtual

Implements PJoystick.

Definition at line 136 of file sdl/PlatformJoystick.cpp.

137 {
138
139 if(GetNumButtons()<button)
140 {
141 PError::SignalWarning(Variant("Unavailable joystick button ")+Variant((int)button)+Variant(" requested"));
142 return 0;
143 }
144
145 SDL_JoystickUpdate();
146 //check to be sure button exists.
147 return SDL_JoystickGetButton(mJoystick,button-1);
148
149 }
int GetNumButtons()
Definition PJoystick.h:55

References PJoystick::GetNumButtons(), and PError::SignalWarning().

Referenced by PEBLEnvironment::GetJoystickButtonState().

◆ GetButtonState() [2/2]

virtual signed int PlatformJoystick::GetButtonState ( unsigned int  button)
virtual

Implements PJoystick.

◆ GetHatState() [1/2]

signed int PlatformJoystick::GetHatState ( unsigned int  hat)
virtual

Implements PJoystick.

Definition at line 81 of file sdl/PlatformJoystick.cpp.

82 {
83
84 //check to be sure hat exists.
85 if(GetNumHats()<hat)
86 {
87 PError::SignalWarning(Variant("Unavailable joystick hat ")+Variant((int)hat)+Variant(" requested"));
88 return 0;
89 }
90
91
92 SDL_JoystickUpdate();
93 return SDL_JoystickGetHat(mJoystick,hat-1);
94 }
int GetNumHats()
Definition PJoystick.h:52

References PJoystick::GetNumHats(), and PError::SignalWarning().

Referenced by PEBLEnvironment::GetJoystickHatState().

◆ GetHatState() [2/2]

virtual signed int PlatformJoystick::GetHatState ( unsigned int  hat)
virtual

Implements PJoystick.

◆ SendToStream() [1/2]

std::ostream & PlatformJoystick::SendToStream ( std::ostream &  out) const
protectedvirtual

Reimplemented from PJoystick.

Definition at line 13 of file validator/PlatformJoystick.cpp.

13 {
14 out << "PlatformJoystick (validator)";
15 return out;
16}

◆ SendToStream() [2/2]

virtual std::ostream & PlatformJoystick::SendToStream ( std::ostream &  out) const
protectedvirtual

Reimplemented from PJoystick.


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