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
6df76d4e
Commit
6df76d4e
authored
Jun 10, 2013
by
Bryant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The JoystickInput class now emits signals for both button press and button release events.
parent
6b2e1915
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
22 deletions
+24
-22
JoystickInput.cc
src/input/JoystickInput.cc
+15
-20
JoystickInput.h
src/input/JoystickInput.h
+9
-2
No files found.
src/input/JoystickInput.cc
View file @
6df76d4e
...
...
@@ -299,35 +299,29 @@ void JoystickInput::run()
// Send new values to rest of groundstation
emit
hatDirectionChanged
(
xHat
,
yHat
);
// Display all buttons
int
buttons
=
0
;
for
(
int
i
=
0
;
i
<
SDL_JoystickNumButtons
(
joystick
);
i
++
)
// Emit signals for each button individually
for
(
int
i
=
0
;
i
<
SDL_JoystickNumButtons
(
joystick
);
i
++
)
{
//qDebug() << "BUTTON" << i << "is: " << SDL_JoystickGetAxis(joystick, i);
if
(
SDL_JoystickGetButton
(
joystick
,
i
))
// If the button was down, but now it's up, trigger a buttonPressed event
quint16
lastButtonState
=
buttonState
&
(
1
<<
i
);
if
(
SDL_JoystickGetButton
(
joystick
,
i
)
&&
!
lastButtonState
)
{
emit
buttonPressed
(
i
);
buttons
|=
1
<<
i
;
// Check if button is a UAS select button
if
(
uasButtonList
.
contains
(
i
))
{
UASInterface
*
uas
=
UASManager
::
instance
()
->
getUASForId
(
i
);
if
(
uas
)
{
UASManager
::
instance
()
->
setActiveUAS
(
uas
);
}
}
buttonState
|=
1
<<
i
;
}
else
if
(
!
SDL_JoystickGetButton
(
joystick
,
i
)
&&
lastButtonState
)
{
emit
buttonReleased
(
i
);
buttonState
&=
~
(
1
<<
i
);
}
}
emit
joystickChanged
(
y
,
x
,
yaw
,
thrust
,
xHat
,
yHat
,
buttons
);
// Now signal an update for all UI together.
emit
joystickChanged
(
y
,
x
,
yaw
,
thrust
,
xHat
,
yHat
,
buttonState
);
// Sleep, update rate of joystick is approx. 50 Hz (1000 ms / 50 = 20 ms)
QGC
::
SLEEP
::
msleep
(
20
);
}
}
void
JoystickInput
::
setActiveJoystick
(
int
id
)
...
...
@@ -340,6 +334,7 @@ void JoystickInput::setActiveJoystick(int id)
joystickButtons
=
SDL_JoystickNumButtons
(
joystick
);
qDebug
()
<<
QString
(
"Switching to joystick '%1' with %2 buttons"
).
arg
(
joystickName
,
QString
::
number
(
joystickButtons
));
}
buttonState
=
0
;
}
const
QString
&
JoystickInput
::
getName
()
...
...
src/input/JoystickInput.h
View file @
6df76d4e
...
...
@@ -150,6 +150,7 @@ protected:
int
joystickButtons
;
int
joystickID
;
int
joysticksFound
;
quint16
buttonState
;
///< Track the state of the buttons so we can trigger on Up and Down events
void
init
();
...
...
@@ -196,12 +197,18 @@ signals:
void
yawChanged
(
int
yaw
);
/**
* @brief Joystick button has been pressed
*
* @brief Joystick button has changed state from unpressed to pressed.
* @param key index of the pressed key
*/
void
buttonPressed
(
int
key
);
/**
* @brief Joystick button has changed state from pressed to unpressed.
*
* @param key index of the released key
*/
void
buttonReleased
(
int
key
);
/**
* @brief Hat (8-way switch on the top) has changed position
*
...
...
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