Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
fengzch-das
OIS
Commits
ce6fcfcd
Commit
ce6fcfcd
authored
Apr 02, 2010
by
Phillip Castaneda
Browse files
Adding Joystick patch/fixes
parent
6be8481b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
16 deletions
+69
-16
includes/mac/MacJoyStick.h
includes/mac/MacJoyStick.h
+11
-2
src/mac/MacHIDManager.cpp
src/mac/MacHIDManager.cpp
+5
-1
src/mac/MacJoyStick.cpp
src/mac/MacJoyStick.cpp
+53
-13
No files found.
includes/mac/MacJoyStick.h
View file @
ce6fcfcd
...
...
@@ -28,9 +28,18 @@
namespace
OIS
{
struct
AxisInfo
{
int
min
;
int
max
;
AxisInfo
(
int
min
,
int
max
)
:
min
(
min
),
max
(
max
)
{}
};
typedef
struct
cookie_struct
{
std
::
vector
<
IOHIDElementCookie
>
axisCookies
;
std
::
map
<
IOHIDElementCookie
,
AxisInfo
>
axisCookies
;
std
::
vector
<
IOHIDElementCookie
>
buttonCookies
;
}
cookie_struct_t
;
...
...
@@ -39,7 +48,7 @@ namespace OIS
class
MacJoyStick
:
public
JoyStick
{
public:
MacJoyStick
(
const
std
::
string
&
vendor
,
bool
buffered
,
HidInfo
*
info
,
InputManager
*
creator
);
MacJoyStick
(
const
std
::
string
&
vendor
,
bool
buffered
,
HidInfo
*
info
,
InputManager
*
creator
,
int
devID
);
virtual
~
MacJoyStick
();
...
...
src/mac/MacHIDManager.cpp
View file @
ce6fcfcd
...
...
@@ -406,7 +406,11 @@ Object* MacHIDManager::createObject(InputManager* creator, Type iType, bool buff
switch
(
iType
)
{
case
OISJoyStick
:
obj
=
new
MacJoyStick
(
vendor
,
bufferMode
,
*
it
,
creator
);
int
totalDevs
=
totalDevices
(
iType
);
int
freeDevs
=
freeDevices
(
iType
);
int
devID
=
totalDevs
-
freeDevs
;
obj
=
new
MacJoyStick
((
*
it
)
->
combinedKey
,
bufferMode
,
*
it
,
creator
,
devID
);
(
*
it
)
->
inUse
=
true
;
return
obj
;
case
OISTablet
:
...
...
src/mac/MacJoyStick.cpp
View file @
ce6fcfcd
...
...
@@ -32,8 +32,8 @@
using
namespace
OIS
;
//--------------------------------------------------------------------------------------------------//
MacJoyStick
::
MacJoyStick
(
const
std
::
string
&
vendor
,
bool
buffered
,
HidInfo
*
info
,
InputManager
*
creator
)
:
JoyStick
(
vendor
,
buffered
,
0
/*device id*/
,
creator
),
mInfo
(
info
)
MacJoyStick
::
MacJoyStick
(
const
std
::
string
&
vendor
,
bool
buffered
,
HidInfo
*
info
,
InputManager
*
creator
,
int
devID
)
:
JoyStick
(
vendor
,
buffered
,
devID
,
creator
),
mInfo
(
info
)
{
}
...
...
@@ -75,6 +75,18 @@ void MacJoyStick::_initialize()
mQueue
=
_createQueue
();
}
class
FindAxisCookie
:
public
std
::
unary_function
<
std
::
pair
<
IOHIDElementCookie
,
AxisInfo
>&
,
bool
>
{
public:
FindAxisCookie
(
IOHIDElementCookie
cookie
)
:
m_Cookie
(
cookie
)
{}
bool
operator
()(
const
std
::
pair
<
IOHIDElementCookie
,
AxisInfo
>&
pair
)
const
{
return
pair
.
first
==
m_Cookie
;
}
private:
IOHIDElementCookie
m_Cookie
;
};
//--------------------------------------------------------------------------------------------------//
void
MacJoyStick
::
capture
()
{
...
...
@@ -106,8 +118,15 @@ void MacJoyStick::capture()
case
kIOHIDElementTypeInput_Misc
:
//TODO: It's an axis! - kind of - for gamepads - or should this be a pov?
case
kIOHIDElementTypeInput_Axis
:
mState
.
mAxes
[(
int
)
event
.
elementCookie
].
abs
=
event
.
value
;
if
(
mBuffered
&&
mListener
)
mListener
->
axisMoved
(
JoyStickEvent
(
this
,
mState
),
(
int
)
event
.
elementCookie
);
std
::
map
<
IOHIDElementCookie
,
AxisInfo
>::
iterator
axisIt
=
std
::
find_if
(
mCookies
.
axisCookies
.
begin
(),
mCookies
.
axisCookies
.
end
(),
FindAxisCookie
(
event
.
elementCookie
));
int
axis
=
std
::
distance
(
mCookies
.
axisCookies
.
begin
(),
axisIt
);
//Copied from LinuxJoyStickEvents.cpp, line 149
const
AxisInfo
&
axisInfo
=
axisIt
->
second
;
float
proportion
=
(
float
)
(
event
.
value
-
axisInfo
.
max
)
/
(
float
)
(
axisInfo
.
min
-
axisInfo
.
max
);
mState
.
mAxes
[
axis
].
abs
=
-
JoyStick
::
MIN_AXIS
-
(
JoyStick
::
MAX_AXIS
*
2
*
proportion
);
if
(
mBuffered
&&
mListener
)
mListener
->
axisMoved
(
JoyStickEvent
(
this
,
mState
),
axis
);
break
;
}
...
...
@@ -144,6 +163,8 @@ void MacJoyStick::_enumerateCookies()
IOHIDElementCookie
cookie
;
long
usage
;
long
usagePage
;
int
min
;
int
max
;
CFDictionaryRef
element
;
...
...
@@ -181,6 +202,25 @@ void MacJoyStick::_enumerateCookies()
continue
;
usage
=
number
;
//Get min
object
=
CFDictionaryGetValue
(
element
,
CFSTR
(
kIOHIDElementMinKey
));
// kIOHIDElementMinKey or kIOHIDElementScaledMinKey?, no idea ...
if
(
object
==
0
||
CFGetTypeID
(
object
)
!=
CFNumberGetTypeID
())
continue
;
if
(
!
CFNumberGetValue
((
CFNumberRef
)
object
,
kCFNumberIntType
,
&
number
))
continue
;
min
=
number
;
//Get max
object
=
CFDictionaryGetValue
(
element
,
CFSTR
(
kIOHIDElementMaxKey
));
// kIOHIDElementMaxKey or kIOHIDElementScaledMaxKey?, no idea ...
if
(
object
==
0
||
CFGetTypeID
(
object
)
!=
CFNumberGetTypeID
())
continue
;
if
(
!
CFNumberGetValue
((
CFNumberRef
)
object
,
kCFNumberIntType
,
&
number
))
continue
;
max
=
number
;
//Get usage page
object
=
CFDictionaryGetValue
(
element
,
...
...
@@ -207,7 +247,7 @@ void MacJoyStick::_enumerateCookies()
case
kHIDUsage_GD_Rx
:
case
kHIDUsage_GD_Ry
:
case
kHIDUsage_GD_Rz
:
mCookies
.
axisCookies
.
push_back
(
cookie
);
mCookies
.
axisCookies
.
insert
(
std
::
make_pair
(
cookie
,
AxisInfo
(
min
,
max
))
);
break
;
case
kHIDUsage_GD_Slider
:
case
kHIDUsage_GD_Dial
:
...
...
@@ -250,16 +290,16 @@ IOHIDQueueInterface** MacJoyStick::_createQueue(unsigned int depth)
if
(
result
==
kIOReturnSuccess
)
{
//add elements to the queue
std
::
vector
<
IOHIDElementCookie
>::
iterator
i
t
=
mCookies
.
axisCookies
.
begin
();
for
(;
i
t
!=
mCookies
.
axisCookies
.
end
();
++
i
t
)
std
::
map
<
IOHIDElementCookie
,
AxisInfo
>::
iterator
axisI
t
=
mCookies
.
axisCookies
.
begin
();
for
(;
axisI
t
!=
mCookies
.
axisCookies
.
end
();
++
axisI
t
)
{
result
=
(
*
queue
)
->
addElement
(
queue
,
(
*
it
)
,
0
);
result
=
(
*
queue
)
->
addElement
(
queue
,
axisIt
->
first
,
0
);
}
i
t
=
mCookies
.
buttonCookies
.
begin
();
for
(;
i
t
!=
mCookies
.
buttonCookies
.
end
();
++
i
t
)
std
::
vector
<
IOHIDElementCookie
>::
iterator
buttonI
t
=
mCookies
.
buttonCookies
.
begin
();
for
(;
buttonI
t
!=
mCookies
.
buttonCookies
.
end
();
++
buttonI
t
)
{
result
=
(
*
queue
)
->
addElement
(
queue
,
(
*
i
t
),
0
);
result
=
(
*
queue
)
->
addElement
(
queue
,
(
*
buttonI
t
),
0
);
}
//start data delivery to queue
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment