Fix doc path
[opentx.git] / companion / src / firmwares / eeprominterface.cpp
blob4c36a97d31320309bfc100f0582fae95010b9c4b
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
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"
25 #include <QtCore>
26 #include <QMessageBox>
27 #include <bitset>
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)
36 int temp;
37 if (value>60) {
38 temp=136+round((value-60));
40 else if (value>2) {
41 temp=20+round((value-2.0)*2.0);
43 else {
44 temp=round(value*10.0);
46 return (temp-129);
51 * EEpromInterface globals
54 // TODO: No 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 );
62 delete intf;
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);
101 msgBox.exec();
103 #endif
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);
119 msgBox.exec();
124 * Firmware
127 // static
128 QVector<Firmware *> Firmware::registeredFirmwares;
129 Firmware * Firmware::defaultVariant = NULL;
130 Firmware * Firmware::currentVariant = NULL;
132 // static
133 Firmware * Firmware::getFirmwareForId(const QString & id)
135 foreach(Firmware * firmware, registeredFirmwares) {
136 Firmware * result = firmware->getFirmwareVariant(id);
137 if (result) {
138 return result;
142 return defaultVariant;
145 void Firmware::addOption(const char *option, QString tooltip, uint32_t variant)
147 Option options[] = { { option, tooltip, variant }, { NULL } };
148 addOptions(options);
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;
165 return result;
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[])
180 QList<Option> opts;
181 for (int i=0; options[i].name; i++) {
182 opts.push_back(options[i]);
184 this->opts.push_back(opts);