feat(cpn): simulator allow manually setting transmitter battery voltage (#5763)
This commit is contained in:
@@ -192,6 +192,7 @@ class SimulatorInterface : public QObject
|
||||
void auxSerialSetBaudrate(const quint8 port_num, const quint32 baudrate);
|
||||
void auxSerialStart(const quint8 port_num);
|
||||
void auxSerialStop(const quint8 port_num);
|
||||
void txBatteryVoltageChanged(const int voltage);
|
||||
};
|
||||
|
||||
class SimulatorFactory {
|
||||
|
||||
@@ -60,7 +60,11 @@ SimulatorMainWindow::SimulatorMainWindow(QWidget *parent, const QString & simula
|
||||
m_radioSizeConstraint(Qt::Horizontal | Qt::Vertical),
|
||||
m_firstShow(true),
|
||||
m_showRadioDocked(true),
|
||||
m_showMenubar(true)
|
||||
m_showMenubar(true),
|
||||
m_batMin(0),
|
||||
m_batMax(0),
|
||||
m_batWarn(0),
|
||||
m_batVoltage(0)
|
||||
{
|
||||
if (m_simulatorId.isEmpty()) {
|
||||
m_simulatorId = SimulatorLoader::findSimulatorByName(getCurrentFirmware()->getSimulatorId());
|
||||
@@ -143,6 +147,7 @@ SimulatorMainWindow::SimulatorMainWindow(QWidget *parent, const QString & simula
|
||||
connect(ui->actionReloadRadioData, &QAction::triggered, this, &SimulatorMainWindow::simulatorRestart);
|
||||
|
||||
connect(ui->actionReloadLua, &QAction::triggered, m_simulator, &SimulatorInterface::setLuaStateReloadPermanentScripts);
|
||||
connect(ui->actionSetTxBatteryVoltage, &QAction::triggered, this, &SimulatorMainWindow::openTxBatteryVoltageDialog);
|
||||
|
||||
if (m_outputsWidget) {
|
||||
connect(this, &SimulatorMainWindow::simulatorStart, m_outputsWidget, &RadioOutputsWidget::start);
|
||||
@@ -154,6 +159,7 @@ SimulatorMainWindow::SimulatorMainWindow(QWidget *parent, const QString & simula
|
||||
connect(this, &SimulatorMainWindow::simulatorRestart, m_simulatorWidget, &SimulatorWidget::restart);
|
||||
connect(ui->actionScreenshot, &QAction::triggered, m_simulatorWidget, &SimulatorWidget::captureScreenshot);
|
||||
connect(m_simulatorWidget, &SimulatorWidget::windowTitleChanged, this, &SimulatorMainWindow::setWindowTitle);
|
||||
connect(m_simulatorWidget, &SimulatorWidget::settingsBatteryChanged, this, &SimulatorMainWindow::onSettingsBatteryChanged);
|
||||
}
|
||||
|
||||
connect(m_simulator, &SimulatorInterface::auxSerialSendData, hostSerialConnector, &HostSerialConnector::sendSerialData);
|
||||
@@ -161,6 +167,7 @@ SimulatorMainWindow::SimulatorMainWindow(QWidget *parent, const QString & simula
|
||||
connect(m_simulator, &SimulatorInterface::auxSerialSetBaudrate, hostSerialConnector, &HostSerialConnector::setSerialBaudRate);
|
||||
connect(m_simulator, &SimulatorInterface::auxSerialStart, hostSerialConnector, &HostSerialConnector::serialStart);
|
||||
connect(m_simulator, &SimulatorInterface::auxSerialStop, hostSerialConnector, &HostSerialConnector::serialStop);
|
||||
connect(m_simulator, &SimulatorInterface::txBatteryVoltageChanged, this, &SimulatorMainWindow::onTxBatteryVoltageChanged);
|
||||
}
|
||||
|
||||
SimulatorMainWindow::~SimulatorMainWindow()
|
||||
@@ -555,3 +562,49 @@ void SimulatorMainWindow::showAbout(bool show)
|
||||
msgBox.setText(aboutStr);
|
||||
msgBox.exec();
|
||||
}
|
||||
|
||||
void SimulatorMainWindow::onSettingsBatteryChanged(const int batMin, const int batMax, const unsigned int batWarn)
|
||||
{
|
||||
m_batMin = batMin;
|
||||
m_batMax = batMax;
|
||||
m_batWarn = batWarn;
|
||||
m_batVoltage = batWarn + 5; // abitary +0.5V
|
||||
}
|
||||
|
||||
void SimulatorMainWindow::openTxBatteryVoltageDialog()
|
||||
{
|
||||
QDialog *dlg = new QDialog(this, Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
|
||||
|
||||
QLabel *lbl = new QLabel(tr("Set voltage"));
|
||||
QDoubleSpinBox *sb = new QDoubleSpinBox();
|
||||
sb->setDecimals(1);
|
||||
// vBatWarn is voltage in 100mV, vBatMin is in 100mV but with -9V offset, vBatMax has a -12V offset
|
||||
sb->setMinimum((float)((m_batMin + 90) / 10.0f));
|
||||
sb->setMaximum((float)((m_batMax + 120) / 10.0f));
|
||||
sb->setSingleStep(0.1);
|
||||
sb->setSuffix(tr("V"));
|
||||
sb->setValue((float)m_batVoltage / 10.0f);
|
||||
|
||||
auto *btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
|
||||
connect(btnBox, &QDialogButtonBox::accepted, dlg, &QDialog::accept);
|
||||
connect(btnBox, &QDialogButtonBox::rejected, dlg, &QDialog::reject);
|
||||
|
||||
auto * lo = new QGridLayout(dlg);
|
||||
lo->addWidget(lbl, 0, 0);
|
||||
lo->addWidget(sb, 0, 1);
|
||||
lo->addWidget(btnBox, 1, 0, 1, 2);
|
||||
|
||||
dlg->setWindowTitle(tr("Battery"));
|
||||
dlg->deleteLater();
|
||||
|
||||
if(dlg->exec()) {
|
||||
unsigned int volts = (unsigned int)((float)sb->value() * 10.0f);
|
||||
m_batVoltage = volts;
|
||||
emit txBatteryVoltageChanged(volts);
|
||||
}
|
||||
}
|
||||
|
||||
void SimulatorMainWindow::onTxBatteryVoltageChanged(const unsigned int voltage)
|
||||
{
|
||||
m_batVoltage = voltage;
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ class SimulatorMainWindow : public QMainWindow
|
||||
signals:
|
||||
void simulatorStart();
|
||||
void simulatorRestart();
|
||||
void txBatteryVoltageChanged(int volts); // this changed value
|
||||
|
||||
protected slots:
|
||||
virtual void closeEvent(QCloseEvent *);
|
||||
@@ -84,6 +85,10 @@ class SimulatorMainWindow : public QMainWindow
|
||||
void openSerialPortsDialog(bool);
|
||||
void showHelp(bool show);
|
||||
void showAbout(bool show);
|
||||
void openTxBatteryVoltageDialog();
|
||||
// TODO: detect if changed via ui as currently event only on GeneralSettings (re)load
|
||||
void onSettingsBatteryChanged(const int batMin, const int batMax, const unsigned int batWarn);
|
||||
void onTxBatteryVoltageChanged(const unsigned int voltage); // something else changed voltage
|
||||
|
||||
protected:
|
||||
void createDockWidgets();
|
||||
@@ -114,6 +119,10 @@ class SimulatorMainWindow : public QMainWindow
|
||||
bool m_firstShow;
|
||||
bool m_showRadioDocked;
|
||||
bool m_showMenubar;
|
||||
int m_batMin;
|
||||
int m_batMax;
|
||||
unsigned int m_batWarn;
|
||||
unsigned int m_batVoltage;
|
||||
|
||||
const static quint16 m_savedUiStateVersion;
|
||||
};
|
||||
|
||||
@@ -69,6 +69,7 @@
|
||||
<property name="title">
|
||||
<string>Tools</string>
|
||||
</property>
|
||||
<addaction name="actionSetTxBatteryVoltage"/>
|
||||
<addaction name="actionScreenshot"/>
|
||||
<addaction name="actionJoystickSettings"/>
|
||||
<addaction name="actionSerialPorts"/>
|
||||
@@ -234,6 +235,14 @@
|
||||
<string>About</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSetTxBatteryVoltage">
|
||||
<property name="text">
|
||||
<string>TX Battery Voltage...</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Open set transmitter battery voltage dialog</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../companion.qrc"/>
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "joystickdialog.h"
|
||||
#endif
|
||||
#include "simulateduiwidgetGeneric.h"
|
||||
#include "simulatormainwindow.h"
|
||||
|
||||
#include <AppDebugMessageHandler>
|
||||
#include <QFile>
|
||||
@@ -106,6 +107,8 @@ SimulatorWidget::SimulatorWidget(QWidget * parent, SimulatorInterface * simulato
|
||||
connect(simulator, &SimulatorInterface::runtimeError, this, &SimulatorWidget::onSimulatorError);
|
||||
connect(simulator, &SimulatorInterface::phaseChanged, this, &SimulatorWidget::onPhaseChanged);
|
||||
|
||||
connect((SimulatorMainWindow *)parent, &SimulatorMainWindow::txBatteryVoltageChanged, this, &SimulatorWidget::onTxBatteryVoltageChanged);
|
||||
|
||||
m_timer.setInterval(SIMULATOR_INTERFACE_HEARTBEAT_PERIOD * 6);
|
||||
connect(&m_timer, &QTimer::timeout, this, &SimulatorWidget::onTimerEvent);
|
||||
|
||||
@@ -154,6 +157,7 @@ void SimulatorWidget::setPaths(const QString & sdPath, const QString & dataPath)
|
||||
void SimulatorWidget::setRadioSettings(const GeneralSettings settings)
|
||||
{
|
||||
radioSettings = settings;
|
||||
emit settingsBatteryChanged(settings.vBatMin, settings.vBatMax, settings.vBatWarn);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -228,7 +232,7 @@ bool SimulatorWidget::setStartupData(const QByteArray & dataSource, bool fromFil
|
||||
return false;
|
||||
}
|
||||
|
||||
radioSettings = simuData.generalSettings;
|
||||
setRadioSettings(simuData.generalSettings);
|
||||
startupFromFile = fromFile;
|
||||
|
||||
return true;
|
||||
@@ -259,7 +263,7 @@ bool SimulatorWidget::setRadioData(RadioData * radioData)
|
||||
}
|
||||
|
||||
if (ret)
|
||||
radioSettings = radioData->generalSettings;
|
||||
setRadioSettings(radioData->generalSettings);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -670,8 +674,7 @@ void SimulatorWidget::restoreRadioWidgetsState()
|
||||
// Set throttle stick down and locked, side depends on mode
|
||||
emit stickModeChange(radioSettings.stickMode);
|
||||
|
||||
// TODO : custom voltages
|
||||
qint16 volts = radioSettings.vBatWarn + 20; // 1V above min
|
||||
qint16 volts = radioSettings.vBatWarn + 5; // +0.5V
|
||||
emit inputValueChange(SimulatorInterface::INPUT_SRC_TXVIN, 0, volts);
|
||||
}
|
||||
|
||||
@@ -686,7 +689,6 @@ void SimulatorWidget::saveRadioWidgetsState(QList<QByteArray> & state)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Event handlers/private slots
|
||||
*/
|
||||
@@ -889,3 +891,8 @@ void SimulatorWidget::onjoystickButtonValueChanged(int button, bool state)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void SimulatorWidget::onTxBatteryVoltageChanged(qint16 volts)
|
||||
{
|
||||
emit inputValueChange(SimulatorInterface::INPUT_SRC_TXVIN, 0, volts);
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ class SimulatorWidget : public QWidget
|
||||
void simulatorStop();
|
||||
void simulatorSdPathChange(const QString & sdPath, const QString & dataPath);
|
||||
void simulatorVolumeGainChange(const int gain);
|
||||
void settingsBatteryChanged(const int batMin, const int batMax, const unsigned int batWarn);
|
||||
|
||||
private slots:
|
||||
virtual void mousePressEvent(QMouseEvent *event);
|
||||
@@ -114,6 +115,7 @@ class SimulatorWidget : public QWidget
|
||||
void onRadioWidgetValueChange(const RadioWidget::RadioWidgetType type, int index, int value);
|
||||
void onjoystickAxisValueChanged(int axis, int value);
|
||||
void onjoystickButtonValueChanged(int button, bool state);
|
||||
void onTxBatteryVoltageChanged(qint16 volts);
|
||||
|
||||
void setRadioProfileId(int value);
|
||||
void setupRadioWidgets();
|
||||
|
||||
Reference in New Issue
Block a user