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
2542a7c0
Unverified
Commit
2542a7c0
authored
Mar 06, 2019
by
Gus Grubba
Committed by
GitHub
Mar 06, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7270 from mavlink/jniException
Properly handle jni exceptions.
parents
07e88661
89fc9397
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
18 deletions
+22
-18
JoystickAndroid.cc
src/Joystick/JoystickAndroid.cc
+22
-18
No files found.
src/Joystick/JoystickAndroid.cc
View file @
2542a7c0
...
...
@@ -10,6 +10,15 @@ int JoystickAndroid::ACTION_DOWN;
int
JoystickAndroid
::
ACTION_UP
;
QMutex
JoystickAndroid
::
m_mutex
;
static
void
clear_jni_exception
()
{
QAndroidJniEnvironment
jniEnv
;
if
(
jniEnv
->
ExceptionCheck
())
{
jniEnv
->
ExceptionDescribe
();
jniEnv
->
ExceptionClear
();
}
}
JoystickAndroid
::
JoystickAndroid
(
const
QString
&
name
,
int
axisCount
,
int
buttonCount
,
int
id
,
MultiVehicleManager
*
multiVehicleManager
)
:
Joystick
(
name
,
axisCount
,
buttonCount
,
0
,
multiVehicleManager
)
,
deviceId
(
id
)
...
...
@@ -30,12 +39,13 @@ JoystickAndroid::JoystickAndroid(const QString& name, int axisCount, int buttonC
btnValue
=
new
bool
[
_buttonCount
];
btnCode
=
new
int
[
_buttonCount
];
int
c
=
0
;
for
(
i
=
0
;
i
<
_androidBtnListCount
;
i
++
)
for
(
i
=
0
;
i
<
_androidBtnListCount
;
i
++
)
{
if
(
supportedButtons
[
i
])
{
btnValue
[
c
]
=
false
;
btnCode
[
c
]
=
_androidBtnList
[
i
];
c
++
;
}
}
env
->
ReleaseBooleanArrayElements
(
jSupportedButtons
,
supportedButtons
,
0
);
...
...
@@ -147,10 +157,10 @@ bool JoystickAndroid::handleKeyEvent(jobject event) {
const
int
action
=
ev
.
callMethod
<
jint
>
(
"getAction"
,
"()I"
);
const
int
keyCode
=
ev
.
callMethod
<
jint
>
(
"getKeyCode"
,
"()I"
);
for
(
int
i
=
0
;
i
<
_buttonCount
;
i
++
)
{
if
(
btnCode
[
i
]
==
keyCode
)
{
if
(
action
==
ACTION_DOWN
)
btnValue
[
i
]
=
true
;
if
(
action
==
ACTION_UP
)
btnValue
[
i
]
=
false
;
for
(
int
i
=
0
;
i
<
_buttonCount
;
i
++
)
{
if
(
btnCode
[
i
]
==
keyCode
)
{
if
(
action
==
ACTION_DOWN
)
btnValue
[
i
]
=
true
;
if
(
action
==
ACTION_UP
)
btnValue
[
i
]
=
false
;
return
true
;
}
}
...
...
@@ -163,9 +173,9 @@ bool JoystickAndroid::handleGenericMotionEvent(jobject event) {
const
int
_deviceId
=
ev
.
callMethod
<
jint
>
(
"getDeviceId"
,
"()I"
);
if
(
_deviceId
!=
deviceId
)
return
false
;
for
(
int
i
=
0
;
i
<
_axisCount
;
i
++
)
{
for
(
int
i
=
0
;
i
<
_axisCount
;
i
++
)
{
const
float
v
=
ev
.
callMethod
<
jfloat
>
(
"getAxisValue"
,
"(I)F"
,
axisCode
[
i
]);
axisValue
[
i
]
=
(
int
)(
v
*
32767.
f
);
axisValue
[
i
]
=
static_cast
<
int
>
((
v
*
32767.
f
)
);
}
return
true
;
}
...
...
@@ -215,7 +225,8 @@ bool JoystickAndroid::init(JoystickManager *manager) {
//int *JoystickAndroid::
_androidBtnList
=
ret
;
for
(
i
=
1
;
i
<=
16
;
i
++
)
{
clear_jni_exception
();
for
(
i
=
1
;
i
<=
16
;
i
++
)
{
QString
name
=
"KEYCODE_BUTTON_"
+
QString
::
number
(
i
);
ret
[
i
-
1
]
=
QAndroidJniObject
::
getStaticField
<
jint
>
(
"android/view/KeyEvent"
,
name
.
toStdString
().
c_str
());
}
...
...
@@ -267,14 +278,11 @@ void JoystickAndroid::setNativeMethods(JoystickManager *manager)
{
"nativeUpdateAvailableJoysticks"
,
"()V"
,
reinterpret_cast
<
void
*>
(
jniUpdateAvailableJoysticks
)}
};
clear_jni_exception
();
QAndroidJniEnvironment
jniEnv
;
if
(
jniEnv
->
ExceptionCheck
())
{
jniEnv
->
ExceptionDescribe
();
jniEnv
->
ExceptionClear
();
}
jclass
objectClass
=
jniEnv
->
FindClass
(
kJniClassName
);
if
(
!
objectClass
)
{
clear_jni_exception
();
qWarning
()
<<
"Couldn't find class:"
<<
kJniClassName
;
return
;
}
...
...
@@ -286,9 +294,5 @@ void JoystickAndroid::setNativeMethods(JoystickManager *manager)
}
else
{
qCDebug
(
JoystickLog
)
<<
"Native Functions Registered"
;
}
if
(
jniEnv
->
ExceptionCheck
())
{
jniEnv
->
ExceptionDescribe
();
jniEnv
->
ExceptionClear
();
}
clear_jni_exception
();
}
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