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
431180fd
Commit
431180fd
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
7b8f0a14
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
20 deletions
+55
-20
Joystick.cc
src/Joystick/Joystick.cc
+27
-8
Joystick.h
src/Joystick/Joystick.h
+8
-3
JoystickSDL.cc
src/Joystick/JoystickSDL.cc
+15
-5
JoystickSDL.h
src/Joystick/JoystickSDL.h
+2
-1
JoystickConfig.qml
src/VehicleSetup/JoystickConfig.qml
+3
-3
No files found.
src/Joystick/Joystick.cc
View file @
431180fd
...
...
@@ -30,11 +30,14 @@ const char* Joystick::_rgFunctionSettingsKey[Joystick::maxFunction] = {
"ThrottleAxis"
};
Joystick
::
Joystick
(
const
QString
&
name
,
int
axisCount
,
int
buttonCount
,
MultiVehicleManager
*
multiVehicleManager
)
Joystick
::
Joystick
(
const
QString
&
name
,
int
axisCount
,
int
buttonCount
,
int
hatCount
,
MultiVehicleManager
*
multiVehicleManager
)
:
_exitThread
(
false
)
,
_name
(
name
)
,
_axisCount
(
axisCount
)
,
_buttonCount
(
buttonCount
)
,
_hatCount
(
hatCount
)
,
_hatButtonCount
(
4
*
hatCount
)
,
_totalButtonCount
(
_buttonCount
+
_hatButtonCount
)
,
_calibrationMode
(
CalibrationModeOff
)
,
_rgAxisValues
(
NULL
)
,
_rgCalibration
(
NULL
)
...
...
@@ -46,15 +49,16 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, MultiVeh
,
_pollingStartedForCalibration
(
false
)
,
_multiVehicleManager
(
multiVehicleManager
)
{
_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
;
}
...
...
@@ -242,6 +246,21 @@ void Joystick::run(void)
emit
rawButtonPressedChanged
(
buttonIndex
,
newButtonValue
);
}
}
// Update hat - append hat buttons to the end of the normal button list
int
numHatButtons
=
4
;
for
(
int
hatIndex
=
0
;
hatIndex
<
_hatCount
;
hatIndex
++
)
{
for
(
int
hatButtonIndex
=
0
;
hatButtonIndex
<
numHatButtons
;
hatButtonIndex
++
)
{
// Create new index value that includes the normal button list
int
rgButtonValueIndex
=
hatIndex
*
numHatButtons
+
hatButtonIndex
+
_buttonCount
;
// Get hat value from joystick
bool
newButtonValue
=
_getHat
(
hatIndex
,
hatButtonIndex
);
if
(
newButtonValue
!=
_rgButtonValues
[
rgButtonValueIndex
])
{
_rgButtonValues
[
rgButtonValueIndex
]
=
newButtonValue
;
emit
rawButtonPressedChanged
(
rgButtonValueIndex
,
newButtonValue
);
}
}
}
if
(
_calibrationMode
!=
CalibrationModeCalibrating
)
{
int
axis
=
_rgFunctionAxis
[
rollFunction
];
...
...
@@ -279,13 +298,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
])
{
...
...
@@ -313,7 +332,7 @@ void Joystick::run(void)
_lastButtonBits
=
newButtonBits
;
qCDebug
(
JoystickValuesLog
)
<<
"name:roll:pitch:yaw:throttle"
<<
name
()
<<
roll
<<
-
pitch
<<
yaw
<<
throttle
;
emit
manualControl
(
roll
,
-
pitch
,
yaw
,
throttle
,
buttonPressedBits
,
_activeVehicle
->
joystickMode
());
}
...
...
@@ -535,6 +554,6 @@ bool Joystick::_validAxis(int axis)
bool
Joystick
::
_validButton
(
int
button
)
{
return
button
>=
0
&&
button
<
_
b
uttonCount
;
return
button
>=
0
&&
button
<
_
totalB
uttonCount
;
}
src/Joystick/Joystick.h
View file @
431180fd
...
...
@@ -26,7 +26,8 @@ class Joystick : public QThread
Q_OBJECT
public:
Joystick
(
const
QString
&
name
,
int
axisCount
,
int
buttonCount
,
MultiVehicleManager
*
multiVehicleManager
);
Joystick
(
const
QString
&
name
,
int
axisCount
,
int
buttonCount
,
int
hatCount
,
MultiVehicleManager
*
multiVehicleManager
);
~
Joystick
();
typedef
struct
{
...
...
@@ -54,7 +55,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
)
...
...
@@ -68,7 +69,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
);
...
...
@@ -138,6 +139,7 @@ private:
virtual
bool
_getButton
(
int
i
)
=
0
;
virtual
int
_getAxis
(
int
i
)
=
0
;
virtual
uint8_t
_getHat
(
int
hat
,
int
i
)
=
0
;
// Override from QThread
virtual
void
run
(
void
);
...
...
@@ -150,6 +152,9 @@ protected:
bool
_calibrated
;
int
_axisCount
;
int
_buttonCount
;
int
_hatCount
;
int
_hatButtonCount
;
int
_totalButtonCount
;
CalibrationMode_t
_calibrationMode
;
...
...
src/Joystick/JoystickSDL.cc
View file @
431180fd
...
...
@@ -4,8 +4,8 @@
#include <QQmlEngine>
JoystickSDL
::
JoystickSDL
(
const
QString
&
name
,
int
axisCount
,
int
buttonCount
,
int
index
,
MultiVehicleManager
*
multiVehicleManager
)
:
Joystick
(
name
,
axisCount
,
buttonCount
,
multiVehicleManager
)
JoystickSDL
::
JoystickSDL
(
const
QString
&
name
,
int
axisCount
,
int
buttonCount
,
int
hatCount
,
int
index
,
MultiVehicleManager
*
multiVehicleManager
)
:
Joystick
(
name
,
axisCount
,
buttonCount
,
hatCount
,
multiVehicleManager
)
,
_index
(
index
)
{
}
...
...
@@ -26,15 +26,16 @@ QMap<QString, Joystick*> JoystickSDL::discover(MultiVehicleManager* _multiVehicl
QString
name
=
SDL_JoystickName
(
i
);
if
(
!
ret
.
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
(
JoystickLog
)
<<
"
\t
"
<<
name
<<
"axes:"
<<
axisCount
<<
"buttons:"
<<
buttonCount
;
ret
[
name
]
=
new
JoystickSDL
(
name
,
axisCount
,
buttonCount
,
i
,
_multiVehicleManager
);
qCDebug
(
JoystickLog
)
<<
"
\t
"
<<
name
<<
"axes:"
<<
axisCount
<<
"buttons:"
<<
buttonCount
<<
"hats:"
<<
hatCount
;
ret
[
name
]
=
new
JoystickSDL
(
name
,
axisCount
,
buttonCount
,
hatCount
,
i
,
_multiVehicleManager
);
}
else
{
qCDebug
(
JoystickLog
)
<<
"
\t
Skipping duplicate"
<<
name
;
}
...
...
@@ -71,3 +72,12 @@ int JoystickSDL::_getAxis(int i) {
return
SDL_JoystickGetAxis
(
sdlJoystick
,
i
);
}
uint8_t
JoystickSDL
::
_getHat
(
int
hat
,
int
i
)
{
uint8_t
hatButtons
[]
=
{
SDL_HAT_UP
,
SDL_HAT_DOWN
,
SDL_HAT_LEFT
,
SDL_HAT_RIGHT
};
if
(
i
<
int
(
sizeof
(
hatButtons
))
)
{
return
!!
(
SDL_JoystickGetHat
(
sdlJoystick
,
hat
)
&
hatButtons
[
i
]);
}
return
0
;
}
src/Joystick/JoystickSDL.h
View file @
431180fd
...
...
@@ -15,7 +15,7 @@
class
JoystickSDL
:
public
Joystick
{
public:
JoystickSDL
(
const
QString
&
name
,
int
axisCount
,
int
buttonCount
,
int
index
,
MultiVehicleManager
*
multiVehicleManager
);
JoystickSDL
(
const
QString
&
name
,
int
axisCount
,
int
buttonCount
,
int
hatCount
,
int
index
,
MultiVehicleManager
*
multiVehicleManager
);
static
QMap
<
QString
,
Joystick
*>
discover
(
MultiVehicleManager
*
_multiVehicleManager
);
...
...
@@ -26,6 +26,7 @@ private:
bool
_getButton
(
int
i
)
final
;
int
_getAxis
(
int
i
)
final
;
uint8_t
_getHat
(
int
hat
,
int
i
)
final
;
SDL_Joystick
*
sdlJoystick
;
int
_index
;
///< Index for SDL_JoystickOpen
...
...
src/VehicleSetup/JoystickConfig.qml
View file @
431180fd
...
...
@@ -460,7 +460,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
{
...
...
@@ -599,10 +599,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