mirror of
https://github.com/opentx/opentx.git
synced 2025-07-23 16:25:16 +03:00
Fixes #1917
This commit is contained in:
parent
cde0824f05
commit
274303a658
7 changed files with 1870 additions and 1751 deletions
|
@ -576,8 +576,10 @@ int OpenTxFirmware::getCapability(const Capability capability)
|
|||
case Pots:
|
||||
if (IS_TARANIS_X9E(board))
|
||||
return 4;
|
||||
else if (IS_TARANIS(board))
|
||||
else if (IS_TARANIS_PLUS(board))
|
||||
return 3;
|
||||
else if (IS_TARANIS(board))
|
||||
return 2;
|
||||
else
|
||||
return 3;
|
||||
case Sliders:
|
||||
|
|
|
@ -940,10 +940,20 @@ void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx)
|
|||
}
|
||||
BoardEnum board = GetCurrentFirmware()->getBoard();
|
||||
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);
|
||||
else
|
||||
}
|
||||
else {
|
||||
sd = new SimulatorDialog9X(parent, si, flags);
|
||||
}
|
||||
QByteArray eeprom(GetEepromInterface()->getEEpromSize(), 0);
|
||||
GetEepromInterface()->save((uint8_t *)eeprom.data(), *simuData, GetCurrentFirmware()->getCapability(SimulatorVariant));
|
||||
delete simuData;
|
||||
|
|
|
@ -136,6 +136,26 @@ QString getFrSkySrc(int index);
|
|||
|
||||
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
|
||||
QPixmap makePixMap( QImage image, QString firmwareType );
|
||||
|
||||
|
|
|
@ -1020,7 +1020,7 @@ QPushButton:checked {
|
|||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="myQDial" name="dialP_1">
|
||||
<widget class="myQDial" name="dial0">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
|
@ -1054,7 +1054,7 @@ QPushButton:checked {
|
|||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="dialP_1value">
|
||||
<widget class="QLabel" name="dialValue0">
|
||||
<property name="text">
|
||||
<string notr="true">0 %</string>
|
||||
</property>
|
||||
|
@ -1077,7 +1077,7 @@ QPushButton:checked {
|
|||
</spacer>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="myQDial" name="dialP_2">
|
||||
<widget class="myQDial" name="dial1">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
|
@ -1114,7 +1114,7 @@ QPushButton:checked {
|
|||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="dialP_2value">
|
||||
<widget class="QLabel" name="dialValue1">
|
||||
<property name="text">
|
||||
<string notr="true">0 %</string>
|
||||
</property>
|
||||
|
@ -1137,7 +1137,7 @@ QPushButton:checked {
|
|||
</spacer>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="myQDial" name="dialP_3">
|
||||
<widget class="myQDial" name="dial2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
|
@ -1171,7 +1171,7 @@ QPushButton:checked {
|
|||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<widget class="QLabel" name="dialP_3value">
|
||||
<widget class="QLabel" name="dialValue2">
|
||||
<property name="text">
|
||||
<string notr="true">0 %</string>
|
||||
</property>
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -50,7 +50,6 @@ void SimulatorDialog::updateDebugOutput()
|
|||
SimulatorDialog::SimulatorDialog(QWidget * parent, SimulatorInterface *simulator, unsigned int flags):
|
||||
QDialog(parent),
|
||||
flags(flags),
|
||||
dialP_4(NULL),
|
||||
timer(NULL),
|
||||
lightOn(false),
|
||||
simulator(simulator),
|
||||
|
@ -118,10 +117,9 @@ SimulatorDialog9X::SimulatorDialog9X(QWidget * parent, SimulatorInterface *simul
|
|||
ui->trimHL_R->setText(QString::fromUtf8(rightArrow));
|
||||
ui->trimVL_U->setText(QString::fromUtf8(upArrow));
|
||||
ui->trimVL_D->setText(QString::fromUtf8(downArrow));
|
||||
|
||||
connect(ui->dialP_1, SIGNAL(valueChanged(int)), this, SLOT(dialChanged()));
|
||||
connect(ui->dialP_2, SIGNAL(valueChanged(int)), this, SLOT(dialChanged()));
|
||||
connect(ui->dialP_3, SIGNAL(valueChanged(int)), this, SLOT(dialChanged()));
|
||||
for (int i=0; i<pots.count(); i++) {
|
||||
connect(pots[i], SIGNAL(valueChanged(int)), this, SLOT(dialChanged(i)));
|
||||
}
|
||||
connect(ui->cursor, 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()));
|
||||
|
@ -162,13 +160,24 @@ SimulatorDialogTaranis::SimulatorDialogTaranis(QWidget * parent, SimulatorInterf
|
|||
// install simulator TRACE hook
|
||||
simulator->installTraceHook(traceCb);
|
||||
|
||||
dialP_4 = ui->dialP_4;
|
||||
|
||||
ui->lcd->setBackgroundColor(47, 123, 227);
|
||||
|
||||
//restore switches
|
||||
if (g.simuSW())
|
||||
// restore switches
|
||||
if (g.simuSW()) {
|
||||
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_R->setText(QString::fromUtf8(rightArrow));
|
||||
|
@ -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));
|
||||
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));
|
||||
potValues[index]->setText(QString("%1 %").arg((pots[index]->value()*100)/1024));
|
||||
}
|
||||
|
||||
void SimulatorDialog::wheelEvent (QWheelEvent *event)
|
||||
|
@ -371,9 +378,11 @@ void SimulatorDialog::initUi(T * ui)
|
|||
lcd = ui->lcd;
|
||||
leftStick = ui->leftStick;
|
||||
rightStick = ui->rightStick;
|
||||
dialP_1 = ui->dialP_1;
|
||||
dialP_2 = ui->dialP_2;
|
||||
dialP_3 = ui->dialP_3;
|
||||
pots = findWidgets<QDial *>(this, "pot%1");
|
||||
potLabels = findWidgets<QLabel *>(this, "potLabel%1");
|
||||
potValues = findWidgets<QLabel *>(this, "potValue%1");
|
||||
sliders = findWidgets<QSlider *>(this, "slider%1");
|
||||
|
||||
trimHLeft = ui->trimHLeft;
|
||||
trimVLeft = ui->trimVLeft;
|
||||
trimHRight = ui->trimHRight;
|
||||
|
@ -726,9 +735,9 @@ void SimulatorDialog9X::getValues()
|
|||
},
|
||||
|
||||
{
|
||||
ui->dialP_1->value(),
|
||||
ui->dialP_2->value(),
|
||||
ui->dialP_3->value(), 0
|
||||
pots[0]->value(),
|
||||
pots[1]->value(),
|
||||
pots[2]->value()
|
||||
},
|
||||
|
||||
{
|
||||
|
@ -820,6 +829,13 @@ void SimulatorDialogTaranis::on_switchH_sliderReleased()
|
|||
|
||||
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 = {
|
||||
{
|
||||
int(1024*nodeLeft->getX()), // LEFT HORZ
|
||||
|
@ -829,11 +845,11 @@ void SimulatorDialogTaranis::getValues()
|
|||
},
|
||||
|
||||
{
|
||||
-ui->dialP_1->value(),
|
||||
ui->dialP_2->value(),
|
||||
0,
|
||||
-ui->dialP_3->value(),
|
||||
ui->dialP_4->value()
|
||||
-pots[0]->value(),
|
||||
pots[1]->value(),
|
||||
((flags && SIMULATOR_FLAGS_S3) ? pots[2]->value() : 0),
|
||||
-sliders[0]->value(),
|
||||
sliders[1]->value()
|
||||
},
|
||||
|
||||
{
|
||||
|
@ -1108,17 +1124,8 @@ void SimulatorDialog::onjoystickAxisValueChanged(int axis, int value)
|
|||
else if (stick==4) {
|
||||
nodeLeft->setX(stickval/1024.0);
|
||||
}
|
||||
else if (stick==5) {
|
||||
dialP_1->setValue(stickval);
|
||||
}
|
||||
else if (stick==6) {
|
||||
dialP_2->setValue(stickval);
|
||||
}
|
||||
else if (stick==7) {
|
||||
dialP_3->setValue(stickval);
|
||||
}
|
||||
else if (stick==8 && dialP_4) {
|
||||
dialP_4->setValue(stickval);
|
||||
else if (stick >= 5 && stick < 5+pots.count()) {
|
||||
pots[stick-5]->setValue(stickval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,16 @@ namespace Ui {
|
|||
class lcdWidget;
|
||||
class mySlider;
|
||||
|
||||
#define SIMULATOR_FLAGS_NOTX 1
|
||||
#define SIMULATOR_FLAGS_STICK_MODE_LEFT 2
|
||||
#define SIMULATOR_FLAGS_NOTX 1
|
||||
#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
|
||||
{
|
||||
|
@ -50,7 +58,11 @@ class SimulatorDialog : public QDialog
|
|||
unsigned int flags;
|
||||
lcdWidget * lcd;
|
||||
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;
|
||||
QLabel * leftXPerc, * rightXPerc, * leftYPerc, * rightYPerc;
|
||||
QTabWidget * tabWidget;
|
||||
|
@ -119,6 +131,7 @@ class SimulatorDialog : public QDialog
|
|||
|
||||
private slots:
|
||||
void onButtonPressed(int value);
|
||||
void dialChanged(int index);
|
||||
void on_FixRightY_clicked(bool checked);
|
||||
void on_FixRightX_clicked(bool checked);
|
||||
void on_FixLeftY_clicked(bool checked);
|
||||
|
@ -160,9 +173,6 @@ class SimulatorDialog9X: public SimulatorDialog
|
|||
void saveSwitches(void);
|
||||
void restoreSwitches(void);
|
||||
|
||||
private slots:
|
||||
void dialChanged();
|
||||
|
||||
private:
|
||||
Ui::SimulatorDialog9X * ui;
|
||||
static uint32_t switchstatus;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue