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
afc2ee52
Commit
afc2ee52
authored
Feb 05, 2019
by
Matej Frančeškin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Detect bluetooth gamepad connect/disconnect events
parent
3b3a0d4a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
90 additions
and
6 deletions
+90
-6
AndroidManifest.xml
android/AndroidManifest.xml
+2
-0
QGCActivity.java
android/src/org/mavlink/qgroundcontrol/QGCActivity.java
+11
-0
JoystickAndroid.cc
src/Joystick/JoystickAndroid.cc
+56
-3
JoystickAndroid.h
src/Joystick/JoystickAndroid.h
+3
-1
JoystickManager.cc
src/Joystick/JoystickManager.cc
+14
-2
JoystickManager.h
src/Joystick/JoystickManager.h
+4
-0
No files found.
android/AndroidManifest.xml
View file @
afc2ee52
...
...
@@ -7,6 +7,8 @@
<category
android:name=
"android.intent.category.LAUNCHER"
/>
<action
android:name=
"android.hardware.usb.action.USB_DEVICE_ATTACHED"
/>
<action
android:name=
"android.hardware.usb.action.USB_DEVICE_DETACHED"
/>
<action
android:name=
"android.bluetooth.device.action.ACL_CONNECTED"
/>
<action
android:name=
"android.bluetooth.device.action.ACL_DISCONNECTED"
/>
</intent-filter>
<meta-data
android:resource=
"@xml/device_filter"
android:name=
"android.hardware.usb.action.USB_DEVICE_ATTACHED"
/>
...
...
android/src/org/mavlink/qgroundcontrol/QGCActivity.java
View file @
afc2ee52
...
...
@@ -48,6 +48,7 @@ import android.util.Log;
import
android.os.PowerManager
;
import
android.view.WindowManager
;
import
android.os.Bundle
;
import
android.bluetooth.BluetoothDevice
;
import
com.hoho.android.usbserial.driver.*
;
import
org.qtproject.qt5.android.bindings.QtActivity
;
...
...
@@ -133,6 +134,12 @@ public class QGCActivity extends QtActivity
}
}
}
try
{
nativeUpdateAvailableJoysticks
();
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
"Exception nativeUpdateAvailableJoysticks()"
);
}
}
};
...
...
@@ -140,6 +147,7 @@ public class QGCActivity extends QtActivity
private
static
native
void
nativeDeviceHasDisconnected
(
int
userData
);
private
static
native
void
nativeDeviceException
(
int
userData
,
String
messageA
);
private
static
native
void
nativeDeviceNewData
(
int
userData
,
byte
[]
dataA
);
private
static
native
void
nativeUpdateAvailableJoysticks
();
// Native C++ functions called to log output
public
static
native
void
qgcLogDebug
(
String
message
);
...
...
@@ -171,8 +179,11 @@ public class QGCActivity extends QtActivity
// Register for USB Detach and USB Permission intent
IntentFilter
filter
=
new
IntentFilter
();
filter
.
addAction
(
UsbManager
.
ACTION_USB_DEVICE_ATTACHED
);
filter
.
addAction
(
UsbManager
.
ACTION_USB_DEVICE_DETACHED
);
filter
.
addAction
(
ACTION_USB_PERMISSION
);
filter
.
addAction
(
BluetoothDevice
.
ACTION_ACL_CONNECTED
);
filter
.
addAction
(
BluetoothDevice
.
ACTION_ACL_DISCONNECTED
);
_instance
.
registerReceiver
(
_instance
.
_usbReceiver
,
filter
);
// Create intent for usb permission request
...
...
src/Joystick/JoystickAndroid.cc
View file @
afc2ee52
...
...
@@ -134,7 +134,6 @@ QMap<QString, Joystick*> JoystickAndroid::discover(MultiVehicleManager* _multiVe
env
->
ReleaseIntArrayElements
(
jarr
,
buff
,
0
);
return
ret
;
}
...
...
@@ -171,7 +170,6 @@ bool JoystickAndroid::handleGenericMotionEvent(jobject event) {
return
true
;
}
bool
JoystickAndroid
::
_open
(
void
)
{
return
true
;
}
...
...
@@ -199,8 +197,14 @@ uint8_t JoystickAndroid::_getHat(int hat,int i) {
return
0
;
}
static
JoystickManager
*
_manager
=
nullptr
;
//helper method
bool
JoystickAndroid
::
init
()
{
bool
JoystickAndroid
::
init
(
JoystickManager
*
manager
)
{
if
(
_manager
==
nullptr
)
{
setNativeMethods
(
manager
);
}
//this gets list of all possible buttons - this is needed to check how many buttons our gamepad supports
//instead of the whole logic below we could have just a simple array of hardcoded int values as these 'should' not change
...
...
@@ -239,3 +243,52 @@ bool JoystickAndroid::init() {
return
true
;
}
static
const
char
kJniClassName
[]
{
"org/mavlink/qgroundcontrol/QGCActivity"
};
static
void
jniUpdateAvailableJoysticks
(
JNIEnv
*
envA
,
jobject
thizA
)
{
Q_UNUSED
(
envA
);
Q_UNUSED
(
thizA
);
if
(
_manager
!=
nullptr
)
{
qCDebug
(
JoystickLog
)
<<
"jniUpdateAvailableJoysticks triggered"
;
emit
_manager
->
updateAvailableJoysticksSignal
();
}
}
void
JoystickAndroid
::
setNativeMethods
(
JoystickManager
*
manager
)
{
qCDebug
(
JoystickLog
)
<<
"Registering Native Functions"
;
_manager
=
manager
;
// REGISTER THE C++ FUNCTION WITH JNI
JNINativeMethod
javaMethods
[]
{
{
"nativeUpdateAvailableJoysticks"
,
"()V"
,
reinterpret_cast
<
void
*>
(
jniUpdateAvailableJoysticks
)}
};
QAndroidJniEnvironment
jniEnv
;
if
(
jniEnv
->
ExceptionCheck
())
{
jniEnv
->
ExceptionDescribe
();
jniEnv
->
ExceptionClear
();
}
jclass
objectClass
=
jniEnv
->
FindClass
(
kJniClassName
);
if
(
!
objectClass
)
{
qWarning
()
<<
"Couldn't find class:"
<<
kJniClassName
;
return
;
}
jint
val
=
jniEnv
->
RegisterNatives
(
objectClass
,
javaMethods
,
sizeof
(
javaMethods
)
/
sizeof
(
javaMethods
[
0
]));
if
(
val
<
0
)
{
qWarning
()
<<
"Error registering methods: "
<<
val
;
}
else
{
qCDebug
(
JoystickLog
)
<<
"Native Functions Registered"
;
}
if
(
jniEnv
->
ExceptionCheck
())
{
jniEnv
->
ExceptionDescribe
();
jniEnv
->
ExceptionClear
();
}
}
src/Joystick/JoystickAndroid.h
View file @
afc2ee52
...
...
@@ -19,7 +19,7 @@ public:
~
JoystickAndroid
();
static
bool
init
();
static
bool
init
(
JoystickManager
*
manager
);
static
QMap
<
QString
,
Joystick
*>
discover
(
MultiVehicleManager
*
_multiVehicleManager
);
...
...
@@ -27,6 +27,8 @@ private:
bool
handleKeyEvent
(
jobject
event
);
bool
handleGenericMotionEvent
(
jobject
event
);
static
void
setNativeMethods
(
JoystickManager
*
manager
);
virtual
bool
_open
();
virtual
void
_close
();
virtual
bool
_update
();
...
...
src/Joystick/JoystickManager.cc
View file @
afc2ee52
...
...
@@ -59,11 +59,13 @@ void JoystickManager::init() {
}
_setActiveJoystickFromSettings
();
#elif defined(__android__)
if
(
!
JoystickAndroid
::
init
())
{
if
(
!
JoystickAndroid
::
init
(
this
))
{
return
;
}
connect
(
this
,
&
JoystickManager
::
updateAvailableJoysticksSignal
,
this
,
&
JoystickManager
::
restartJoystickCheckTimer
);
#endif
connect
(
&
_joystickCheckTimer
,
&
QTimer
::
timeout
,
this
,
&
JoystickManager
::
_updateAvailableJoysticks
);
_joystickCheckTimerCounter
=
5
;
_joystickCheckTimer
.
start
(
1000
);
}
...
...
@@ -185,7 +187,7 @@ void JoystickManager::setActiveJoystickName(const QString& name)
/*
* TODO: move this to the right place: JoystickSDL.cc and JoystickAndroid.cc respectively and call through Joystick.cc
*/
void
JoystickManager
::
_updateAvailableJoysticks
(
void
)
void
JoystickManager
::
_updateAvailableJoysticks
()
{
#ifdef __sdljoystick__
SDL_Event
event
;
...
...
@@ -207,6 +209,16 @@ void JoystickManager::_updateAvailableJoysticks(void)
}
}
#elif defined(__android__)
_joystickCheckTimerCounter
--
;
_setActiveJoystickFromSettings
();
if
(
_joystickCheckTimerCounter
<=
0
)
{
_joystickCheckTimer
.
stop
();
}
#endif
}
void
JoystickManager
::
restartJoystickCheckTimer
()
{
_joystickCheckTimerCounter
=
5
;
_joystickCheckTimer
.
start
(
1000
);
}
src/Joystick/JoystickManager.h
View file @
afc2ee52
...
...
@@ -45,6 +45,8 @@ public:
QString
activeJoystickName
(
void
);
void
setActiveJoystickName
(
const
QString
&
name
);
void
restartJoystickCheckTimer
(
void
);
// Override from QGCTool
virtual
void
setToolbox
(
QGCToolbox
*
toolbox
);
...
...
@@ -55,6 +57,7 @@ signals:
void
activeJoystickChanged
(
Joystick
*
joystick
);
void
activeJoystickNameChanged
(
const
QString
&
name
);
void
availableJoysticksChanged
(
void
);
void
updateAvailableJoysticksSignal
();
private
slots
:
void
_updateAvailableJoysticks
(
void
);
...
...
@@ -70,6 +73,7 @@ private:
static
const
char
*
_settingsGroup
;
static
const
char
*
_settingsKeyActiveJoystick
;
int
_joystickCheckTimerCounter
;
QTimer
_joystickCheckTimer
;
};
...
...
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