Unverified Commit 0720c373 authored by Gus Grubba's avatar Gus Grubba Committed by GitHub

Merge pull request #7647 from mavlink/joystickButtonState

Joystick button state
parents acfd001f ce588588
...@@ -379,6 +379,8 @@ QGCCameraManager::_activeJoystickChanged(Joystick* joystick) ...@@ -379,6 +379,8 @@ QGCCameraManager::_activeJoystickChanged(Joystick* joystick)
qCDebug(CameraManagerLog) << "Joystick changed"; qCDebug(CameraManagerLog) << "Joystick changed";
if(_activeJoystick) { if(_activeJoystick) {
disconnect(_activeJoystick, &Joystick::stepZoom, this, &QGCCameraManager::_stepZoom); disconnect(_activeJoystick, &Joystick::stepZoom, this, &QGCCameraManager::_stepZoom);
disconnect(_activeJoystick, &Joystick::startContinuousZoom, this, &QGCCameraManager::_startZoom);
disconnect(_activeJoystick, &Joystick::stopContinuousZoom, this, &QGCCameraManager::_stopZoom);
disconnect(_activeJoystick, &Joystick::stepCamera, this, &QGCCameraManager::_stepCamera); disconnect(_activeJoystick, &Joystick::stepCamera, this, &QGCCameraManager::_stepCamera);
disconnect(_activeJoystick, &Joystick::stepStream, this, &QGCCameraManager::_stepStream); disconnect(_activeJoystick, &Joystick::stepStream, this, &QGCCameraManager::_stepStream);
disconnect(_activeJoystick, &Joystick::triggerCamera, this, &QGCCameraManager::_triggerCamera); disconnect(_activeJoystick, &Joystick::triggerCamera, this, &QGCCameraManager::_triggerCamera);
...@@ -388,13 +390,15 @@ QGCCameraManager::_activeJoystickChanged(Joystick* joystick) ...@@ -388,13 +390,15 @@ QGCCameraManager::_activeJoystickChanged(Joystick* joystick)
} }
_activeJoystick = joystick; _activeJoystick = joystick;
if(_activeJoystick) { if(_activeJoystick) {
connect(_activeJoystick, &Joystick::stepZoom, this, &QGCCameraManager::_stepZoom); connect(_activeJoystick, &Joystick::stepZoom, this, &QGCCameraManager::_stepZoom);
connect(_activeJoystick, &Joystick::stepCamera, this, &QGCCameraManager::_stepCamera); connect(_activeJoystick, &Joystick::startContinuousZoom, this, &QGCCameraManager::_startZoom);
connect(_activeJoystick, &Joystick::stepStream, this, &QGCCameraManager::_stepStream); connect(_activeJoystick, &Joystick::stopContinuousZoom, this, &QGCCameraManager::_stopZoom);
connect(_activeJoystick, &Joystick::triggerCamera, this, &QGCCameraManager::_triggerCamera); connect(_activeJoystick, &Joystick::stepCamera, this, &QGCCameraManager::_stepCamera);
connect(_activeJoystick, &Joystick::startVideoRecord, this, &QGCCameraManager::_startVideoRecording); connect(_activeJoystick, &Joystick::stepStream, this, &QGCCameraManager::_stepStream);
connect(_activeJoystick, &Joystick::stopVideoRecord, this, &QGCCameraManager::_stopVideoRecording); connect(_activeJoystick, &Joystick::triggerCamera, this, &QGCCameraManager::_triggerCamera);
connect(_activeJoystick, &Joystick::toggleVideoRecord, this, &QGCCameraManager::_toggleVideoRecording); connect(_activeJoystick, &Joystick::startVideoRecord, this, &QGCCameraManager::_startVideoRecording);
connect(_activeJoystick, &Joystick::stopVideoRecord, this, &QGCCameraManager::_stopVideoRecording);
connect(_activeJoystick, &Joystick::toggleVideoRecord, this, &QGCCameraManager::_toggleVideoRecording);
} }
} }
...@@ -442,7 +446,7 @@ QGCCameraManager::_toggleVideoRecording() ...@@ -442,7 +446,7 @@ QGCCameraManager::_toggleVideoRecording()
void void
QGCCameraManager::_stepZoom(int direction) QGCCameraManager::_stepZoom(int direction)
{ {
if(_lastZoomChange.elapsed() > 250) { if(_lastZoomChange.elapsed() > 40) {
_lastZoomChange.start(); _lastZoomChange.start();
qCDebug(CameraManagerLog) << "Step Camera Zoom" << direction; qCDebug(CameraManagerLog) << "Step Camera Zoom" << direction;
QGCCameraControl* pCamera = currentCameraInstance(); QGCCameraControl* pCamera = currentCameraInstance();
...@@ -452,6 +456,28 @@ QGCCameraManager::_stepZoom(int direction) ...@@ -452,6 +456,28 @@ QGCCameraManager::_stepZoom(int direction)
} }
} }
//-----------------------------------------------------------------------------
void
QGCCameraManager::_startZoom(int direction)
{
qCDebug(CameraManagerLog) << "Start Camera Zoom" << direction;
QGCCameraControl* pCamera = currentCameraInstance();
if(pCamera) {
pCamera->startZoom(direction);
}
}
//-----------------------------------------------------------------------------
void
QGCCameraManager::_stopZoom()
{
qCDebug(CameraManagerLog) << "Stop Camera Zoom";
QGCCameraControl* pCamera = currentCameraInstance();
if(pCamera) {
pCamera->stopZoom();
}
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
QGCCameraManager::_stepCamera(int direction) QGCCameraManager::_stepCamera(int direction)
......
...@@ -57,6 +57,8 @@ protected slots: ...@@ -57,6 +57,8 @@ protected slots:
virtual void _mavlinkMessageReceived (const mavlink_message_t& message); virtual void _mavlinkMessageReceived (const mavlink_message_t& message);
virtual void _activeJoystickChanged (Joystick* joystick); virtual void _activeJoystickChanged (Joystick* joystick);
virtual void _stepZoom (int direction); virtual void _stepZoom (int direction);
virtual void _startZoom (int direction);
virtual void _stopZoom ();
virtual void _stepCamera (int direction); virtual void _stepCamera (int direction);
virtual void _stepStream (int direction); virtual void _stepStream (int direction);
virtual void _cameraTimeout (); virtual void _cameraTimeout ();
......
...@@ -477,9 +477,12 @@ void Joystick::run() ...@@ -477,9 +477,12 @@ void Joystick::run()
void Joystick::_handleButtons() void Joystick::_handleButtons()
{ {
int lastBbuttonValues[256];
//-- Update button states //-- Update button states
for (int buttonIndex = 0; buttonIndex < _buttonCount; buttonIndex++) { for (int buttonIndex = 0; buttonIndex < _buttonCount; buttonIndex++) {
bool newButtonValue = _getButton(buttonIndex); bool newButtonValue = _getButton(buttonIndex);
if(buttonIndex < 256)
lastBbuttonValues[buttonIndex] = _rgButtonValues[buttonIndex];
if (newButtonValue && _rgButtonValues[buttonIndex] == BUTTON_UP) { if (newButtonValue && _rgButtonValues[buttonIndex] == BUTTON_UP) {
_rgButtonValues[buttonIndex] = BUTTON_DOWN; _rgButtonValues[buttonIndex] = BUTTON_DOWN;
emit rawButtonPressedChanged(buttonIndex, newButtonValue); emit rawButtonPressedChanged(buttonIndex, newButtonValue);
...@@ -505,7 +508,7 @@ void Joystick::_handleButtons() ...@@ -505,7 +508,7 @@ void Joystick::_handleButtons()
} }
} }
} }
//-- Process button press //-- Process button press/release
for (int buttonIndex = 0; buttonIndex < _totalButtonCount; buttonIndex++) { for (int buttonIndex = 0; buttonIndex < _totalButtonCount; buttonIndex++) {
if(_rgButtonValues[buttonIndex] == BUTTON_DOWN || _rgButtonValues[buttonIndex] == BUTTON_REPEAT) { if(_rgButtonValues[buttonIndex] == BUTTON_DOWN || _rgButtonValues[buttonIndex] == BUTTON_REPEAT) {
if(_buttonActionArray[buttonIndex]) { if(_buttonActionArray[buttonIndex]) {
...@@ -517,7 +520,7 @@ void Joystick::_handleButtons() ...@@ -517,7 +520,7 @@ void Joystick::_handleButtons()
//-- This button just went down //-- This button just went down
if(_rgButtonValues[buttonIndex] == BUTTON_DOWN) { if(_rgButtonValues[buttonIndex] == BUTTON_DOWN) {
qCDebug(JoystickLog) << "Single button triggered" << buttonIndex << buttonAction; qCDebug(JoystickLog) << "Single button triggered" << buttonIndex << buttonAction;
_executeButtonAction(buttonAction); _executeButtonAction(buttonAction, true);
} }
} else { } else {
//-- Process repeat buttons //-- Process repeat buttons
...@@ -525,12 +528,25 @@ void Joystick::_handleButtons() ...@@ -525,12 +528,25 @@ void Joystick::_handleButtons()
if(_buttonActionArray[buttonIndex]->buttonTime.elapsed() > buttonDelay) { if(_buttonActionArray[buttonIndex]->buttonTime.elapsed() > buttonDelay) {
_buttonActionArray[buttonIndex]->buttonTime.start(); _buttonActionArray[buttonIndex]->buttonTime.start();
qCDebug(JoystickLog) << "Repeat button triggered" << buttonIndex << buttonAction; qCDebug(JoystickLog) << "Repeat button triggered" << buttonIndex << buttonAction;
_executeButtonAction(buttonAction); _executeButtonAction(buttonAction, true);
} }
} }
} }
//-- Flag it as processed //-- Flag it as processed
_rgButtonValues[buttonIndex] = BUTTON_REPEAT; _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) ...@@ -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) { if (!_activeVehicle || !_activeVehicle->joystickEnabled() || action == _buttonActionNone) {
return; return;
} }
if (action == _buttonActionArm) { if (action == _buttonActionArm) {
emit setArmed(true); if (buttonDown) emit setArmed(true);
} else if (action == _buttonActionDisarm) { } else if (action == _buttonActionDisarm) {
emit setArmed(false); if (buttonDown) emit setArmed(false);
} else if (action == _buttonActionToggleArm) { } else if (action == _buttonActionToggleArm) {
emit setArmed(!_activeVehicle->armed()); if (buttonDown) emit setArmed(!_activeVehicle->armed());
} else if (action == _buttonActionVTOLFixedWing) { } else if (action == _buttonActionVTOLFixedWing) {
emit setVtolInFwdFlight(true); if (buttonDown) emit setVtolInFwdFlight(true);
} else if (action == _buttonActionVTOLMultiRotor) { } else if (action == _buttonActionVTOLMultiRotor) {
emit setVtolInFwdFlight(false); if (buttonDown) emit setVtolInFwdFlight(false);
} else if (_activeVehicle->flightModes().contains(action)) { } else if (_activeVehicle->flightModes().contains(action)) {
emit setFlightMode(action); if (buttonDown) emit setFlightMode(action);
} else if(action == _buttonActionContinuousZoomIn || action == _buttonActionContinuousZoomOut) { } 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) { } 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) { } 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) { } else if(action == _buttonActionNextCamera || action == _buttonActionPreviousCamera) {
emit stepCamera(action == _buttonActionNextCamera ? 1 : -1); if (buttonDown) emit stepCamera(action == _buttonActionNextCamera ? 1 : -1);
} else if(action == _buttonActionTriggerCamera) { } else if(action == _buttonActionTriggerCamera) {
emit triggerCamera(); if (buttonDown) emit triggerCamera();
} else if(action == _buttonActionStartVideoRecord) { } else if(action == _buttonActionStartVideoRecord) {
emit startVideoRecord(); if (buttonDown) emit startVideoRecord();
} else if(action == _buttonActionStopVideoRecord) { } else if(action == _buttonActionStopVideoRecord) {
emit stopVideoRecord(); if (buttonDown) emit stopVideoRecord();
} else if(action == _buttonActionToggleVideoRecord) { } else if(action == _buttonActionToggleVideoRecord) {
emit toggleVideoRecord(); if (buttonDown) emit toggleVideoRecord();
} else if(action == _buttonActionGimbalUp) { } else if(action == _buttonActionGimbalUp) {
_pitchStep(1); if (buttonDown) _pitchStep(1);
} else if(action == _buttonActionGimbalDown) { } else if(action == _buttonActionGimbalDown) {
_pitchStep(-1); if (buttonDown) _pitchStep(-1);
} else if(action == _buttonActionGimbalLeft) { } else if(action == _buttonActionGimbalLeft) {
_yawStep(-1); if (buttonDown) _yawStep(-1);
} else if(action == _buttonActionGimbalRight) { } else if(action == _buttonActionGimbalRight) {
_yawStep(1); if (buttonDown) _yawStep(1);
} else if(action == _buttonActionGimbalCenter) { } else if(action == _buttonActionGimbalCenter) {
_localPitch = 0.0; if (buttonDown) {
_localYaw = 0.0; _localPitch = 0.0;
emit gimbalControlValue(0.0, 0.0); _localYaw = 0.0;
emit gimbalControlValue(0.0, 0.0);
}
} else { } else {
qCDebug(JoystickLog) << "_buttonAction unknown action:" << action; qCDebug(JoystickLog) << "_buttonAction unknown action:" << action;
} }
......
...@@ -225,7 +225,7 @@ protected: ...@@ -225,7 +225,7 @@ protected:
void _saveButtonSettings (); void _saveButtonSettings ();
void _loadSettings (); void _loadSettings ();
float _adjustRange (int value, Calibration_t calibration, bool withDeadbands); 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); int _findAssignableButtonAction(const QString& action);
bool _validAxis (int axis); bool _validAxis (int axis);
bool _validButton (int button); bool _validButton (int button);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment