5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "eeprominterface.h"
22 #include "firmwares/opentx/opentxeeprom.h"
23 #include "firmwareinterface.h"
26 #include <QMessageBox>
29 float ValToTim(int value
)
31 return ((value
< -109 ? 129+value
: (value
< 7 ? (113+value
)*5 : (53+value
)*10))/10.0);
34 int TimToVal(float value
)
38 temp
=136+round((value
-60));
41 temp
=20+round((value
-2.0)*2.0);
44 temp
=round(value
*10.0);
51 * EEpromInterface globals
56 QList
<EEPROMInterface
*> eepromInterfaces
;
58 void unregisterEEpromInterfaces()
60 foreach(EEPROMInterface
* intf
, eepromInterfaces
) {
61 // qDebug() << "UnregisterEepromInterfaces(): deleting " << QString::number( reinterpret_cast<uint64_t>(intf), 16 );
64 OpenTxEepromCleanup();
67 #if 0 // TODO: remove if unused, currently commented out in mdiChild.cpp
68 // TODO: No GUI here, e.g. return string list instead
69 void EEPROMInterface::showEepromErrors(QWidget
*parent
, const QString
&title
, const QString
&mainMessage
, unsigned long errorsFound
)
71 std::bitset
<NUM_ERRORS
> errors((unsigned long long)errorsFound
);
72 QStringList errorsList
;
74 errorsList
<< tr("Possible causes for this:");
76 if (errors
.test(UNSUPPORTED_NEWER_VERSION
)) { errorsList
<< tr("- Eeprom is from a newer version of OpenTX"); }
77 if (errors
.test(NOT_OPENTX
)) { errorsList
<< tr("- Eeprom is not from OpenTX"); }
78 if (errors
.test(NOT_TH9X
)) { errorsList
<< tr("- Eeprom is not from Th9X"); }
79 if (errors
.test(NOT_GRUVIN9X
)) { errorsList
<< tr("- Eeprom is not from Gruvin9X"); }
80 if (errors
.test(NOT_ERSKY9X
)) { errorsList
<< tr("- Eeprom is not from ErSky9X"); }
81 if (errors
.test(NOT_ER9X
)) { errorsList
<< tr("- Eeprom is not from Er9X"); }
82 if (errors
.test(WRONG_SIZE
)) { errorsList
<< tr("- Eeprom size is invalid"); }
83 if (errors
.test(WRONG_FILE_SYSTEM
)) { errorsList
<< tr("- Eeprom file system is invalid"); }
84 if (errors
.test(UNKNOWN_BOARD
)) { errorsList
<< tr("- Eeprom is from a unknown board"); }
85 if (errors
.test(WRONG_BOARD
)) { errorsList
<< tr("- Eeprom is from the wrong board"); }
86 if (errors
.test(BACKUP_NOT_SUPPORTED
)) { errorsList
<< tr("- Eeprom backup not supported"); }
88 if (errors
.test(UNKNOWN_ERROR
)) { errorsList
<< tr("- Something that couldn't be guessed, sorry"); }
90 if (errors
.test(HAS_WARNINGS
)) {
91 errorsList
<< tr("Warning:");
92 if (errors
.test(WARNING_WRONG_FIRMWARE
)) { errorsList
<< tr("- Your radio probably uses a wrong firmware,\n eeprom size is 4096 but only the first 2048 are used"); }
95 QMessageBox
msgBox(parent
);
96 msgBox
.setWindowTitle(title
);
97 msgBox
.setIcon(QMessageBox::Critical
);
98 msgBox
.setText(mainMessage
);
99 msgBox
.setInformativeText(errorsList
.join("\n"));
100 msgBox
.setStandardButtons(QMessageBox::Ok
);
105 // TODO: No GUI here, e.g. return string list instead
106 void EEPROMInterface::showEepromWarnings(QWidget
*parent
, const QString
&title
, unsigned long errorsFound
)
108 std::bitset
<NUM_ERRORS
> errors((unsigned long long)errorsFound
);
109 QStringList warningsList
;
110 if (errors
.test(WARNING_WRONG_FIRMWARE
)) { warningsList
<< tr("- Your radio probably uses a wrong firmware,\n eeprom size is 4096 but only the first 2048 are used"); }
111 if (errors
.test(OLD_VERSION
)) { warningsList
<< tr("- Your eeprom is from an old version of OpenTX, upgrading!\n To keep your original file as a backup, please choose File -> Save As specifying a different name."); }
113 QMessageBox
msgBox(parent
);
114 msgBox
.setWindowTitle(title
);
115 msgBox
.setIcon(QMessageBox::Warning
);
116 msgBox
.setText(tr("Warnings!"));
117 msgBox
.setInformativeText(warningsList
.join("\n"));
118 msgBox
.setStandardButtons(QMessageBox::Ok
);
128 QVector
<Firmware
*> Firmware::registeredFirmwares
;
129 Firmware
* Firmware::defaultVariant
= NULL
;
130 Firmware
* Firmware::currentVariant
= NULL
;
133 Firmware
* Firmware::getFirmwareForId(const QString
& id
)
135 foreach(Firmware
* firmware
, registeredFirmwares
) {
136 Firmware
* result
= firmware
->getFirmwareVariant(id
);
142 return defaultVariant
;
145 void Firmware::addOption(const char *option
, QString tooltip
, uint32_t variant
)
147 Option options
[] = { { option
, tooltip
, variant
}, { NULL
} };
151 unsigned int Firmware::getVariantNumber()
153 unsigned int result
= 0;
154 const Firmware
* base
= getFirmwareBase();
155 QStringList options
= id
.mid(base
->getId().length()+1).split("-", QString::SkipEmptyParts
);
156 foreach(QString option
, options
) {
157 foreach(QList
<Option
> group
, base
->opts
) {
158 foreach(Option opt
, group
) {
159 if (opt
.name
== option
) {
160 result
+= opt
.variant
;
168 void Firmware::addLanguage(const char *lang
)
170 languages
.push_back(lang
);
173 void Firmware::addTTSLanguage(const char *lang
)
175 ttslanguages
.push_back(lang
);
178 void Firmware::addOptions(Option options
[])
181 for (int i
=0; options
[i
].name
; i
++) {
182 opts
.push_back(options
[i
]);
184 this->opts
.push_back(opts
);