Browse Source

Enable joystick automatically on the active vehicle when the active vehicle is changed

When there are multiple vehicles, and you select a vehicle, the joystick should switch over to the newly active vehicle, and only the active vehicle (so that joystick inputs are not sent to a vehicle you do not intend to control). 

To resolve this, we connect Vehicle to the activeVehicleAvailableChanged and activeVehicleChanged signals produced by the MultiVehicleManager. ALL vehicles disable joystick when activeVehicleAvailableChanged(false), because this signals when there is no longer an active vehicle available. When activeVehicleChanged is signalled, ONLY the currently active vehicle enables joystick. 

See issue #10544.
QGC4.4
Christopher Vo 2 years ago committed by Philipp Borgers
parent
commit
434e76a747
  1. 19
      src/Vehicle/Vehicle.cc
  2. 2
      src/Vehicle/Vehicle.h

19
src/Vehicle/Vehicle.cc

@ -178,7 +178,8 @@ Vehicle::Vehicle(LinkInterface* link, @@ -178,7 +178,8 @@ Vehicle::Vehicle(LinkInterface* link,
_linkManager = _toolbox->linkManager();
connect(_joystickManager, &JoystickManager::activeJoystickChanged, this, &Vehicle::_loadSettings);
connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleAvailableChanged, this, &Vehicle::_loadSettings);
connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleAvailableChanged, this, &Vehicle::_activeVehicleAvailableChanged);
connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &Vehicle::_activeVehicleChanged);
_mavlink = _toolbox->mavlinkProtocol();
qCDebug(VehicleLog) << "Link started with Mavlink " << (_mavlink->getCurrentVersion() >= 200 ? "V2" : "V1");
@ -2084,6 +2085,22 @@ void Vehicle::_loadSettings() @@ -2084,6 +2085,22 @@ void Vehicle::_loadSettings()
}
}
void Vehicle::_activeVehicleAvailableChanged(bool isActiveVehicleAvailable)
{
// if there is no longer an active vehicle, disconnect the joystick
if(!isActiveVehicleAvailable) {
setJoystickEnabled(false);
}
}
void Vehicle::_activeVehicleChanged(Vehicle *newActiveVehicle)
{
if(newActiveVehicle == this) {
// this vehicle is the newly active vehicle
setJoystickEnabled(true);
}
}
void Vehicle::_saveSettings()
{
QSettings settings;

2
src/Vehicle/Vehicle.h

@ -1018,6 +1018,8 @@ private slots: @@ -1018,6 +1018,8 @@ private slots:
private:
void _loadSettings ();
void _activeVehicleAvailableChanged (bool isActiveVehicleAvailable);
void _activeVehicleChanged (Vehicle* newActiveVehicle);
void _saveSettings ();
void _startJoystick (bool start);
void _handlePing (LinkInterface* link, mavlink_message_t& message);

Loading…
Cancel
Save