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
0720c373
Unverified
Commit
0720c373
authored
Jul 30, 2019
by
Gus Grubba
Committed by
GitHub
Jul 30, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7647 from mavlink/joystickButtonState
Joystick button state
parents
acfd001f
ce588588
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
34 deletions
+84
-34
QGCCameraManager.cc
src/Camera/QGCCameraManager.cc
+34
-8
QGCCameraManager.h
src/Camera/QGCCameraManager.h
+2
-0
Joystick.cc
src/Joystick/Joystick.cc
+47
-25
Joystick.h
src/Joystick/Joystick.h
+1
-1
No files found.
src/Camera/QGCCameraManager.cc
View file @
0720c373
...
@@ -379,6 +379,8 @@ QGCCameraManager::_activeJoystickChanged(Joystick* joystick)
...
@@ -379,6 +379,8 @@ QGCCameraManager::_activeJoystickChanged(Joystick* joystick)
qCDebug
(
CameraManagerLog
)
<<
"Joystick changed"
;
qCDebug
(
CameraManagerLog
)
<<
"Joystick changed"
;
if
(
_activeJoystick
)
{
if
(
_activeJoystick
)
{
disconnect
(
_activeJoystick
,
&
Joystick
::
stepZoom
,
this
,
&
QGCCameraManager
::
_stepZoom
);
disconnect
(
_activeJoystick
,
&
Joystick
::
stepZoom
,
this
,
&
QGCCameraManager
::
_stepZoom
);
disconnect
(
_activeJoystick
,
&
Joystick
::
startContinuousZoom
,
this
,
&
QGCCameraManager
::
_startZoom
);
disconnect
(
_activeJoystick
,
&
Joystick
::
stopContinuousZoom
,
this
,
&
QGCCameraManager
::
_stopZoom
);
disconnect
(
_activeJoystick
,
&
Joystick
::
stepCamera
,
this
,
&
QGCCameraManager
::
_stepCamera
);
disconnect
(
_activeJoystick
,
&
Joystick
::
stepCamera
,
this
,
&
QGCCameraManager
::
_stepCamera
);
disconnect
(
_activeJoystick
,
&
Joystick
::
stepStream
,
this
,
&
QGCCameraManager
::
_stepStream
);
disconnect
(
_activeJoystick
,
&
Joystick
::
stepStream
,
this
,
&
QGCCameraManager
::
_stepStream
);
disconnect
(
_activeJoystick
,
&
Joystick
::
triggerCamera
,
this
,
&
QGCCameraManager
::
_triggerCamera
);
disconnect
(
_activeJoystick
,
&
Joystick
::
triggerCamera
,
this
,
&
QGCCameraManager
::
_triggerCamera
);
...
@@ -388,13 +390,15 @@ QGCCameraManager::_activeJoystickChanged(Joystick* joystick)
...
@@ -388,13 +390,15 @@ QGCCameraManager::_activeJoystickChanged(Joystick* joystick)
}
}
_activeJoystick
=
joystick
;
_activeJoystick
=
joystick
;
if
(
_activeJoystick
)
{
if
(
_activeJoystick
)
{
connect
(
_activeJoystick
,
&
Joystick
::
stepZoom
,
this
,
&
QGCCameraManager
::
_stepZoom
);
connect
(
_activeJoystick
,
&
Joystick
::
stepZoom
,
this
,
&
QGCCameraManager
::
_stepZoom
);
connect
(
_activeJoystick
,
&
Joystick
::
stepCamera
,
this
,
&
QGCCameraManager
::
_stepCamera
);
connect
(
_activeJoystick
,
&
Joystick
::
startContinuousZoom
,
this
,
&
QGCCameraManager
::
_startZoom
);
connect
(
_activeJoystick
,
&
Joystick
::
stepStream
,
this
,
&
QGCCameraManager
::
_stepStream
);
connect
(
_activeJoystick
,
&
Joystick
::
stopContinuousZoom
,
this
,
&
QGCCameraManager
::
_stopZoom
);
connect
(
_activeJoystick
,
&
Joystick
::
triggerCamera
,
this
,
&
QGCCameraManager
::
_triggerCamera
);
connect
(
_activeJoystick
,
&
Joystick
::
stepCamera
,
this
,
&
QGCCameraManager
::
_stepCamera
);
connect
(
_activeJoystick
,
&
Joystick
::
startVideoRecord
,
this
,
&
QGCCameraManager
::
_startVideoRecording
);
connect
(
_activeJoystick
,
&
Joystick
::
stepStream
,
this
,
&
QGCCameraManager
::
_stepStream
);
connect
(
_activeJoystick
,
&
Joystick
::
stopVideoRecord
,
this
,
&
QGCCameraManager
::
_stopVideoRecording
);
connect
(
_activeJoystick
,
&
Joystick
::
triggerCamera
,
this
,
&
QGCCameraManager
::
_triggerCamera
);
connect
(
_activeJoystick
,
&
Joystick
::
toggleVideoRecord
,
this
,
&
QGCCameraManager
::
_toggleVideoRecording
);
connect
(
_activeJoystick
,
&
Joystick
::
startVideoRecord
,
this
,
&
QGCCameraManager
::
_startVideoRecording
);
connect
(
_activeJoystick
,
&
Joystick
::
stopVideoRecord
,
this
,
&
QGCCameraManager
::
_stopVideoRecording
);
connect
(
_activeJoystick
,
&
Joystick
::
toggleVideoRecord
,
this
,
&
QGCCameraManager
::
_toggleVideoRecording
);
}
}
}
}
...
@@ -442,7 +446,7 @@ QGCCameraManager::_toggleVideoRecording()
...
@@ -442,7 +446,7 @@ QGCCameraManager::_toggleVideoRecording()
void
void
QGCCameraManager
::
_stepZoom
(
int
direction
)
QGCCameraManager
::
_stepZoom
(
int
direction
)
{
{
if
(
_lastZoomChange
.
elapsed
()
>
25
0
)
{
if
(
_lastZoomChange
.
elapsed
()
>
4
0
)
{
_lastZoomChange
.
start
();
_lastZoomChange
.
start
();
qCDebug
(
CameraManagerLog
)
<<
"Step Camera Zoom"
<<
direction
;
qCDebug
(
CameraManagerLog
)
<<
"Step Camera Zoom"
<<
direction
;
QGCCameraControl
*
pCamera
=
currentCameraInstance
();
QGCCameraControl
*
pCamera
=
currentCameraInstance
();
...
@@ -452,6 +456,28 @@ QGCCameraManager::_stepZoom(int direction)
...
@@ -452,6 +456,28 @@ QGCCameraManager::_stepZoom(int direction)
}
}
}
}
//-----------------------------------------------------------------------------
void
QGCCameraManager
::
_startZoom
(
int
direction
)
{
qCDebug
(
CameraManagerLog
)
<<
"Start Camera Zoom"
<<
direction
;
QGCCameraControl
*
pCamera
=
currentCameraInstance
();
if
(
pCamera
)
{
pCamera
->
startZoom
(
direction
);
}
}
//-----------------------------------------------------------------------------
void
QGCCameraManager
::
_stopZoom
()
{
qCDebug
(
CameraManagerLog
)
<<
"Stop Camera Zoom"
;
QGCCameraControl
*
pCamera
=
currentCameraInstance
();
if
(
pCamera
)
{
pCamera
->
stopZoom
();
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void
void
QGCCameraManager
::
_stepCamera
(
int
direction
)
QGCCameraManager
::
_stepCamera
(
int
direction
)
...
...
src/Camera/QGCCameraManager.h
View file @
0720c373
...
@@ -57,6 +57,8 @@ protected slots:
...
@@ -57,6 +57,8 @@ protected slots:
virtual
void
_mavlinkMessageReceived
(
const
mavlink_message_t
&
message
);
virtual
void
_mavlinkMessageReceived
(
const
mavlink_message_t
&
message
);
virtual
void
_activeJoystickChanged
(
Joystick
*
joystick
);
virtual
void
_activeJoystickChanged
(
Joystick
*
joystick
);
virtual
void
_stepZoom
(
int
direction
);
virtual
void
_stepZoom
(
int
direction
);
virtual
void
_startZoom
(
int
direction
);
virtual
void
_stopZoom
();
virtual
void
_stepCamera
(
int
direction
);
virtual
void
_stepCamera
(
int
direction
);
virtual
void
_stepStream
(
int
direction
);
virtual
void
_stepStream
(
int
direction
);
virtual
void
_cameraTimeout
();
virtual
void
_cameraTimeout
();
...
...
src/Joystick/Joystick.cc
View file @
0720c373
...
@@ -477,9 +477,12 @@ void Joystick::run()
...
@@ -477,9 +477,12 @@ void Joystick::run()
void
Joystick
::
_handleButtons
()
void
Joystick
::
_handleButtons
()
{
{
int
lastBbuttonValues
[
256
];
//-- Update button states
//-- Update button states
for
(
int
buttonIndex
=
0
;
buttonIndex
<
_buttonCount
;
buttonIndex
++
)
{
for
(
int
buttonIndex
=
0
;
buttonIndex
<
_buttonCount
;
buttonIndex
++
)
{
bool
newButtonValue
=
_getButton
(
buttonIndex
);
bool
newButtonValue
=
_getButton
(
buttonIndex
);
if
(
buttonIndex
<
256
)
lastBbuttonValues
[
buttonIndex
]
=
_rgButtonValues
[
buttonIndex
];
if
(
newButtonValue
&&
_rgButtonValues
[
buttonIndex
]
==
BUTTON_UP
)
{
if
(
newButtonValue
&&
_rgButtonValues
[
buttonIndex
]
==
BUTTON_UP
)
{
_rgButtonValues
[
buttonIndex
]
=
BUTTON_DOWN
;
_rgButtonValues
[
buttonIndex
]
=
BUTTON_DOWN
;
emit
rawButtonPressedChanged
(
buttonIndex
,
newButtonValue
);
emit
rawButtonPressedChanged
(
buttonIndex
,
newButtonValue
);
...
@@ -505,7 +508,7 @@ void Joystick::_handleButtons()
...
@@ -505,7 +508,7 @@ void Joystick::_handleButtons()
}
}
}
}
}
}
//-- Process button press
//-- Process button press
/release
for
(
int
buttonIndex
=
0
;
buttonIndex
<
_totalButtonCount
;
buttonIndex
++
)
{
for
(
int
buttonIndex
=
0
;
buttonIndex
<
_totalButtonCount
;
buttonIndex
++
)
{
if
(
_rgButtonValues
[
buttonIndex
]
==
BUTTON_DOWN
||
_rgButtonValues
[
buttonIndex
]
==
BUTTON_REPEAT
)
{
if
(
_rgButtonValues
[
buttonIndex
]
==
BUTTON_DOWN
||
_rgButtonValues
[
buttonIndex
]
==
BUTTON_REPEAT
)
{
if
(
_buttonActionArray
[
buttonIndex
])
{
if
(
_buttonActionArray
[
buttonIndex
])
{
...
@@ -517,7 +520,7 @@ void Joystick::_handleButtons()
...
@@ -517,7 +520,7 @@ void Joystick::_handleButtons()
//-- This button just went down
//-- This button just went down
if
(
_rgButtonValues
[
buttonIndex
]
==
BUTTON_DOWN
)
{
if
(
_rgButtonValues
[
buttonIndex
]
==
BUTTON_DOWN
)
{
qCDebug
(
JoystickLog
)
<<
"Single button triggered"
<<
buttonIndex
<<
buttonAction
;
qCDebug
(
JoystickLog
)
<<
"Single button triggered"
<<
buttonIndex
<<
buttonAction
;
_executeButtonAction
(
buttonAction
);
_executeButtonAction
(
buttonAction
,
true
);
}
}
}
else
{
}
else
{
//-- Process repeat buttons
//-- Process repeat buttons
...
@@ -525,12 +528,25 @@ void Joystick::_handleButtons()
...
@@ -525,12 +528,25 @@ void Joystick::_handleButtons()
if
(
_buttonActionArray
[
buttonIndex
]
->
buttonTime
.
elapsed
()
>
buttonDelay
)
{
if
(
_buttonActionArray
[
buttonIndex
]
->
buttonTime
.
elapsed
()
>
buttonDelay
)
{
_buttonActionArray
[
buttonIndex
]
->
buttonTime
.
start
();
_buttonActionArray
[
buttonIndex
]
->
buttonTime
.
start
();
qCDebug
(
JoystickLog
)
<<
"Repeat button triggered"
<<
buttonIndex
<<
buttonAction
;
qCDebug
(
JoystickLog
)
<<
"Repeat button triggered"
<<
buttonIndex
<<
buttonAction
;
_executeButtonAction
(
buttonAction
);
_executeButtonAction
(
buttonAction
,
true
);
}
}
}
}
}
}
//-- Flag it as processed
//-- Flag it as processed
_rgButtonValues
[
buttonIndex
]
=
BUTTON_REPEAT
;
_rgButtonValues
[
buttonIndex
]
=
BUTTON_REPEAT
;
}
else
if
(
_rgButtonValues
[
buttonIndex
]
==
BUTTON_UP
)
{
//-- Button up transition
if
(
buttonIndex
<
256
)
{
if
(
lastBbuttonValues
[
buttonIndex
]
==
BUTTON_DOWN
||
lastBbuttonValues
[
buttonIndex
]
==
BUTTON_REPEAT
)
{
if
(
_buttonActionArray
[
buttonIndex
])
{
QString
buttonAction
=
_buttonActionArray
[
buttonIndex
]
->
action
;
if
(
buttonAction
.
isEmpty
()
||
buttonAction
==
_buttonActionNone
)
continue
;
qCDebug
(
JoystickLog
)
<<
"Button up"
<<
buttonIndex
<<
buttonAction
;
_executeButtonAction
(
buttonAction
,
false
);
}
}
}
}
}
}
}
}
}
...
@@ -941,51 +957,57 @@ void Joystick::setCalibrationMode(bool calibrating)
...
@@ -941,51 +957,57 @@ void Joystick::setCalibrationMode(bool calibrating)
}
}
void
Joystick
::
_executeButtonAction
(
const
QString
&
action
)
void
Joystick
::
_executeButtonAction
(
const
QString
&
action
,
bool
buttonDown
)
{
{
if
(
!
_activeVehicle
||
!
_activeVehicle
->
joystickEnabled
()
||
action
==
_buttonActionNone
)
{
if
(
!
_activeVehicle
||
!
_activeVehicle
->
joystickEnabled
()
||
action
==
_buttonActionNone
)
{
return
;
return
;
}
}
if
(
action
==
_buttonActionArm
)
{
if
(
action
==
_buttonActionArm
)
{
emit
setArmed
(
true
);
if
(
buttonDown
)
emit
setArmed
(
true
);
}
else
if
(
action
==
_buttonActionDisarm
)
{
}
else
if
(
action
==
_buttonActionDisarm
)
{
emit
setArmed
(
false
);
if
(
buttonDown
)
emit
setArmed
(
false
);
}
else
if
(
action
==
_buttonActionToggleArm
)
{
}
else
if
(
action
==
_buttonActionToggleArm
)
{
emit
setArmed
(
!
_activeVehicle
->
armed
());
if
(
buttonDown
)
emit
setArmed
(
!
_activeVehicle
->
armed
());
}
else
if
(
action
==
_buttonActionVTOLFixedWing
)
{
}
else
if
(
action
==
_buttonActionVTOLFixedWing
)
{
emit
setVtolInFwdFlight
(
true
);
if
(
buttonDown
)
emit
setVtolInFwdFlight
(
true
);
}
else
if
(
action
==
_buttonActionVTOLMultiRotor
)
{
}
else
if
(
action
==
_buttonActionVTOLMultiRotor
)
{
emit
setVtolInFwdFlight
(
false
);
if
(
buttonDown
)
emit
setVtolInFwdFlight
(
false
);
}
else
if
(
_activeVehicle
->
flightModes
().
contains
(
action
))
{
}
else
if
(
_activeVehicle
->
flightModes
().
contains
(
action
))
{
emit
setFlightMode
(
action
);
if
(
buttonDown
)
emit
setFlightMode
(
action
);
}
else
if
(
action
==
_buttonActionContinuousZoomIn
||
action
==
_buttonActionContinuousZoomOut
)
{
}
else
if
(
action
==
_buttonActionContinuousZoomIn
||
action
==
_buttonActionContinuousZoomOut
)
{
emit
startContinuousZoom
(
action
==
_buttonActionStepZoomIn
?
1
:
-
1
);
if
(
buttonDown
)
{
emit
startContinuousZoom
(
action
==
_buttonActionContinuousZoomIn
?
1
:
-
1
);
}
else
{
emit
stopContinuousZoom
();
}
}
else
if
(
action
==
_buttonActionStepZoomIn
||
action
==
_buttonActionStepZoomOut
)
{
}
else
if
(
action
==
_buttonActionStepZoomIn
||
action
==
_buttonActionStepZoomOut
)
{
emit
stepZoom
(
action
==
_buttonActionStepZoomIn
?
1
:
-
1
);
if
(
buttonDown
)
emit
stepZoom
(
action
==
_buttonActionStepZoomIn
?
1
:
-
1
);
}
else
if
(
action
==
_buttonActionNextStream
||
action
==
_buttonActionPreviousStream
)
{
}
else
if
(
action
==
_buttonActionNextStream
||
action
==
_buttonActionPreviousStream
)
{
emit
stepStream
(
action
==
_buttonActionNextStream
?
1
:
-
1
);
if
(
buttonDown
)
emit
stepStream
(
action
==
_buttonActionNextStream
?
1
:
-
1
);
}
else
if
(
action
==
_buttonActionNextCamera
||
action
==
_buttonActionPreviousCamera
)
{
}
else
if
(
action
==
_buttonActionNextCamera
||
action
==
_buttonActionPreviousCamera
)
{
emit
stepCamera
(
action
==
_buttonActionNextCamera
?
1
:
-
1
);
if
(
buttonDown
)
emit
stepCamera
(
action
==
_buttonActionNextCamera
?
1
:
-
1
);
}
else
if
(
action
==
_buttonActionTriggerCamera
)
{
}
else
if
(
action
==
_buttonActionTriggerCamera
)
{
emit
triggerCamera
();
if
(
buttonDown
)
emit
triggerCamera
();
}
else
if
(
action
==
_buttonActionStartVideoRecord
)
{
}
else
if
(
action
==
_buttonActionStartVideoRecord
)
{
emit
startVideoRecord
();
if
(
buttonDown
)
emit
startVideoRecord
();
}
else
if
(
action
==
_buttonActionStopVideoRecord
)
{
}
else
if
(
action
==
_buttonActionStopVideoRecord
)
{
emit
stopVideoRecord
();
if
(
buttonDown
)
emit
stopVideoRecord
();
}
else
if
(
action
==
_buttonActionToggleVideoRecord
)
{
}
else
if
(
action
==
_buttonActionToggleVideoRecord
)
{
emit
toggleVideoRecord
();
if
(
buttonDown
)
emit
toggleVideoRecord
();
}
else
if
(
action
==
_buttonActionGimbalUp
)
{
}
else
if
(
action
==
_buttonActionGimbalUp
)
{
_pitchStep
(
1
);
if
(
buttonDown
)
_pitchStep
(
1
);
}
else
if
(
action
==
_buttonActionGimbalDown
)
{
}
else
if
(
action
==
_buttonActionGimbalDown
)
{
_pitchStep
(
-
1
);
if
(
buttonDown
)
_pitchStep
(
-
1
);
}
else
if
(
action
==
_buttonActionGimbalLeft
)
{
}
else
if
(
action
==
_buttonActionGimbalLeft
)
{
_yawStep
(
-
1
);
if
(
buttonDown
)
_yawStep
(
-
1
);
}
else
if
(
action
==
_buttonActionGimbalRight
)
{
}
else
if
(
action
==
_buttonActionGimbalRight
)
{
_yawStep
(
1
);
if
(
buttonDown
)
_yawStep
(
1
);
}
else
if
(
action
==
_buttonActionGimbalCenter
)
{
}
else
if
(
action
==
_buttonActionGimbalCenter
)
{
_localPitch
=
0.0
;
if
(
buttonDown
)
{
_localYaw
=
0.0
;
_localPitch
=
0.0
;
emit
gimbalControlValue
(
0.0
,
0.0
);
_localYaw
=
0.0
;
emit
gimbalControlValue
(
0.0
,
0.0
);
}
}
else
{
}
else
{
qCDebug
(
JoystickLog
)
<<
"_buttonAction unknown action:"
<<
action
;
qCDebug
(
JoystickLog
)
<<
"_buttonAction unknown action:"
<<
action
;
}
}
...
...
src/Joystick/Joystick.h
View file @
0720c373
...
@@ -225,7 +225,7 @@ protected:
...
@@ -225,7 +225,7 @@ protected:
void
_saveButtonSettings
();
void
_saveButtonSettings
();
void
_loadSettings
();
void
_loadSettings
();
float
_adjustRange
(
int
value
,
Calibration_t
calibration
,
bool
withDeadbands
);
float
_adjustRange
(
int
value
,
Calibration_t
calibration
,
bool
withDeadbands
);
void
_executeButtonAction
(
const
QString
&
action
);
void
_executeButtonAction
(
const
QString
&
action
,
bool
buttonDown
);
int
_findAssignableButtonAction
(
const
QString
&
action
);
int
_findAssignableButtonAction
(
const
QString
&
action
);
bool
_validAxis
(
int
axis
);
bool
_validAxis
(
int
axis
);
bool
_validButton
(
int
button
);
bool
_validButton
(
int
button
);
...
...
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