diff --git a/companion/src/simulation/debugoutput.cpp b/companion/src/simulation/debugoutput.cpp index 4f25a228c..03aa757d6 100644 --- a/companion/src/simulation/debugoutput.cpp +++ b/companion/src/simulation/debugoutput.cpp @@ -41,5 +41,3 @@ void DebugOutput::traceCallback(const QString & text) ui->Output->verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMaximum); } } - - diff --git a/companion/src/simulation/simulatordialog.cpp b/companion/src/simulation/simulatordialog.cpp index a072baad2..158a3dc32 100644 --- a/companion/src/simulation/simulatordialog.cpp +++ b/companion/src/simulation/simulatordialog.cpp @@ -270,24 +270,45 @@ void SimulatorDialog::onTrimReleased() void SimulatorDialog::openTelemetrySimulator() { - TelemetrySimu = new TelemetrySimulator(this, simulator); - TelemetrySimu->setAttribute(Qt::WA_DeleteOnClose, true); - TelemetrySimu->show(); + // allow only one instance + if (TelemetrySimu == 0) { + TelemetrySimu = new TelemetrySimulator(this, simulator); + TelemetrySimu->show(); + } + else if (!TelemetrySimu->isVisible()) { + TelemetrySimu->show(); + } } void SimulatorDialog::openTrainerSimulator() { - TrainerSimu = new TrainerSimulator(this, simulator); - TrainerSimu->setAttribute(Qt::WA_DeleteOnClose, true); - TrainerSimu->show(); + // allow only one instance + if (TrainerSimu == 0) { + TrainerSimu = new TrainerSimulator(this, simulator); + TrainerSimu->show(); + } + else if (!TrainerSimu->isVisible()) { + TrainerSimu->show(); + } } void SimulatorDialog::openDebugOutput() { - DebugOut = new DebugOutput(this); - DebugOut->setAttribute(Qt::WA_DeleteOnClose, true); - DebugOut->traceCallback(traceBuffer); - DebugOut->show(); + // allow only one instance, but install signal handler to catch dialog destruction just in case + if (DebugOut == 0) { + DebugOut = new DebugOutput(this); + QObject::connect(DebugOut, SIGNAL(destroyed()), this, SLOT(onDebugOutputClose())); + DebugOut->traceCallback(traceBuffer); + DebugOut->show(); + } + else if (!DebugOut->isVisible()) { + DebugOut->show(); + } +} + +void SimulatorDialog::onDebugOutputClose() +{ + DebugOut = 0; } void SimulatorDialog::keyPressEvent (QKeyEvent *event) diff --git a/companion/src/simulation/simulatordialog.h b/companion/src/simulation/simulatordialog.h index 1da6e5e3e..40f8a5c2a 100644 --- a/companion/src/simulation/simulatordialog.h +++ b/companion/src/simulation/simulatordialog.h @@ -140,6 +140,7 @@ class SimulatorDialog : public QDialog void openTelemetrySimulator(); void openTrainerSimulator(); void openDebugOutput(); + void onDebugOutputClose(); #ifdef JOYSTICKS void onjoystickAxisValueChanged(int axis, int value); diff --git a/companion/src/simulation/telemetrysimu.cpp b/companion/src/simulation/telemetrysimu.cpp index 36e6982ab..150d48d63 100644 --- a/companion/src/simulation/telemetrysimu.cpp +++ b/companion/src/simulation/telemetrysimu.cpp @@ -28,6 +28,12 @@ void TelemetrySimulator::onTimerEvent() } } +void TelemetrySimulator::closeEvent(QCloseEvent *event) +{ + ui->Simulate->setChecked(false); + event->accept(); +} + void setSportPacketCrc(uint8_t * packet) { short crc = 0; diff --git a/companion/src/simulation/telemetrysimu.h b/companion/src/simulation/telemetrysimu.h index 2d89d9613..22767b026 100644 --- a/companion/src/simulation/telemetrysimu.h +++ b/companion/src/simulation/telemetrysimu.h @@ -2,6 +2,7 @@ #define telemetrysimu_h +#include #include #include #include "simulatorinterface.h" @@ -21,6 +22,7 @@ class TelemetrySimulator : public QDialog protected: + virtual void closeEvent(QCloseEvent *event); private: Ui::TelemetrySimulator * ui; diff --git a/companion/src/simulation/trainersimu.cpp b/companion/src/simulation/trainersimu.cpp index e96369230..61c2cd407 100644 --- a/companion/src/simulation/trainersimu.cpp +++ b/companion/src/simulation/trainersimu.cpp @@ -22,7 +22,6 @@ TrainerSimulator::TrainerSimulator(QWidget * parent, SimulatorInterface * simula timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(onTimerEvent())); - timer->start(10); } TrainerSimulator::~TrainerSimulator() @@ -31,6 +30,18 @@ TrainerSimulator::~TrainerSimulator() delete ui; } +void TrainerSimulator::showEvent(QShowEvent *event) +{ + timer->start(10); + event->accept(); +} + +void TrainerSimulator::closeEvent(QCloseEvent *event) +{ + timer->stop(); + event->accept(); +} + void TrainerSimulator::centerSticks() { if (leftStick->scene()) diff --git a/companion/src/simulation/trainersimu.h b/companion/src/simulation/trainersimu.h index 0bfc646dd..1752c75fd 100644 --- a/companion/src/simulation/trainersimu.h +++ b/companion/src/simulation/trainersimu.h @@ -2,6 +2,8 @@ #define trainersimu_h +#include +#include #include #include #include "modeledit/node.h" @@ -22,6 +24,8 @@ class TrainerSimulator : public QDialog protected: + virtual void showEvent(QShowEvent *event); + virtual void closeEvent(QCloseEvent *event); private: Ui::TrainerSimulator * ui; diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 12090b09f..61d6c7ac7 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -206,7 +206,7 @@ void per10ms() } #endif -#if defined(FRSKY) || defined(JETI) +#if defined(FRSKY) || defined(JETI) || defined(SIMU) if (!IS_DSM2_SERIAL_PROTOCOL(s_current_protocol[0])) telemetryInterrupt10ms(); #endif