mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
GCS Control plugin: now fully configurable (mode 1 to mode 4), and with joystick channel mapping as well. Not tested in-flight!
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2093 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
d826350b26
commit
3c4a5a04c0
@ -26,13 +26,15 @@
|
|||||||
*/
|
*/
|
||||||
#include "gcscontrolgadget.h"
|
#include "gcscontrolgadget.h"
|
||||||
#include "gcscontrolgadgetwidget.h"
|
#include "gcscontrolgadgetwidget.h"
|
||||||
|
#include "gcscontrolgadgetconfiguration.h"
|
||||||
#include "extensionsystem/pluginmanager.h"
|
#include "extensionsystem/pluginmanager.h"
|
||||||
#include "uavobjects/uavobjectmanager.h"
|
#include "uavobjects/uavobjectmanager.h"
|
||||||
#include "uavobjects/uavobject.h"
|
#include "uavobjects/uavobject.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#define JOYSTICK_UPDATE_RATE 50
|
#define JOYSTICK_UPDATE_RATE 50
|
||||||
|
|
||||||
GCSControlGadget::GCSControlGadget(QString classId, GCSControlGadgetWidget *widget, QWidget *parent) :
|
GCSControlGadget::GCSControlGadget(QString classId, GCSControlGadgetWidget *widget, QWidget *parent, QObject *plugin) :
|
||||||
IUAVGadget(classId, parent),
|
IUAVGadget(classId, parent),
|
||||||
m_widget(widget)
|
m_widget(widget)
|
||||||
{
|
{
|
||||||
@ -42,17 +44,12 @@ GCSControlGadget::GCSControlGadget(QString classId, GCSControlGadgetWidget *widg
|
|||||||
|
|
||||||
manualControlCommandUpdated(getManualControlCommand());
|
manualControlCommandUpdated(getManualControlCommand());
|
||||||
|
|
||||||
connect(this, SIGNAL(aboutToQuit()), &sdlGamepad, SLOT(quit()));
|
joystickTime.start();
|
||||||
if(sdlGamepad.init()) {
|
GCSControlPlugin *pl = dynamic_cast<GCSControlPlugin*>(plugin);
|
||||||
joystickTime.start();
|
connect(pl->sdlGamepad,SIGNAL(gamepads(quint8)),this,SLOT(gamepads(quint8)));
|
||||||
sdlGamepad.start();
|
connect(pl->sdlGamepad,SIGNAL(buttonState(ButtonNumber,bool)),this,SLOT(buttonState(ButtonNumber,bool)));
|
||||||
qRegisterMetaType<QListInt16>("QListInt16");
|
connect(pl->sdlGamepad,SIGNAL(axesValues(QListInt16)),this,SLOT(axesValues(QListInt16)));
|
||||||
qRegisterMetaType<ButtonNumber>("ButtonNumber");
|
|
||||||
|
|
||||||
connect(&sdlGamepad,SIGNAL(gamepads(quint8)),this,SLOT(gamepads(quint8)));
|
|
||||||
connect(&sdlGamepad,SIGNAL(buttonState(ButtonNumber,bool)),this,SLOT(buttonState(ButtonNumber,bool)));
|
|
||||||
connect(&sdlGamepad,SIGNAL(axesValues(QListInt16)),this,SLOT(axesValues(QListInt16)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GCSControlGadget::~GCSControlGadget()
|
GCSControlGadget::~GCSControlGadget()
|
||||||
@ -62,10 +59,16 @@ GCSControlGadget::~GCSControlGadget()
|
|||||||
|
|
||||||
void GCSControlGadget::loadConfiguration(IUAVGadgetConfiguration* config)
|
void GCSControlGadget::loadConfiguration(IUAVGadgetConfiguration* config)
|
||||||
{
|
{
|
||||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
GCSControlGadgetConfiguration *GCSControlConfig = qobject_cast< GCSControlGadgetConfiguration*>(config);
|
||||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
|
||||||
|
QList<int> ql = GCSControlConfig->getChannelsMapping();
|
||||||
|
rollChannel = ql.at(0);
|
||||||
|
pitchChannel = ql.at(1);
|
||||||
|
yawChannel = ql.at(2);
|
||||||
|
throttleChannel = ql.at(3);
|
||||||
|
|
||||||
|
controlsMode = GCSControlConfig->getControlsMode();
|
||||||
|
|
||||||
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(QString("ManualControlCommand")) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ManualControlCommand* GCSControlGadget::getManualControlCommand() {
|
ManualControlCommand* GCSControlGadget::getManualControlCommand() {
|
||||||
@ -79,9 +82,30 @@ void GCSControlGadget::manualControlCommandUpdated(UAVObject * obj) {
|
|||||||
double pitch = obj->getField("Pitch")->getDouble();
|
double pitch = obj->getField("Pitch")->getDouble();
|
||||||
double yaw = obj->getField("Yaw")->getDouble();
|
double yaw = obj->getField("Yaw")->getDouble();
|
||||||
double throttle = obj->getField("Throttle")->getDouble();
|
double throttle = obj->getField("Throttle")->getDouble();
|
||||||
emit sticksChangedRemotely(yaw,-pitch,roll,throttle);
|
// Remap RPYT to left X/Y and right X/Y depending on mode
|
||||||
|
switch (controlsMode) {
|
||||||
|
case 1:
|
||||||
|
// Mode 1: LeftX = Yaw, LeftY = Pitch, RightX = Roll, RightY = Throttle
|
||||||
|
emit sticksChangedRemotely(yaw,pitch,roll,throttle);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
// Mode 2: LeftX = Yaw, LeftY = Throttle, RightX = Roll, RightY = Pitch
|
||||||
|
emit sticksChangedRemotely(yaw,throttle,roll,pitch);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
// Mode 3: LeftX = Roll, LeftY = Pitch, RightX = Yaw, RightY = Throttle
|
||||||
|
emit sticksChangedRemotely(roll,pitch,yaw,throttle);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
// Mode 4: LeftX = Roll, LeftY = Throttle, RightX = Yaw, RightY = Pitch;
|
||||||
|
emit sticksChangedRemotely(roll,throttle,yaw,pitch);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Update the manual commands - maps depending on mode
|
||||||
|
*/
|
||||||
void GCSControlGadget::sticksChangedLocally(double leftX, double leftY, double rightX, double rightY) {
|
void GCSControlGadget::sticksChangedLocally(double leftX, double leftY, double rightX, double rightY) {
|
||||||
ManualControlCommand * obj = getManualControlCommand();
|
ManualControlCommand * obj = getManualControlCommand();
|
||||||
double oldRoll = obj->getField("Roll")->getDouble();
|
double oldRoll = obj->getField("Roll")->getDouble();
|
||||||
@ -89,10 +113,42 @@ void GCSControlGadget::sticksChangedLocally(double leftX, double leftY, double r
|
|||||||
double oldYaw = obj->getField("Yaw")->getDouble();
|
double oldYaw = obj->getField("Yaw")->getDouble();
|
||||||
double oldThrottle = obj->getField("Throttle")->getDouble();
|
double oldThrottle = obj->getField("Throttle")->getDouble();
|
||||||
|
|
||||||
double newRoll = rightX;
|
double newRoll;
|
||||||
double newPitch = -leftY;
|
double newPitch;
|
||||||
double newYaw = leftX;
|
double newYaw;
|
||||||
double newThrottle = rightY;
|
double newThrottle;
|
||||||
|
|
||||||
|
// Remap left X/Y and right X/Y to RPYT depending on mode
|
||||||
|
switch (controlsMode) {
|
||||||
|
case 1:
|
||||||
|
// Mode 1: LeftX = Yaw, LeftY = Pitch, RightX = Roll, RightY = Throttle
|
||||||
|
newRoll = rightX;
|
||||||
|
newPitch = leftY;
|
||||||
|
newYaw = leftX;
|
||||||
|
newThrottle = rightY;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
// Mode 2: LeftX = Yaw, LeftY = Throttle, RightX = Roll, RightY = Pitch
|
||||||
|
newRoll = rightX;
|
||||||
|
newPitch = rightY;
|
||||||
|
newYaw = leftX;
|
||||||
|
newThrottle = leftY;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
// Mode 3: LeftX = Roll, LeftY = Pitch, RightX = Yaw, RightY = Throttle
|
||||||
|
newRoll = leftX;
|
||||||
|
newPitch = leftY;
|
||||||
|
newYaw = rightX;
|
||||||
|
newThrottle = rightY;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
// Mode 4: LeftX = Roll, LeftY = Throttle, RightX = Yaw, RightY = Pitch;
|
||||||
|
newRoll = leftX;
|
||||||
|
newPitch = rightY;
|
||||||
|
newYaw = rightX;
|
||||||
|
newThrottle = leftY;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if((newThrottle != oldThrottle) || (newPitch != oldPitch) || (newYaw != oldYaw) || (newRoll != oldRoll)) {
|
if((newThrottle != oldThrottle) || (newPitch != oldPitch) || (newYaw != oldYaw) || (newRoll != oldRoll)) {
|
||||||
obj->getField("Roll")->setDouble(newRoll);
|
obj->getField("Roll")->setDouble(newRoll);
|
||||||
@ -105,8 +161,8 @@ void GCSControlGadget::sticksChangedLocally(double leftX, double leftY, double r
|
|||||||
|
|
||||||
void GCSControlGadget::gamepads(quint8 count)
|
void GCSControlGadget::gamepads(quint8 count)
|
||||||
{
|
{
|
||||||
sdlGamepad.setGamepad(0);
|
// sdlGamepad.setGamepad(0);
|
||||||
sdlGamepad.setTickRate(JOYSTICK_UPDATE_RATE);
|
// sdlGamepad.setTickRate(JOYSTICK_UPDATE_RATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCSControlGadget::buttonState(ButtonNumber number, bool pressed)
|
void GCSControlGadget::buttonState(ButtonNumber number, bool pressed)
|
||||||
@ -115,13 +171,38 @@ void GCSControlGadget::buttonState(ButtonNumber number, bool pressed)
|
|||||||
|
|
||||||
void GCSControlGadget::axesValues(QListInt16 values)
|
void GCSControlGadget::axesValues(QListInt16 values)
|
||||||
{
|
{
|
||||||
double leftX = values[0];
|
int chMax = values.length();
|
||||||
double leftY = values[1];
|
if (rollChannel > chMax || pitchChannel > chMax ||
|
||||||
double rightX = values[2];
|
yawChannel > chMax || throttleChannel > chMax ) {
|
||||||
double rightY = values[3];
|
qDebug() << "GCSControl: configuration is inconsistent with current joystick! Aborting update.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double rValue = (rollChannel > -1) ? values[rollChannel] : 0;
|
||||||
|
double pValue = (pitchChannel > -1) ? values[pitchChannel] : 0;
|
||||||
|
double yValue = (yawChannel > -1) ? values[yawChannel] : 0;
|
||||||
|
double tValue = (throttleChannel > -1) ? values[throttleChannel] : 0;
|
||||||
double max = 32767;
|
double max = 32767;
|
||||||
if(joystickTime.elapsed() > JOYSTICK_UPDATE_RATE) {
|
if(joystickTime.elapsed() > JOYSTICK_UPDATE_RATE) {
|
||||||
joystickTime.restart();
|
joystickTime.restart();
|
||||||
sticksChangedLocally(leftX/max,-leftY/max,rightX/max,-rightY/max);
|
// Remap RPYT to left X/Y and right X/Y depending on mode
|
||||||
|
// Mode 1: LeftX = Yaw, LeftY = Pitch, RightX = Roll, RightY = Throttle
|
||||||
|
// Mode 2: LeftX = Yaw, LeftY = THrottle, RightX = Roll, RightY = Pitch
|
||||||
|
// Mode 3: LeftX = Roll, LeftY = Pitch, RightX = Yaw, RightY = Throttle
|
||||||
|
// Mode 4: LeftX = Roll, LeftY = Throttle, RightX = Yaw, RightY = Pitch;
|
||||||
|
switch (controlsMode) {
|
||||||
|
case 1:
|
||||||
|
sticksChangedLocally(yValue/max,-pValue/max,rValue/max,-tValue/max);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
sticksChangedLocally(yValue/max,-tValue/max,rValue/max,-pValue/max);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
sticksChangedLocally(rValue/max,-pValue/max,yValue/max,-tValue/max);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
sticksChangedLocally(rValue/max,-tValue/max,yValue/max,-pValue/max);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include <uavobjects/manualcontrolcommand.h>
|
#include <uavobjects/manualcontrolcommand.h>
|
||||||
#include "sdlgamepad/sdlgamepad.h"
|
#include "sdlgamepad/sdlgamepad.h"
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
#include "gcscontrolplugin.h"
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
class IUAVGadget;
|
class IUAVGadget;
|
||||||
@ -46,7 +47,7 @@ class GCSControlGadget : public Core::IUAVGadget
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
GCSControlGadget(QString classId, GCSControlGadgetWidget *widget, QWidget *parent = 0);
|
GCSControlGadget(QString classId, GCSControlGadgetWidget *widget, QWidget *parent = 0, QObject *plugin=0);
|
||||||
~GCSControlGadget();
|
~GCSControlGadget();
|
||||||
|
|
||||||
QList<int> context() const { return m_context; }
|
QList<int> context() const { return m_context; }
|
||||||
@ -57,11 +58,15 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
ManualControlCommand* getManualControlCommand();
|
ManualControlCommand* getManualControlCommand();
|
||||||
SDLGamepad sdlGamepad;
|
|
||||||
QTime joystickTime;
|
QTime joystickTime;
|
||||||
QWidget *m_widget;
|
QWidget *m_widget;
|
||||||
QList<int> m_context;
|
QList<int> m_context;
|
||||||
UAVObject::Metadata mccInitialData;
|
UAVObject::Metadata mccInitialData;
|
||||||
|
int rollChannel;
|
||||||
|
int pitchChannel;
|
||||||
|
int yawChannel;
|
||||||
|
int throttleChannel;
|
||||||
|
int controlsMode;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void sticksChangedRemotely(double leftX, double leftY, double rightX, double rightY);
|
void sticksChangedRemotely(double leftX, double leftY, double rightX, double rightY);
|
||||||
|
@ -32,42 +32,38 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
GCSControlGadgetConfiguration::GCSControlGadgetConfiguration(QString classId, QSettings* qSettings, QObject *parent) :
|
GCSControlGadgetConfiguration::GCSControlGadgetConfiguration(QString classId, QSettings* qSettings, QObject *parent) :
|
||||||
IUAVGadgetConfiguration(classId, parent)
|
IUAVGadgetConfiguration(classId, parent),
|
||||||
|
rollChannel(-1),
|
||||||
|
pitchChannel(-1),
|
||||||
|
yawChannel(-1),
|
||||||
|
throttleChannel(-1)
|
||||||
{
|
{
|
||||||
//if a saved configuration exists load it
|
//if a saved configuration exists load it
|
||||||
if(qSettings != 0) {
|
if(qSettings != 0) {
|
||||||
/*
|
controlsMode = qSettings->value("controlsMode").toInt();
|
||||||
BaudRateType speed;
|
rollChannel = qSettings->value("rollChannel").toInt();
|
||||||
DataBitsType databits;
|
pitchChannel = qSettings->value("pitchChannel").toInt();
|
||||||
FlowType flow;
|
yawChannel = qSettings->value("yawChannel").toInt();
|
||||||
ParityType parity;
|
throttleChannel = qSettings->value("throttleChannel").toInt();
|
||||||
StopBitsType stopbits;
|
|
||||||
|
|
||||||
int ispeed = qSettings->value("defaultSpeed").toInt();
|
|
||||||
int idatabits = qSettings->value("defaultDataBits").toInt();
|
|
||||||
int iflow = qSettings->value("defaultFlow").toInt();
|
|
||||||
int iparity = qSettings->value("defaultParity").toInt();
|
|
||||||
int istopbits = qSettings->value("defaultStopBits").toInt();
|
|
||||||
QString port = qSettings->value("defaultPort").toString();
|
|
||||||
QString conMode = qSettings->value("connectionMode").toString();
|
|
||||||
|
|
||||||
databits = (DataBitsType) idatabits;
|
|
||||||
flow = (FlowType)iflow;
|
|
||||||
parity = (ParityType)iparity;
|
|
||||||
stopbits = (StopBitsType)istopbits;
|
|
||||||
speed = (BaudRateType)ispeed;
|
|
||||||
m_defaultPort = port;
|
|
||||||
m_defaultSpeed = speed;
|
|
||||||
m_defaultDataBits = databits;
|
|
||||||
m_defaultFlow = flow;
|
|
||||||
m_defaultParity = parity;
|
|
||||||
m_defaultStopBits = stopbits;
|
|
||||||
m_connectionMode = conMode;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GCSControlGadgetConfiguration::setRPYTchannels(int roll, int pitch, int yaw, int throttle) {
|
||||||
|
rollChannel = roll;
|
||||||
|
pitchChannel = pitch;
|
||||||
|
yawChannel = yaw;
|
||||||
|
throttleChannel = throttle;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<int> GCSControlGadgetConfiguration::getChannelsMapping()
|
||||||
|
{
|
||||||
|
QList<int> ql;
|
||||||
|
ql << rollChannel << pitchChannel << yawChannel << throttleChannel;
|
||||||
|
return ql;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clones a configuration.
|
* Clones a configuration.
|
||||||
*
|
*
|
||||||
@ -76,16 +72,12 @@ IUAVGadgetConfiguration *GCSControlGadgetConfiguration::clone()
|
|||||||
{
|
{
|
||||||
GCSControlGadgetConfiguration *m = new GCSControlGadgetConfiguration(this->classId());
|
GCSControlGadgetConfiguration *m = new GCSControlGadgetConfiguration(this->classId());
|
||||||
|
|
||||||
/*
|
m->controlsMode = controlsMode;
|
||||||
|
m->rollChannel = rollChannel;
|
||||||
|
m->pitchChannel = pitchChannel;
|
||||||
|
m->yawChannel = yawChannel;
|
||||||
|
m->throttleChannel = throttleChannel;
|
||||||
|
|
||||||
m->m_defaultSpeed = m_defaultSpeed;
|
|
||||||
m->m_defaultDataBits = m_defaultDataBits;
|
|
||||||
m->m_defaultFlow = m_defaultFlow;
|
|
||||||
m->m_defaultParity = m_defaultParity;
|
|
||||||
m->m_defaultStopBits = m_defaultStopBits;
|
|
||||||
m->m_defaultPort = m_defaultPort;
|
|
||||||
m->m_connectionMode = m_connectionMode;
|
|
||||||
*/
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,13 +86,9 @@ IUAVGadgetConfiguration *GCSControlGadgetConfiguration::clone()
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void GCSControlGadgetConfiguration::saveConfig(QSettings* settings) const {
|
void GCSControlGadgetConfiguration::saveConfig(QSettings* settings) const {
|
||||||
/*
|
settings->setValue("controlsMode", controlsMode);
|
||||||
settings->setValue("defaultSpeed", m_defaultSpeed);
|
settings->setValue("rollChannel", rollChannel);
|
||||||
settings->setValue("defaultDataBits", m_defaultDataBits);
|
settings->setValue("pitchChannel", pitchChannel);
|
||||||
settings->setValue("defaultFlow", m_defaultFlow);
|
settings->setValue("yawChannel", yawChannel);
|
||||||
settings->setValue("defaultParity", m_defaultParity);
|
settings->setValue("throttleChannel", throttleChannel);
|
||||||
settings->setValue("defaultStopBits", m_defaultStopBits);
|
|
||||||
settings->setValue("defaultPort", m_defaultPort);
|
|
||||||
settings->setValue("connectionMode", m_connectionMode);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
@ -38,43 +38,24 @@ class GCSControlGadgetConfiguration : public IUAVGadgetConfiguration
|
|||||||
public:
|
public:
|
||||||
explicit GCSControlGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0);
|
explicit GCSControlGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0);
|
||||||
|
|
||||||
/*
|
void setControlsMode(int mode) { controlsMode = mode; }
|
||||||
void setConnectionMode(QString mode) { m_connectionMode = mode; }
|
void setRPYTchannels(int roll, int pitch, int yaw, int throttle);
|
||||||
QString connectionMode() { return m_connectionMode; }
|
int getControlsMode() { return controlsMode; }
|
||||||
|
QList<int> getChannelsMapping();
|
||||||
|
|
||||||
|
|
||||||
//set port configuration functions
|
|
||||||
void setSpeed(BaudRateType speed) {m_defaultSpeed=speed;}
|
|
||||||
void setDataBits(DataBitsType databits) {m_defaultDataBits=databits;}
|
|
||||||
void setFlow(FlowType flow) {m_defaultFlow=flow;}
|
|
||||||
void setParity(ParityType parity) {m_defaultParity=parity;}
|
|
||||||
void setStopBits(StopBitsType stopbits) {m_defaultStopBits=stopbits;}
|
|
||||||
void setPort(QString port){m_defaultPort=port;}
|
|
||||||
void setTimeOut(long timeout){m_defaultTimeOut=timeout;}
|
|
||||||
|
|
||||||
//get port configuration functions
|
|
||||||
QString port(){return m_defaultPort;}
|
|
||||||
BaudRateType speed() {return m_defaultSpeed;}
|
|
||||||
FlowType flow() {return m_defaultFlow;}
|
|
||||||
DataBitsType dataBits() {return m_defaultDataBits;}
|
|
||||||
StopBitsType stopBits() {return m_defaultStopBits;}
|
|
||||||
ParityType parity() {return m_defaultParity;}
|
|
||||||
long timeOut(){return m_defaultTimeOut;}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void saveConfig(QSettings* settings) const;
|
void saveConfig(QSettings* settings) const;
|
||||||
IUAVGadgetConfiguration *clone();
|
IUAVGadgetConfiguration *clone();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*
|
int controlsMode; // Mode1 to Mode4
|
||||||
QString m_connectionMode;
|
// Joystick mappings for roll/pitch/yaw/throttle:
|
||||||
QString m_defaultPort;
|
int rollChannel;
|
||||||
BaudRateType m_defaultSpeed;
|
int pitchChannel;
|
||||||
DataBitsType m_defaultDataBits;
|
int yawChannel;
|
||||||
FlowType m_defaultFlow;
|
int throttleChannel;
|
||||||
ParityType m_defaultParity;
|
|
||||||
StopBitsType m_defaultStopBits;
|
|
||||||
long m_defaultTimeOut;
|
|
||||||
*/
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ GCSControlGadgetFactory::~GCSControlGadgetFactory()
|
|||||||
|
|
||||||
IUAVGadget* GCSControlGadgetFactory::createGadget(QWidget *parent) {
|
IUAVGadget* GCSControlGadgetFactory::createGadget(QWidget *parent) {
|
||||||
GCSControlGadgetWidget* gadgetWidget = new GCSControlGadgetWidget(parent);
|
GCSControlGadgetWidget* gadgetWidget = new GCSControlGadgetWidget(parent);
|
||||||
return new GCSControlGadget(QString("GCSControlGadget"), gadgetWidget, parent);
|
return new GCSControlGadget(QString("GCSControlGadget"), gadgetWidget, parent, this->parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
IUAVGadgetConfiguration *GCSControlGadgetFactory::createConfiguration(QSettings* qSettings)
|
IUAVGadgetConfiguration *GCSControlGadgetFactory::createConfiguration(QSettings* qSettings)
|
||||||
@ -53,7 +53,7 @@ IUAVGadgetConfiguration *GCSControlGadgetFactory::createConfiguration(QSettings*
|
|||||||
|
|
||||||
IOptionsPage *GCSControlGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config)
|
IOptionsPage *GCSControlGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config)
|
||||||
{
|
{
|
||||||
return new GCSControlGadgetOptionsPage(qobject_cast<GCSControlGadgetConfiguration*>(config));
|
return new GCSControlGadgetOptionsPage(qobject_cast<GCSControlGadgetConfiguration*>(config), this->parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,7 +37,47 @@ GCSControlGadgetOptionsPage::GCSControlGadgetOptionsPage(GCSControlGadgetConfigu
|
|||||||
IOptionsPage(parent),
|
IOptionsPage(parent),
|
||||||
m_config(config)
|
m_config(config)
|
||||||
{
|
{
|
||||||
|
options_page = NULL;
|
||||||
|
|
||||||
|
sdlGamepad = dynamic_cast<GCSControlPlugin*>(parent)->sdlGamepad;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
GCSControlGadgetOptionsPage::~GCSControlGadgetOptionsPage()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GCSControlGadgetOptionsPage::buttonState(ButtonNumber number, bool pressed)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GCSControlGadgetOptionsPage::gamepads(quint8 count)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GCSControlGadgetOptionsPage::axesValues(QListInt16 values)
|
||||||
|
{
|
||||||
|
if (options_page) {
|
||||||
|
QList<QProgressBar*> pbList;
|
||||||
|
pbList << options_page->joyCh0 <<
|
||||||
|
options_page->joyCh1 << options_page->joyCh2 <<
|
||||||
|
options_page->joyCh3 << options_page->joyCh4 <<
|
||||||
|
options_page->joyCh5 << options_page->joyCh6 <<
|
||||||
|
options_page->joyCh7;
|
||||||
|
int i=0;
|
||||||
|
foreach (qint16 value, values) {
|
||||||
|
if (i>7) break; // We only support 7 channels
|
||||||
|
if (pbList.at(i)->minimum() > value)
|
||||||
|
pbList.at(i)->setMinimum(value);
|
||||||
|
if (pbList.at(i)->maximum() < value)
|
||||||
|
pbList.at(i)->setMaximum(value);
|
||||||
|
pbList.at(i++)->setValue(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -48,6 +88,31 @@ QWidget *GCSControlGadgetOptionsPage::createPage(QWidget *parent)
|
|||||||
QWidget *optionsPageWidget = new QWidget;
|
QWidget *optionsPageWidget = new QWidget;
|
||||||
options_page->setupUi(optionsPageWidget);
|
options_page->setupUi(optionsPageWidget);
|
||||||
|
|
||||||
|
QList<QComboBox*> chList;
|
||||||
|
chList << options_page->channel0 << options_page->channel1 <<
|
||||||
|
options_page->channel2 << options_page->channel3 <<
|
||||||
|
options_page->channel4 << options_page->channel5 <<
|
||||||
|
options_page->channel6 << options_page->channel7;
|
||||||
|
QStringList chOptions;
|
||||||
|
chOptions << "None" << "Roll" << "Pitch" << "Yaw" << "Throttle";
|
||||||
|
foreach (QComboBox* qb, chList) {
|
||||||
|
qb->addItems(chOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Controls mode are from 1 to 4.
|
||||||
|
if (m_config->getControlsMode()>0 && m_config->getControlsMode() < 5)
|
||||||
|
options_page->controlsMode->setCurrentIndex(m_config->getControlsMode()-1);
|
||||||
|
else
|
||||||
|
qDebug() << "GCSControl: Invalid control modes setting! Did you edit by hand?";
|
||||||
|
|
||||||
|
QList<int> ql = m_config->getChannelsMapping();
|
||||||
|
for (int i=0; i<4; i++) {
|
||||||
|
if (ql.at(i) > -1)
|
||||||
|
chList.at(ql.at(i))->setCurrentIndex(i+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(sdlGamepad,SIGNAL(axesValues(QListInt16)),this,SLOT(axesValues(QListInt16)));
|
||||||
|
|
||||||
return optionsPageWidget;
|
return optionsPageWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,10 +124,36 @@ QWidget *GCSControlGadgetOptionsPage::createPage(QWidget *parent)
|
|||||||
*/
|
*/
|
||||||
void GCSControlGadgetOptionsPage::apply()
|
void GCSControlGadgetOptionsPage::apply()
|
||||||
{
|
{
|
||||||
|
m_config->setControlsMode(options_page->controlsMode->currentIndex()+1);
|
||||||
|
QList<QComboBox*> chList;
|
||||||
|
chList << options_page->channel0 << options_page->channel1 <<
|
||||||
|
options_page->channel2 << options_page->channel3 <<
|
||||||
|
options_page->channel4 << options_page->channel5 <<
|
||||||
|
options_page->channel6 << options_page->channel7;
|
||||||
|
int roll=-1 , pitch=-1, yaw=-1, throttle=-1;
|
||||||
|
for (int i=0; i<chList.length(); i++) {
|
||||||
|
switch (chList.at(i)->currentIndex()) {
|
||||||
|
case 1:
|
||||||
|
roll = i;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
pitch =i;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
yaw = i;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
throttle = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_config->setRPYTchannels(roll,pitch,yaw,throttle);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCSControlGadgetOptionsPage::finish()
|
void GCSControlGadgetOptionsPage::finish()
|
||||||
{
|
{
|
||||||
|
disconnect(sdlGamepad,0,this,0);
|
||||||
delete options_page;
|
delete options_page;
|
||||||
|
options_page = NULL;
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,8 @@
|
|||||||
#define GCSCONTROLGADGETOPTIONSPAGE_H
|
#define GCSCONTROLGADGETOPTIONSPAGE_H
|
||||||
|
|
||||||
#include "coreplugin/dialogs/ioptionspage.h"
|
#include "coreplugin/dialogs/ioptionspage.h"
|
||||||
#include "QString"
|
#include "gcscontrolplugin.h"
|
||||||
#include <QStringList>
|
#include "sdlgamepad/sdlgamepad.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
@ -50,6 +50,7 @@ class GCSControlGadgetOptionsPage : public IOptionsPage
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit GCSControlGadgetOptionsPage(GCSControlGadgetConfiguration *config, QObject *parent = 0);
|
explicit GCSControlGadgetOptionsPage(GCSControlGadgetConfiguration *config, QObject *parent = 0);
|
||||||
|
~GCSControlGadgetOptionsPage();
|
||||||
|
|
||||||
QWidget *createPage(QWidget *parent);
|
QWidget *createPage(QWidget *parent);
|
||||||
void apply();
|
void apply();
|
||||||
@ -58,20 +59,14 @@ public:
|
|||||||
private:
|
private:
|
||||||
Ui::GCSControlGadgetOptionsPage *options_page;
|
Ui::GCSControlGadgetOptionsPage *options_page;
|
||||||
GCSControlGadgetConfiguration *m_config;
|
GCSControlGadgetConfiguration *m_config;
|
||||||
|
SDLGamepad *sdlGamepad;
|
||||||
|
|
||||||
/*
|
protected slots:
|
||||||
QStringList BaudRateTypeString;
|
// signals from joystick
|
||||||
QStringList BaudRateTypeStringALL;
|
void gamepads(quint8 count);
|
||||||
QStringList DataBitsTypeStringALL;
|
void buttonState(ButtonNumber number, bool pressed);
|
||||||
QStringList ParityTypeStringALL;
|
void axesValues(QListInt16 values);
|
||||||
QStringList StopBitsTypeStringALL;
|
|
||||||
QStringList DataBitsTypeString;
|
|
||||||
QStringList ParityTypeString;
|
|
||||||
QStringList StopBitsTypeString;
|
|
||||||
QStringList FlowTypeString;
|
|
||||||
*/
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GCSCONTROLGADGETOPTIONSPAGE_H
|
#endif // GCSCONTROLGADGETOPTIONSPAGE_H
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>587</width>
|
<width>587</width>
|
||||||
<height>359</height>
|
<height>379</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@ -36,7 +36,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QComboBox" name="connectionMode">
|
<widget class="QComboBox" name="controlsMode">
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Mode 1</string>
|
<string>Mode 1</string>
|
||||||
@ -81,8 +81,11 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QComboBox" name="comboBox">
|
<widget class="QComboBox" name="comboBox">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Define the external input device you want to use here.</string>
|
<string>Only joystick is implemented at this stage, so this control is disabled.</string>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -110,7 +113,7 @@
|
|||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="tabWidgetPage2" native="true">
|
<widget class="QWidget" name="tabWidgetPage2">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Joystick</string>
|
<string>Joystick</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
@ -121,7 +124,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QComboBox" name="comboBox_2"/>
|
<widget class="QComboBox" name="channel0"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="2">
|
<item row="2" column="2">
|
||||||
<widget class="QCheckBox" name="checkBox">
|
<widget class="QCheckBox" name="checkBox">
|
||||||
@ -138,77 +141,77 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
<item row="3" column="0">
|
||||||
<widget class="QComboBox" name="comboBox_3"/>
|
<widget class="QComboBox" name="channel1"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="0">
|
<item row="4" column="0">
|
||||||
<widget class="QComboBox" name="comboBox_4"/>
|
<widget class="QComboBox" name="channel2"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="0">
|
<item row="5" column="0">
|
||||||
<widget class="QComboBox" name="comboBox_5"/>
|
<widget class="QComboBox" name="channel3"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="0">
|
<item row="6" column="0">
|
||||||
<widget class="QComboBox" name="comboBox_6"/>
|
<widget class="QComboBox" name="channel4"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="0">
|
<item row="7" column="0">
|
||||||
<widget class="QComboBox" name="comboBox_7"/>
|
<widget class="QComboBox" name="channel5"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="8" column="0">
|
<item row="8" column="0">
|
||||||
<widget class="QComboBox" name="comboBox_8"/>
|
<widget class="QComboBox" name="channel6"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="9" column="0">
|
<item row="9" column="0">
|
||||||
<widget class="QComboBox" name="comboBox_9"/>
|
<widget class="QComboBox" name="channel7"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1">
|
<item row="3" column="1">
|
||||||
<widget class="QProgressBar" name="progressBar">
|
<widget class="QProgressBar" name="joyCh1">
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<number>24</number>
|
<number>24</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QProgressBar" name="progressBar_2">
|
<widget class="QProgressBar" name="joyCh0">
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<number>24</number>
|
<number>24</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="1">
|
<item row="4" column="1">
|
||||||
<widget class="QProgressBar" name="progressBar_3">
|
<widget class="QProgressBar" name="joyCh2">
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<number>24</number>
|
<number>24</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="1">
|
<item row="5" column="1">
|
||||||
<widget class="QProgressBar" name="progressBar_4">
|
<widget class="QProgressBar" name="joyCh3">
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<number>24</number>
|
<number>24</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="1">
|
<item row="6" column="1">
|
||||||
<widget class="QProgressBar" name="progressBar_5">
|
<widget class="QProgressBar" name="joyCh4">
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<number>24</number>
|
<number>24</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="1">
|
<item row="7" column="1">
|
||||||
<widget class="QProgressBar" name="progressBar_6">
|
<widget class="QProgressBar" name="joyCh5">
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<number>24</number>
|
<number>24</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="8" column="1">
|
<item row="8" column="1">
|
||||||
<widget class="QProgressBar" name="progressBar_7">
|
<widget class="QProgressBar" name="joyCh6">
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<number>24</number>
|
<number>24</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="9" column="1">
|
<item row="9" column="1">
|
||||||
<widget class="QProgressBar" name="progressBar_8">
|
<widget class="QProgressBar" name="joyCh7">
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<number>24</number>
|
<number>24</number>
|
||||||
</property>
|
</property>
|
||||||
@ -267,7 +270,7 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="tabWidgetPage3" native="true">
|
<widget class="QWidget" name="tabWidgetPage3">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Audio</string>
|
<string>Audio</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
@ -78,7 +78,11 @@ GCSControlGadgetWidget::~GCSControlGadgetWidget()
|
|||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCSControlGadgetWidget::updateSticks(double leftX, double leftY, double rightX, double rightY) {
|
void GCSControlGadgetWidget::updateSticks(double nleftX, double nleftY, double nrightX, double nrightY) {
|
||||||
|
leftX = nleftX;
|
||||||
|
leftY = nleftY;
|
||||||
|
rightX = nrightX;
|
||||||
|
rightY = nrightY;
|
||||||
m_gcscontrol->widgetLeftStick->changePosition(leftX,leftY);
|
m_gcscontrol->widgetLeftStick->changePosition(leftX,leftY);
|
||||||
m_gcscontrol->widgetRightStick->changePosition(rightX,rightY);
|
m_gcscontrol->widgetRightStick->changePosition(rightX,rightY);
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,12 @@ bool GCSControlPlugin::initialize(const QStringList& args, QString *errMsg)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(args);
|
Q_UNUSED(args);
|
||||||
Q_UNUSED(errMsg);
|
Q_UNUSED(errMsg);
|
||||||
|
sdlGamepad = new SDLGamepad();
|
||||||
|
if(sdlGamepad->init()) {
|
||||||
|
sdlGamepad->start();
|
||||||
|
qRegisterMetaType<QListInt16>("QListInt16");
|
||||||
|
qRegisterMetaType<ButtonNumber>("ButtonNumber");
|
||||||
|
}
|
||||||
mf = new GCSControlGadgetFactory(this);
|
mf = new GCSControlGadgetFactory(this);
|
||||||
addAutoReleasedObject(mf);
|
addAutoReleasedObject(mf);
|
||||||
|
|
||||||
|
@ -29,19 +29,23 @@
|
|||||||
#define GCSControlPLUGIN_H_
|
#define GCSControlPLUGIN_H_
|
||||||
|
|
||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
|
#include "sdlgamepad/sdlgamepad.h"
|
||||||
|
|
||||||
class GCSControlGadgetFactory;
|
class GCSControlGadgetFactory;
|
||||||
|
|
||||||
class GCSControlPlugin : public ExtensionSystem::IPlugin
|
class GCSControlPlugin : public ExtensionSystem::IPlugin
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GCSControlPlugin();
|
GCSControlPlugin();
|
||||||
~GCSControlPlugin();
|
~GCSControlPlugin();
|
||||||
|
|
||||||
void extensionsInitialized();
|
void extensionsInitialized();
|
||||||
bool initialize(const QStringList & arguments, QString * errorString);
|
bool initialize(const QStringList & arguments, QString * errorString);
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
SDLGamepad *sdlGamepad;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GCSControlGadgetFactory *mf;
|
GCSControlGadgetFactory *mf;
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif /* GCSControlPLUGIN_H_ */
|
#endif /* GCSControlPLUGIN_H_ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user