diff --git a/companion/src/simulation/telemetrysimu.cpp b/companion/src/simulation/telemetrysimu.cpp index 2d5d8f7a4..8253c8e77 100644 --- a/companion/src/simulation/telemetrysimu.cpp +++ b/companion/src/simulation/telemetrysimu.cpp @@ -32,8 +32,8 @@ TelemetrySimulator::TelemetrySimulator(QWidget * parent, SimulatorInterface * si ui(new Ui::TelemetrySimulator), simulator(simulator), m_simuStarted(false), - m_telemEnable(false), - m_logReplayEnable(false) + m_logReplayEnable(false), + logPlayback(new LogPlaybackController(ui)) { ui->setupUi(this); @@ -48,56 +48,102 @@ TelemetrySimulator::TelemetrySimulator(QWidget * parent, SimulatorInterface * si ui->A1_ratio->setEnabled(false); ui->A2_ratio->setEnabled(false); + ui->Simulate->setChecked(g.currentProfile().telemSimEnabled()); + ui->cbPauseOnHide->setChecked(g.currentProfile().telemSimPauseOnHide()); + ui->cbResetRssiOnStop->setChecked(g.currentProfile().telemSimResetRssiOnStop()); timer.setInterval(10); - connect(&timer, &QTimer::timeout, this, &TelemetrySimulator::generateTelemetryFrame); - + connect(&timer, &QTimer::timeout, this, &TelemetrySimulator::generateTelemetryFrame); connect(&logTimer, &QTimer::timeout, this, &TelemetrySimulator::onLogTimerEvent); - logPlayback = new LogPlaybackController(ui); + connect(ui->Simulate, &QCheckBox::toggled, [&](bool on) { g.currentProfile().telemSimEnabled(on); }); + connect(ui->cbPauseOnHide, &QCheckBox::toggled, [&](bool on) { g.currentProfile().telemSimPauseOnHide(on); }); + connect(ui->cbResetRssiOnStop, &QCheckBox::toggled, [&](bool on) { g.currentProfile().telemSimResetRssiOnStop(on); }); - connect(ui->Simulate, SIGNAL(toggled(bool)), this, SLOT(onSimulateToggled(bool))); - connect(ui->loadLogFile, SIGNAL(released()), this, SLOT(onLoadLogFile())); - connect(ui->play, SIGNAL(released()), this, SLOT(onPlay())); - connect(ui->rewind, SIGNAL(clicked()), this, SLOT(onRewind())); - connect(ui->stepForward, SIGNAL(clicked()), this, SLOT(onStepForward())); - connect(ui->stepBack, SIGNAL(clicked()), this, SLOT(onStepBack())); - connect(ui->stop, SIGNAL(clicked()), this, SLOT(onStop())); - connect(ui->positionIndicator, SIGNAL(valueChanged(int)), this, SLOT(onPositionIndicatorChanged(int))); - connect(ui->replayRate, SIGNAL(valueChanged(int)), this, SLOT(onReplayRateChanged(int))); + connect(ui->loadLogFile, &QPushButton::released, this, &TelemetrySimulator::onLoadLogFile); + connect(ui->play, &QPushButton::released, this, &TelemetrySimulator::onPlay); + connect(ui->rewind, &QPushButton::clicked, this, &TelemetrySimulator::onRewind); + connect(ui->stepForward, &QPushButton::clicked, this, &TelemetrySimulator::onStepForward); + connect(ui->stepBack, &QPushButton::clicked, this, &TelemetrySimulator::onStepBack); + connect(ui->stop, &QPushButton::clicked, this, &TelemetrySimulator::onStop); + connect(ui->positionIndicator, &QScrollBar::valueChanged, this, &TelemetrySimulator::onPositionIndicatorChanged); + connect(ui->replayRate, &QSlider::valueChanged, this, &TelemetrySimulator::onReplayRateChanged); - connect(this, &TelemetrySimulator::telemetryDataChanged, simulator, &SimulatorInterface::sendTelemetry); - connect(simulator, &SimulatorInterface::started, this, &TelemetrySimulator::onSimulatorStarted); - connect(simulator, &SimulatorInterface::stopped, this, &TelemetrySimulator::onSimulatorStopped); + connect(this, &TelemetrySimulator::telemetryDataChanged, simulator, &SimulatorInterface::sendTelemetry); + connect(simulator, &SimulatorInterface::started, this, &TelemetrySimulator::onSimulatorStarted); + connect(simulator, &SimulatorInterface::stopped, this, &TelemetrySimulator::onSimulatorStopped); + connect(&g.currentProfile(), &Profile::telemSimEnabledChanged, this, &TelemetrySimulator::onSimulateToggled); } TelemetrySimulator::~TelemetrySimulator() { - timer.stop(); - logTimer.stop(); + stopTelemetry(); delete logPlayback; delete ui; } +void TelemetrySimulator::hideEvent(QHideEvent *event) +{ + if (g.currentProfile().telemSimPauseOnHide()) + stopTelemetry(); + event->accept(); +} + +void TelemetrySimulator::showEvent(QShowEvent * event) +{ + if (g.currentProfile().telemSimEnabled()) + startTelemetry(); +} + +void TelemetrySimulator::startTelemetry() +{ + if (!m_simuStarted) + return; + + timer.start(); + if (m_logReplayEnable) + onPlay(); +} + +void TelemetrySimulator::stopTelemetry() +{ + timer.stop(); + m_logReplayEnable = logTimer.isActive(); + onStop(); + + if (!(g.currentProfile().telemSimResetRssiOnStop() && ui && ui->rssi_inst)) + return; + + bool ok = false; + const int id = ui->rssi_inst->text().toInt(&ok, 0); + if (!ok) + return; + + uint8_t buffer[FRSKY_SPORT_PACKET_SIZE] = {0}; + generateSportPacket(buffer, id - 1, DATA_FRAME, RSSI_ID, 0); + emit telemetryDataChanged(QByteArray((char *)buffer, FRSKY_SPORT_PACKET_SIZE)); +} + void TelemetrySimulator::onSimulatorStarted() { m_simuStarted = true; setupDataFields(); + if (isVisible() && g.currentProfile().telemSimEnabled()) + startTelemetry(); } void TelemetrySimulator::onSimulatorStopped() { m_simuStarted = false; + stopTelemetry(); } void TelemetrySimulator::onSimulateToggled(bool isChecked) { - if (isChecked) { - timer.start(); - } - else { - timer.stop(); - } + if (isChecked) + startTelemetry(); + else + stopTelemetry(); } void TelemetrySimulator::onLogTimerEvent() @@ -113,6 +159,7 @@ void TelemetrySimulator::onLoadLogFile() void TelemetrySimulator::onPlay() { + ui->Simulate->setChecked(true); if (logPlayback->isReady()) { logTimer.start(logPlayback->logFrequency * 1000 / SPEEDS[ui->replayRate->value()]); logPlayback->play(); @@ -166,23 +213,6 @@ void TelemetrySimulator::onReplayRateChanged(int value) } } -void TelemetrySimulator::hideEvent(QHideEvent *event) -{ - m_telemEnable = ui->Simulate->isChecked(); - m_logReplayEnable = logTimer.isActive(); - - ui->Simulate->setChecked(false); - ui->stop->click(); - event->accept(); -} - -void TelemetrySimulator::showEvent(QShowEvent * event) -{ - ui->Simulate->setChecked(m_telemEnable); - if (m_logReplayEnable) - ui->play->click(); -} - #define SET_INSTANCE(control, id, def) ui->control->setText(QString::number(simulator->getSensorInstance(id, ((def) & 0x1F) + 1))) void TelemetrySimulator::setupDataFields() @@ -235,7 +265,7 @@ uint8_t getBit(uint8_t position, uint8_t value) return (value & (uint8_t)(1 << position)) ? 1 : 0; } -bool generateSportPacket(uint8_t * packet, uint8_t dataId, uint8_t prim, uint16_t appId, uint32_t data) +bool TelemetrySimulator::generateSportPacket(uint8_t * packet, uint8_t dataId, uint8_t prim, uint16_t appId, uint32_t data) { if (dataId > 0x1B ) return false; diff --git a/companion/src/simulation/telemetrysimu.h b/companion/src/simulation/telemetrysimu.h index 1ff3c78e4..c317e2fb5 100644 --- a/companion/src/simulation/telemetrysimu.h +++ b/companion/src/simulation/telemetrysimu.h @@ -46,14 +46,18 @@ class TelemetrySimulator : public QWidget explicit TelemetrySimulator(QWidget * parent, SimulatorInterface * simulator); virtual ~TelemetrySimulator(); - signals: + public slots: + bool generateSportPacket(uint8_t * packet, uint8_t dataId, uint8_t prim, uint16_t appId, uint32_t data); + signals: void telemetryDataChanged(const QByteArray data); protected slots: - virtual void hideEvent(QHideEvent *event); - virtual void showEvent(QShowEvent *event); + void hideEvent(QHideEvent *event) override; + void showEvent(QShowEvent *event) override; + void startTelemetry(); + void stopTelemetry(); void onSimulatorStarted(); void onSimulatorStopped(); void setupDataFields(); @@ -77,7 +81,6 @@ class TelemetrySimulator : public QWidget QTimer logTimer; SimulatorInterface *simulator; bool m_simuStarted; - bool m_telemEnable; bool m_logReplayEnable; // protected classes follow @@ -204,7 +207,6 @@ class TelemetrySimulator : public QWidget uint32_t encodeLatLon(double latLon, bool isLat); uint32_t encodeDateTime(uint8_t yearOrHour, uint8_t monthOrMinute, uint8_t dayOrSecond, bool isDate); }; // GPSEmulator - }; // TelemetrySimulator #endif // _TELEMETRYSIMU_H_ diff --git a/companion/src/simulation/telemetrysimu.ui b/companion/src/simulation/telemetrysimu.ui index 3ad9ae83e..c192c9acb 100644 --- a/companion/src/simulation/telemetrysimu.ui +++ b/companion/src/simulation/telemetrysimu.ui @@ -18,7 +18,7 @@ Telemetry Simulator - + 7 @@ -37,7 +37,7 @@ 7 - + @@ -58,334 +58,7 @@ - - - - - 0 - 0 - - - - - 8 - - - - Replay SD Log File - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - 0 - - - 3 - - - 0 - - - - - - 8 - - - - Replay rate - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - Load - - - false - - - - - - - false - - - - 0 - 0 - - - - 8 - - - 1 - - - 4 - - - Qt::Horizontal - - - - - - - 4 - - - - - QLayout::SetMinimumSize - - - - - false - - - - 30 - 16777215 - - - - Qt::StrongFocus - - - |> - - - false - - - true - - - false - - - - - - - false - - - - 30 - 16777215 - - - - Qt::StrongFocus - - - <| - - - false - - - true - - - false - - - - - - - false - - - - 0 - 0 - - - - - 30 - 16777215 - - - - Qt::StrongFocus - - - > - - - true - - - true - - - false - - - - - - - false - - - - 0 - 0 - - - - - 30 - 16777215 - - - - Qt::StrongFocus - - - <- - - - false - - - true - - - false - - - false - - - - - - - false - - - - 30 - 16777215 - - - - Qt::StrongFocus - - - X - - - true - - - true - - - false - - - - - - - - - false - - - Qt::Horizontal - - - - - - - - 8 - - - - Qt::LeftToRight - - - Row # -Timestamp - - - Qt::AlignCenter - - - - - - - - - - 0 - 0 - - - - 1/5x - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - 5x - - - - - - - - 8 - - - - No Log File Currently Loaded - - - - - - - + @@ -434,8 +107,8 @@ Timestamp 0 0 - 346 - 370 + 329 + 412 @@ -1729,8 +1402,8 @@ Timestamp 0 0 - 339 - 370 + 330 + 384 @@ -2954,6 +2627,365 @@ hh:mm:ss + + + + + 0 + 0 + + + + + 8 + + + + Replay SD Log File + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + 0 + + + 3 + + + 0 + + + + + + 8 + + + + Replay rate + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + Load + + + false + + + + + + + false + + + + 0 + 0 + + + + 8 + + + 1 + + + 4 + + + Qt::Horizontal + + + + + + + 4 + + + + + QLayout::SetMinimumSize + + + + + false + + + + 30 + 16777215 + + + + Qt::StrongFocus + + + |> + + + false + + + true + + + false + + + + + + + false + + + + 30 + 16777215 + + + + Qt::StrongFocus + + + <| + + + false + + + true + + + false + + + + + + + false + + + + 0 + 0 + + + + + 30 + 16777215 + + + + Qt::StrongFocus + + + > + + + true + + + true + + + false + + + + + + + false + + + + 0 + 0 + + + + + 30 + 16777215 + + + + Qt::StrongFocus + + + <- + + + false + + + true + + + false + + + false + + + + + + + false + + + + 30 + 16777215 + + + + Qt::StrongFocus + + + X + + + true + + + true + + + false + + + + + + + + + false + + + Qt::Horizontal + + + + + + + + 8 + + + + Qt::LeftToRight + + + Row # +Timestamp + + + Qt::AlignCenter + + + + + + + + + + 0 + 0 + + + + 1/5x + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + 5x + + + + + + + + 8 + + + + No Log File Currently Loaded + + + + + + + + + + + 0 + 0 + + + + Setting RSSI to zero simulates telemetry and radio link loss. + + + Set RSSI to zero when paused. + + + + + + + + 0 + 0 + + + + Stop sending telemetry data when the Telemetry Simulator window is hidden. + + + Pause simulation when hidden. + + + diff --git a/companion/src/storage/appdata.h b/companion/src/storage/appdata.h index 8818a416c..b4020759f 100644 --- a/companion/src/storage/appdata.h +++ b/companion/src/storage/appdata.h @@ -383,6 +383,9 @@ class Profile: public CompStoreObj // Simulator variables PROPERTY(SimulatorOptions, simulatorOptions, SimulatorOptions()) + PROPERTY(bool, telemSimEnabled, false) + PROPERTY(bool, telemSimPauseOnHide, true) + PROPERTY(bool, telemSimResetRssiOnStop, false) // Firmware Variables PROPERTYSTR2(beeper, "Beeper")