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 #ifndef _EEPROMINTERFACE_H_
22 #define _EEPROMINTERFACE_H_
26 #include "radiodata.h"
27 #include "../../radio/src/definitions.h"
28 #include "simulatorinterface.h"
31 #include <QStringList>
37 const uint8_t modn12x3
[4][4]= {
58 SafetyChannelCustomFunction
,
102 TelemetryCustomScreens
,
103 TelemetryCustomScreensFieldsPerLine
,
104 TelemetryMaxMultiplier
,
110 NumFirstUsableModule
,
116 HastxCurrentCalibration
,
155 class EEPROMInterface
157 Q_DECLARE_TR_FUNCTIONS(EEPROMInterface
)
161 EEPROMInterface(Board::Type board
):
166 virtual ~EEPROMInterface() {}
168 inline Board::Type
getBoard() { return board
; }
170 virtual unsigned long load(RadioData
&radioData
, const uint8_t * eeprom
, int size
) = 0;
172 virtual unsigned long loadBackup(RadioData
& radioData
, const uint8_t * eeprom
, int esize
, int index
) = 0;
174 virtual int save(uint8_t * eeprom
, const RadioData
& radioData
, uint8_t version
=0, uint32_t variant
=0) = 0;
176 virtual int getSize(const ModelData
&) = 0;
178 virtual int getSize(const GeneralSettings
&) = 0;
180 //static void showEepromErrors(QWidget *parent, const QString &title, const QString &mainMessage, unsigned long errorsFound);
181 static QString
getEepromWarnings(unsigned long errorsFound
);
193 /* EEPROM string conversion function (used only by er9xeeprom and ersky9xeeprom) */
194 inline void getEEPROMString(char *dst
, const char *src
, int size
)
196 memcpy(dst
, src
, size
);
198 for (int i
=size
-1; i
>=0; i
--) {
206 // (used only by er9xeeprom and ersky9xeeprom)
207 inline int applyStickMode(int stick
, unsigned int mode
)
209 if (mode
== 0 || mode
> 4) {
210 std::cerr
<< "Incorrect stick mode" << mode
;
214 if (stick
>= 1 && stick
<= 4)
215 return modn12x3
[mode
-1][stick
-1];
220 float ValToTim(int value
);
221 int TimToVal(float value
);
223 void registerEEpromInterfaces();
224 void unregisterEEpromInterfaces();
225 void registerOpenTxFirmwares();
226 void unregisterOpenTxFirmwares();
228 enum EepromLoadErrors
{
231 UNSUPPORTED_NEWER_VERSION
,
241 BACKUP_NOT_SUPPORTED
,
245 WARNING_WRONG_FIRMWARE
,
252 Q_DECLARE_TR_FUNCTIONS(Firmware
)
256 const char * name
= nullptr;
258 unsigned variant
= 0;
260 explicit Option(const char * name
, const QString
& description
, unsigned variant
= 0) :
261 name(name
), tooltip(description
), variant(variant
) { }
263 typedef QList
<Option
> OptionsGroup
;
264 typedef QList
<OptionsGroup
> OptionsList
;
267 explicit Firmware(const QString
& id
, const QString
& name
, Board::Type board
) :
268 Firmware(nullptr, id
, name
, board
)
271 explicit Firmware(Firmware
* base
, const QString
& id
, const QString
& name
, Board::Type board
) :
277 eepromInterface(nullptr)
280 virtual ~Firmware() { }
282 inline const Firmware
* getFirmwareBase() const
284 return base
? base
: this;
287 virtual Firmware
* getFirmwareVariant(const QString
& id
) { return NULL
; }
289 unsigned int getVariantNumber();
291 virtual void addLanguage(const char * lang
);
293 //virtual void addTTSLanguage(const char * lang);
295 virtual void addOption(const char * option
, const QString
& tooltip
= QString(), unsigned variant
= 0);
297 virtual void addOption(const Option
& option
);
299 virtual void addOptionsGroup(const OptionsGroup
& options
);
301 virtual QString
getStampUrl() = 0;
303 virtual QString
getReleaseNotesUrl() = 0;
305 virtual QString
getFirmwareUrl() = 0;
307 Board::Type
getBoard() const
312 void setEEpromInterface(EEPROMInterface
* eeprom
)
314 eepromInterface
= eeprom
;
317 EEPROMInterface
* getEEpromInterface()
319 return eepromInterface
;
322 QString
getName() const
327 QString
getId() const
332 QList
<const char *> languageList() const
337 OptionsList
optionGroups() const
342 virtual int getCapability(Capability
) = 0;
344 virtual QString
getAnalogInputName(unsigned int index
) = 0;
346 virtual QTime
getMaxTimerStart() = 0;
348 virtual bool isAvailable(PulsesProtocol proto
, int port
=0) = 0;
350 const int getFlashSize();
352 static Firmware
* getFirmwareForId(const QString
& id
);
354 static QVector
<Firmware
*> getRegisteredFirmwares()
356 return registeredFirmwares
;
359 static void addRegisteredFirmware(Firmware
* fw
)
361 registeredFirmwares
.append(fw
);
364 static Firmware
* getDefaultVariant()
366 return defaultVariant
;
368 static void setDefaultVariant(Firmware
* value
)
370 defaultVariant
= value
;
373 static Firmware
* getCurrentVariant()
375 return currentVariant
;
378 static void setCurrentVariant(Firmware
* value
)
380 currentVariant
= value
;
387 unsigned int variantBase
;
389 EEPROMInterface
* eepromInterface
;
390 QList
<const char *> languages
;
391 //QList<const char *> ttslanguages;
394 static QVector
<Firmware
*> registeredFirmwares
;
395 static Firmware
* defaultVariant
;
396 static Firmware
* currentVariant
;
399 inline Firmware
* getCurrentFirmware()
401 return Firmware::getCurrentVariant();
404 inline EEPROMInterface
* getCurrentEEpromInterface()
406 return Firmware::getCurrentVariant()->getEEpromInterface();
409 inline Board::Type
getCurrentBoard()
411 return Firmware::getCurrentVariant()->getBoard();
414 inline int divRoundClosest(const int n
, const int d
)
416 return ((n
< 0) ^ (d
< 0)) ? ((n
- d
/2)/d
) : ((n
+ d
/2)/d
);
419 inline int calcRESXto100(int x
)
421 return divRoundClosest(x
*100, 1024);
424 extern QList
<EEPROMInterface
*> eepromInterfaces
;
427 #endif // _EEPROMINTERFACE_H_