1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-19 14:25:11 +03:00
This commit is contained in:
bsongis 2015-05-10 12:31:43 +02:00
parent cde0824f05
commit 274303a658
7 changed files with 1870 additions and 1751 deletions

View file

@ -576,8 +576,10 @@ int OpenTxFirmware::getCapability(const Capability capability)
case Pots: case Pots:
if (IS_TARANIS_X9E(board)) if (IS_TARANIS_X9E(board))
return 4; return 4;
else if (IS_TARANIS(board)) else if (IS_TARANIS_PLUS(board))
return 3; return 3;
else if (IS_TARANIS(board))
return 2;
else else
return 3; return 3;
case Sliders: case Sliders:

View file

@ -940,10 +940,20 @@ void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx)
} }
BoardEnum board = GetCurrentFirmware()->getBoard(); BoardEnum board = GetCurrentFirmware()->getBoard();
SimulatorDialog * sd; SimulatorDialog * sd;
if (IS_TARANIS(board)) if (IS_TARANIS(board)) {
for (int i=0; i<GetCurrentFirmware()->getCapability(Pots); i++) {
if (radioData.generalSettings.potConfig[i] != GeneralSettings::POT_NONE) {
flags |= (SIMULATOR_FLAGS_S1 << i);
if (radioData.generalSettings.potConfig[1] == GeneralSettings::POT_MULTIPOS_SWITCH ) {
flags |= (SIMULATOR_FLAGS_S1_MULTI << i);
}
}
}
sd = new SimulatorDialogTaranis(parent, si, flags); sd = new SimulatorDialogTaranis(parent, si, flags);
else }
else {
sd = new SimulatorDialog9X(parent, si, flags); sd = new SimulatorDialog9X(parent, si, flags);
}
QByteArray eeprom(GetEepromInterface()->getEEpromSize(), 0); QByteArray eeprom(GetEepromInterface()->getEEpromSize(), 0);
GetEepromInterface()->save((uint8_t *)eeprom.data(), *simuData, GetCurrentFirmware()->getCapability(SimulatorVariant)); GetEepromInterface()->save((uint8_t *)eeprom.data(), *simuData, GetCurrentFirmware()->getCapability(SimulatorVariant));
delete simuData; delete simuData;

View file

@ -136,6 +136,26 @@ QString getFrSkySrc(int index);
void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx); void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx);
template <class T>
QVector<T> findWidgets(QObject * object, const QString & name)
{
QVector<T> result;
QRegExp rx(name.arg("([0-9]+)"));
QList<T> children = object->findChildren<T>();
foreach(T child, children) {
int pos = rx.indexIn(child->objectName());
if (pos >= 0) {
QStringList list = rx.capturedTexts();
int index = list[1].toInt();
if (result.size() <= index) {
result.resize(index+1);
}
result[index] = child;
}
}
return result;
}
// Format a pixmap to fit on the radio using a specific firmware // Format a pixmap to fit on the radio using a specific firmware
QPixmap makePixMap( QImage image, QString firmwareType ); QPixmap makePixMap( QImage image, QString firmwareType );

View file

@ -1020,7 +1020,7 @@ QPushButton:checked {
</spacer> </spacer>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="myQDial" name="dialP_1"> <widget class="myQDial" name="dial0">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -1054,7 +1054,7 @@ QPushButton:checked {
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="3" column="0">
<widget class="QLabel" name="dialP_1value"> <widget class="QLabel" name="dialValue0">
<property name="text"> <property name="text">
<string notr="true">0 %</string> <string notr="true">0 %</string>
</property> </property>
@ -1077,7 +1077,7 @@ QPushButton:checked {
</spacer> </spacer>
</item> </item>
<item row="5" column="0"> <item row="5" column="0">
<widget class="myQDial" name="dialP_2"> <widget class="myQDial" name="dial1">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -1114,7 +1114,7 @@ QPushButton:checked {
</widget> </widget>
</item> </item>
<item row="6" column="0"> <item row="6" column="0">
<widget class="QLabel" name="dialP_2value"> <widget class="QLabel" name="dialValue1">
<property name="text"> <property name="text">
<string notr="true">0 %</string> <string notr="true">0 %</string>
</property> </property>
@ -1137,7 +1137,7 @@ QPushButton:checked {
</spacer> </spacer>
</item> </item>
<item row="8" column="0"> <item row="8" column="0">
<widget class="myQDial" name="dialP_3"> <widget class="myQDial" name="dial2">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -1171,7 +1171,7 @@ QPushButton:checked {
</widget> </widget>
</item> </item>
<item row="9" column="0"> <item row="9" column="0">
<widget class="QLabel" name="dialP_3value"> <widget class="QLabel" name="dialValue2">
<property name="text"> <property name="text">
<string notr="true">0 %</string> <string notr="true">0 %</string>
</property> </property>

File diff suppressed because it is too large Load diff

View file

@ -50,7 +50,6 @@ void SimulatorDialog::updateDebugOutput()
SimulatorDialog::SimulatorDialog(QWidget * parent, SimulatorInterface *simulator, unsigned int flags): SimulatorDialog::SimulatorDialog(QWidget * parent, SimulatorInterface *simulator, unsigned int flags):
QDialog(parent), QDialog(parent),
flags(flags), flags(flags),
dialP_4(NULL),
timer(NULL), timer(NULL),
lightOn(false), lightOn(false),
simulator(simulator), simulator(simulator),
@ -118,10 +117,9 @@ SimulatorDialog9X::SimulatorDialog9X(QWidget * parent, SimulatorInterface *simul
ui->trimHL_R->setText(QString::fromUtf8(rightArrow)); ui->trimHL_R->setText(QString::fromUtf8(rightArrow));
ui->trimVL_U->setText(QString::fromUtf8(upArrow)); ui->trimVL_U->setText(QString::fromUtf8(upArrow));
ui->trimVL_D->setText(QString::fromUtf8(downArrow)); ui->trimVL_D->setText(QString::fromUtf8(downArrow));
for (int i=0; i<pots.count(); i++) {
connect(ui->dialP_1, SIGNAL(valueChanged(int)), this, SLOT(dialChanged())); connect(pots[i], SIGNAL(valueChanged(int)), this, SLOT(dialChanged(i)));
connect(ui->dialP_2, SIGNAL(valueChanged(int)), this, SLOT(dialChanged())); }
connect(ui->dialP_3, SIGNAL(valueChanged(int)), this, SLOT(dialChanged()));
connect(ui->cursor, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int))); connect(ui->cursor, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int)));
connect(ui->menu, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int))); connect(ui->menu, SIGNAL(buttonPressed(int)), this, SLOT(onButtonPressed(int)));
connect(ui->trimHR_L, SIGNAL(pressed()), this, SLOT(onTrimPressed())); connect(ui->trimHR_L, SIGNAL(pressed()), this, SLOT(onTrimPressed()));
@ -156,20 +154,31 @@ SimulatorDialogTaranis::SimulatorDialogTaranis(QWidget * parent, SimulatorInterf
{ {
lcdWidth = 212; lcdWidth = 212;
lcdDepth = 4; lcdDepth = 4;
initUi<Ui::SimulatorDialogTaranis>(ui); initUi<Ui::SimulatorDialogTaranis>(ui);
// install simulator TRACE hook // install simulator TRACE hook
simulator->installTraceHook(traceCb); simulator->installTraceHook(traceCb);
dialP_4 = ui->dialP_4;
ui->lcd->setBackgroundColor(47, 123, 227); ui->lcd->setBackgroundColor(47, 123, 227);
//restore switches // restore switches
if (g.simuSW()) if (g.simuSW()) {
restoreSwitches(); restoreSwitches();
}
for (int i=0; i<pots.count(); i++) {
if (flags & (SIMULATOR_FLAGS_S1_MULTI << i)) {
pots[i]->setValue(-1024);
pots[i]->setSingleStep(2048/5);
pots[i]->setPageStep(2048/5);
}
else if (!(flags & (SIMULATOR_FLAGS_S1 << i))) {
pots[i]->hide();
potLabels[i]->hide();
}
}
ui->trimHR_L->setText(QString::fromUtf8(leftArrow)); ui->trimHR_L->setText(QString::fromUtf8(leftArrow));
ui->trimHR_R->setText(QString::fromUtf8(rightArrow)); ui->trimHR_R->setText(QString::fromUtf8(rightArrow));
ui->trimVR_U->setText(QString::fromUtf8(upArrow)); ui->trimVR_U->setText(QString::fromUtf8(upArrow));
@ -232,11 +241,9 @@ void SimulatorDialog::mouseReleaseEvent(QMouseEvent *event)
} }
} }
void SimulatorDialog9X::dialChanged() void SimulatorDialog::dialChanged(int index)
{ {
ui->dialP_1value->setText(QString("%1 %").arg((ui->dialP_1->value()*100)/1024)); potValues[index]->setText(QString("%1 %").arg((pots[index]->value()*100)/1024));
ui->dialP_2value->setText(QString("%1 %").arg((ui->dialP_2->value()*100)/1024));
ui->dialP_3value->setText(QString("%1 %").arg((ui->dialP_3->value()*100)/1024));
} }
void SimulatorDialog::wheelEvent (QWheelEvent *event) void SimulatorDialog::wheelEvent (QWheelEvent *event)
@ -371,9 +378,11 @@ void SimulatorDialog::initUi(T * ui)
lcd = ui->lcd; lcd = ui->lcd;
leftStick = ui->leftStick; leftStick = ui->leftStick;
rightStick = ui->rightStick; rightStick = ui->rightStick;
dialP_1 = ui->dialP_1; pots = findWidgets<QDial *>(this, "pot%1");
dialP_2 = ui->dialP_2; potLabels = findWidgets<QLabel *>(this, "potLabel%1");
dialP_3 = ui->dialP_3; potValues = findWidgets<QLabel *>(this, "potValue%1");
sliders = findWidgets<QSlider *>(this, "slider%1");
trimHLeft = ui->trimHLeft; trimHLeft = ui->trimHLeft;
trimVLeft = ui->trimVLeft; trimVLeft = ui->trimVLeft;
trimHRight = ui->trimHRight; trimHRight = ui->trimHRight;
@ -726,9 +735,9 @@ void SimulatorDialog9X::getValues()
}, },
{ {
ui->dialP_1->value(), pots[0]->value(),
ui->dialP_2->value(), pots[1]->value(),
ui->dialP_3->value(), 0 pots[2]->value()
}, },
{ {
@ -820,6 +829,13 @@ void SimulatorDialogTaranis::on_switchH_sliderReleased()
void SimulatorDialogTaranis::getValues() void SimulatorDialogTaranis::getValues()
{ {
for (int i=0; i<pots.count(); i++) {
if (flags & (SIMULATOR_FLAGS_S1_MULTI << i)) {
int s1 = round((pots[i]->value()+1024)/(2048.0/5))*(2048.0/5)-1024;
pots[i]->setValue(s1);
}
}
TxInputs inputs = { TxInputs inputs = {
{ {
int(1024*nodeLeft->getX()), // LEFT HORZ int(1024*nodeLeft->getX()), // LEFT HORZ
@ -829,11 +845,11 @@ void SimulatorDialogTaranis::getValues()
}, },
{ {
-ui->dialP_1->value(), -pots[0]->value(),
ui->dialP_2->value(), pots[1]->value(),
0, ((flags && SIMULATOR_FLAGS_S3) ? pots[2]->value() : 0),
-ui->dialP_3->value(), -sliders[0]->value(),
ui->dialP_4->value() sliders[1]->value()
}, },
{ {
@ -1107,18 +1123,9 @@ void SimulatorDialog::onjoystickAxisValueChanged(int axis, int value)
} }
else if (stick==4) { else if (stick==4) {
nodeLeft->setX(stickval/1024.0); nodeLeft->setX(stickval/1024.0);
}
else if (stick==5) {
dialP_1->setValue(stickval);
} }
else if (stick==6) { else if (stick >= 5 && stick < 5+pots.count()) {
dialP_2->setValue(stickval); pots[stick-5]->setValue(stickval);
}
else if (stick==7) {
dialP_3->setValue(stickval);
}
else if (stick==8 && dialP_4) {
dialP_4->setValue(stickval);
} }
} }
} }

View file

@ -27,8 +27,16 @@ namespace Ui {
class lcdWidget; class lcdWidget;
class mySlider; class mySlider;
#define SIMULATOR_FLAGS_NOTX 1 #define SIMULATOR_FLAGS_NOTX 1
#define SIMULATOR_FLAGS_STICK_MODE_LEFT 2 #define SIMULATOR_FLAGS_STICK_MODE_LEFT 2
#define SIMULATOR_FLAGS_S1 4
#define SIMULATOR_FLAGS_S2 8
#define SIMULATOR_FLAGS_S3 16
#define SIMULATOR_FLAGS_S4 32 // reserved for the future
#define SIMULATOR_FLAGS_S1_MULTI 64
#define SIMULATOR_FLAGS_S2_MULTI 128
#define SIMULATOR_FLAGS_S3_MULTI 256
#define SIMULATOR_FLAGS_S4_MULTI 512 // reserved for the future
class SimulatorDialog : public QDialog class SimulatorDialog : public QDialog
{ {
@ -50,7 +58,11 @@ class SimulatorDialog : public QDialog
unsigned int flags; unsigned int flags;
lcdWidget * lcd; lcdWidget * lcd;
QGraphicsView * leftStick, * rightStick; QGraphicsView * leftStick, * rightStick;
QDial * dialP_1, * dialP_2, * dialP_3, * dialP_4; QVector<QDial *> pots;
QVector<QLabel *> potLabels;
QVector<QLabel *> potValues;
QVector<QSlider *> sliders;
mySlider * trimHLeft, * trimVLeft, * trimHRight, * trimVRight; mySlider * trimHLeft, * trimVLeft, * trimHRight, * trimVRight;
QLabel * leftXPerc, * rightXPerc, * leftYPerc, * rightYPerc; QLabel * leftXPerc, * rightXPerc, * leftYPerc, * rightYPerc;
QTabWidget * tabWidget; QTabWidget * tabWidget;
@ -119,6 +131,7 @@ class SimulatorDialog : public QDialog
private slots: private slots:
void onButtonPressed(int value); void onButtonPressed(int value);
void dialChanged(int index);
void on_FixRightY_clicked(bool checked); void on_FixRightY_clicked(bool checked);
void on_FixRightX_clicked(bool checked); void on_FixRightX_clicked(bool checked);
void on_FixLeftY_clicked(bool checked); void on_FixLeftY_clicked(bool checked);
@ -160,9 +173,6 @@ class SimulatorDialog9X: public SimulatorDialog
void saveSwitches(void); void saveSwitches(void);
void restoreSwitches(void); void restoreSwitches(void);
private slots:
void dialChanged();
private: private:
Ui::SimulatorDialog9X * ui; Ui::SimulatorDialog9X * ui;
static uint32_t switchstatus; static uint32_t switchstatus;