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
21e4b332
Commit
21e4b332
authored
Jul 26, 2010
by
Phillip Castaneda
Browse files
Adding joy patch - perform more reads per capture
parent
d9b8990a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
83 deletions
+86
-83
includes/linux/LinuxPrereqs.h
includes/linux/LinuxPrereqs.h
+1
-1
src/linux/LinuxJoyStickEvents.cpp
src/linux/LinuxJoyStickEvents.cpp
+85
-82
No files found.
includes/linux/LinuxPrereqs.h
View file @
21e4b332
...
...
@@ -31,7 +31,7 @@ restrictions:
#include "OISPrereqs.h"
//! Max number of elements to collect from buffered input
#define JOY_BUFFERSIZE
10
#define JOY_BUFFERSIZE
64
namespace
OIS
{
...
...
src/linux/LinuxJoyStickEvents.cpp
View file @
21e4b332
...
...
@@ -95,106 +95,109 @@ void LinuxJoyStick::capture()
//We are in non blocking mode - we just read once, and try to fill up buffer
input_event
js
[
JOY_BUFFERSIZE
];
int
ret
=
read
(
mJoyStick
,
&
js
,
sizeof
(
struct
input_event
)
*
JOY_BUFFERSIZE
);
if
(
ret
<=
0
)
return
;
//Determine how many whole events re read up
ret
/=
sizeof
(
struct
input_event
);
for
(
int
i
=
0
;
i
<
ret
;
++
i
)
while
(
true
)
{
switch
(
js
[
i
].
type
)
{
case
EV_KEY
:
//Button
{
int
button
=
mButtonMap
[
js
[
i
].
code
];
#ifdef OIS_LINUX_JOY_DEBUG
cout
<<
"
\n
Button Code: "
<<
js
[
i
].
code
<<
", OIS Value: "
<<
button
<<
endl
;
#endif
//Check to see whether push or released event...
if
(
js
[
i
].
value
)
{
mState
.
mButtons
[
button
]
=
true
;
if
(
mBuffered
&&
mListener
)
if
(
!
mListener
->
buttonPressed
(
JoyStickEvent
(
this
,
mState
),
button
))
return
;
}
else
{
mState
.
mButtons
[
button
]
=
false
;
if
(
mBuffered
&&
mListener
)
if
(
!
mListener
->
buttonReleased
(
JoyStickEvent
(
this
,
mState
),
button
))
return
;
}
int
ret
=
read
(
mJoyStick
,
&
js
,
sizeof
(
struct
input_event
)
*
JOY_BUFFERSIZE
);
if
(
ret
<
0
)
break
;
}
case
EV_ABS
:
//Absolute Axis
//Determine how many whole events re read up
ret
/=
sizeof
(
struct
input_event
);
for
(
int
i
=
0
;
i
<
ret
;
++
i
)
{
//A Stick (BrakeDefine is the highest possible Axis)
if
(
js
[
i
].
code
<=
ABS_BRAKE
)
switch
(
js
[
i
].
type
)
{
int
axis
=
mAxisMap
[
js
[
i
].
code
];
assert
(
axis
<
32
&&
"Too many axes (Max supported is 32). Report this to OIS forums!"
);
case
EV_KEY
:
//Button
{
int
button
=
mButtonMap
[
js
[
i
].
code
];
axisMoved
[
axis
]
=
true
;
#ifdef OIS_LINUX_JOY_DEBUG
cout
<<
"
\n
Button Code: "
<<
js
[
i
].
code
<<
", OIS Value: "
<<
button
<<
endl
;
#endif
//check for rescaling:
if
(
mRanges
[
axis
].
min
==
JoyStick
::
MIN_AXIS
&&
mRanges
[
axis
].
max
!=
JoyStick
::
MAX_AXIS
)
{
//Scale is perfect
mState
.
mAxes
[
axis
].
abs
=
js
[
i
].
value
;
//Check to see whether push or released event...
if
(
js
[
i
].
value
)
{
mState
.
mButtons
[
button
]
=
true
;
if
(
mBuffered
&&
mListener
)
if
(
!
mListener
->
buttonPressed
(
JoyStickEvent
(
this
,
mState
),
button
))
return
;
}
else
{
//Rescale
float
proportion
=
(
float
)(
js
[
i
].
value
-
mRanges
[
axis
].
max
)
/
(
float
)(
mRanges
[
axis
].
min
-
mRanges
[
axis
].
max
);
mState
.
mAxes
[
axis
].
abs
=
(
int
)(
32767.0
f
-
(
65535.0
f
*
proportion
));
{
mState
.
mButtons
[
button
]
=
false
;
if
(
mBuffered
&&
mListener
)
if
(
!
mListener
->
buttonReleased
(
JoyStickEvent
(
this
,
mState
),
button
))
return
;
}
break
;
}
else
if
(
js
[
i
].
code
<=
ABS_HAT3Y
)
//A POV - Max four POVs allowed
{
//Normalise the POV to between 0-7
//Even is X Axis, Odd is Y Axis
unsigned
char
LinuxPovNumber
=
js
[
i
].
code
-
16
;
short
OIS_POVIndex
=
POV_MASK
[
LinuxPovNumber
];
//Handle X Axis first (Even) (left right)
if
((
LinuxPovNumber
&
0x0001
)
==
0
)
case
EV_ABS
:
//Absolute Axis
{
//A Stick (BrakeDefine is the highest possible Axis)
if
(
js
[
i
].
code
<=
ABS_BRAKE
)
{
//Why do this? Because, we use a bit field, and when this axis is east,
//it can't possibly be west too. So clear out the two X axes, then refil
//it in with the new direction bit.
//Clear the East/West Bit Flags first
mState
.
mPOV
[
OIS_POVIndex
].
direction
&=
0x11110011
;
if
(
js
[
i
].
value
==
-
1
)
//Left
mState
.
mPOV
[
OIS_POVIndex
].
direction
|=
Pov
::
West
;
else
if
(
js
[
i
].
value
==
1
)
//Right
mState
.
mPOV
[
OIS_POVIndex
].
direction
|=
Pov
::
East
;
int
axis
=
mAxisMap
[
js
[
i
].
code
];
assert
(
axis
<
32
&&
"Too many axes (Max supported is 32). Report this to OIS forums!"
);
axisMoved
[
axis
]
=
true
;
//check for rescaling:
if
(
mRanges
[
axis
].
min
==
JoyStick
::
MIN_AXIS
&&
mRanges
[
axis
].
max
!=
JoyStick
::
MAX_AXIS
)
{
//Scale is perfect
mState
.
mAxes
[
axis
].
abs
=
js
[
i
].
value
;
}
else
{
//Rescale
float
proportion
=
(
float
)(
js
[
i
].
value
-
mRanges
[
axis
].
max
)
/
(
float
)(
mRanges
[
axis
].
min
-
mRanges
[
axis
].
max
);
mState
.
mAxes
[
axis
].
abs
=
(
int
)(
32767.0
f
-
(
65535.0
f
*
proportion
));
}
}
//Handle Y Axis (Odd) (up down)
else
else
if
(
js
[
i
].
code
<=
ABS_HAT3Y
)
//A POV - Max four POVs allowed
{
//Clear the North/South Bit Flags first
mState
.
mPOV
[
OIS_POVIndex
].
direction
&=
0x11111100
;
if
(
js
[
i
].
value
==
-
1
)
//Up
mState
.
mPOV
[
OIS_POVIndex
].
direction
|=
Pov
::
North
;
else
if
(
js
[
i
].
value
==
1
)
//Down
mState
.
mPOV
[
OIS_POVIndex
].
direction
|=
Pov
::
South
;
//Normalise the POV to between 0-7
//Even is X Axis, Odd is Y Axis
unsigned
char
LinuxPovNumber
=
js
[
i
].
code
-
16
;
short
OIS_POVIndex
=
POV_MASK
[
LinuxPovNumber
];
//Handle X Axis first (Even) (left right)
if
((
LinuxPovNumber
&
0x0001
)
==
0
)
{
//Why do this? Because, we use a bit field, and when this axis is east,
//it can't possibly be west too. So clear out the two X axes, then refil
//it in with the new direction bit.
//Clear the East/West Bit Flags first
mState
.
mPOV
[
OIS_POVIndex
].
direction
&=
0x11110011
;
if
(
js
[
i
].
value
==
-
1
)
//Left
mState
.
mPOV
[
OIS_POVIndex
].
direction
|=
Pov
::
West
;
else
if
(
js
[
i
].
value
==
1
)
//Right
mState
.
mPOV
[
OIS_POVIndex
].
direction
|=
Pov
::
East
;
}
//Handle Y Axis (Odd) (up down)
else
{
//Clear the North/South Bit Flags first
mState
.
mPOV
[
OIS_POVIndex
].
direction
&=
0x11111100
;
if
(
js
[
i
].
value
==
-
1
)
//Up
mState
.
mPOV
[
OIS_POVIndex
].
direction
|=
Pov
::
North
;
else
if
(
js
[
i
].
value
==
1
)
//Down
mState
.
mPOV
[
OIS_POVIndex
].
direction
|=
Pov
::
South
;
}
if
(
mBuffered
&&
mListener
)
if
(
mListener
->
povMoved
(
JoyStickEvent
(
this
,
mState
),
OIS_POVIndex
)
==
false
)
return
;
}
if
(
mBuffered
&&
mListener
)
if
(
mListener
->
povMoved
(
JoyStickEvent
(
this
,
mState
),
OIS_POVIndex
)
==
false
)
return
;
break
;
}
break
;
}
case
EV_REL
:
//Relative Axes (Do any joystick actually have a relative axis?)
#ifdef OIS_LINUX_JOY_DEBUG
cout
<<
"
\n
Warning: Relatives axes not supported yet"
<<
endl
;
#endif
break
;
default:
break
;
case
EV_REL
:
//Relative Axes (Do any joystick actually have a relative axis?)
#ifdef OIS_LINUX_JOY_DEBUG
cout
<<
"
\n
Warning: Relatives axes not supported yet"
<<
endl
;
#endif
break
;
default:
break
;
}
}
}
...
...
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