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)
qCDebug(CameraManagerLog) << "Joystick changed";
if(_activeJoystick) {
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::stepStream, this, &QGCCameraManager::_stepStream);
disconnect(_activeJoystick, &Joystick::triggerCamera, this, &QGCCameraManager::_triggerCamera);
......@@ -388,13 +390,15 @@ QGCCameraManager::_activeJoystickChanged(Joystick* joystick)
}
_activeJoystick = joystick;
if(_activeJoystick) {
connect(_activeJoystick, &Joystick::stepZoom, this, &QGCCameraManager::_stepZoom);
connect(_activeJoystick, &Joystick::stepCamera, this, &QGCCameraManager::_stepCamera);
connect(_activeJoystick, &Joystick::stepStream, this, &QGCCameraManager::_stepStream);
connect(_activeJoystick, &Joystick::triggerCamera, this, &QGCCameraManager::_triggerCamera);
connect(_activeJoystick, &Joystick::startVideoRecord, this, &QGCCameraManager::_startVideoRecording);
connect(_activeJoystick, &Joystick::stopVideoRecord, this, &QGCCameraManager::_stopVideoRecording);
connect(_activeJoystick, &Joystick::toggleVideoRecord, this, &QGCCameraManager::_toggleVideoRecording);
connect(_activeJoystick, &Joystick::stepZoom, this, &QGCCameraManager::_stepZoom);
connect(_activeJoystick, &Joystick::startContinuousZoom, this, &QGCCameraManager::_startZoom);
connect(_activeJoystick, &Joystick::stopContinuousZoom, this, &QGCCameraManager::_stopZoom);
connect(_activeJoystick, &Joystick::stepCamera, this, &QGCCameraManager::_stepCamera);
connect(_activeJoystick, &Joystick::stepStream, this, &QGCCameraManager::_stepStream);
connect(_activeJoystick, &Joystick::triggerCamera, this, &QGCCameraManager::_triggerCamera);
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()
void
QGCCameraManager::_stepZoom(int direction)
{
if(_lastZoomChange.elapsed() > 250) {
if(_lastZoomChange.elapsed() > 40) {
_lastZoomChange.start();
qCDebug(CameraManagerLog) << "Step Camera Zoom" << direction;
QGCCameraControl* pCamera = currentCameraInstance();
......@@ -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
QGCCameraManager::_stepCamera(int direction)
......
......@@ -57,6 +57,8 @@ protected slots:
virtual void _mavlinkMessageReceived (const mavlink_message_t& message);
virtual void _activeJoystickChanged (Joystick* joystick);
virtual void _stepZoom (int direction);
virtual void _startZoom (int direction);
virtual void _stopZoom ();
virtual void _stepCamera (int direction);
virtual void _stepStream (int direction);
virtual void _cameraTimeout ();
......
......@@ -477,9 +477,12 @@ void Joystick::run()
void Joystick::_handleButtons()
{
int lastBbuttonValues[256];
//-- Update button states
for (int buttonIndex = 0; buttonIndex < _buttonCount; buttonIndex++) {
bool newButtonValue = _getButton(buttonIndex);
if(buttonIndex < 256)
lastBbuttonValues[buttonIndex] = _rgButtonValues[buttonIndex];
if (newButtonValue && _rgButtonValues[buttonIndex] == BUTTON_UP) {
_rgButtonValues[buttonIndex] = BUTTON_DOWN;
emit rawButtonPressedChanged(buttonIndex, newButtonValue);
......@@ -505,7 +508,7 @@ void Joystick::_handleButtons()
}
}
}
//-- Process button press
//-- Process button press/release
for (int buttonIndex = 0; buttonIndex < _totalButtonCount; buttonIndex++) {
if(_rgButtonValues[buttonIndex] == BUTTON_DOWN || _rgButtonValues[buttonIndex] == BUTTON_REPEAT) {
if(_buttonActionArray[buttonIndex]) {
......@@ -517,7 +520,7 @@ void Joystick::_handleButtons()
//-- This button just went down
if(_rgButtonValues[buttonIndex] == BUTTON_DOWN) {
qCDebug(JoystickLog) << "Single button triggered" << buttonIndex << buttonAction;
_executeButtonAction(buttonAction);
_executeButtonAction(buttonAction, true);
}
} else {
//-- Process repeat buttons
......@@ -525,12 +528,25 @@ void Joystick::_handleButtons()
if(_buttonActionArray[buttonIndex]->buttonTime.elapsed() > buttonDelay) {
_buttonActionArray[buttonIndex]->buttonTime.start();
qCDebug(JoystickLog) << "Repeat button triggered" << buttonIndex << buttonAction;
_executeButtonAction(buttonAction);
_executeButtonAction(buttonAction, true);
}
}
}
//-- Flag it as processed
_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)
}
void Joystick::_executeButtonAction(const QString& action)
void Joystick::_executeButtonAction(const QString& action, bool buttonDown)
{
if (!_activeVehicle || !_activeVehicle->joystickEnabled() || action == _buttonActionNone) {
return;
}
if (action == _buttonActionArm) {
emit setArmed(true);
if (buttonDown) emit setArmed(true);
} else if (action == _buttonActionDisarm) {
emit setArmed(false);
if (buttonDown) emit setArmed(false);
} else if (action == _buttonActionToggleArm) {
emit setArmed(!_activeVehicle->armed());
if (buttonDown) emit setArmed(!_activeVehicle->armed());
} else if (action == _buttonActionVTOLFixedWing) {
emit setVtolInFwdFlight(true);
if (buttonDown) emit setVtolInFwdFlight(true);
} else if (action == _buttonActionVTOLMultiRotor) {
emit setVtolInFwdFlight(false);
if (buttonDown) emit setVtolInFwdFlight(false);
} else if (_activeVehicle->flightModes().contains(action)) {
emit setFlightMode(action);
if (buttonDown) emit setFlightMode(action);
} 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) {
emit stepZoom(action == _buttonActionStepZoomIn ? 1 : -1);
if (buttonDown) emit stepZoom(action == _buttonActionStepZoomIn ? 1 : -1);
} 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) {
emit stepCamera(action == _buttonActionNextCamera ? 1 : -1);
if (buttonDown) emit stepCamera(action == _buttonActionNextCamera ? 1 : -1);
} else if(action == _buttonActionTriggerCamera) {
emit triggerCamera();
if (buttonDown) emit triggerCamera();
} else if(action == _buttonActionStartVideoRecord) {
emit startVideoRecord();
if (buttonDown) emit startVideoRecord();
} else if(action == _buttonActionStopVideoRecord) {
emit stopVideoRecord();
if (buttonDown) emit stopVideoRecord();
} else if(action == _buttonActionToggleVideoRecord) {
emit toggleVideoRecord();
if (buttonDown) emit toggleVideoRecord();
} else if(action == _buttonActionGimbalUp) {
_pitchStep(1);
if (buttonDown) _pitchStep(1);
} else if(action == _buttonActionGimbalDown) {
_pitchStep(-1);
if (buttonDown) _pitchStep(-1);
} else if(action == _buttonActionGimbalLeft) {
_yawStep(-1);
if (buttonDown) _yawStep(-1);
} else if(action == _buttonActionGimbalRight) {
_yawStep(1);
if (buttonDown) _yawStep(1);
} else if(action == _buttonActionGimbalCenter) {
_localPitch = 0.0;
_localYaw = 0.0;
emit gimbalControlValue(0.0, 0.0);
if (buttonDown) {
_localPitch = 0.0;
_localYaw = 0.0;
emit gimbalControlValue(0.0, 0.0);
}
} else {
qCDebug(JoystickLog) << "_buttonAction unknown action:" << action;
}
......
......@@ -225,7 +225,7 @@ protected:
void _saveButtonSettings ();
void _loadSettings ();
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);
bool _validAxis (int axis);
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