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
7170ae4f
Commit
7170ae4f
authored
Oct 21, 2015
by
Lorenz Meier
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2068 from mavlink/Joystick
Joystick fix
parents
c2a3cd0b
7125c130
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
123 additions
and
72 deletions
+123
-72
Joystick.cc
src/Joystick/Joystick.cc
+36
-17
Joystick.h
src/Joystick/Joystick.h
+14
-9
JoystickConfig.qml
src/VehicleSetup/JoystickConfig.qml
+1
-2
JoystickConfigController.cc
src/VehicleSetup/JoystickConfigController.cc
+62
-29
JoystickConfigController.h
src/VehicleSetup/JoystickConfigController.h
+10
-15
No files found.
src/Joystick/Joystick.cc
View file @
7170ae4f
...
...
@@ -60,6 +60,10 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int sdlI
,
_axisCount
(
axisCount
)
,
_buttonCount
(
buttonCount
)
,
_calibrationMode
(
CalibrationModeOff
)
,
_rgAxisValues
(
NULL
)
,
_rgCalibration
(
NULL
)
,
_rgButtonValues
(
NULL
)
,
_rgButtonActions
(
NULL
)
,
_lastButtonBits
(
0
)
,
_throttleMode
(
ThrottleModeCenterZero
)
,
_activeVehicle
(
NULL
)
...
...
@@ -72,12 +76,16 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int sdlI
Q_UNUSED
(
buttonCount
)
Q_UNUSED
(
sdlIndex
)
#else
for
(
int
i
=
0
;
i
<
_cAxes
;
i
++
)
{
_rgAxisValues
=
new
int
[
_axisCount
];
_rgCalibration
=
new
Calibration_t
[
_axisCount
];
_rgButtonValues
=
new
bool
[
_buttonCount
];
_rgButtonActions
=
new
QString
[
_buttonCount
];
for
(
int
i
=
0
;
i
<
_axisCount
;
i
++
)
{
_rgAxisValues
[
i
]
=
0
;
}
for
(
int
i
=
0
;
i
<
_
cButtons
;
i
++
)
{
for
(
int
i
=
0
;
i
<
_
buttonCount
;
i
++
)
{
_rgButtonValues
[
i
]
=
false
;
_rgButtonActions
[
i
]
=
-
1
;
}
_loadSettings
();
...
...
@@ -86,7 +94,12 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int sdlI
Joystick
::~
Joystick
()
{
#ifndef __mobile__
delete
_rgAxisValues
;
delete
_rgCalibration
;
delete
_rgButtonValues
;
delete
_rgButtonActions
;
#endif
}
#ifndef __mobile__
...
...
@@ -115,7 +128,7 @@ void Joystick::_loadSettings(void)
QString
trimTpl
(
"Axis%1Trim"
);
QString
revTpl
(
"Axis%1Rev"
);
for
(
int
axis
=
0
;
axis
<
_
cAxes
;
axis
++
)
{
for
(
int
axis
=
0
;
axis
<
_
axisCount
;
axis
++
)
{
Calibration_t
*
calibration
=
&
_rgCalibration
[
axis
];
calibration
->
center
=
settings
.
value
(
trimTpl
.
arg
(
axis
),
0
).
toInt
(
&
convertOk
);
...
...
@@ -143,7 +156,7 @@ void Joystick::_loadSettings(void)
qCDebug
(
JoystickLog
)
<<
"_loadSettings function:axis:badsettings"
<<
function
<<
functionAxis
<<
badSettings
;
}
for
(
int
button
=
0
;
button
<
_
cButtons
;
button
++
)
{
for
(
int
button
=
0
;
button
<
_
buttonCount
;
button
++
)
{
_rgButtonActions
[
button
]
=
settings
.
value
(
QString
(
_buttonActionSettingsKey
).
arg
(
button
),
QString
()).
toString
();
qCDebug
(
JoystickLog
)
<<
"_loadSettings button:action"
<<
button
<<
_rgButtonActions
[
button
];
}
...
...
@@ -171,7 +184,7 @@ void Joystick::_saveSettings(void)
QString
trimTpl
(
"Axis%1Trim"
);
QString
revTpl
(
"Axis%1Rev"
);
for
(
int
axis
=
0
;
axis
<
_
cAxes
;
axis
++
)
{
for
(
int
axis
=
0
;
axis
<
_
axisCount
;
axis
++
)
{
Calibration_t
*
calibration
=
&
_rgCalibration
[
axis
];
settings
.
setValue
(
trimTpl
.
arg
(
axis
),
calibration
->
center
);
...
...
@@ -193,7 +206,7 @@ void Joystick::_saveSettings(void)
qCDebug
(
JoystickLog
)
<<
"_saveSettings name:function:axis"
<<
_name
<<
function
<<
_rgFunctionSettingsKey
[
function
];
}
for
(
int
button
=
0
;
button
<
_
cButtons
;
button
++
)
{
for
(
int
button
=
0
;
button
<
_
buttonCount
;
button
++
)
{
settings
.
setValue
(
QString
(
_buttonActionSettingsKey
).
arg
(
button
),
_rgButtonActions
[
button
]);
qCDebug
(
JoystickLog
)
<<
"_saveSettings button:action"
<<
button
<<
_rgButtonActions
[
button
];
}
...
...
@@ -278,10 +291,6 @@ void Joystick::run(void)
float
pitch
=
_adjustRange
(
_rgAxisValues
[
axis
],
_rgCalibration
[
axis
]);
axis
=
_rgFunctionAxis
[
yawFunction
];
_rgCalibration
[
axis
].
min
=
-
32768
;
_rgCalibration
[
axis
].
max
=
32767
;
_rgCalibration
[
axis
].
center
=
0
;
_rgCalibration
[
axis
].
reversed
=
false
;
float
yaw
=
_adjustRange
(
_rgAxisValues
[
axis
],
_rgCalibration
[
axis
]);
axis
=
_rgFunctionAxis
[
throttleFunction
];
...
...
@@ -398,7 +407,7 @@ void Joystick::stopPolling(void)
void
Joystick
::
setCalibration
(
int
axis
,
Calibration_t
&
calibration
)
{
if
(
axis
<
0
||
axis
>
_cAxes
)
{
if
(
!
_validAxis
(
axis
)
)
{
qCWarning
(
JoystickLog
)
<<
"Invalid axis index"
<<
axis
;
return
;
}
...
...
@@ -411,7 +420,7 @@ void Joystick::setCalibration(int axis, Calibration_t& calibration)
Joystick
::
Calibration_t
Joystick
::
getCalibration
(
int
axis
)
{
if
(
axis
<
0
||
axis
>
_cAxes
)
{
if
(
!
_validAxis
(
axis
)
)
{
qCWarning
(
JoystickLog
)
<<
"Invalid axis index"
<<
axis
;
}
...
...
@@ -420,7 +429,7 @@ Joystick::Calibration_t Joystick::getCalibration(int axis)
void
Joystick
::
setFunctionAxis
(
AxisFunction_t
function
,
int
axis
)
{
if
(
axis
<
0
||
axis
>
_cAxes
)
{
if
(
!
_validAxis
(
axis
)
)
{
qCWarning
(
JoystickLog
)
<<
"Invalid axis index"
<<
axis
;
return
;
}
...
...
@@ -451,7 +460,7 @@ QStringList Joystick::actions(void)
void
Joystick
::
setButtonAction
(
int
button
,
const
QString
&
action
)
{
if
(
button
<
0
||
button
>
_cButtons
)
{
if
(
!
_validButton
(
button
)
)
{
qCWarning
(
JoystickLog
)
<<
"Invalid button index"
<<
button
;
return
;
}
...
...
@@ -465,7 +474,7 @@ void Joystick::setButtonAction(int button, const QString& action)
QString
Joystick
::
getButtonAction
(
int
button
)
{
if
(
button
<
0
||
button
>
_cButtons
)
{
if
(
!
_validButton
(
button
)
)
{
qCWarning
(
JoystickLog
)
<<
"Invalid button index"
<<
button
;
}
...
...
@@ -543,4 +552,14 @@ void Joystick::_buttonAction(const QString& action)
}
}
bool
Joystick
::
_validAxis
(
int
axis
)
{
return
axis
>=
0
&&
axis
<
_axisCount
;
}
bool
Joystick
::
_validButton
(
int
button
)
{
return
button
>=
0
&&
button
<
_buttonCount
;
}
#endif // __mobile__
src/Joystick/Joystick.h
View file @
7170ae4f
...
...
@@ -67,8 +67,8 @@ public:
Q_PROPERTY
(
bool
calibrated
MEMBER
_calibrated
NOTIFY
calibratedChanged
)
Q_PROPERTY
(
int
buttonCount
MEMBER
_buttonCount
CONSTANT
)
Q_PROPERTY
(
int
axisCount
MEMBER
_axisCount
CONSTANT
)
Q_PROPERTY
(
int
buttonCount
READ
buttonCount
CONSTANT
)
Q_PROPERTY
(
int
axisCount
READ
axisCount
CONSTANT
)
Q_PROPERTY
(
QStringList
actions
READ
actions
CONSTANT
)
...
...
@@ -77,6 +77,11 @@ public:
Q_INVOKABLE
QString
getButtonAction
(
int
button
);
Q_PROPERTY
(
int
throttleMode
READ
throttleMode
WRITE
setThrottleMode
NOTIFY
throttleModeChanged
)
// Property accessors
int
axisCount
(
void
)
{
return
_axisCount
;
}
int
buttonCount
(
void
)
{
return
_buttonCount
;
}
/// Start the polling thread which will in turn emit joystick signals
void
startPolling
(
Vehicle
*
vehicle
);
...
...
@@ -136,7 +141,9 @@ private:
void
_loadSettings
(
void
);
float
_adjustRange
(
int
value
,
Calibration_t
calibration
);
void
_buttonAction
(
const
QString
&
action
);
bool
_validAxis
(
int
axis
);
bool
_validButton
(
int
button
);
// Override from QThread
virtual
void
run
(
void
);
...
...
@@ -152,14 +159,12 @@ private:
CalibrationMode_t
_calibrationMode
;
static
const
int
_cAxes
=
4
;
int
_rgAxisValues
[
_cAxes
];
Calibration_t
_rgCalibration
[
_cAxes
];
int
*
_rgAxisValues
;
Calibration_t
*
_rgCalibration
;
int
_rgFunctionAxis
[
maxFunction
];
static
const
int
_cButtons
=
12
;
bool
_rgButtonValues
[
_cButtons
];
QString
_rgButtonActions
[
_cButtons
];
bool
*
_rgButtonValues
;
QString
*
_rgButtonActions
;
quint16
_lastButtonBits
;
ThrottleMode_t
_throttleMode
;
...
...
src/VehicleSetup/JoystickConfig.qml
View file @
7170ae4f
...
...
@@ -67,7 +67,6 @@ QGCView {
if
(
controllerCompleted
)
{
controllerAndViewReady
=
true
controller
.
start
()
updateAxisCount
()
}
}
...
...
@@ -564,7 +563,7 @@ QGCView {
Repeater
{
id
:
axisMonitorRepeater
model
:
controller
.
axisCount
model
:
_activeJoystick
.
axisCount
width
:
parent
.
width
Row
{
...
...
src/VehicleSetup/JoystickConfigController.cc
View file @
7170ae4f
This diff is collapsed.
Click to expand it.
src/VehicleSetup/JoystickConfigController.h
View file @
7170ae4f
...
...
@@ -54,9 +54,6 @@ public:
JoystickConfigController
(
void
);
~
JoystickConfigController
();
Q_PROPERTY
(
int
minAxisCount
MEMBER
_axisMinimum
CONSTANT
)
Q_PROPERTY
(
int
axisCount
READ
axisCount
NOTIFY
axisCountChanged
)
Q_PROPERTY
(
QQuickItem
*
statusText
MEMBER
_statusText
)
Q_PROPERTY
(
QQuickItem
*
cancelButton
MEMBER
_cancelButton
)
Q_PROPERTY
(
QQuickItem
*
nextButton
MEMBER
_nextButton
)
...
...
@@ -102,7 +99,6 @@ public:
int
axisCount
(
void
);
signals:
void
axisCountChanged
(
int
axisCount
);
void
axisValueChanged
(
int
axis
,
int
value
);
void
rollAxisMappedChanged
(
bool
mapped
);
...
...
@@ -171,6 +167,8 @@ private:
void
_advanceState
(
void
);
void
_setupCurrentState
(
void
);
bool
_validAxis
(
int
axis
);
void
_inputCenterWaitBegin
(
Joystick
::
AxisFunction_t
function
,
int
axis
,
int
value
);
void
_inputStickDetect
(
Joystick
::
AxisFunction_t
function
,
int
axis
,
int
value
);
void
_inputStickMin
(
Joystick
::
AxisFunction_t
function
,
int
axis
,
int
value
);
...
...
@@ -219,12 +217,13 @@ private:
static
const
int
_attitudeControls
=
5
;
int
_axisCount
;
///< Number of actual joystick axes available
static
const
int
_axisMax
=
4
;
///< Maximum number of supported joystick axes
static
const
int
_axisMinimum
=
4
;
///< Minimum numner of joystick axes required to run PX4
struct
AxisInfo
_rgAxisInfo
[
_axisMax
];
///< Information associated with each axis
int
_axisCount
;
///< Number of actual joystick axes available
static
const
int
_axisNoAxis
=
-
1
;
///< Signals no axis set
static
const
int
_axisMinimum
=
4
;
///< Minimum numner of joystick axes required to run PX4
struct
AxisInfo
*
_rgAxisInfo
;
///< Information associated with each axis
int
*
_axisValueSave
;
///< Saved values prior to detecting axis movement
int
*
_axisRawValue
;
///< Current set of raw axis values
enum
calStates
_calState
;
///< Current calibration state
int
_calStateCurrentAxis
;
///< Current axis being worked on in calStateIdentify and calStateDetectInversion
bool
_calStateAxisComplete
;
///< Work associated with current axis is complete
...
...
@@ -239,11 +238,7 @@ private:
static
const
int
_calRoughCenterDelta
;
static
const
int
_calMoveDelta
;
static
const
int
_calSettleDelta
;
static
const
int
_calMinDelta
;
int
_axisValueSave
[
_axisMax
];
///< Saved values prior to detecting axis movement
int
_axisRawValue
[
_axisMax
];
///< Current set of raw axis values
static
const
int
_calMinDelta
;
int
_stickDetectAxis
;
int
_stickDetectInitialValue
;
...
...
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