1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

GCS control - implemented channel reversal for joystick input.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2215 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
andrew 2010-12-11 06:39:05 +00:00 committed by andrew
parent f30aa1d719
commit b48953a5b4
7 changed files with 145 additions and 53 deletions

View File

@ -75,6 +75,8 @@ void GCSControlGadget::loadConfiguration(IUAVGadgetConfiguration* config)
buttonSettings[i].ActionID=GCSControlConfig->getbuttonSettings(i).ActionID;
buttonSettings[i].FunctionID=GCSControlConfig->getbuttonSettings(i).FunctionID;
buttonSettings[i].Amount=GCSControlConfig->getbuttonSettings(i).Amount;
buttonSettings[i].Amount=GCSControlConfig->getbuttonSettings(i).Amount;
channelReverse[i]=GCSControlConfig->getChannelsReverse().at(i);
}
}
@ -251,7 +253,6 @@ void GCSControlGadget::buttonState(ButtonNumber number, bool pressed)
break;
}
obj->updated();
}
//buttonSettings[number].ActionID NIDT
@ -273,7 +274,14 @@ void GCSControlGadget::axesValues(QListInt16 values)
double yValue = (yawChannel > -1) ? values[yawChannel] : 0;
double tValue = (throttleChannel > -1) ? values[throttleChannel] : 0;
double max = 32767;
if(joystickTime.elapsed() > JOYSTICK_UPDATE_RATE) {
if (rollChannel > -1) if(channelReverse[rollChannel]==true)rValue = -rValue;
if (pitchChannel > -1) if(channelReverse[pitchChannel]==true)pValue = -pValue;
if (yawChannel > -1) if(channelReverse[yawChannel]==true)yValue = -yValue;
if (throttleChannel > -1) if(channelReverse[throttleChannel]==true)tValue = -tValue;
if(joystickTime.elapsed() > JOYSTICK_UPDATE_RATE) {
joystickTime.restart();
// Remap RPYT to left X/Y and right X/Y depending on mode
// Mode 1: LeftX = Yaw, LeftY = Pitch, RightX = Roll, RightY = Throttle

View File

@ -71,6 +71,7 @@ private:
buttonSettingsStruct buttonSettings[8];
double bound(double input);
double wrap(double input);
bool channelReverse[8];
signals:
void sticksChangedRemotely(double leftX, double leftY, double rightX, double rightY);

View File

@ -44,6 +44,7 @@ GCSControlGadgetConfiguration::GCSControlGadgetConfiguration(QString classId, QS
buttonSettings[i].ActionID=0;
buttonSettings[i].FunctionID=0;
buttonSettings[i].Amount=0;
channelReverse[i] = 0;
}
//if a saved configuration exists load it
if(qSettings != 0) {
@ -59,6 +60,7 @@ GCSControlGadgetConfiguration::GCSControlGadgetConfiguration(QString classId, QS
buttonSettings[i].ActionID = qSettings->value(QString().sprintf("button%dAction",i)).toInt();
buttonSettings[i].FunctionID = qSettings->value(QString().sprintf("button%dFunction",i)).toInt();
buttonSettings[i].Amount = qSettings->value(QString().sprintf("button%dAmount",i)).toDouble();
channelReverse[i] = qSettings->value(QString().sprintf("channel%dReverse",i)).toBool();
}
}
@ -77,7 +79,14 @@ QList<int> GCSControlGadgetConfiguration::getChannelsMapping()
ql << rollChannel << pitchChannel << yawChannel << throttleChannel;
return ql;
}
QList<bool> GCSControlGadgetConfiguration::getChannelsReverse()
{
QList<bool> ql;
int i;
for (i=0;i<8;i++)ql << channelReverse[i];
return ql;
}
/**
* Clones a configuration.
@ -93,6 +102,16 @@ IUAVGadgetConfiguration *GCSControlGadgetConfiguration::clone()
m->yawChannel = yawChannel;
m->throttleChannel = throttleChannel;
int i;
for (i=0;i<8;i++)
{
m->buttonSettings[i].ActionID = buttonSettings[i].ActionID;
m->buttonSettings[i].FunctionID = buttonSettings[i].FunctionID;
m->buttonSettings[i].Amount = buttonSettings[i].Amount;
m->channelReverse[i] = channelReverse[i];
}
return m;
}
@ -113,6 +132,7 @@ void GCSControlGadgetConfiguration::saveConfig(QSettings* settings) const {
settings->setValue(QString().sprintf("button%dAction",i), buttonSettings[i].ActionID);
settings->setValue(QString().sprintf("button%dFunction",i), buttonSettings[i].FunctionID);
settings->setValue(QString().sprintf("button%dAmount",i), buttonSettings[i].Amount);
settings->setValue(QString().sprintf("channel%dReverse",i), channelReverse[i]);
}
}

View File

@ -51,11 +51,13 @@ class GCSControlGadgetConfiguration : public IUAVGadgetConfiguration
void setRPYTchannels(int roll, int pitch, int yaw, int throttle);
int getControlsMode() { return controlsMode; }
QList<int> getChannelsMapping();
QList<bool> getChannelsReverse();
buttonSettingsStruct getbuttonSettings(int i){return buttonSettings[i];}
void setbuttonSettingsAction(int i, int ActionID ){buttonSettings[i].ActionID=ActionID;return;}
void setbuttonSettingsFunction(int i, int FunctionID ){buttonSettings[i].FunctionID=FunctionID;return;}
void setbuttonSettingsAmount(int i, double Amount ){buttonSettings[i].Amount=Amount;return;}
void setChannelReverse(int i, bool Reverse ){channelReverse[i]=Reverse;return;}
void saveConfig(QSettings* settings) const;
@ -69,6 +71,7 @@ class GCSControlGadgetConfiguration : public IUAVGadgetConfiguration
int yawChannel;
int throttleChannel;
buttonSettingsStruct buttonSettings[8];
bool channelReverse[8];
};

View File

@ -86,6 +86,7 @@ void GCSControlGadgetOptionsPage::axesValues(QListInt16 values)
int i=0;
foreach (qint16 value, values) {
if (i>7) break; // We only support 7 channels
if (chRevList.at(i)->isChecked()==1)value = 65535 - value;
if (pbList.at(i)->minimum() > value)
pbList.at(i)->setMinimum(value);
if (pbList.at(i)->maximum() < value)
@ -106,7 +107,8 @@ QWidget *GCSControlGadgetOptionsPage::createPage(QWidget *parent)
QList<QComboBox*> chList;
//QList<QComboBox*> chList;
chList.clear();
chList << options_page->channel0 << options_page->channel1 <<
options_page->channel2 << options_page->channel3 <<
options_page->channel4 << options_page->channel5 <<
@ -116,9 +118,15 @@ QWidget *GCSControlGadgetOptionsPage::createPage(QWidget *parent)
foreach (QComboBox* qb, chList) {
qb->addItems(chOptions);
}
//QList<QCheckBox*> chRevList;
chRevList.clear();
chRevList << options_page->revCheckBox_1 << options_page->revCheckBox_2 <<
options_page->revCheckBox_3 << options_page->revCheckBox_4 <<
options_page->revCheckBox_5 << options_page->revCheckBox_6 <<
options_page->revCheckBox_7 << options_page->revCheckBox_8;
QList<QComboBox*> buttonFunctionList;
//QList<QComboBox*> buttonFunctionList;
buttonFunctionList.clear();
buttonFunctionList << options_page->buttonFunction0 << options_page->buttonFunction1 <<
options_page->buttonFunction2 << options_page->buttonFunction3 <<
options_page->buttonFunction4 << options_page->buttonFunction5 <<
@ -128,7 +136,8 @@ QWidget *GCSControlGadgetOptionsPage::createPage(QWidget *parent)
foreach (QComboBox* qb, buttonFunctionList) {
qb->addItems(buttonOptions);
}
QList<QComboBox*> buttonActionList;
//QList<QComboBox*> buttonActionList;
buttonActionList.clear();
buttonActionList << options_page->buttonAction0 << options_page->buttonAction1 <<
options_page->buttonAction2 << options_page->buttonAction3 <<
options_page->buttonAction4 << options_page->buttonAction5 <<
@ -138,11 +147,18 @@ QWidget *GCSControlGadgetOptionsPage::createPage(QWidget *parent)
foreach (QComboBox* qb, buttonActionList) {
qb->addItems(buttonActionOptions);
}
QList<QDoubleSpinBox*> buttonValueList;
//QList<QDoubleSpinBox*> buttonValueList;
buttonValueList.clear();
buttonValueList << options_page->buttonAmount0 << options_page->buttonAmount1 <<
options_page->buttonAmount2 << options_page->buttonAmount3 <<
options_page->buttonAmount4 << options_page->buttonAmount5 <<
options_page->buttonAmount6 << options_page->buttonAmount7;
//QList<QLabel*> buttonLabelList;
buttonLabelList.clear();
buttonLabelList << options_page->buttonLabel0 << options_page->buttonLabel1 <<
options_page->buttonLabel2 << options_page->buttonLabel3 <<
options_page->buttonLabel4 << options_page->buttonLabel5 <<
options_page->buttonLabel6 << options_page->buttonLabel7;
for (i=0;i<8;i++)
{
@ -178,6 +194,11 @@ QWidget *GCSControlGadgetOptionsPage::createPage(QWidget *parent)
if (ql.at(i) > -1)
chList.at(ql.at(i))->setCurrentIndex(i+1);
}
QList<bool> qlChRev = m_config->getChannelsReverse();
for (i=0; i<8; i++)
{
chRevList.at(i)->setChecked(qlChRev.at(i));;
}
connect(sdlGamepad,SIGNAL(axesValues(QListInt16)),this,SLOT(axesValues(QListInt16)));
connect(sdlGamepad,SIGNAL(buttonState(ButtonNumber,bool)),this,SLOT(buttonState(ButtonNumber,bool)));
@ -194,7 +215,7 @@ QWidget *GCSControlGadgetOptionsPage::createPage(QWidget *parent)
void GCSControlGadgetOptionsPage::apply()
{
m_config->setControlsMode(options_page->controlsMode->currentIndex()+1);
QList<QComboBox*> chList;
/*QList<QComboBox*> chList;
chList << options_page->channel0 << options_page->channel1 <<
options_page->channel2 << options_page->channel3 <<
options_page->channel4 << options_page->channel5 <<
@ -214,7 +235,7 @@ void GCSControlGadgetOptionsPage::apply()
options_page->buttonAmount2 << options_page->buttonAmount3 <<
options_page->buttonAmount4 << options_page->buttonAmount5 <<
options_page->buttonAmount6 << options_page->buttonAmount7;
*/
int roll=-1 , pitch=-1, yaw=-1, throttle=-1;
for (int i=0; i<chList.length(); i++) {
@ -241,6 +262,7 @@ void GCSControlGadgetOptionsPage::apply()
m_config->setbuttonSettingsAction(j,buttonActionList.at(j)->currentIndex());
m_config->setbuttonSettingsFunction(j,buttonFunctionList.at(j)->currentIndex());
m_config->setbuttonSettingsAmount(j,buttonValueList.at(j)->value());
m_config->setChannelReverse(j,chRevList.at(j)->isChecked());
}
}
@ -256,7 +278,7 @@ void GCSControlGadgetOptionsPage::finish()
void GCSControlGadgetOptionsPage::updateButtonFunction()
{
int i;
QList<QComboBox*> buttonFunctionList;
/*QList<QComboBox*> buttonFunctionList;
buttonFunctionList << options_page->buttonFunction0 << options_page->buttonFunction1 <<
options_page->buttonFunction2 << options_page->buttonFunction3 <<
options_page->buttonFunction4 << options_page->buttonFunction5 <<
@ -276,7 +298,7 @@ void GCSControlGadgetOptionsPage::updateButtonFunction()
options_page->buttonLabel2 << options_page->buttonLabel3 <<
options_page->buttonLabel4 << options_page->buttonLabel5 <<
options_page->buttonLabel6 << options_page->buttonLabel7;
*/
for (i=0;i<8;i++)
{
if (buttonActionList.at(i)->currentText().compare("Does nothing")==0)
@ -307,7 +329,7 @@ void GCSControlGadgetOptionsPage::updateButtonAction(int controlID)
{
int i;
QStringList buttonOptions;
QList<QComboBox*> buttonFunctionList;
/*QList<QComboBox*> buttonFunctionList;
buttonFunctionList << options_page->buttonFunction0 << options_page->buttonFunction1 <<
options_page->buttonFunction2 << options_page->buttonFunction3 <<
options_page->buttonFunction4 << options_page->buttonFunction5 <<
@ -327,7 +349,7 @@ void GCSControlGadgetOptionsPage::updateButtonAction(int controlID)
options_page->buttonLabel2 << options_page->buttonLabel3 <<
options_page->buttonLabel4 << options_page->buttonLabel5 <<
options_page->buttonLabel6 << options_page->buttonLabel7;
*/
//for (i=0;i<8;i++)
i=controlID;
{

View File

@ -32,6 +32,10 @@
#include "gcscontrolplugin.h"
#include "sdlgamepad/sdlgamepad.h"
#include <QDebug>
#include <QtGui/QCheckBox>
#include <QtGui/QComboBox>
#include <QtGui/QDoubleSpinBox>
#include <QtGui/QLabel>
namespace Core {
class IUAVGadgetConfiguration;
@ -61,6 +65,13 @@ private:
GCSControlGadgetConfiguration *m_config;
SDLGamepad *sdlGamepad;
QList<QComboBox*> chList;
QList<QCheckBox*> chRevList;
QList<QComboBox*> buttonFunctionList;
QList<QComboBox*> buttonActionList;
QList<QDoubleSpinBox*> buttonValueList;
QList<QLabel*> buttonLabelList;
protected slots:
// signals from joystick
void gamepads(quint8 count);

View File

@ -99,6 +99,33 @@
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Available controllers</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="AvailableControllerList">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
@ -115,7 +142,7 @@
</property>
<widget class="QWidget" name="tabWidgetPage2">
<attribute name="title">
<string>Joystick</string>
<string>Joystick Axes</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="1">
<property name="margin">
@ -127,14 +154,14 @@
<widget class="QComboBox" name="channel0"/>
</item>
<item row="2" column="2">
<widget class="QCheckBox" name="checkBox">
<widget class="QCheckBox" name="revCheckBox_1">
<property name="text">
<string>Rev</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QCheckBox" name="checkBox_2">
<widget class="QCheckBox" name="revCheckBox_2">
<property name="text">
<string>Rev</string>
</property>
@ -218,42 +245,42 @@
</widget>
</item>
<item row="4" column="2">
<widget class="QCheckBox" name="checkBox_3">
<widget class="QCheckBox" name="revCheckBox_3">
<property name="text">
<string>Rev</string>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QCheckBox" name="checkBox_4">
<widget class="QCheckBox" name="revCheckBox_4">
<property name="text">
<string>Rev</string>
</property>
</widget>
</item>
<item row="6" column="2">
<widget class="QCheckBox" name="checkBox_5">
<widget class="QCheckBox" name="revCheckBox_5">
<property name="text">
<string>Rev</string>
</property>
</widget>
</item>
<item row="7" column="2">
<widget class="QCheckBox" name="checkBox_6">
<widget class="QCheckBox" name="revCheckBox_6">
<property name="text">
<string>Rev</string>
</property>
</widget>
</item>
<item row="8" column="2">
<widget class="QCheckBox" name="checkBox_7">
<widget class="QCheckBox" name="revCheckBox_7">
<property name="text">
<string>Rev</string>
</property>
</widget>
</item>
<item row="9" column="2">
<widget class="QCheckBox" name="checkBox_8">
<widget class="QCheckBox" name="revCheckBox_8">
<property name="text">
<string>Rev</string>
</property>
@ -270,39 +297,9 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tabWidgetPage3">
<attribute name="title">
<string>Audio</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="telemetryLabel">
<property name="text">
<string>Audio: soundcard-based PPM decoding for trainer port. Not implemented yet.</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>276</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Buttons</string>
<string>Joystick Buttons</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
@ -979,6 +976,36 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tabWidgetPage3">
<attribute name="title">
<string>Audio</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="telemetryLabel">
<property name="text">
<string>Audio: soundcard-based PPM decoding for trainer port. Not implemented yet.</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>276</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>