Commit 174962a1 authored by tstellanova's avatar tstellanova

Fixing rc calibration and realtime display

parent 00b6d2fc
...@@ -24,6 +24,10 @@ ...@@ -24,6 +24,10 @@
#define WIDGET_INDEX_GENERAL_CONFIG 2 #define WIDGET_INDEX_GENERAL_CONFIG 2
#define WIDGET_INDEX_ADV_CONFIG 3 #define WIDGET_INDEX_ADV_CONFIG 3
#define MIN_PWM_VAL 800
#define MAX_PWM_VAL 2200
QGCPX4VehicleConfig::QGCPX4VehicleConfig(QWidget *parent) : QGCPX4VehicleConfig::QGCPX4VehicleConfig(QWidget *parent) :
QWidget(parent), QWidget(parent),
mav(NULL), mav(NULL),
...@@ -36,7 +40,7 @@ QGCPX4VehicleConfig::QGCPX4VehicleConfig(QWidget *parent) : ...@@ -36,7 +40,7 @@ QGCPX4VehicleConfig::QGCPX4VehicleConfig(QWidget *parent) :
rcAux1(0.0f), rcAux1(0.0f),
rcAux2(0.0f), rcAux2(0.0f),
rcAux3(0.0f), rcAux3(0.0f),
changed(true), dataModelChanged(true),
rc_mode(RC_MODE_NONE), rc_mode(RC_MODE_NONE),
calibrationEnabled(false), calibrationEnabled(false),
ui(new Ui::QGCPX4VehicleConfig) ui(new Ui::QGCPX4VehicleConfig)
...@@ -66,7 +70,9 @@ QGCPX4VehicleConfig::QGCPX4VehicleConfig(QWidget *parent) : ...@@ -66,7 +70,9 @@ QGCPX4VehicleConfig::QGCPX4VehicleConfig(QWidget *parent) :
connect(ui->generalMenuButton,SIGNAL(clicked()),this,SLOT(generalMenuButtonClicked())); connect(ui->generalMenuButton,SIGNAL(clicked()),this,SLOT(generalMenuButtonClicked()));
connect(ui->advancedMenuButton,SIGNAL(clicked()),this,SLOT(advancedMenuButtonClicked())); connect(ui->advancedMenuButton,SIGNAL(clicked()),this,SLOT(advancedMenuButtonClicked()));
ui->rcModeComboBox->setCurrentIndex((int)rc_mode - 1);
int selectedRcModeIdx = (RC_MODE_NONE != rc_mode) ? (int)(rc_mode -1) : -1;
ui->rcModeComboBox->setCurrentIndex(selectedRcModeIdx);
ui->rcCalibrationButton->setCheckable(true); ui->rcCalibrationButton->setCheckable(true);
connect(ui->rcCalibrationButton, SIGNAL(clicked(bool)), this, SLOT(toggleCalibrationRC(bool))); connect(ui->rcCalibrationButton, SIGNAL(clicked(bool)), this, SLOT(toggleCalibrationRC(bool)));
...@@ -74,32 +80,35 @@ QGCPX4VehicleConfig::QGCPX4VehicleConfig(QWidget *parent) : ...@@ -74,32 +80,35 @@ QGCPX4VehicleConfig::QGCPX4VehicleConfig(QWidget *parent) :
connect(ui->rcModeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setRCModeIndex(int))); connect(ui->rcModeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setRCModeIndex(int)));
//connect(ui->setTrimButton, SIGNAL(clicked()), this, SLOT(setTrimPositions())); //connect(ui->setTrimButton, SIGNAL(clicked()), this, SLOT(setTrimPositions()));
/* Connect RC mapping assignments */
connect(ui->rollSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setRollChan(int)));
connect(ui->pitchSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPitchChan(int))); //TODO the following methods are not yet implemented
connect(ui->yawSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setYawChan(int)));
connect(ui->throttleSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setThrottleChan(int))); // Connect RC mapping assignments
connect(ui->modeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setModeChan(int))); // connect(ui->rollSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setRollChan(int)));
connect(ui->aux1SpinBox, SIGNAL(valueChanged(int)), this, SLOT(setAux1Chan(int))); // connect(ui->pitchSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPitchChan(int)));
connect(ui->aux2SpinBox, SIGNAL(valueChanged(int)), this, SLOT(setAux2Chan(int))); // connect(ui->yawSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setYawChan(int)));
connect(ui->aux3SpinBox, SIGNAL(valueChanged(int)), this, SLOT(setAux3Chan(int))); // connect(ui->throttleSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setThrottleChan(int)));
// connect(ui->modeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setModeChan(int)));
// Connect RC reverse assignments // connect(ui->aux1SpinBox, SIGNAL(valueChanged(int)), this, SLOT(setAux1Chan(int)));
connect(ui->invertCheckBox, SIGNAL(clicked(bool)), this, SLOT(setRollInverted(bool))); // connect(ui->aux2SpinBox, SIGNAL(valueChanged(int)), this, SLOT(setAux2Chan(int)));
connect(ui->invertCheckBox_2, SIGNAL(clicked(bool)), this, SLOT(setPitchInverted(bool))); // connect(ui->aux3SpinBox, SIGNAL(valueChanged(int)), this, SLOT(setAux3Chan(int)));
connect(ui->invertCheckBox_3, SIGNAL(clicked(bool)), this, SLOT(setYawInverted(bool)));
connect(ui->invertCheckBox_4, SIGNAL(clicked(bool)), this, SLOT(setThrottleInverted(bool))); // // Connect RC reverse assignments
connect(ui->invertCheckBox_5, SIGNAL(clicked(bool)), this, SLOT(setModeInverted(bool))); // connect(ui->invertCheckBox, SIGNAL(clicked(bool)), this, SLOT(setRollInverted(bool)));
connect(ui->invertCheckBox_6, SIGNAL(clicked(bool)), this, SLOT(setAux1Inverted(bool))); // connect(ui->invertCheckBox_2, SIGNAL(clicked(bool)), this, SLOT(setPitchInverted(bool)));
connect(ui->invertCheckBox_7, SIGNAL(clicked(bool)), this, SLOT(setAux2Inverted(bool))); // connect(ui->invertCheckBox_3, SIGNAL(clicked(bool)), this, SLOT(setYawInverted(bool)));
connect(ui->invertCheckBox_8, SIGNAL(clicked(bool)), this, SLOT(setAux3Inverted(bool))); // connect(ui->invertCheckBox_4, SIGNAL(clicked(bool)), this, SLOT(setThrottleInverted(bool)));
// connect(ui->invertCheckBox_5, SIGNAL(clicked(bool)), this, SLOT(setModeInverted(bool)));
// connect(ui->invertCheckBox_6, SIGNAL(clicked(bool)), this, SLOT(setAux1Inverted(bool)));
// connect(ui->invertCheckBox_7, SIGNAL(clicked(bool)), this, SLOT(setAux2Inverted(bool)));
// connect(ui->invertCheckBox_8, SIGNAL(clicked(bool)), this, SLOT(setAux3Inverted(bool)));
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*))); connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*)));
setActiveUAS(UASManager::instance()->getActiveUAS()); setActiveUAS(UASManager::instance()->getActiveUAS());
for (unsigned int i = 0; i < chanMax; i++) for (unsigned int i = 0; i < chanMax; i++) {
{
rcValue[i] = UINT16_MAX; rcValue[i] = UINT16_MAX;
rcMapping[i] = i; rcMapping[i] = i;
} }
...@@ -139,10 +148,10 @@ QGCPX4VehicleConfig::~QGCPX4VehicleConfig() ...@@ -139,10 +148,10 @@ QGCPX4VehicleConfig::~QGCPX4VehicleConfig()
void QGCPX4VehicleConfig::setRCModeIndex(int newRcMode) void QGCPX4VehicleConfig::setRCModeIndex(int newRcMode)
{ {
if (newRcMode > 0 && newRcMode < 6) newRcMode += 1; //promote from an index to a mode enum
{ if (newRcMode > 0 && newRcMode < 5) {
//rc_mode = (enum RC_MODE) (newRcMode+1); rc_mode = (enum RC_MODE) (newRcMode);
changed = true; dataModelChanged = true;
} }
} }
...@@ -172,7 +181,6 @@ void QGCPX4VehicleConfig::setTrimPositions() ...@@ -172,7 +181,6 @@ void QGCPX4VehicleConfig::setTrimPositions()
} }
else else
{ {
// Reject // Reject
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setText(tr("Throttle Stick Trim Position Invalid")); msgBox.setText(tr("Throttle Stick Trim Position Invalid"));
...@@ -202,7 +210,6 @@ void QGCPX4VehicleConfig::startCalibrationRC() ...@@ -202,7 +210,6 @@ void QGCPX4VehicleConfig::startCalibrationRC()
{ {
QMessageBox::information(0,"Warning!","You are about to start radio calibration.\nPlease ensure all motor power is disconnected AND all props are removed from the vehicle.\nAlso ensure transmitter and reciever are powered and connected\n\nClick OK to confirm"); QMessageBox::information(0,"Warning!","You are about to start radio calibration.\nPlease ensure all motor power is disconnected AND all props are removed from the vehicle.\nAlso ensure transmitter and reciever are powered and connected\n\nClick OK to confirm");
QMessageBox::information(0,"Information","Click OK, then move all sticks to their extreme positions, watching the min/max values to ensure you get the most range from your controller. This includes all switches"); QMessageBox::information(0,"Information","Click OK, then move all sticks to their extreme positions, watching the min/max values to ensure you get the most range from your controller. This includes all switches");
ui->rcTypeComboBox->setEnabled(false);
ui->rcCalibrationButton->setText(tr("Stop RC Calibration")); ui->rcCalibrationButton->setText(tr("Stop RC Calibration"));
resetCalibrationRC(); resetCalibrationRC();
calibrationEnabled = true; calibrationEnabled = true;
...@@ -220,8 +227,8 @@ void QGCPX4VehicleConfig::stopCalibrationRC() ...@@ -220,8 +227,8 @@ void QGCPX4VehicleConfig::stopCalibrationRC()
{ {
QMessageBox::information(0,"Trims","Ensure all sticks are centeres and throttle is in the downmost position, click OK to continue"); QMessageBox::information(0,"Trims","Ensure all sticks are centeres and throttle is in the downmost position, click OK to continue");
calibrationEnabled = false; calibrationEnabled = false;
ui->rcTypeComboBox->setEnabled(true);
ui->rcCalibrationButton->setText(tr("Start RC Calibration")); ui->rcCalibrationButton->setText(tr("Start RC Calibration"));
ui->rollWidget->hideMinMax(); ui->rollWidget->hideMinMax();
ui->pitchWidget->hideMinMax(); ui->pitchWidget->hideMinMax();
ui->yawWidget->hideMinMax(); ui->yawWidget->hideMinMax();
...@@ -230,6 +237,7 @@ void QGCPX4VehicleConfig::stopCalibrationRC() ...@@ -230,6 +237,7 @@ void QGCPX4VehicleConfig::stopCalibrationRC()
ui->radio6Widget->hideMinMax(); ui->radio6Widget->hideMinMax();
ui->radio7Widget->hideMinMax(); ui->radio7Widget->hideMinMax();
ui->radio8Widget->hideMinMax(); ui->radio8Widget->hideMinMax();
QString statusstr; QString statusstr;
statusstr = "Below you will find the detected radio calibration information that will be sent to the autopilot\n"; statusstr = "Below you will find the detected radio calibration information that will be sent to the autopilot\n";
statusstr += "Normal values are around 1100 to 1900, with disconnected channels reading very close to 1500\n\n"; statusstr += "Normal values are around 1100 to 1900, with disconnected channels reading very close to 1500\n\n";
...@@ -237,7 +245,7 @@ void QGCPX4VehicleConfig::stopCalibrationRC() ...@@ -237,7 +245,7 @@ void QGCPX4VehicleConfig::stopCalibrationRC()
statusstr += "--------------------\n"; statusstr += "--------------------\n";
for (int i=0;i<8;i++) for (int i=0;i<8;i++)
{ {
statusstr += QString::number(i) + "\t" + QString::number(rcMin[i]) + "\t" + QString::number(rcValue[i]) + "\t" + QString::number(rcMax[i]) + "\n"; statusstr += QString::number(i) +"\t"+ QString::number(rcMin[i]) +"\t"+ QString::number(rcValue[i]) +"\t"+ QString::number(rcMax[i]) +"\n";
} }
QMessageBox::information(0,"Status",statusstr); QMessageBox::information(0,"Status",statusstr);
} }
...@@ -1009,13 +1017,10 @@ void QGCPX4VehicleConfig::remoteControlChannelRawChanged(int chan, float val) ...@@ -1009,13 +1017,10 @@ void QGCPX4VehicleConfig::remoteControlChannelRawChanged(int chan, float val)
// Update calibration data // Update calibration data
if (calibrationEnabled) { if (calibrationEnabled) {
if (val < rcMin[chan]) if (val < rcMin[chan]) {
{
rcMin[chan] = val; rcMin[chan] = val;
} }
if (val > rcMax[chan]) {
if (val > rcMax[chan])
{
rcMax[chan] = val; rcMax[chan] = val;
} }
} }
...@@ -1026,12 +1031,10 @@ void QGCPX4VehicleConfig::remoteControlChannelRawChanged(int chan, float val) ...@@ -1026,12 +1031,10 @@ void QGCPX4VehicleConfig::remoteControlChannelRawChanged(int chan, float val)
// Normalized value // Normalized value
float normalized; float normalized;
if (val >= rcTrim[chan]) if (val >= rcTrim[chan]) {
{
normalized = (val - rcTrim[chan])/(rcMax[chan] - rcTrim[chan]); normalized = (val - rcTrim[chan])/(rcMax[chan] - rcTrim[chan]);
} }
else else {
{
normalized = -(rcTrim[chan] - val)/(rcTrim[chan] - rcMin[chan]); normalized = -(rcTrim[chan] - val)/(rcTrim[chan] - rcMin[chan]);
} }
...@@ -1040,23 +1043,16 @@ void QGCPX4VehicleConfig::remoteControlChannelRawChanged(int chan, float val) ...@@ -1040,23 +1043,16 @@ void QGCPX4VehicleConfig::remoteControlChannelRawChanged(int chan, float val)
// Invert // Invert
normalized = (rcRev[chan]) ? -1.0f*normalized : normalized; normalized = (rcRev[chan]) ? -1.0f*normalized : normalized;
if (chan == rcMapping[0]) if (chan == rcMapping[0]) {
{
// ROLL
rcRoll = normalized; rcRoll = normalized;
} }
if (chan == rcMapping[1]) else if (chan == rcMapping[1]) {
{
// PITCH
rcPitch = normalized; rcPitch = normalized;
} }
if (chan == rcMapping[2]) else if (chan == rcMapping[2]) {
{
rcYaw = normalized; rcYaw = normalized;
} }
if (chan == rcMapping[3]) else if (chan == rcMapping[3]) {
{
// THROTTLE
if (rcRev[chan]) { if (rcRev[chan]) {
rcThrottle = 1.0f + normalized; rcThrottle = 1.0f + normalized;
} else { } else {
...@@ -1065,28 +1061,20 @@ void QGCPX4VehicleConfig::remoteControlChannelRawChanged(int chan, float val) ...@@ -1065,28 +1061,20 @@ void QGCPX4VehicleConfig::remoteControlChannelRawChanged(int chan, float val)
rcThrottle = qBound(0.0f, rcThrottle, 1.0f); rcThrottle = qBound(0.0f, rcThrottle, 1.0f);
} }
if (chan == rcMapping[4]) else if (chan == rcMapping[4]) {
{ rcMode = normalized;// MODE SWITCH
// MODE SWITCH
rcMode = normalized;
} }
if (chan == rcMapping[5]) else if (chan == rcMapping[5]) {
{ rcAux1 = normalized; // AUX1
// AUX1
rcAux1 = normalized;
} }
if (chan == rcMapping[6]) else if (chan == rcMapping[6]) {
{ rcAux2 = normalized;// AUX2
// AUX2
rcAux2 = normalized;
} }
if (chan == rcMapping[7]) else if (chan == rcMapping[7]) {
{ rcAux3 = normalized; // AUX3
// AUX3
rcAux3 = normalized;
} }
changed = true; dataModelChanged = true;
//qDebug() << "RC CHAN:" << chan << "PPM:" << val << "NORMALIZED:" << normalized; //qDebug() << "RC CHAN:" << chan << "PPM:" << val << "NORMALIZED:" << normalized;
} }
...@@ -1124,52 +1112,182 @@ void QGCPX4VehicleConfig::updateInvertedCheckboxes(int index) ...@@ -1124,52 +1112,182 @@ void QGCPX4VehicleConfig::updateInvertedCheckboxes(int index)
} }
} }
void QGCPX4VehicleConfig::handleRcParameterChange(QString parameterName, QVariant value)
{
if (parameterName.startsWith("RC_")) {
if (parameterName.startsWith("RC_MAP_")) {
//RC Mapping radio channels to meaning
// Order is: roll, pitch, yaw, throttle, mode sw, aux 1-3
int intValue = value.toInt() - 1;
if (parameterName.startsWith("RC_MAP_ROLL")) {
rcMapping[0] = intValue;
ui->rollSpinBox->setValue(rcMapping[0]+1);
ui->rollSpinBox->setEnabled(true);
}
else if (parameterName.startsWith("RC_MAP_PITCH")) {
rcMapping[1] = intValue;
ui->pitchSpinBox->setValue(rcMapping[1]+1);
ui->pitchSpinBox->setEnabled(true);
}
else if (parameterName.startsWith("RC_MAP_YAW")) {
rcMapping[2] = intValue;
ui->yawSpinBox->setValue(rcMapping[2]+1);
ui->yawSpinBox->setEnabled(true);
}
else if (parameterName.startsWith("RC_MAP_THROTTLE")) {
rcMapping[3] = intValue;
ui->throttleSpinBox->setValue(rcMapping[3]+1);
ui->throttleSpinBox->setEnabled(true);
}
else if (parameterName.startsWith("RC_MAP_MODE_SW")) {
rcMapping[4] = intValue;
ui->modeSpinBox->setValue(rcMapping[4]+1);
ui->modeSpinBox->setEnabled(true);
}
else if (parameterName.startsWith("RC_MAP_AUX1")) {
rcMapping[5] = intValue;
ui->aux1SpinBox->setValue(rcMapping[5]+1);
ui->aux1SpinBox->setEnabled(true);
}
else if (parameterName.startsWith("RC_MAP_AUX2")) {
rcMapping[6] = intValue;
ui->aux2SpinBox->setValue(rcMapping[6]+1);
ui->aux2SpinBox->setEnabled(true);
}
else if (parameterName.startsWith("RC_MAP_AUX3")) {
rcMapping[7] = intValue;
ui->aux3SpinBox->setValue(rcMapping[7]+1);
ui->aux3SpinBox->setEnabled(true);
}
}
else if (parameterName.startsWith("RC_SCALE_")) {
// Scaling
float floatVal = value.toFloat();
if (parameterName.startsWith("RC_SCALE_ROLL")) {
rcScaling[0] = floatVal;
}
else if (parameterName.startsWith("RC_SCALE_PITCH")) {
rcScaling[1] = floatVal;
}
else if (parameterName.startsWith("RC_SCALE_YAW")) {
rcScaling[2] = floatVal;
}
else if (parameterName.startsWith("RC_SCALE_THROTTLE")) {
rcScaling[3] = floatVal;
}
else if (parameterName.startsWith("RC_SCALE_MODE_SW")) {
rcScaling[4] = floatVal;
}
else if (parameterName.startsWith("RC_SCALE_AUX1")) {
rcScaling[5] = floatVal;
}
else if (parameterName.startsWith("RC_SCALE_AUX2")) {
rcScaling[6] = floatVal;
}
else if (parameterName.startsWith("RC_SCALE_AUX3")) {
rcScaling[7] = floatVal;
}
}
else if (parameterName.startsWith("RC_TYPE")) {
if (0 != rcTypeUpdateRequested) {
rcTypeUpdateRequested = 0;
updateStatus(tr("Received RC type update, setting parameters based on model."));
rcType = value.toInt();
// Request all other parameters as well
requestCalibrationRC();
}
}
}
else {
// Channel calibration values
bool ok = false;
unsigned int index = chanMax;
QRegExp minTpl("RC?_MIN");
minTpl.setPatternSyntax(QRegExp::Wildcard);
QRegExp maxTpl("RC?_MAX");
maxTpl.setPatternSyntax(QRegExp::Wildcard);
QRegExp trimTpl("RC?_TRIM");
trimTpl.setPatternSyntax(QRegExp::Wildcard);
QRegExp revTpl("RC?_REV");
revTpl.setPatternSyntax(QRegExp::Wildcard);
// Do not write the RC type, as these values depend on this
// active onboard parameter
int intVal = value.toInt();
if (minTpl.exactMatch(parameterName)) {
index = parameterName.mid(2, 1).toInt(&ok) - 1;
if (ok && index < chanMax) {
rcMin[index] = intVal;
updateRcWidgetValues();
}
}
else if (maxTpl.exactMatch(parameterName)) {
index = parameterName.mid(2, 1).toInt(&ok) - 1;
if (ok && index < chanMax) {
rcMax[index] = intVal;
updateRcWidgetValues();
}
}
else if (trimTpl.exactMatch(parameterName)) {
index = parameterName.mid(2, 1).toInt(&ok) - 1;
if (ok && index < chanMax) {
rcTrim[index] = intVal;
}
}
else if (revTpl.exactMatch(parameterName)) {
index = parameterName.mid(2, 1).toInt(&ok) - 1;
if (ok && index < chanMax) {
rcRev[index] = (intVal == -1) ? true : false;
updateInvertedCheckboxes(index);
}
}
}
}
void QGCPX4VehicleConfig::parameterChanged(int uas, int component, QString parameterName, QVariant value) void QGCPX4VehicleConfig::parameterChanged(int uas, int component, QString parameterName, QVariant value)
{ {
Q_UNUSED(uas); Q_UNUSED(uas);
Q_UNUSED(component); Q_UNUSED(component);
if (!doneLoadingConfig) if (!doneLoadingConfig) {
{
//We do not want to attempt to generate any UI elements until loading of the config file is complete. //We do not want to attempt to generate any UI elements until loading of the config file is complete.
//We should re-request params later if needed, that is not implemented yet. //We should re-request params later if needed, that is not implemented yet.
return; return;
} }
if (paramToWidgetMap.contains(parameterName)) if (parameterName.startsWith("RC")) {
{ handleRcParameterChange(parameterName,value);
return;
}
if (paramToWidgetMap.contains(parameterName)) {
//Main group of parameters of the selected airframe //Main group of parameters of the selected airframe
paramToWidgetMap.value(parameterName)->setParameterValue(uas,component,parameterName,value); paramToWidgetMap.value(parameterName)->setParameterValue(uas,component,parameterName,value);
if (toolToBoxMap.contains(paramToWidgetMap.value(parameterName))) if (toolToBoxMap.contains(paramToWidgetMap.value(parameterName))) {
{
toolToBoxMap[paramToWidgetMap.value(parameterName)]->show(); toolToBoxMap[paramToWidgetMap.value(parameterName)]->show();
} }
else else {
{
qCritical() << "Widget with no box, possible memory corruption for param:" << parameterName; qCritical() << "Widget with no box, possible memory corruption for param:" << parameterName;
} }
} }
else if (libParamToWidgetMap.contains(parameterName)) else if (libParamToWidgetMap.contains(parameterName)) {
{
//All the library parameters //All the library parameters
libParamToWidgetMap.value(parameterName)->setParameterValue(uas,component,parameterName,value); libParamToWidgetMap.value(parameterName)->setParameterValue(uas,component,parameterName,value);
if (toolToBoxMap.contains(libParamToWidgetMap.value(parameterName))) if (toolToBoxMap.contains(libParamToWidgetMap.value(parameterName))) {
{
toolToBoxMap[libParamToWidgetMap.value(parameterName)]->show(); toolToBoxMap[libParamToWidgetMap.value(parameterName)]->show();
} }
else else {
{
qCritical() << "Widget with no box, possible memory corruption for param:" << parameterName; qCritical() << "Widget with no box, possible memory corruption for param:" << parameterName;
} }
} }
else else {
{
//Param recieved that we have no metadata for. Search to see if it belongs in a //Param recieved that we have no metadata for. Search to see if it belongs in a
//group with some other params //group with some other params
bool found = false; bool found = false;
for (int i=0;i<toolWidgets.size();i++) for (int i=0;i<toolWidgets.size();i++) {
{ if (parameterName.startsWith(toolWidgets[i]->objectName())) {
if (parameterName.startsWith(toolWidgets[i]->objectName()))
{
//It should be grouped with this one, add it. //It should be grouped with this one, add it.
toolWidgets[i]->addParam(uas,component,parameterName,value); toolWidgets[i]->addParam(uas,component,parameterName,value);
libParamToWidgetMap.insert(parameterName,toolWidgets[i]); libParamToWidgetMap.insert(parameterName,toolWidgets[i]);
...@@ -1177,16 +1295,14 @@ void QGCPX4VehicleConfig::parameterChanged(int uas, int component, QString param ...@@ -1177,16 +1295,14 @@ void QGCPX4VehicleConfig::parameterChanged(int uas, int component, QString param
break; break;
} }
} }
if (!found) if (!found) {
{
//New param type, create a QGroupBox for it. //New param type, create a QGroupBox for it.
QWidget* parent = ui->advanceColumnContents; QWidget* parent = ui->advanceColumnContents;
// Create the tool, attaching it to the QGroupBox // Create the tool, attaching it to the QGroupBox
QGCToolWidget *tool = new QGCToolWidget("", parent); QGCToolWidget *tool = new QGCToolWidget("", parent);
QString tooltitle = parameterName; QString tooltitle = parameterName;
if (parameterName.split("_").size() > 1) if (parameterName.split("_").size() > 1) {
{
tooltitle = parameterName.split("_")[0] + "_"; tooltitle = parameterName.split("_")[0] + "_";
} }
tool->setTitle(tooltitle); tool->setTitle(tooltitle);
...@@ -1208,156 +1324,6 @@ void QGCPX4VehicleConfig::parameterChanged(int uas, int component, QString param ...@@ -1208,156 +1324,6 @@ void QGCPX4VehicleConfig::parameterChanged(int uas, int component, QString param
} }
} }
// Channel calibration values
QRegExp minTpl("RC?_MIN");
minTpl.setPatternSyntax(QRegExp::Wildcard);
QRegExp maxTpl("RC?_MAX");
maxTpl.setPatternSyntax(QRegExp::Wildcard);
QRegExp trimTpl("RC?_TRIM");
trimTpl.setPatternSyntax(QRegExp::Wildcard);
QRegExp revTpl("RC?_REV");
revTpl.setPatternSyntax(QRegExp::Wildcard);
// Do not write the RC type, as these values depend on this
// active onboard parameter
if (minTpl.exactMatch(parameterName)) {
bool ok;
unsigned int index = parameterName.mid(2, 1).toInt(&ok) - 1;
//qDebug() << "PARAM:" << parameterName << "index:" << index;
if (ok && index < chanMax)
{
rcMin[index] = value.toInt();
updateMinMax();
}
}
if (maxTpl.exactMatch(parameterName)) {
bool ok;
unsigned int index = parameterName.mid(2, 1).toInt(&ok) - 1;
if (ok && index < chanMax)
{
rcMax[index] = value.toInt();
updateMinMax();
}
}
if (trimTpl.exactMatch(parameterName)) {
bool ok;
unsigned int index = parameterName.mid(2, 1).toInt(&ok) - 1;
if (ok && index < chanMax)
{
rcTrim[index] = value.toInt();
}
}
if (revTpl.exactMatch(parameterName)) {
bool ok;
unsigned int index = parameterName.mid(2, 1).toInt(&ok) - 1;
if (ok && index < chanMax)
{
rcRev[index] = (value.toInt() == -1) ? true : false;
updateInvertedCheckboxes(index);
}
}
// mav->setParameter(0, trimTpl.arg(i), rcTrim[i]);
// mav->setParameter(0, maxTpl.arg(i), rcMax[i]);
// mav->setParameter(0, revTpl.arg(i), (rcRev[i]) ? -1 : 1);
// }
if (rcTypeUpdateRequested > 0 && parameterName == QString("RC_TYPE"))
{
rcTypeUpdateRequested = 0;
updateStatus(tr("Received RC type update, setting parameters based on model."));
rcType = value.toInt();
// Request all other parameters as well
requestCalibrationRC();
}
// Order is: roll, pitch, yaw, throttle, mode sw, aux 1-3
if (parameterName.contains("RC_MAP_ROLL")) {
rcMapping[0] = value.toInt() - 1;
ui->rollSpinBox->setValue(rcMapping[0]+1);
ui->rollSpinBox->setEnabled(true);
}
if (parameterName.contains("RC_MAP_PITCH")) {
rcMapping[1] = value.toInt() - 1;
ui->pitchSpinBox->setValue(rcMapping[1]+1);
ui->pitchSpinBox->setEnabled(true);
}
if (parameterName.contains("RC_MAP_YAW")) {
rcMapping[2] = value.toInt() - 1;
ui->yawSpinBox->setValue(rcMapping[2]+1);
ui->yawSpinBox->setEnabled(true);
}
if (parameterName.contains("RC_MAP_THROTTLE")) {
rcMapping[3] = value.toInt() - 1;
ui->throttleSpinBox->setValue(rcMapping[3]+1);
ui->throttleSpinBox->setEnabled(true);
}
if (parameterName.contains("RC_MAP_MODE_SW")) {
rcMapping[4] = value.toInt() - 1;
ui->modeSpinBox->setValue(rcMapping[4]+1);
ui->modeSpinBox->setEnabled(true);
}
if (parameterName.contains("RC_MAP_AUX1")) {
rcMapping[5] = value.toInt() - 1;
ui->aux1SpinBox->setValue(rcMapping[5]+1);
ui->aux1SpinBox->setEnabled(true);
}
if (parameterName.contains("RC_MAP_AUX2")) {
rcMapping[6] = value.toInt() - 1;
ui->aux2SpinBox->setValue(rcMapping[6]+1);
ui->aux2SpinBox->setEnabled(true);
}
if (parameterName.contains("RC_MAP_AUX3")) {
rcMapping[7] = value.toInt() - 1;
ui->aux3SpinBox->setValue(rcMapping[7]+1);
ui->aux3SpinBox->setEnabled(true);
}
// Scaling
if (parameterName.contains("RC_SCALE_ROLL")) {
rcScaling[0] = value.toFloat();
}
if (parameterName.contains("RC_SCALE_PITCH")) {
rcScaling[1] = value.toFloat();
}
if (parameterName.contains("RC_SCALE_YAW")) {
rcScaling[2] = value.toFloat();
}
if (parameterName.contains("RC_SCALE_THROTTLE")) {
rcScaling[3] = value.toFloat();
}
if (parameterName.contains("RC_SCALE_MODE_SW")) {
rcScaling[4] = value.toFloat();
}
if (parameterName.contains("RC_SCALE_AUX1")) {
rcScaling[5] = value.toFloat();
}
if (parameterName.contains("RC_SCALE_AUX2")) {
rcScaling[6] = value.toFloat();
}
if (parameterName.contains("RC_SCALE_AUX3")) {
rcScaling[7] = value.toFloat();
}
} }
void QGCPX4VehicleConfig::updateStatus(const QString& str) void QGCPX4VehicleConfig::updateStatus(const QString& str)
...@@ -1371,28 +1337,7 @@ void QGCPX4VehicleConfig::updateError(const QString& str) ...@@ -1371,28 +1337,7 @@ void QGCPX4VehicleConfig::updateError(const QString& str)
ui->advancedStatusLabel->setText(str); ui->advancedStatusLabel->setText(str);
ui->advancedStatusLabel->setStyleSheet(QString("QLabel { margin: 0px 2px; font: 14px; color: %1; background-color: %2; }").arg(QGC::colorDarkWhite.name()).arg(QGC::colorMagenta.name())); ui->advancedStatusLabel->setStyleSheet(QString("QLabel { margin: 0px 2px; font: 14px; color: %1; background-color: %2; }").arg(QGC::colorDarkWhite.name()).arg(QGC::colorMagenta.name()));
} }
void QGCPX4VehicleConfig::updateMinMax()
{
// Order is: roll, pitch, yaw, throttle, mode sw, aux 1-3
/*
*ui->rollWidget->setMin(rcMin[0]);
ui->rollWidget->setMax(rcMax[0]);
ui->pitchWidget->setMin(rcMin[1]);
ui->pitchWidget->setMax(rcMax[1]);
ui->yawWidget->setMin(rcMin[2]);
ui->yawWidget->setMax(rcMax[2]);
ui->throttleWidget->setMin(rcMin[3]);
ui->throttleWidget->setMax(rcMax[3]);
ui->radio5Widget->setMin(rcMin[4]);
ui->radio5Widget->setMax(rcMax[4]);
ui->radio6Widget->setMin(rcMin[5]);
ui->radio6Widget->setMax(rcMax[5]);
ui->radio7Widget->setMin(rcMin[6]);
ui->radio7Widget->setMax(rcMax[6]);
ui->radio8Widget->setMin(rcMin[7]);
ui->radio8Widget->setMax(rcMax[7]);
*/
}
void QGCPX4VehicleConfig::setRCType(int type) void QGCPX4VehicleConfig::setRCType(int type)
{ {
...@@ -1419,143 +1364,87 @@ void QGCPX4VehicleConfig::checktimeOuts() ...@@ -1419,143 +1364,87 @@ void QGCPX4VehicleConfig::checktimeOuts()
void QGCPX4VehicleConfig::updateRcWidgetValues() void QGCPX4VehicleConfig::updateRcWidgetValues()
{ {
//TODO set eg pitchSpinBox values
switch (rc_mode) { switch (rc_mode) {
case RC_MODE_1: case RC_MODE_1:
ui->rollWidget->setValue(rcValue[0]); ui->rollWidget->setValueAndRange(rcValue[0],rcMin[0],rcMax[0]);
ui->throttleWidget->setValue(rcValue[1]); ui->throttleWidget->setValueAndRange(rcValue[1],rcMin[1],rcMax[1]);
ui->yawWidget->setValue(rcValue[2]); ui->yawWidget->setValueAndRange(rcValue[2],rcMin[2],rcMax[2]);
ui->pitchWidget->setValue(rcValue[3]); ui->pitchWidget->setValueAndRange(rcValue[3],rcMin[3],rcMax[3]);
setRollChan(1);
ui->rollWidget->setMin(rcMin[0]); setThrottleChan(2);
ui->rollWidget->setMax(rcMax[0]);
ui->throttleWidget->setMin(rcMin[1]);
ui->throttleWidget->setMax(rcMax[1]);
ui->yawWidget->setMin(rcMin[2]);
ui->yawWidget->setMax(rcMax[2]);
ui->pitchWidget->setMin(rcMin[3]);
ui->pitchWidget->setMax(rcMax[3]);
break; break;
case RC_MODE_NONE:
case RC_MODE_2: case RC_MODE_2:
ui->rollWidget->setValue(rcValue[0]); ui->rollWidget->setValueAndRange(rcValue[0],rcMin[0],rcMax[0]);
ui->pitchWidget->setValue(rcValue[1]); ui->pitchWidget->setValueAndRange(rcValue[1],rcMin[1],rcMax[1]);
ui->yawWidget->setValue(rcValue[2]); ui->throttleWidget->setValueAndRange(rcValue[2],rcMin[2],rcMax[2]);
ui->throttleWidget->setValue(rcValue[3]); ui->yawWidget->setValueAndRange(rcValue[3],rcMin[3],rcMax[3]);
ui->rollWidget->setMin(rcMin[0]);
ui->rollWidget->setMax(rcMax[0]);
ui->pitchWidget->setMin(rcMin[1]);
ui->pitchWidget->setMax(rcMax[1]);
ui->yawWidget->setMin(rcMin[2]);
ui->yawWidget->setMax(rcMax[2]);
ui->throttleWidget->setMin(rcMin[3]);
ui->throttleWidget->setMax(rcMax[3]);
break; break;
case RC_MODE_3: case RC_MODE_3:
ui->yawWidget->setValue(rcValue[0]); ui->yawWidget->setValueAndRange(rcValue[0],rcMin[0],rcMax[0]);
ui->throttleWidget->setValue(rcValue[1]); ui->throttleWidget->setValueAndRange(rcValue[1],rcMin[1],rcMax[1]);
ui->rollWidget->setValue(rcValue[2]); ui->rollWidget->setValueAndRange(rcValue[2],rcMin[2],rcMax[2]);
ui->pitchWidget->setValue(rcValue[3]); ui->pitchWidget->setValueAndRange(rcValue[3],rcMin[3],rcMax[3]);
ui->yawWidget->setMin(rcMin[0]);
ui->yawWidget->setMax(rcMax[0]);
ui->throttleWidget->setMin(rcMin[1]);
ui->throttleWidget->setMax(rcMax[1]);
ui->rollWidget->setMin(rcMin[2]);
ui->rollWidget->setMax(rcMax[2]);
ui->pitchWidget->setMin(rcMin[3]);
ui->pitchWidget->setMax(rcMax[3]);
break; break;
case RC_MODE_4: case RC_MODE_4:
ui->yawWidget->setValue(rcValue[0]); ui->yawWidget->setValueAndRange(rcValue[0],rcMin[0],rcMax[0]);
ui->pitchWidget->setValue(rcValue[1]); ui->pitchWidget->setValueAndRange(rcValue[1],rcMin[1],rcMax[1]);
ui->rollWidget->setValue(rcValue[2]); ui->rollWidget->setValueAndRange(rcValue[2],rcMin[2],rcMax[2]);
ui->throttleWidget->setValue(rcValue[3]); ui->throttleWidget->setValueAndRange(rcValue[3],rcMin[3],rcMax[3]);
ui->yawWidget->setMin(rcMin[0]);
ui->yawWidget->setMax(rcMax[0]);
ui->pitchWidget->setMin(rcMin[1]);
ui->pitchWidget->setMax(rcMax[1]);
ui->rollWidget->setMin(rcMin[2]);
ui->rollWidget->setMax(rcMax[2]);
ui->throttleWidget->setMin(rcMin[3]);
ui->throttleWidget->setMax(rcMax[3]);
break;
case RC_MODE_NONE:
ui->rollWidget->setValue(rcValue[0]);
ui->pitchWidget->setValue(rcValue[1]);
ui->throttleWidget->setValue(rcValue[2]);
ui->yawWidget->setValue(rcValue[3]);
ui->rollWidget->setMin(800);
ui->rollWidget->setMax(2200);
ui->pitchWidget->setMin(800);
ui->pitchWidget->setMax(2200);
ui->throttleWidget->setMin(800);
ui->throttleWidget->setMax(2200);
ui->yawWidget->setMin(800);
ui->yawWidget->setMax(2200);
break; break;
} }
ui->radio5Widget->setValueAndRange(rcValue[4],rcMin[4],rcMax[4]);
ui->radio5Widget->setMin(rcMin[4]); ui->radio6Widget->setValueAndRange(rcValue[5],rcMin[5],rcMax[5]);
ui->radio5Widget->setMax(rcMax[4]); ui->radio7Widget->setValueAndRange(rcValue[6],rcMin[6],rcMax[6]);
ui->radio5Widget->setValue(rcValue[4]); ui->radio8Widget->setValueAndRange(rcValue[7],rcMin[7],rcMax[7]);
ui->radio6Widget->setMin(rcMin[5]);
ui->radio6Widget->setMax(rcMax[5]);
ui->radio6Widget->setValue(rcValue[5]);
ui->radio7Widget->setMin(rcMin[6]);
ui->radio7Widget->setMax(rcMax[6]);
ui->radio7Widget->setValue(rcValue[6]);
ui->radio8Widget->setMin(rcMin[7]);
ui->radio8Widget->setMax(rcMax[7]);
ui->radio8Widget->setValue(rcValue[7]);
} }
void QGCPX4VehicleConfig::updateView() void QGCPX4VehicleConfig::updateView()
{ {
if (changed) if (dataModelChanged) {
{ dataModelChanged = false;
//update the selected RC mode
int selectedRcModeIdx = (RC_MODE_NONE != rc_mode) ? (rc_mode -1) : -1;
ui->rcModeComboBox->setCurrentIndex(selectedRcModeIdx);
updateRcWidgetValues(); updateRcWidgetValues();
//update the channel labels //update the channel labels
ui->chanLabel->setText(QString("%1/%2").arg(rcValue[rcMapping[0]]).arg(rcRoll, 5, 'f', 2, QChar(' '))); ui->rollChanLabel->setText(QString("%1").arg(rcRoll, 5, 'f', 2, QChar(' ')));
ui->chanLabel_2->setText(QString("%1/%2").arg(rcValue[rcMapping[1]]).arg(rcPitch, 5, 'f', 2, QChar(' '))); ui->pitchChanLabel->setText(QString("%1").arg(rcPitch, 5, 'f', 2, QChar(' ')));
ui->chanLabel_3->setText(QString("%1/%2").arg(rcValue[rcMapping[2]]).arg(rcYaw, 5, 'f', 2, QChar(' '))); ui->yawChanLabel->setText(QString("%1").arg(rcYaw, 5, 'f', 2, QChar(' ')));
ui->chanLabel_4->setText(QString("%1/%2").arg(rcValue[rcMapping[3]]).arg(rcThrottle, 5, 'f', 2, QChar(' '))); ui->throttleChanLabel->setText(QString("%1").arg(rcThrottle, 5, 'f', 2, QChar(' ')));
if (rcValue[rcMapping[4] != UINT16_MAX]) { if (rcValue[rcMapping[4] != UINT16_MAX]) {
ui->chanLabel_5->setText(QString("%1/%2").arg(rcValue[rcMapping[4]]).arg(rcMode, 5, 'f', 2, QChar(' '))); ui->modeChanLabel->setText(QString("%1").arg(rcMode, 5, 'f', 2, QChar(' ')));
} else { } else {
ui->chanLabel_5->setText(tr("---")); ui->modeChanLabel->setText(tr("---"));
} }
if (rcValue[rcMapping[5]] != UINT16_MAX) { if (rcValue[rcMapping[5]] != UINT16_MAX) {
ui->chanLabel_6->setText(QString("%1/%2").arg(rcValue[rcMapping[5]]).arg(rcAux1, 5, 'f', 2, QChar(' '))); ui->aux1ChanLabel->setText(QString("%1").arg(rcAux1, 5, 'f', 2, QChar(' ')));
} else { } else {
ui->chanLabel_6->setText(tr("---")); ui->aux1ChanLabel->setText(tr("---"));
} }
if (rcValue[rcMapping[6]] != UINT16_MAX) { if (rcValue[rcMapping[6]] != UINT16_MAX) {
ui->chanLabel_7->setText(QString("%1/%2").arg(rcValue[rcMapping[6]]).arg(rcAux2, 5, 'f', 2, QChar(' '))); ui->aux2ChanLabel->setText(QString("%1").arg(rcAux2, 5, 'f', 2, QChar(' ')));
} else { } else {
ui->chanLabel_7->setText(tr("---")); ui->aux2ChanLabel->setText(tr("---"));
} }
if (rcValue[rcMapping[7]] != UINT16_MAX) { if (rcValue[rcMapping[7]] != UINT16_MAX) {
ui->chanLabel_8->setText(QString("%1/%2").arg(rcValue[rcMapping[7]]).arg(rcAux3, 5, 'f', 2, QChar(' '))); ui->aux3ChanLabel->setText(QString("%1").arg(rcAux3, 5, 'f', 2, QChar(' ')));
} else { } else {
ui->chanLabel_8->setText(tr("---")); ui->aux3ChanLabel->setText(tr("---"));
} }
changed = false;
} }
} }
...@@ -57,8 +57,8 @@ public slots: ...@@ -57,8 +57,8 @@ public slots:
/** Render the data updated */ /** Render the data updated */
void updateView(); void updateView();
void updateRcWidgetValues(); void updateRcWidgetValues();
void handleRcParameterChange(QString parameterName, QVariant value);
void updateMinMax();
/** Set the RC channel */ /** Set the RC channel */
void setRollChan(int channel) { void setRollChan(int channel) {
...@@ -180,7 +180,7 @@ protected: ...@@ -180,7 +180,7 @@ protected:
float rcAux2; ///< PPM input channel used as aux 2 input float rcAux2; ///< PPM input channel used as aux 2 input
float rcAux3; ///< PPM input channel used as aux 3 input float rcAux3; ///< PPM input channel used as aux 3 input
bool rcCalChanged; ///< Set if the calibration changes (and needs to be written) bool rcCalChanged; ///< Set if the calibration changes (and needs to be written)
bool changed; ///< Set if any of the input data changed bool dataModelChanged; ///< Set if any of the input data changed
QTimer updateTimer; ///< Controls update intervals QTimer updateTimer; ///< Controls update intervals
enum RC_MODE rc_mode; ///< Mode of the remote control, according to usual convention enum RC_MODE rc_mode; ///< Mode of the remote control, according to usual convention
QList<QGCToolWidget*> toolWidgets; ///< Configurable widgets QList<QGCToolWidget*> toolWidgets; ///< Configurable widgets
......
...@@ -338,18 +338,13 @@ Config</string> ...@@ -338,18 +338,13 @@ Config</string>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QComboBox" name="rcTypeComboBox"> <widget class="QLabel" name="label">
<property name="enabled">
<bool>false</bool>
</property>
<property name="editable">
<bool>false</bool>
</property>
<item>
<property name="text"> <property name="text">
<string>Select transmitter model</string> <string>RC Transmitter Mode</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</item>
</widget> </widget>
</item> </item>
<item> <item>
...@@ -357,6 +352,12 @@ Config</string> ...@@ -357,6 +352,12 @@ Config</string>
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="maximumSize">
<size>
<width>320</width>
<height>16777215</height>
</size>
</property>
<item> <item>
<property name="text"> <property name="text">
<string>Mode 1</string> <string>Mode 1</string>
...@@ -383,8 +384,8 @@ Config</string> ...@@ -383,8 +384,8 @@ Config</string>
</item> </item>
<item> <item>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="1"> <item row="1" column="6">
<widget class="QLabel" name="chanLabel_3"> <widget class="QLabel" name="aux1ChanLabel">
<property name="text"> <property name="text">
<string>0000</string> <string>0000</string>
</property> </property>
...@@ -393,72 +394,89 @@ Config</string> ...@@ -393,72 +394,89 @@ Config</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="7"> <item row="3" column="5">
<widget class="QCheckBox" name="invertCheckBox_8"> <widget class="QLabel" name="chanName_8">
<property name="text"> <property name="text">
<string>Invert</string> <string>Aux 3</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="4"> <item row="0" column="8">
<spacer name="horizontalSpacer_2"> <widget class="QSpinBox" name="modeSpinBox">
<property name="orientation"> <property name="enabled">
<enum>Qt::Horizontal</enum> <bool>false</bool>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="minimum">
<size> <number>1</number>
<width>40</width>
<height>20</height>
</size>
</property> </property>
</spacer> <property name="maximum">
<number>8</number>
</property>
</widget>
</item> </item>
<item row="2" column="0"> <item row="1" column="7">
<widget class="QLabel" name="chanName_3"> <widget class="QCheckBox" name="invertCheckBox_6">
<property name="text"> <property name="text">
<string>Yaw / Rudder</string> <string>Invert</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="6"> <item row="0" column="0">
<widget class="QLabel" name="chanLabel_5"> <widget class="QLabel" name="chanName">
<property name="text"> <property name="text">
<string>0000</string> <string>Roll / Ailerons</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="4"> <item row="1" column="5">
<spacer name="horizontalSpacer"> <widget class="QLabel" name="chanName_6">
<property name="orientation"> <property name="text">
<enum>Qt::Horizontal</enum> <string>Aux 1</string>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="alignment">
<size> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<width>40</width>
<height>20</height>
</size>
</property> </property>
</spacer> </widget>
</item> </item>
<item row="0" column="7"> <item row="1" column="2">
<widget class="QCheckBox" name="invertCheckBox_5"> <widget class="QCheckBox" name="invertCheckBox_2">
<property name="text"> <property name="text">
<string>Invert</string> <string>Invert</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2"> <item row="0" column="5">
<widget class="QCheckBox" name="invertCheckBox"> <widget class="QLabel" name="chanName_5">
<property name="text">
<string>Mode Switch</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="7">
<widget class="QCheckBox" name="invertCheckBox_8">
<property name="text"> <property name="text">
<string>Invert</string> <string>Invert</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="8"> <item row="3" column="2">
<widget class="QSpinBox" name="aux2SpinBox"> <widget class="QCheckBox" name="invertCheckBox_4">
<property name="text">
<string>Invert</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QSpinBox" name="rollSpinBox">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
...@@ -470,18 +488,21 @@ Config</string> ...@@ -470,18 +488,21 @@ Config</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="6"> <item row="1" column="8">
<widget class="QLabel" name="chanLabel_7"> <widget class="QSpinBox" name="aux1SpinBox">
<property name="text"> <property name="enabled">
<string>0000</string> <bool>false</bool>
</property> </property>
<property name="alignment"> <property name="minimum">
<set>Qt::AlignCenter</set> <number>1</number>
</property>
<property name="maximum">
<number>8</number>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="2" column="6">
<widget class="QLabel" name="chanLabel_2"> <widget class="QLabel" name="aux2ChanLabel">
<property name="text"> <property name="text">
<string>0000</string> <string>0000</string>
</property> </property>
...@@ -490,45 +511,48 @@ Config</string> ...@@ -490,45 +511,48 @@ Config</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="3" column="3">
<widget class="QLabel" name="chanName_2"> <widget class="QSpinBox" name="throttleSpinBox">
<property name="text"> <property name="enabled">
<string>Pitch / Elevator</string> <bool>false</bool>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>8</number>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="2" column="0">
<widget class="QLabel" name="chanLabel"> <widget class="QLabel" name="chanName_3">
<property name="text"> <property name="text">
<string>0000</string> <string>Yaw / Rudder</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="5"> <item row="2" column="7">
<widget class="QLabel" name="chanName_7"> <widget class="QCheckBox" name="invertCheckBox_7">
<property name="text"> <property name="text">
<string>Aux 2</string> <string>Invert</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="4"> <item row="3" column="0">
<spacer name="horizontalSpacer_3"> <widget class="QLabel" name="chanName_4">
<property name="orientation"> <property name="text">
<enum>Qt::Horizontal</enum> <string>Throttle</string>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="alignment">
<size> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<width>40</width>
<height>20</height>
</size>
</property> </property>
</spacer> </widget>
</item> </item>
<item row="3" column="6"> <item row="3" column="6">
<widget class="QLabel" name="chanLabel_8"> <widget class="QLabel" name="aux3ChanLabel">
<property name="text"> <property name="text">
<string>0000</string> <string>0000</string>
</property> </property>
...@@ -537,15 +561,8 @@ Config</string> ...@@ -537,15 +561,8 @@ Config</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="2"> <item row="2" column="3">
<widget class="QCheckBox" name="invertCheckBox_3"> <widget class="QSpinBox" name="yawSpinBox">
<property name="text">
<string>Invert</string>
</property>
</widget>
</item>
<item row="3" column="8">
<widget class="QSpinBox" name="aux3SpinBox">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
...@@ -557,48 +574,48 @@ Config</string> ...@@ -557,48 +574,48 @@ Config</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="4"> <item row="1" column="0">
<spacer name="horizontalSpacer_4"> <widget class="QLabel" name="chanName_2">
<property name="orientation"> <property name="text">
<enum>Qt::Horizontal</enum> <string>Pitch / Elevator</string>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="alignment">
<size> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<width>40</width>
<height>20</height>
</size>
</property> </property>
</spacer> </widget>
</item> </item>
<item row="3" column="0"> <item row="0" column="1">
<widget class="QLabel" name="chanName_4"> <widget class="QLabel" name="rollChanLabel">
<property name="text"> <property name="text">
<string>Throttle</string> <string>0000</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="7"> <item row="2" column="5">
<widget class="QCheckBox" name="invertCheckBox_7"> <widget class="QLabel" name="chanName_7">
<property name="text"> <property name="text">
<string>Invert</string> <string>Aux 2</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="3"> <item row="0" column="6">
<widget class="QSpinBox" name="yawSpinBox"> <widget class="QLabel" name="modeChanLabel">
<property name="enabled"> <property name="text">
<bool>false</bool> <string>0000</string>
</property>
<property name="minimum">
<number>1</number>
</property> </property>
<property name="maximum"> <property name="alignment">
<number>8</number> <set>Qt::AlignCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="3"> <item row="1" column="3">
<widget class="QSpinBox" name="throttleSpinBox"> <widget class="QSpinBox" name="pitchSpinBox">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
...@@ -610,15 +627,8 @@ Config</string> ...@@ -610,15 +627,8 @@ Config</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="5">
<widget class="QLabel" name="chanName_5">
<property name="text">
<string>Mode Switch</string>
</property>
</widget>
</item>
<item row="3" column="1"> <item row="3" column="1">
<widget class="QLabel" name="chanLabel_4"> <widget class="QLabel" name="throttleChanLabel">
<property name="text"> <property name="text">
<string>0000</string> <string>0000</string>
</property> </property>
...@@ -627,8 +637,8 @@ Config</string> ...@@ -627,8 +637,8 @@ Config</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="3"> <item row="3" column="8">
<widget class="QSpinBox" name="pitchSpinBox"> <widget class="QSpinBox" name="aux3SpinBox">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
...@@ -640,28 +650,25 @@ Config</string> ...@@ -640,28 +650,25 @@ Config</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="8"> <item row="2" column="1">
<widget class="QSpinBox" name="aux1SpinBox"> <widget class="QLabel" name="yawChanLabel">
<property name="enabled"> <property name="text">
<bool>false</bool> <string>0000</string>
</property>
<property name="minimum">
<number>1</number>
</property> </property>
<property name="maximum"> <property name="alignment">
<number>8</number> <set>Qt::AlignCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="5"> <item row="0" column="7">
<widget class="QLabel" name="chanName_6"> <widget class="QCheckBox" name="invertCheckBox_5">
<property name="text"> <property name="text">
<string>Aux 1</string> <string>Invert</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="3"> <item row="2" column="8">
<widget class="QSpinBox" name="rollSpinBox"> <widget class="QSpinBox" name="aux2SpinBox">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
...@@ -673,8 +680,8 @@ Config</string> ...@@ -673,8 +680,8 @@ Config</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="6"> <item row="1" column="1">
<widget class="QLabel" name="chanLabel_6"> <widget class="QLabel" name="pitchChanLabel">
<property name="text"> <property name="text">
<string>0000</string> <string>0000</string>
</property> </property>
...@@ -683,53 +690,71 @@ Config</string> ...@@ -683,53 +690,71 @@ Config</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="5"> <item row="0" column="2">
<widget class="QLabel" name="chanName_8"> <widget class="QCheckBox" name="invertCheckBox">
<property name="text"> <property name="text">
<string>Aux 3</string> <string>Invert</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="7"> <item row="2" column="2">
<widget class="QCheckBox" name="invertCheckBox_6"> <widget class="QCheckBox" name="invertCheckBox_3">
<property name="text"> <property name="text">
<string>Invert</string> <string>Invert</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="8"> <item row="3" column="4">
<widget class="QSpinBox" name="modeSpinBox"> <spacer name="horizontalSpacer_4">
<property name="enabled"> <property name="orientation">
<bool>false</bool> <enum>Qt::Horizontal</enum>
</property>
<property name="minimum">
<number>1</number>
</property> </property>
<property name="maximum"> <property name="sizeHint" stdset="0">
<number>8</number> <size>
<width>40</width>
<height>20</height>
</size>
</property> </property>
</widget> </spacer>
</item> </item>
<item row="3" column="2"> <item row="2" column="4">
<widget class="QCheckBox" name="invertCheckBox_4"> <spacer name="horizontalSpacer_3">
<property name="text"> <property name="orientation">
<string>Invert</string> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> <property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item> </item>
<item row="1" column="2"> <item row="1" column="4">
<widget class="QCheckBox" name="invertCheckBox_2"> <spacer name="horizontalSpacer_2">
<property name="text"> <property name="orientation">
<string>Invert</string> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> <property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item> </item>
<item row="0" column="0"> <item row="0" column="4">
<widget class="QLabel" name="chanName"> <spacer name="horizontalSpacer">
<property name="text"> <property name="orientation">
<string>Roll / Ailerons</string> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> <property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item> </item>
</layout> </layout>
</item> </item>
......
#include "QGCRadioChannelDisplay.h" #include "QGCRadioChannelDisplay.h"
#include <QPainter> #include <QPainter>
#define DIMMEST_COLOR QColor::fromRgb(0,100,0)
#define MIDBRIGHT_COLOR QColor::fromRgb(0,180,0)
#define BRIGHTEST_COLOR QColor::fromRgb(64,255,0)
QGCRadioChannelDisplay::QGCRadioChannelDisplay(QWidget *parent) : QWidget(parent) QGCRadioChannelDisplay::QGCRadioChannelDisplay(QWidget *parent) : QWidget(parent)
{ {
m_showMinMax = false; m_showMinMax = false;
...@@ -53,9 +58,9 @@ void QGCRadioChannelDisplay::paintEvent(QPaintEvent *event) ...@@ -53,9 +58,9 @@ void QGCRadioChannelDisplay::paintEvent(QPaintEvent *event)
if (m_orientation == Qt::Vertical) if (m_orientation == Qt::Vertical)
{ {
QLinearGradient gradientBrush(0, 0, this->width(), this->height()); QLinearGradient gradientBrush(0, 0, this->width(), this->height());
gradientBrush.setColorAt(1.0,QColor::fromRgb(0,128,0)); gradientBrush.setColorAt(1.0,DIMMEST_COLOR);
gradientBrush.setColorAt(0.5,QColor::fromRgb(0,200,0)); gradientBrush.setColorAt(0.5,MIDBRIGHT_COLOR);
gradientBrush.setColorAt(0.0, QColor::fromRgb(64,255,0)); gradientBrush.setColorAt(0.0, BRIGHTEST_COLOR);
//draw border //draw border
painter.drawRect(0,0,width()-1,(height()-1) - twiceFontHeight); painter.drawRect(0,0,width()-1,(height()-1) - twiceFontHeight);
...@@ -105,9 +110,9 @@ void QGCRadioChannelDisplay::paintEvent(QPaintEvent *event) ...@@ -105,9 +110,9 @@ void QGCRadioChannelDisplay::paintEvent(QPaintEvent *event)
else //horizontal orientation else //horizontal orientation
{ {
QLinearGradient hGradientBrush(0, 0, this->width(), this->height()); QLinearGradient hGradientBrush(0, 0, this->width(), this->height());
hGradientBrush.setColorAt(0.0,QColor::fromRgb(0,128,0)); hGradientBrush.setColorAt(0.0,DIMMEST_COLOR);
hGradientBrush.setColorAt(0.5,QColor::fromRgb(0,200,0)); hGradientBrush.setColorAt(0.5,MIDBRIGHT_COLOR);
hGradientBrush.setColorAt(1.0, QColor::fromRgb(64,255,0)); hGradientBrush.setColorAt(1.0, BRIGHTEST_COLOR);
//draw the value //draw the value
painter.drawRect(0,0,width()-1,(height()-1) - twiceFontHeight); painter.drawRect(0,0,width()-1,(height()-1) - twiceFontHeight);
...@@ -178,6 +183,19 @@ void QGCRadioChannelDisplay::hideMinMax() ...@@ -178,6 +183,19 @@ void QGCRadioChannelDisplay::hideMinMax()
update(); update();
} }
void QGCRadioChannelDisplay::setValueAndRange(int val, int min, int max)
{
setValue(val);
setMinMax(min,max);
}
void QGCRadioChannelDisplay::setMinMax(int min, int max)
{
setMin(min);
setMax(max);
}
void QGCRadioChannelDisplay::setMin(int value) void QGCRadioChannelDisplay::setMin(int value)
{ {
m_min = value; m_min = value;
......
...@@ -12,6 +12,8 @@ public: ...@@ -12,6 +12,8 @@ public:
void setValue(int value); void setValue(int value);
void showMinMax(); void showMinMax();
void hideMinMax(); void hideMinMax();
void setValueAndRange(int val, int min, int max);
void setMinMax(int min, int max);
void setMin(int value); void setMin(int value);
void setMax(int value); void setMax(int value);
void setName(QString name); void setName(QString name);
......
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