mirror of
https://github.com/opentx/opentx.git
synced 2025-07-16 12:55:12 +03:00
Refactoring
This commit is contained in:
parent
5620a76679
commit
fdde364307
11 changed files with 53 additions and 26 deletions
|
@ -188,7 +188,7 @@ void AppPreferencesDialog::initSettings()
|
||||||
FirmwareInterface * current_firmware = GetCurrentFirmware();
|
FirmwareInterface * current_firmware = GetCurrentFirmware();
|
||||||
|
|
||||||
foreach(FirmwareInterface * firmware, firmwares) {
|
foreach(FirmwareInterface * firmware, firmwares) {
|
||||||
ui->downloadVerCB->addItem(firmware->name, firmware->id);
|
ui->downloadVerCB->addItem(firmware->getName(), firmware->getId());
|
||||||
if (current_firmware == firmware) {
|
if (current_firmware == firmware) {
|
||||||
ui->downloadVerCB->setCurrentIndex(ui->downloadVerCB->count() - 1);
|
ui->downloadVerCB->setCurrentIndex(ui->downloadVerCB->count() - 1);
|
||||||
}
|
}
|
||||||
|
@ -366,7 +366,7 @@ void AppPreferencesDialog::baseFirmwareChanged()
|
||||||
QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex());
|
QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex());
|
||||||
voice=NULL;
|
voice=NULL;
|
||||||
foreach(FirmwareInterface * firmware, firmwares) {
|
foreach(FirmwareInterface * firmware, firmwares) {
|
||||||
if (firmware->id == selected_firmware) {
|
if (firmware->getId() == selected_firmware) {
|
||||||
showVoice(firmware->voice);
|
showVoice(firmware->voice);
|
||||||
populateFirmwareOptions(firmware);
|
populateFirmwareOptions(firmware);
|
||||||
break;
|
break;
|
||||||
|
@ -380,8 +380,8 @@ FirmwareVariant AppPreferencesDialog::getFirmwareVariant()
|
||||||
QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex());
|
QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex());
|
||||||
bool voice=false;
|
bool voice=false;
|
||||||
foreach(FirmwareInterface * firmware, firmwares) {
|
foreach(FirmwareInterface * firmware, firmwares) {
|
||||||
if (firmware->id == selected_firmware) {
|
QString id = firmware->getId();
|
||||||
QString id = firmware->id;
|
if (id == selected_firmware) {
|
||||||
foreach(QCheckBox *cb, optionsCheckBoxes) {
|
foreach(QCheckBox *cb, optionsCheckBoxes) {
|
||||||
if (cb->isChecked()) {
|
if (cb->isChecked()) {
|
||||||
if (cb->text()=="voice" && cb->isChecked())
|
if (cb->text()=="voice" && cb->isChecked())
|
||||||
|
@ -414,7 +414,7 @@ void AppPreferencesDialog::firmwareOptionChanged(bool state)
|
||||||
if (cb && state) {
|
if (cb && state) {
|
||||||
QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex());
|
QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex());
|
||||||
foreach(firmware, firmwares) {
|
foreach(firmware, firmwares) {
|
||||||
if (firmware->id == selected_firmware) {
|
if (firmware->getId() == selected_firmware) {
|
||||||
foreach(QList<Option> opts, firmware->opts) {
|
foreach(QList<Option> opts, firmware->opts) {
|
||||||
foreach(Option opt, opts) {
|
foreach(Option opt, opts) {
|
||||||
if (cb->text() == opt.name) {
|
if (cb->text() == opt.name) {
|
||||||
|
|
|
@ -328,7 +328,7 @@ void avrOutputDialog::errorWizard()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
FirmwareInterface *firmware = GetCurrentFirmware();
|
FirmwareInterface *firmware = GetCurrentFirmware();
|
||||||
QMessageBox::warning(this, "Companion - Tip of the day", tr("Your radio uses a %1 CPU!!!\n\nPlease select an appropriate firmware type to program it.").arg(DeviceStr)+FwStr+tr("\nYou are currently using:\n %1").arg(firmware->name));
|
QMessageBox::warning(this, "Companion - Tip of the day", tr("Your radio uses a %1 CPU!!!\n\nPlease select an appropriate firmware type to program it.").arg(DeviceStr)+FwStr+tr("\nYou are currently using:\n %1").arg(firmware->getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1285,13 +1285,34 @@ bool LoadEepromXml(RadioData &radioData, QDomDocument &doc)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString getBoardName(BoardEnum board)
|
||||||
|
{
|
||||||
|
switch (board) {
|
||||||
|
case BOARD_STOCK:
|
||||||
|
return "9X";
|
||||||
|
case BOARD_M128:
|
||||||
|
return "9X128";
|
||||||
|
case BOARD_GRUVIN9X:
|
||||||
|
return "Gruvin9x";
|
||||||
|
case BOARD_MEGA2560:
|
||||||
|
return "MEGA2560";
|
||||||
|
case BOARD_TARANIS:
|
||||||
|
return "Taranis";
|
||||||
|
case BOARD_TARANIS_PLUS:
|
||||||
|
return "Taranis Plus";
|
||||||
|
case BOARD_SKY9X:
|
||||||
|
return "Sky9x";
|
||||||
|
case BOARD_9XRPRO:
|
||||||
|
return "9XR-PRO";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FirmwareVariant GetFirmwareVariant(QString id)
|
FirmwareVariant GetFirmwareVariant(QString id)
|
||||||
{
|
{
|
||||||
FirmwareVariant result;
|
FirmwareVariant result;
|
||||||
|
|
||||||
foreach(FirmwareInterface * firmware, firmwares) {
|
foreach(FirmwareInterface * firmware, firmwares) {
|
||||||
if (id.contains(firmware->id+"-") || (!id.contains("-") && id.contains(firmware->id))) {
|
if (id.contains(firmware->getId()+"-") || (!id.contains("-") && id.contains(firmware->getId()))) {
|
||||||
result.id = id;
|
result.id = id;
|
||||||
result.firmware = firmware;
|
result.firmware = firmware;
|
||||||
result.variant = firmware->getVariant(id);
|
result.variant = firmware->getVariant(id);
|
||||||
|
|
|
@ -52,6 +52,8 @@ enum BoardEnum {
|
||||||
BOARD_TARANIS_PLUS
|
BOARD_TARANIS_PLUS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QString getBoardName(BoardEnum board);
|
||||||
|
|
||||||
#define IS_9X(board) (board==BOARD_STOCK || board==BOARD_M128)
|
#define IS_9X(board) (board==BOARD_STOCK || board==BOARD_M128)
|
||||||
#define IS_STOCK(board) (board==BOARD_STOCK)
|
#define IS_STOCK(board) (board==BOARD_STOCK)
|
||||||
#define IS_2560(board) (board==BOARD_GRUVIN9X || board==BOARD_MEGA2560)
|
#define IS_2560(board) (board==BOARD_GRUVIN9X || board==BOARD_MEGA2560)
|
||||||
|
@ -1162,8 +1164,6 @@ class EEPROMInterface
|
||||||
|
|
||||||
virtual ~EEPROMInterface() {}
|
virtual ~EEPROMInterface() {}
|
||||||
|
|
||||||
virtual const char * getName() = 0;
|
|
||||||
|
|
||||||
inline BoardEnum getBoard() { return board; }
|
inline BoardEnum getBoard() { return board; }
|
||||||
|
|
||||||
virtual bool load(RadioData &radioData, const uint8_t *eeprom, int size) = 0;
|
virtual bool load(RadioData &radioData, const uint8_t *eeprom, int size) = 0;
|
||||||
|
@ -1351,6 +1351,16 @@ class FirmwareInterface {
|
||||||
return board;
|
return board;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline QString getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline QString getId()
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
inline EEPROMInterface * getEepromInterface()
|
inline EEPROMInterface * getEepromInterface()
|
||||||
{
|
{
|
||||||
return eepromInterface;
|
return eepromInterface;
|
||||||
|
@ -1367,10 +1377,10 @@ class FirmwareInterface {
|
||||||
QList<const char *> languages;
|
QList<const char *> languages;
|
||||||
QList<const char *> ttslanguages;
|
QList<const char *> ttslanguages;
|
||||||
QList< QList<Option> > opts;
|
QList< QList<Option> > opts;
|
||||||
QString id;
|
|
||||||
QString name;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
QString id;
|
||||||
|
QString name;
|
||||||
BoardEnum board;
|
BoardEnum board;
|
||||||
EEPROMInterface * eepromInterface;
|
EEPROMInterface * eepromInterface;
|
||||||
|
|
||||||
|
|
|
@ -31,8 +31,6 @@ class OpenTxEepromInterface : public EEPROMInterface
|
||||||
|
|
||||||
virtual ~OpenTxEepromInterface();
|
virtual ~OpenTxEepromInterface();
|
||||||
|
|
||||||
virtual const char * getName();
|
|
||||||
|
|
||||||
virtual const int getEEpromSize();
|
virtual const int getEEpromSize();
|
||||||
|
|
||||||
virtual const int getMaxModels();
|
virtual const int getMaxModels();
|
||||||
|
@ -53,6 +51,8 @@ class OpenTxEepromInterface : public EEPROMInterface
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
const char * getName();
|
||||||
|
|
||||||
bool checkVersion(unsigned int version);
|
bool checkVersion(unsigned int version);
|
||||||
|
|
||||||
bool checkVariant(unsigned int version, unsigned int variant);
|
bool checkVariant(unsigned int version, unsigned int variant);
|
||||||
|
|
|
@ -8,7 +8,7 @@ class GoogleAnalytics: public QObject
|
||||||
GoogleAnalytics();
|
GoogleAnalytics();
|
||||||
~GoogleAnalytics();
|
~GoogleAnalytics();
|
||||||
void sendPageView(QString page);
|
void sendPageView(QString page);
|
||||||
void sendEvent(QString category, QString action, QString label);
|
void sendEvent(QString category, QString action, QString label="");
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void slot_receive(QNetworkReply * reply);
|
void slot_receive(QNetworkReply * reply);
|
||||||
|
|
|
@ -164,7 +164,7 @@ MainWindow::MainWindow():
|
||||||
QTimer::singleShot(0, this, SLOT(autoClose()));
|
QTimer::singleShot(0, this, SLOT(autoClose()));
|
||||||
}
|
}
|
||||||
|
|
||||||
ga.sendPageView("Companion");
|
ga.sendEvent(getBoardName(GetCurrentFirmware()->getBoard()), "Start Companion");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::displayWarnings()
|
void MainWindow::displayWarnings()
|
||||||
|
@ -523,7 +523,7 @@ void MainWindow::startFirmwareDownload(QString url, QString filename)
|
||||||
downloadDialog * dd = new downloadDialog(this, url, filename);
|
downloadDialog * dd = new downloadDialog(this, url, filename);
|
||||||
connect(dd, SIGNAL(accepted()), this, SLOT(firmwareDownloadAccepted()));
|
connect(dd, SIGNAL(accepted()), this, SLOT(firmwareDownloadAccepted()));
|
||||||
dd->exec();
|
dd->exec();
|
||||||
ga.sendEvent("Firmwares", "Download", url);
|
ga.sendEvent(getBoardName(GetCurrentFirmware()->getBoard()), "Download", url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1468,7 +1468,7 @@ void MainWindow::updateMenus()
|
||||||
updateIconSizeActions();
|
updateIconSizeActions();
|
||||||
updateIconThemeActions();
|
updateIconThemeActions();
|
||||||
|
|
||||||
setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->name).arg( g.profile[g.id()].name() ));
|
setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->getName()).arg( g.profile[g.id()].name() ));
|
||||||
}
|
}
|
||||||
|
|
||||||
MdiChild *MainWindow::createMdiChild()
|
MdiChild *MainWindow::createMdiChild()
|
||||||
|
|
|
@ -134,8 +134,8 @@ bool MdiChild::hasSelection()
|
||||||
|
|
||||||
void MdiChild::updateTitle()
|
void MdiChild::updateTitle()
|
||||||
{
|
{
|
||||||
QString title = userFriendlyCurrentFile() + "[*]"+" ("+GetEepromInterface()->getName()+QString(")");
|
QString title = userFriendlyCurrentFile() + "[*]" + " (" + GetCurrentFirmware()->getName() + QString(")");
|
||||||
if (!IS_SKY9X(GetEepromInterface()->getBoard()))
|
if (!IS_SKY9X(GetCurrentFirmware()->getBoard()))
|
||||||
title += QString(" - %1 ").arg(EEPromAvail) + tr("free bytes");
|
title += QString(" - %1 ").arg(EEPromAvail) + tr("free bytes");
|
||||||
setWindowTitle(title);
|
setWindowTitle(title);
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ void PrintDialog::printSetup()
|
||||||
str.append(QString("<tr><td colspan=%1 ><table border=0 width=\"100%\"><tr><td><h1>").arg((firmware->getCapability(FlightModes) && !gvars) ? 2 : 1));
|
str.append(QString("<tr><td colspan=%1 ><table border=0 width=\"100%\"><tr><td><h1>").arg((firmware->getCapability(FlightModes) && !gvars) ? 2 : 1));
|
||||||
str.append(g_model->name);
|
str.append(g_model->name);
|
||||||
str.append(" (");
|
str.append(" (");
|
||||||
str.append(firmware->getEepromInterface()->getName());
|
str.append(firmware->getName());
|
||||||
str.append(")</h1></td><td align=right valign=top NOWRAP><font size=-1>"+tr("printed on: %1").arg(QDateTime::currentDateTime().toString(Qt::SystemLocaleShortDate))+"</font></td></tr></table></td></tr><tr><td><table border=0 cellspacing=0 cellpadding=3>");
|
str.append(")</h1></td><td align=right valign=top NOWRAP><font size=-1>"+tr("printed on: %1").arg(QDateTime::currentDateTime().toString(Qt::SystemLocaleShortDate))+"</font></td></tr></table></td></tr><tr><td><table border=0 cellspacing=0 cellpadding=3>");
|
||||||
str.append("<tr><td><h2>"+tr("General Model Settings")+"</h2></td></tr>");
|
str.append("<tr><td><h2>"+tr("General Model Settings")+"</h2></td></tr>");
|
||||||
str.append("<tr><td>");
|
str.append("<tr><td>");
|
||||||
|
|
|
@ -16,7 +16,6 @@ SimulatorDialog::SimulatorDialog(QWidget * parent, unsigned int flags):
|
||||||
dialP_4(NULL),
|
dialP_4(NULL),
|
||||||
timer(NULL),
|
timer(NULL),
|
||||||
lightOn(false),
|
lightOn(false),
|
||||||
txInterface(NULL),
|
|
||||||
simulator(NULL),
|
simulator(NULL),
|
||||||
lastPhase(-1),
|
lastPhase(-1),
|
||||||
beepVal(0),
|
beepVal(0),
|
||||||
|
@ -340,9 +339,7 @@ void SimulatorDialog::initUi(T * ui)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
txInterface = GetEepromInterface();
|
windowName = tr("Simulating Radio (%1)").arg(GetCurrentFirmware()->getName());
|
||||||
|
|
||||||
windowName = tr("Simulating Radio (%1)").arg(txInterface->getName());
|
|
||||||
setWindowTitle(windowName);
|
setWindowTitle(windowName);
|
||||||
|
|
||||||
simulator = GetCurrentFirmware()->getSimulator();
|
simulator = GetCurrentFirmware()->getSimulator();
|
||||||
|
@ -493,7 +490,7 @@ void SimulatorDialog::onTimerEvent()
|
||||||
{
|
{
|
||||||
static unsigned int lcd_counter = 0;
|
static unsigned int lcd_counter = 0;
|
||||||
if (!simulator->timer10ms()) {
|
if (!simulator->timer10ms()) {
|
||||||
QMessageBox::critical(this, "Companion", tr("Firmware %1 error: %2").arg(txInterface->getName()).arg(simulator->getError()));
|
QMessageBox::critical(this, "Companion", tr("Firmware %1 error: %2").arg(GetCurrentFirmware()->getName()).arg(simulator->getError()));
|
||||||
timer->stop();
|
timer->stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,6 @@ class SimulatorDialog : public QDialog
|
||||||
int jsmap[8];
|
int jsmap[8];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
EEPROMInterface *txInterface;
|
|
||||||
SimulatorInterface *simulator;
|
SimulatorInterface *simulator;
|
||||||
unsigned int lastPhase;
|
unsigned int lastPhase;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue