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
fcf1b5d2
Commit
fcf1b5d2
authored
Apr 21, 2016
by
Gregory Dymarek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Android JoystickManager
parent
bf4ab002
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
0 deletions
+95
-0
JoystickManager.cc
src/Joystick/JoystickManager.cc
+81
-0
JoystickManager.h
src/Joystick/JoystickManager.h
+14
-0
No files found.
src/Joystick/JoystickManager.cc
View file @
fcf1b5d2
...
...
@@ -83,6 +83,56 @@ void JoystickManager::setToolbox(QGCToolbox *toolbox)
qCDebug
(
JoystickManagerLog
)
<<
"
\t
Skipping duplicate"
<<
name
;
}
}
#elif defined(__android__)
QMutexLocker
lock
(
&
m_mutex
);
computePossibleButtons
();
//this is just needed to get number of supported buttons
QAndroidJniEnvironment
env
;
QAndroidJniObject
o
=
QAndroidJniObject
::
callStaticObjectMethod
<
jintArray
>
(
"android/view/InputDevice"
,
"getDeviceIds"
);
jintArray
jarr
=
o
.
object
<
jintArray
>
();
size_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
)
{
int
axisCount
,
buttonCount
;
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
&&
((
sources
&
SOURCE_JOYSTICK
)
!=
SOURCE_JOYSTICK
))
continue
;
//get id and name
QString
id
=
inputDevice
.
callObjectMethod
(
"getDescriptor"
,
"()Ljava/lang/String;"
).
toString
();
QString
name
=
inputDevice
.
callObjectMethod
(
"getName"
,
"()Ljava/lang/String;"
).
toString
();
//get number of buttons
jintArray
a
=
env
->
NewIntArray
(
31
);
env
->
SetIntArrayRegion
(
a
,
0
,
31
,
_possibleButtons
);
//QAndroidJniObject keyMap = inputDevice.callObjectMethod("getKeyCharacterMap", "()Landroid/view/KeyCharacterMap;");
//QAndroidJniObject btns = keyMap.callStaticObjectMethod("android/view/KeyCharacterMap","deviceHasKeys", "([I)[Z", a);
QAndroidJniObject
btns
=
inputDevice
.
callObjectMethod
(
"hasKeys"
,
"([I)[Z"
,
a
);
jbooleanArray
jSupportedButtons
=
btns
.
object
<
jbooleanArray
>
();
size_t
btn_sz
=
env
->
GetArrayLength
(
jSupportedButtons
);
jboolean
*
supportedButtons
=
env
->
GetBooleanArrayElements
(
jSupportedButtons
,
nullptr
);
buttonCount
=
0
;
for
(
size_t
j
=
0
;
j
<
btn_sz
;
j
++
)
if
(
supportedButtons
[
j
])
buttonCount
++
;
env
->
ReleaseBooleanArrayElements
(
jSupportedButtons
,
supportedButtons
,
0
);
//get number of axis
QAndroidJniObject
rangeListNative
=
inputDevice
.
callObjectMethod
(
"getMotionRanges"
,
"()Ljava/util/List;"
);
axisCount
=
rangeListNative
.
callMethod
<
jint
>
(
"size"
);
qCDebug
(
JoystickManagerLog
)
<<
"
\t
"
<<
name
<<
"axes:"
<<
axisCount
<<
"buttons:"
<<
buttonCount
;
_name2JoystickMap
[
name
]
=
new
Joystick
(
name
,
axisCount
,
buttonCount
,
buff
[
i
],
_multiVehicleManager
);
}
env
->
ReleaseIntArrayElements
(
jarr
,
buff
,
0
);
#endif
if
(
!
_name2JoystickMap
.
count
())
{
...
...
@@ -93,6 +143,37 @@ void JoystickManager::setToolbox(QGCToolbox *toolbox)
_setActiveJoystickFromSettings
();
}
void
JoystickManager
::
computePossibleButtons
()
{
static
int
ret
[
31
];
int
i
;
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
());
}
i
--
;
ret
[
i
++
]
=
QAndroidJniObject
::
getStaticField
<
jint
>
(
"android/view/KeyEvent"
,
"KEYCODE_BUTTON_A"
);
ret
[
i
++
]
=
QAndroidJniObject
::
getStaticField
<
jint
>
(
"android/view/KeyEvent"
,
"KEYCODE_BUTTON_B"
);
ret
[
i
++
]
=
QAndroidJniObject
::
getStaticField
<
jint
>
(
"android/view/KeyEvent"
,
"KEYCODE_BUTTON_C"
);
ret
[
i
++
]
=
QAndroidJniObject
::
getStaticField
<
jint
>
(
"android/view/KeyEvent"
,
"KEYCODE_BUTTON_L1"
);
ret
[
i
++
]
=
QAndroidJniObject
::
getStaticField
<
jint
>
(
"android/view/KeyEvent"
,
"KEYCODE_BUTTON_L2"
);
ret
[
i
++
]
=
QAndroidJniObject
::
getStaticField
<
jint
>
(
"android/view/KeyEvent"
,
"KEYCODE_BUTTON_R1"
);
ret
[
i
++
]
=
QAndroidJniObject
::
getStaticField
<
jint
>
(
"android/view/KeyEvent"
,
"KEYCODE_BUTTON_R2"
);
ret
[
i
++
]
=
QAndroidJniObject
::
getStaticField
<
jint
>
(
"android/view/KeyEvent"
,
"KEYCODE_BUTTON_MODE"
);
ret
[
i
++
]
=
QAndroidJniObject
::
getStaticField
<
jint
>
(
"android/view/KeyEvent"
,
"KEYCODE_BUTTON_SELECT"
);
ret
[
i
++
]
=
QAndroidJniObject
::
getStaticField
<
jint
>
(
"android/view/KeyEvent"
,
"KEYCODE_BUTTON_START"
);
ret
[
i
++
]
=
QAndroidJniObject
::
getStaticField
<
jint
>
(
"android/view/KeyEvent"
,
"KEYCODE_BUTTON_THUMBL"
);
ret
[
i
++
]
=
QAndroidJniObject
::
getStaticField
<
jint
>
(
"android/view/KeyEvent"
,
"KEYCODE_BUTTON_THUMBR"
);
ret
[
i
++
]
=
QAndroidJniObject
::
getStaticField
<
jint
>
(
"android/view/KeyEvent"
,
"KEYCODE_BUTTON_X"
);
ret
[
i
++
]
=
QAndroidJniObject
::
getStaticField
<
jint
>
(
"android/view/KeyEvent"
,
"KEYCODE_BUTTON_Y"
);
ret
[
i
++
]
=
QAndroidJniObject
::
getStaticField
<
jint
>
(
"android/view/KeyEvent"
,
"KEYCODE_BUTTON_Z"
);
for
(
int
j
=
0
;
j
<
i
;
j
++
)
qCDebug
(
JoystickManagerLog
)
<<
"
\t
possible button: "
+
ret
[
j
];
_possibleButtons
=
ret
;
}
void
JoystickManager
::
_setActiveJoystickFromSettings
(
void
)
{
...
...
src/Joystick/JoystickManager.h
View file @
fcf1b5d2
...
...
@@ -31,6 +31,14 @@
#include <QVariantList>
#ifdef __android__
#include <jni.h>
#include <QtCore/private/qjni_p.h>
#include <QtCore/private/qjnihelpers_p.h>
#include <QtAndroidExtras/QtAndroidExtras>
#include <QtAndroidExtras/QAndroidJniObject>
#endif
Q_DECLARE_LOGGING_CATEGORY
(
JoystickManagerLog
)
class
QGCApplicaiton
;
...
...
@@ -78,6 +86,12 @@ private:
static
const
char
*
_settingsGroup
;
static
const
char
*
_settingsKeyActiveJoystick
;
#ifdef __android__
void
computePossibleButtons
();
int
*
_possibleButtons
;
QMutex
m_mutex
;
#endif
};
#endif
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