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
5e75d2d4
Commit
5e75d2d4
authored
Jul 30, 2019
by
Gus Grubba
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle Button Up state (Joystick)
parent
dee1314f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
26 deletions
+48
-26
Joystick.cc
src/Joystick/Joystick.cc
+47
-25
Joystick.h
src/Joystick/Joystick.h
+1
-1
No files found.
src/Joystick/Joystick.cc
View file @
5e75d2d4
...
...
@@ -477,9 +477,12 @@ void Joystick::run()
void
Joystick
::
_handleButtons
()
{
int
lastBbuttonValues
[
256
];
//-- Update button states
for
(
int
buttonIndex
=
0
;
buttonIndex
<
_buttonCount
;
buttonIndex
++
)
{
bool
newButtonValue
=
_getButton
(
buttonIndex
);
if
(
buttonIndex
<
256
)
lastBbuttonValues
[
buttonIndex
]
=
_rgButtonValues
[
buttonIndex
];
if
(
newButtonValue
&&
_rgButtonValues
[
buttonIndex
]
==
BUTTON_UP
)
{
_rgButtonValues
[
buttonIndex
]
=
BUTTON_DOWN
;
emit
rawButtonPressedChanged
(
buttonIndex
,
newButtonValue
);
...
...
@@ -505,7 +508,7 @@ void Joystick::_handleButtons()
}
}
}
//-- Process button press
//-- Process button press
/release
for
(
int
buttonIndex
=
0
;
buttonIndex
<
_totalButtonCount
;
buttonIndex
++
)
{
if
(
_rgButtonValues
[
buttonIndex
]
==
BUTTON_DOWN
||
_rgButtonValues
[
buttonIndex
]
==
BUTTON_REPEAT
)
{
if
(
_buttonActionArray
[
buttonIndex
])
{
...
...
@@ -517,7 +520,7 @@ void Joystick::_handleButtons()
//-- This button just went down
if
(
_rgButtonValues
[
buttonIndex
]
==
BUTTON_DOWN
)
{
qCDebug
(
JoystickLog
)
<<
"Single button triggered"
<<
buttonIndex
<<
buttonAction
;
_executeButtonAction
(
buttonAction
);
_executeButtonAction
(
buttonAction
,
true
);
}
}
else
{
//-- Process repeat buttons
...
...
@@ -525,12 +528,25 @@ void Joystick::_handleButtons()
if
(
_buttonActionArray
[
buttonIndex
]
->
buttonTime
.
elapsed
()
>
buttonDelay
)
{
_buttonActionArray
[
buttonIndex
]
->
buttonTime
.
start
();
qCDebug
(
JoystickLog
)
<<
"Repeat button triggered"
<<
buttonIndex
<<
buttonAction
;
_executeButtonAction
(
buttonAction
);
_executeButtonAction
(
buttonAction
,
true
);
}
}
}
//-- Flag it as processed
_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)
}
void
Joystick
::
_executeButtonAction
(
const
QString
&
action
)
void
Joystick
::
_executeButtonAction
(
const
QString
&
action
,
bool
buttonDown
)
{
if
(
!
_activeVehicle
||
!
_activeVehicle
->
joystickEnabled
()
||
action
==
_buttonActionNone
)
{
return
;
}
if
(
action
==
_buttonActionArm
)
{
emit
setArmed
(
true
);
if
(
buttonDown
)
emit
setArmed
(
true
);
}
else
if
(
action
==
_buttonActionDisarm
)
{
emit
setArmed
(
false
);
if
(
buttonDown
)
emit
setArmed
(
false
);
}
else
if
(
action
==
_buttonActionToggleArm
)
{
emit
setArmed
(
!
_activeVehicle
->
armed
());
if
(
buttonDown
)
emit
setArmed
(
!
_activeVehicle
->
armed
());
}
else
if
(
action
==
_buttonActionVTOLFixedWing
)
{
emit
setVtolInFwdFlight
(
true
);
if
(
buttonDown
)
emit
setVtolInFwdFlight
(
true
);
}
else
if
(
action
==
_buttonActionVTOLMultiRotor
)
{
emit
setVtolInFwdFlight
(
false
);
if
(
buttonDown
)
emit
setVtolInFwdFlight
(
false
);
}
else
if
(
_activeVehicle
->
flightModes
().
contains
(
action
))
{
emit
setFlightMode
(
action
);
if
(
buttonDown
)
emit
setFlightMode
(
action
);
}
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
)
{
emit
stepZoom
(
action
==
_buttonActionStepZoomIn
?
1
:
-
1
);
if
(
buttonDown
)
emit
stepZoom
(
action
==
_buttonActionStepZoomIn
?
1
:
-
1
);
}
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
)
{
emit
stepCamera
(
action
==
_buttonActionNextCamera
?
1
:
-
1
);
if
(
buttonDown
)
emit
stepCamera
(
action
==
_buttonActionNextCamera
?
1
:
-
1
);
}
else
if
(
action
==
_buttonActionTriggerCamera
)
{
emit
triggerCamera
();
if
(
buttonDown
)
emit
triggerCamera
();
}
else
if
(
action
==
_buttonActionStartVideoRecord
)
{
emit
startVideoRecord
();
if
(
buttonDown
)
emit
startVideoRecord
();
}
else
if
(
action
==
_buttonActionStopVideoRecord
)
{
emit
stopVideoRecord
();
if
(
buttonDown
)
emit
stopVideoRecord
();
}
else
if
(
action
==
_buttonActionToggleVideoRecord
)
{
emit
toggleVideoRecord
();
if
(
buttonDown
)
emit
toggleVideoRecord
();
}
else
if
(
action
==
_buttonActionGimbalUp
)
{
_pitchStep
(
1
);
if
(
buttonDown
)
_pitchStep
(
1
);
}
else
if
(
action
==
_buttonActionGimbalDown
)
{
_pitchStep
(
-
1
);
if
(
buttonDown
)
_pitchStep
(
-
1
);
}
else
if
(
action
==
_buttonActionGimbalLeft
)
{
_yawStep
(
-
1
);
if
(
buttonDown
)
_yawStep
(
-
1
);
}
else
if
(
action
==
_buttonActionGimbalRight
)
{
_yawStep
(
1
);
if
(
buttonDown
)
_yawStep
(
1
);
}
else
if
(
action
==
_buttonActionGimbalCenter
)
{
_localPitch
=
0.0
;
_localYaw
=
0.0
;
emit
gimbalControlValue
(
0.0
,
0.0
);
if
(
buttonDown
)
{
_localPitch
=
0.0
;
_localYaw
=
0.0
;
emit
gimbalControlValue
(
0.0
,
0.0
);
}
}
else
{
qCDebug
(
JoystickLog
)
<<
"_buttonAction unknown action:"
<<
action
;
}
...
...
src/Joystick/Joystick.h
View file @
5e75d2d4
...
...
@@ -225,7 +225,7 @@ protected:
void
_saveButtonSettings
();
void
_loadSettings
();
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
);
bool
_validAxis
(
int
axis
);
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