Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
3c6a4bc1
Commit
3c6a4bc1
authored
Apr 23, 2016
by
Gregory Dymarek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing issue with initialization
parent
bce432ef
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
33 deletions
+47
-33
qgroundcontrol.pro
qgroundcontrol.pro
+4
-0
JoystickAndroid.cc
src/Joystick/JoystickAndroid.cc
+42
-32
JoystickAndroid.h
src/Joystick/JoystickAndroid.h
+1
-1
No files found.
qgroundcontrol.pro
View file @
3c6a4bc1
...
...
@@ -17,6 +17,10 @@
#
along
with
QGroundControl
.
If
not
,
see
<
http
://
www
.
gnu
.
org
/
licenses
/>.
#
-------------------------------------------------
#
QMAKE_CFLAGS_DEBUG
+=
-
g
#
QMAKE_CXXFLAGS
+=
-
g
#
QMAKE_CXXFLAGS_DEBUG
+=
-
g
exists
(
$$
{
OUT_PWD
}
/
qgroundcontrol
.
pro
)
{
error
(
"You must use shadow build (e.g. mkdir build; cd build; qmake ../qgroundcontrol.pro)."
)
}
...
...
src/Joystick/JoystickAndroid.cc
View file @
3c6a4bc1
...
...
@@ -8,46 +8,42 @@ int JoystickAndroid::_androidBtnListCount;
int
*
JoystickAndroid
::
_androidBtnList
;
QMutex
JoystickAndroid
::
m_mutex
;
JoystickAndroid
::
JoystickAndroid
(
const
Q
String
&
name
,
int
id
,
MultiVehicleManager
*
multiVehicleManager
)
:
Joystick
(
name
,
0
,
0
,
multiVehicleManager
)
//buttonCount and axisCount is computed below
JoystickAndroid
::
JoystickAndroid
(
const
Q
AndroidJniObject
&
inputDevice
,
const
QString
&
name
,
int
axisCount
,
int
buttonCount
,
int
id
,
MultiVehicleManager
*
multiVehicleManager
)
:
Joystick
(
name
,
axisCount
,
buttonCount
,
multiVehicleManager
)
,
deviceId
(
id
)
{
int
i
;
QAndroidJniEnvironment
env
;
QAndroidJniObject
inputDevice
=
QAndroidJniObject
::
callStaticObjectMethod
(
"android/view/InputDevice"
,
"getDevice"
,
"(I)Landroid/view/InputDevice;"
,
id
);
//if we define inputDevice in here this will fail for some reason, hence passing through argument
//QAndroidJniObject inputDevice = QAndroidJniObject::callStaticObjectMethod("android/view/InputDevice", "getDevice", "(I)Landroid/view/InputDevice;", id);
//get number of buttons
jintArray
a
=
env
->
NewIntArray
(
_androidBtnListCount
);
env
->
SetIntArrayRegion
(
a
,
0
,
_androidBtnListCount
,
_androidBtnList
);
QAndroidJniObject
btns
=
inputDevice
.
callObjectMethod
(
"hasKeys"
,
"([I)[Z"
,
a
);
//set button mapping (number->code)
jintArray
b
=
env
->
NewIntArray
(
_androidBtnListCount
);
env
->
SetIntArrayRegion
(
b
,
0
,
_androidBtnListCount
,
_androidBtnList
);
QAndroidJniObject
btns
=
inputDevice
.
callObjectMethod
(
"hasKeys"
,
"([I)[Z"
,
b
);
jbooleanArray
jSupportedButtons
=
btns
.
object
<
jbooleanArray
>
();
int
btn_sz
=
env
->
GetArrayLength
(
jSupportedButtons
);
jboolean
*
supportedButtons
=
env
->
GetBooleanArrayElements
(
jSupportedButtons
,
nullptr
);
_buttonCount
=
0
;
for
(
i
=
0
;
i
<
btn_sz
;
i
++
)
if
(
supportedButtons
[
i
])
_buttonCount
++
;
//create a mapping table (btnCode) that maps button number with button code
btnValue
=
new
bool
[
_buttonCount
];
btnCode
=
new
int
[
_buttonCount
];
int
c
=
0
;
for
(
i
=
0
;
i
<
btn_sz
;
i
++
)
for
(
i
=
0
;
i
<
_androidBtnListCount
;
i
++
)
if
(
supportedButtons
[
i
])
{
btnValue
[
c
]
=
false
;
btnCode
[
c
]
=
_androidBtnList
[
i
];
c
++
;
}
btnValue
[
c
]
=
false
;
btnCode
[
c
]
=
_androidBtnList
[
i
];
c
++
;
}
env
->
ReleaseBooleanArrayElements
(
jSupportedButtons
,
supportedButtons
,
0
);
//get number of axis
QAndroidJniObject
rangeListNative
=
inputDevice
.
callObjectMethod
(
"getMotionRanges"
,
"()Ljava/util/List;"
);
_axisCount
=
rangeListNative
.
callMethod
<
jint
>
(
"size"
);
//set axis mapping (number->code)
axisValue
=
new
int
[
_axisCount
];
axisCode
=
new
int
[
_axisCount
];
QAndroidJniObject
rangeListNative
=
inputDevice
.
callObjectMethod
(
"getMotionRanges"
,
"()Ljava/util/List;"
);
for
(
i
=
0
;
i
<
_axisCount
;
i
++
)
{
QAndroidJniObject
range
=
rangeListNative
.
callObjectMethod
(
"get"
,
"()Landroid/view/InputDevice/MotionRange;"
);
if
(
range
.
isValid
())
...
...
@@ -55,7 +51,6 @@ JoystickAndroid::JoystickAndroid(const QString& name, int id, MultiVehicleManage
axisValue
[
i
]
=
0
;
}
_axisCount
=
4
;
qDebug
()
<<
"axis:"
<<
_axisCount
<<
"buttons:"
<<
_buttonCount
;
QtAndroidPrivate
::
registerGenericMotionEventListener
(
this
);
...
...
@@ -63,7 +58,6 @@ JoystickAndroid::JoystickAndroid(const QString& name, int id, MultiVehicleManage
}
JoystickAndroid
::~
JoystickAndroid
()
{
delete
btnCode
;
delete
axisCode
;
delete
btnValue
;
...
...
@@ -79,7 +73,7 @@ bool JoystickAndroid::handleKeyEvent(jobject event) {
const
int
_deviceId
=
ev
.
callMethod
<
jint
>
(
"getDeviceId"
,
"()I"
);
if
(
_deviceId
!=
deviceId
)
return
false
;
qDebug
()
<<
"handleKeyEvent!"
<<
deviceId
;
//
qDebug() << "handleKeyEvent!" << deviceId;
return
true
;
}
...
...
@@ -89,7 +83,7 @@ bool JoystickAndroid::handleGenericMotionEvent(jobject event) {
const
int
_deviceId
=
ev
.
callMethod
<
jint
>
(
"getDeviceId"
,
"()I"
);
if
(
_deviceId
!=
deviceId
)
return
false
;
qDebug
()
<<
"handleMotionEvent!"
<<
deviceId
;
//
qDebug() << "handleMotionEvent!" << deviceId;
return
true
;
}
...
...
@@ -104,13 +98,13 @@ QMap<QString, Joystick*> JoystickAndroid::discover(MultiVehicleManager* _multiVe
QAndroidJniEnvironment
env
;
QAndroidJniObject
o
=
QAndroidJniObject
::
callStaticObjectMethod
<
jintArray
>
(
"android/view/InputDevice"
,
"getDeviceIds"
);
jintArray
jarr
=
o
.
object
<
jintArray
>
();
size_
t
sz
=
env
->
GetArrayLength
(
jarr
);
in
t
sz
=
env
->
GetArrayLength
(
jarr
);
jint
*
buff
=
env
->
GetIntArrayElements
(
jarr
,
nullptr
);
int
SOURCE_GAMEPAD
=
QAndroidJniObject
::
getStaticField
<
jint
>
(
"android/view/InputDevice"
,
"SOURCE_GAMEPAD"
);
int
SOURCE_JOYSTICK
=
QAndroidJniObject
::
getStaticField
<
jint
>
(
"android/view/InputDevice"
,
"SOURCE_JOYSTICK"
);
for
(
size_
t
i
=
0
;
i
<
sz
;
++
i
)
{
for
(
in
t
i
=
0
;
i
<
sz
;
++
i
)
{
QAndroidJniObject
inputDevice
=
QAndroidJniObject
::
callStaticObjectMethod
(
"android/view/InputDevice"
,
"getDevice"
,
"(I)Landroid/view/InputDevice;"
,
buff
[
i
]);
int
sources
=
inputDevice
.
callMethod
<
jint
>
(
"getSources"
,
"()I"
);
if
(((
sources
&
SOURCE_GAMEPAD
)
!=
SOURCE_GAMEPAD
)
//check if the input device is interesting to us
...
...
@@ -121,13 +115,29 @@ QMap<QString, Joystick*> JoystickAndroid::discover(MultiVehicleManager* _multiVe
QString
name
=
inputDevice
.
callObjectMethod
(
"getName"
,
"()Ljava/lang/String;"
).
toString
();
if
(
joystickFound
)
{
//skipping {
qWarning
()
<<
"Skipping joystick:"
<<
name
;
continue
;
}
if
(
joystickFound
)
{
//skipping {
qWarning
()
<<
"Skipping joystick:"
<<
name
;
continue
;
}
//get number of axis
QAndroidJniObject
rangeListNative
=
inputDevice
.
callObjectMethod
(
"getMotionRanges"
,
"()Ljava/util/List;"
);
int
axisCount
=
rangeListNative
.
callMethod
<
jint
>
(
"size"
);
//get number of buttons
jintArray
a
=
env
->
NewIntArray
(
_androidBtnListCount
);
env
->
SetIntArrayRegion
(
a
,
0
,
_androidBtnListCount
,
_androidBtnList
);
QAndroidJniObject
btns
=
inputDevice
.
callObjectMethod
(
"hasKeys"
,
"([I)[Z"
,
a
);
jbooleanArray
jSupportedButtons
=
btns
.
object
<
jbooleanArray
>
();
jboolean
*
supportedButtons
=
env
->
GetBooleanArrayElements
(
jSupportedButtons
,
nullptr
);
int
buttonCount
=
0
;
for
(
i
=
0
;
i
<
_androidBtnListCount
;
i
++
)
if
(
supportedButtons
[
i
])
buttonCount
++
;
env
->
ReleaseBooleanArrayElements
(
jSupportedButtons
,
supportedButtons
,
0
);
qDebug
()
<<
"
\t
"
<<
name
<<
"id:"
<<
buff
[
i
]
<<
"axes:"
<<
axisCount
<<
"buttons:"
<<
buttonCount
;
qDebug
()
<<
"
\t
"
<<
name
<<
"id:"
<<
buff
[
i
];
ret
[
name
]
=
new
JoystickAndroid
(
name
,
buff
[
i
],
_multiVehicleManager
);
ret
[
name
]
=
new
JoystickAndroid
(
inputDevice
,
name
,
axisCount
,
buttonCount
,
buff
[
i
],
_multiVehicleManager
);
joystickFound
=
true
;
}
...
...
src/Joystick/JoystickAndroid.h
View file @
3c6a4bc1
...
...
@@ -15,7 +15,7 @@
class
JoystickAndroid
:
public
Joystick
,
public
QtAndroidPrivate
::
GenericMotionEventListener
,
public
QtAndroidPrivate
::
KeyEventListener
{
public:
JoystickAndroid
(
const
Q
String
&
name
,
int
id
,
MultiVehicleManager
*
multiVehicleManager
);
JoystickAndroid
(
const
Q
AndroidJniObject
&
inputDevice
,
const
QString
&
name
,
int
axisCount
,
int
buttonCount
,
int
id
,
MultiVehicleManager
*
multiVehicleManager
);
~
JoystickAndroid
();
static
QMap
<
QString
,
Joystick
*>
discover
(
MultiVehicleManager
*
_multiVehicleManager
);
...
...
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