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
682da797
Commit
682da797
authored
May 27, 2016
by
Rustom Jehangir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Recognize joystick hats and append to the button list.
parent
276b19e4
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
17 deletions
+40
-17
Joystick.cc
src/Joystick/Joystick.cc
+27
-8
Joystick.h
src/Joystick/Joystick.h
+6
-3
JoystickManager.cc
src/Joystick/JoystickManager.cc
+4
-3
JoystickConfig.qml
src/VehicleSetup/JoystickConfig.qml
+3
-3
No files found.
src/Joystick/Joystick.cc
View file @
682da797
...
...
@@ -51,13 +51,16 @@ const char* Joystick::_rgFunctionSettingsKey[Joystick::maxFunction] = {
"ThrottleAxis"
};
Joystick
::
Joystick
(
const
QString
&
name
,
int
axisCount
,
int
buttonCount
,
int
sdlIndex
,
MultiVehicleManager
*
multiVehicleManager
)
Joystick
::
Joystick
(
const
QString
&
name
,
int
axisCount
,
int
buttonCount
,
int
hatCount
,
int
sdlIndex
,
MultiVehicleManager
*
multiVehicleManager
)
#ifndef __mobile__
:
_sdlIndex
(
sdlIndex
)
,
_exitThread
(
false
)
,
_name
(
name
)
,
_axisCount
(
axisCount
)
,
_buttonCount
(
buttonCount
)
,
_hatCount
(
hatCount
)
,
_hatButtonCount
(
4
*
hatCount
)
,
_totalButtonCount
(
_buttonCount
+
_hatButtonCount
)
,
_calibrationMode
(
CalibrationModeOff
)
,
_rgAxisValues
(
NULL
)
,
_rgCalibration
(
NULL
)
...
...
@@ -74,18 +77,19 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int sdlI
Q_UNUSED
(
name
)
Q_UNUSED
(
axisCount
)
Q_UNUSED
(
buttonCount
)
Q_UNUSED
(
hatCount
)
Q_UNUSED
(
sdlIndex
)
Q_UNUSED
(
multiVehicleManager
)
#else
_rgAxisValues
=
new
int
[
_axisCount
];
_rgCalibration
=
new
Calibration_t
[
_axisCount
];
_rgButtonValues
=
new
bool
[
_
b
uttonCount
];
_rgButtonActions
=
new
QString
[
_
b
uttonCount
];
_rgButtonValues
=
new
bool
[
_
totalB
uttonCount
];
_rgButtonActions
=
new
QString
[
_
totalB
uttonCount
];
for
(
int
i
=
0
;
i
<
_axisCount
;
i
++
)
{
_rgAxisValues
[
i
]
=
0
;
}
for
(
int
i
=
0
;
i
<
_
b
uttonCount
;
i
++
)
{
for
(
int
i
=
0
;
i
<
_
totalB
uttonCount
;
i
++
)
{
_rgButtonValues
[
i
]
=
false
;
}
...
...
@@ -284,6 +288,21 @@ void Joystick::run(void)
}
}
// Update hat - append hat buttons to the end of the normal button list
quint8
hatButtons
[]
=
{
SDL_HAT_UP
,
SDL_HAT_DOWN
,
SDL_HAT_LEFT
,
SDL_HAT_RIGHT
};
for
(
int
hatIndex
=
0
;
hatIndex
<
_hatCount
;
hatIndex
++
)
{
for
(
int
hatButtonIndex
=
0
;
hatButtonIndex
<
int
(
sizeof
(
hatButtons
));
hatButtonIndex
++
)
{
// Create new index value that includes the normal button list
int
rgButtonValueIndex
=
hatIndex
*
sizeof
(
hatButtons
)
+
hatButtonIndex
+
_buttonCount
;
// Get hat value from SDL - Only recognize the values in hatButtonMask
bool
newButtonValue
=
!!
(
SDL_JoystickGetHat
(
sdlJoystick
,
hatIndex
)
&
hatButtons
[
hatButtonIndex
]);
if
(
newButtonValue
!=
_rgButtonValues
[
rgButtonValueIndex
])
{
_rgButtonValues
[
rgButtonValueIndex
]
=
newButtonValue
;
emit
rawButtonPressedChanged
(
rgButtonValueIndex
,
newButtonValue
);
}
}
}
if
(
_calibrationMode
!=
CalibrationModeCalibrating
)
{
int
axis
=
_rgFunctionAxis
[
rollFunction
];
float
roll
=
_adjustRange
(
_rgAxisValues
[
axis
],
_rgCalibration
[
axis
]);
...
...
@@ -320,13 +339,13 @@ void Joystick::run(void)
// We only send the buttons the firmwware has reserved
int
reservedButtonCount
=
_activeVehicle
->
manualControlReservedButtonCount
();
if
(
reservedButtonCount
==
-
1
)
{
reservedButtonCount
=
_
b
uttonCount
;
reservedButtonCount
=
_
totalB
uttonCount
;
}
quint16
newButtonBits
=
0
;
// New set of button which are down
quint16
buttonPressedBits
=
0
;
// Buttons pressed for manualControl signal
for
(
int
buttonIndex
=
0
;
buttonIndex
<
_
b
uttonCount
;
buttonIndex
++
)
{
for
(
int
buttonIndex
=
0
;
buttonIndex
<
_
totalB
uttonCount
;
buttonIndex
++
)
{
quint16
buttonBit
=
1
<<
buttonIndex
;
if
(
!
_rgButtonValues
[
buttonIndex
])
{
...
...
@@ -576,7 +595,7 @@ bool Joystick::_validAxis(int axis)
bool
Joystick
::
_validButton
(
int
button
)
{
return
button
>=
0
&&
button
<
_
b
uttonCount
;
return
button
>=
0
&&
button
<
_
totalB
uttonCount
;
}
#endif // __mobile__
src/Joystick/Joystick.h
View file @
682da797
...
...
@@ -39,7 +39,7 @@ class Joystick : public QThread
Q_OBJECT
public:
Joystick
(
const
QString
&
name
,
int
axisCount
,
int
buttonCount
,
int
sdlIndex
,
MultiVehicleManager
*
multiVehicleManager
);
Joystick
(
const
QString
&
name
,
int
axisCount
,
int
buttonCount
,
int
hatCount
,
int
sdlIndex
,
MultiVehicleManager
*
multiVehicleManager
);
~
Joystick
();
typedef
struct
{
...
...
@@ -68,7 +68,7 @@ public:
Q_PROPERTY
(
bool
calibrated
MEMBER
_calibrated
NOTIFY
calibratedChanged
)
Q_PROPERTY
(
int
buttonCount
READ
b
uttonCount
CONSTANT
)
Q_PROPERTY
(
int
totalButtonCount
READ
totalB
uttonCount
CONSTANT
)
Q_PROPERTY
(
int
axisCount
READ
axisCount
CONSTANT
)
Q_PROPERTY
(
QStringList
actions
READ
actions
CONSTANT
)
...
...
@@ -82,7 +82,7 @@ public:
// Property accessors
int
axisCount
(
void
)
{
return
_axisCount
;
}
int
buttonCount
(
void
)
{
return
_b
uttonCount
;
}
int
totalButtonCount
(
void
)
{
return
_totalB
uttonCount
;
}
/// Start the polling thread which will in turn emit joystick signals
void
startPolling
(
Vehicle
*
vehicle
);
...
...
@@ -157,6 +157,9 @@ private:
bool
_calibrated
;
int
_axisCount
;
int
_buttonCount
;
int
_hatCount
;
int
_hatButtonCount
;
int
_totalButtonCount
;
CalibrationMode_t
_calibrationMode
;
...
...
src/Joystick/JoystickManager.cc
View file @
682da797
...
...
@@ -69,15 +69,16 @@ void JoystickManager::setToolbox(QGCToolbox *toolbox)
QString
name
=
SDL_JoystickName
(
i
);
if
(
!
_name2JoystickMap
.
contains
(
name
))
{
int
axisCount
,
buttonCount
;
int
axisCount
,
buttonCount
,
hatCount
;
SDL_Joystick
*
sdlJoystick
=
SDL_JoystickOpen
(
i
);
axisCount
=
SDL_JoystickNumAxes
(
sdlJoystick
);
buttonCount
=
SDL_JoystickNumButtons
(
sdlJoystick
);
hatCount
=
SDL_JoystickNumHats
(
sdlJoystick
);
SDL_JoystickClose
(
sdlJoystick
);
qCDebug
(
JoystickManagerLog
)
<<
"
\t
"
<<
name
<<
"axes:"
<<
axisCount
<<
"buttons:"
<<
buttonCount
;
_name2JoystickMap
[
name
]
=
new
Joystick
(
name
,
axisCount
,
buttonCount
,
i
,
_multiVehicleManager
);
qCDebug
(
JoystickManagerLog
)
<<
"
\t
"
<<
name
<<
"axes:"
<<
axisCount
<<
"buttons:"
<<
buttonCount
<<
"hats:"
<<
hatCount
;
_name2JoystickMap
[
name
]
=
new
Joystick
(
name
,
axisCount
,
buttonCount
,
hatCount
,
i
,
_multiVehicleManager
);
}
else
{
qCDebug
(
JoystickManagerLog
)
<<
"
\t
Skipping duplicate"
<<
name
;
}
...
...
src/VehicleSetup/JoystickConfig.qml
View file @
682da797
...
...
@@ -473,7 +473,7 @@ QGCView {
visible
:
_activeVehicle
.
manualControlReservedButtonCount
!=
0
text
:
qsTr
(
"
Buttons 0-%1 reserved for firmware use
"
).
arg
(
reservedButtonCount
)
property
int
reservedButtonCount
:
_activeVehicle
.
manualControlReservedButtonCount
==
-
1
?
_activeJoystick
.
b
uttonCount
:
_activeVehicle
.
manualControlReservedButtonCount
property
int
reservedButtonCount
:
_activeVehicle
.
manualControlReservedButtonCount
==
-
1
?
_activeJoystick
.
totalB
uttonCount
:
_activeVehicle
.
manualControlReservedButtonCount
}
Repeater
{
...
...
@@ -612,10 +612,10 @@ QGCView {
Repeater
{
id
:
buttonMonitorRepeater
model
:
_activeJoystick
.
b
uttonCount
model
:
_activeJoystick
.
totalB
uttonCount
Rectangle
{
width
:
ScreenTools
.
defaultFontPixelHeight
*
1.
5
width
:
ScreenTools
.
defaultFontPixelHeight
*
1.
2
height
:
width
border.width
:
1
border.color
:
qgcPal
.
text
...
...
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