Make TX volatge for simu more flexible (#7124)
[opentx.git] / companion / src / firmwares / eeprominterface.cpp
blobd4121a8a452cc6322e2051656720d58085220340
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 QString EEPROMInterface::getEepromWarnings(unsigned long errorsFound)
108 std::bitset<NUM_ERRORS> errors((unsigned long long)errorsFound);
109 QStringList warningsList;
110 if (errors.test(WARNING_WRONG_FIRMWARE)) {
111 warningsList << tr("- Your radio probably uses a wrong firmware,\n eeprom size is 4096 but only the first 2048 are used");
113 if (errors.test(OLD_VERSION)) {
114 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.");
117 return warningsList.join("\n");
122 * Firmware
125 // static
126 QVector<Firmware *> Firmware::registeredFirmwares;
127 Firmware * Firmware::defaultVariant = nullptr;
128 Firmware * Firmware::currentVariant = nullptr;
130 // static
131 Firmware * Firmware::getFirmwareForId(const QString & id)
133 foreach(Firmware * firmware, registeredFirmwares) {
134 Firmware * result = firmware->getFirmwareVariant(id);
135 if (result) {
136 return result;
140 return defaultVariant;
143 unsigned int Firmware::getVariantNumber()
145 unsigned int result = 0;
146 const Firmware * base = getFirmwareBase();
147 QStringList options = id.mid(base->getId().length()+1).split("-", QString::SkipEmptyParts);
148 foreach(QString option, options) {
149 foreach(OptionsGroup group, base->opts) {
150 foreach(Option opt, group) {
151 if (opt.name == option) {
152 result += opt.variant;
157 return result;
160 void Firmware::addLanguage(const char * lang)
162 languages.push_back(lang);
165 //void Firmware::addTTSLanguage(const char * lang)
167 // ttslanguages.push_back(lang);
170 void Firmware::addOption(const char * option, const QString & tooltip, unsigned variant)
172 addOption(Option(option, tooltip, variant));
175 void Firmware::addOption(const Option & option)
177 addOptionsGroup({option});
180 void Firmware::addOptionsGroup(const OptionsGroup & options)
182 this->opts.append(options);