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
,
115 HastxCurrentCalibration
,
152 class EEPROMInterface
154 Q_DECLARE_TR_FUNCTIONS(EEPROMInterface
)
158 EEPROMInterface(Board::Type board
):
163 virtual ~EEPROMInterface() {}
165 inline Board::Type
getBoard() { return board
; }
167 virtual unsigned long load(RadioData
&radioData
, const uint8_t * eeprom
, int size
) = 0;
169 virtual unsigned long loadBackup(RadioData
& radioData
, const uint8_t * eeprom
, int esize
, int index
) = 0;
171 virtual int save(uint8_t * eeprom
, const RadioData
& radioData
, uint8_t version
=0, uint32_t variant
=0) = 0;
173 virtual int getSize(const ModelData
&) = 0;
175 virtual int getSize(const GeneralSettings
&) = 0;
177 //static void showEepromErrors(QWidget *parent, const QString &title, const QString &mainMessage, unsigned long errorsFound);
178 static void showEepromWarnings(QWidget
*parent
, const QString
&title
, unsigned long errorsFound
);
190 /* EEPROM string conversion function (used only by er9xeeprom and ersky9xeeprom) */
191 inline void getEEPROMString(char *dst
, const char *src
, int size
)
193 memcpy(dst
, src
, size
);
195 for (int i
=size
-1; i
>=0; i
--) {
203 // (used only by er9xeeprom and ersky9xeeprom)
204 inline int applyStickMode(int stick
, unsigned int mode
)
206 if (mode
== 0 || mode
> 4) {
207 std::cerr
<< "Incorrect stick mode" << mode
;
211 if (stick
>= 1 && stick
<= 4)
212 return modn12x3
[mode
-1][stick
-1];
217 float ValToTim(int value
);
218 int TimToVal(float value
);
220 void registerEEpromInterfaces();
221 void unregisterEEpromInterfaces();
222 void registerOpenTxFirmwares();
223 void unregisterOpenTxFirmwares();
225 enum EepromLoadErrors
{
228 UNSUPPORTED_NEWER_VERSION
,
238 BACKUP_NOT_SUPPORTED
,
242 WARNING_WRONG_FIRMWARE
,
255 Q_DECLARE_TR_FUNCTIONS(Firmware
)
258 Firmware(const QString
& id
, const QString
& name
, Board::Type board
):
264 eepromInterface(NULL
)
268 Firmware(Firmware
* base
, const QString
& id
, const QString
& name
, Board::Type board
):
274 eepromInterface(NULL
)
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
, QString tooltip
="", uint32_t variant
=0);
297 virtual void addOptions(Option options
[]);
299 virtual QString
getStampUrl() = 0;
301 virtual QString
getReleaseNotesUrl() = 0;
303 virtual QString
getFirmwareUrl() = 0;
305 Board::Type
getBoard() const
310 void setEEpromInterface(EEPROMInterface
* eeprom
)
312 eepromInterface
= eeprom
;
315 EEPROMInterface
* getEEpromInterface()
317 return eepromInterface
;
320 QString
getName() const
325 QString
getId() const
330 virtual int getCapability(Capability
) = 0;
332 virtual QString
getAnalogInputName(unsigned int index
) = 0;
334 virtual QTime
getMaxTimerStart() = 0;
336 virtual int isAvailable(PulsesProtocol proto
, int port
=0) = 0;
338 const int getFlashSize();
340 static Firmware
* getFirmwareForId(const QString
& id
);
342 static QVector
<Firmware
*> getRegisteredFirmwares()
344 return registeredFirmwares
;
347 static void addRegisteredFirmware(Firmware
* fw
)
349 registeredFirmwares
.append(fw
);
352 static Firmware
* getDefaultVariant()
354 return defaultVariant
;
356 static void setDefaultVariant(Firmware
* value
)
358 defaultVariant
= value
;
361 static Firmware
* getCurrentVariant()
363 return currentVariant
;
366 static void setCurrentVariant(Firmware
* value
)
368 currentVariant
= value
;
372 QList
<const char *> languages
;
373 QList
<const char *> ttslanguages
;
374 QList
< QList
<Option
> > opts
;
381 unsigned int variantBase
;
383 EEPROMInterface
* eepromInterface
;
385 static QVector
<Firmware
*> registeredFirmwares
;
386 static Firmware
* defaultVariant
;
387 static Firmware
* currentVariant
;
394 inline Firmware
* getCurrentFirmware()
396 return Firmware::getCurrentVariant();
399 inline EEPROMInterface
* getCurrentEEpromInterface()
401 return Firmware::getCurrentVariant()->getEEpromInterface();
404 inline Board::Type
getCurrentBoard()
406 return Firmware::getCurrentVariant()->getBoard();
409 inline int divRoundClosest(const int n
, const int d
)
411 return ((n
< 0) ^ (d
< 0)) ? ((n
- d
/2)/d
) : ((n
+ d
/2)/d
);
414 inline int calcRESXto100(int x
)
416 return divRoundClosest(x
*100, 1024);
419 #define CHECK_IN_ARRAY(T, index) ((unsigned int)index < DIM(T) ? T[(unsigned int)index] : CPN_STR_UNKNOWN_ITEM)
421 extern QList
<EEPROMInterface
*> eepromInterfaces
;
423 bool loadFile(RadioData
& radioData
, const QString
& filename
);
426 #endif // _EEPROMINTERFACE_H_