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_
25 #include "radiodata.h"
26 #include "../../radio/src/definitions.h"
27 #include "simulatorinterface.h"
28 #include <QStringList>
33 const uint8_t modn12x3
[4][4]= {
54 SafetyChannelCustomFunction
,
98 TelemetryCustomScreens
,
99 TelemetryCustomScreensFieldsPerLine
,
100 TelemetryMaxMultiplier
,
109 HastxCurrentCalibration
,
138 MultiposPotsPositions
,
148 class SimulatorInterface
;
149 class EEPROMInterface
153 EEPROMInterface(Board::Type board
):
158 virtual ~EEPROMInterface() {}
160 inline Board::Type
getBoard() { return board
; }
162 virtual unsigned long load(RadioData
&radioData
, const uint8_t * eeprom
, int size
) = 0;
164 virtual unsigned long loadBackup(RadioData
& radioData
, const uint8_t * eeprom
, int esize
, int index
) = 0;
166 virtual int save(uint8_t * eeprom
, const RadioData
& radioData
, uint8_t version
=0, uint32_t variant
=0) = 0;
168 virtual int getSize(const ModelData
&) = 0;
170 virtual int getSize(const GeneralSettings
&) = 0;
182 /* EEPROM string conversion functions */
183 void setEEPROMString(char *dst
, const char *src
, int size
);
184 void getEEPROMString(char *dst
, const char *src
, int size
);
186 float ValToTim(int value
);
187 int TimToVal(float value
);
189 inline int applyStickMode(int stick
, unsigned int mode
)
191 if (mode
== 0 || mode
> 4) {
192 std::cerr
<< "Incorrect stick mode" << mode
;
196 if (stick
>= 1 && stick
<= 4)
197 return modn12x3
[mode
-1][stick
-1];
202 void registerEEpromInterfaces();
203 void unregisterEEpromInterfaces();
204 void registerOpenTxFirmwares();
205 void unregisterOpenTxFirmwares();
207 enum EepromLoadErrors
{
210 UNSUPPORTED_NEWER_VERSION
,
220 BACKUP_NOT_SUPPORTED
,
224 WARNING_WRONG_FIRMWARE
,
229 void ShowEepromErrors(QWidget
*parent
, const QString
&title
, const QString
&mainMessage
, unsigned long errorsFound
);
230 void ShowEepromWarnings(QWidget
*parent
, const QString
&title
, unsigned long errorsFound
);
242 Firmware(const QString
& id
, const QString
& name
, Board::Type board
):
248 eepromInterface(NULL
)
252 Firmware(Firmware
* base
, const QString
& id
, const QString
& name
, Board::Type board
):
258 eepromInterface(NULL
)
266 inline const Firmware
* getFirmwareBase() const
268 return base
? base
: this;
271 virtual Firmware
* getFirmwareVariant(const QString
& id
) { return NULL
; }
273 unsigned int getVariantNumber();
275 virtual void addLanguage(const char *lang
);
277 virtual void addTTSLanguage(const char *lang
);
279 virtual void addOption(const char *option
, QString tooltip
="", uint32_t variant
=0);
281 virtual void addOptions(Option options
[]);
283 virtual QString
getStampUrl() = 0;
285 virtual QString
getReleaseNotesUrl() = 0;
287 virtual QString
getFirmwareUrl() = 0;
289 Board::Type
getBoard() const
294 void setEEpromInterface(EEPROMInterface
* eeprom
)
296 eepromInterface
= eeprom
;
299 EEPROMInterface
* getEEpromInterface()
301 return eepromInterface
;
304 QString
getName() const
309 QString
getId() const
314 virtual int getCapability(Capability
) = 0;
316 virtual QString
getAnalogInputName(unsigned int index
) = 0;
318 virtual QTime
getMaxTimerStart() = 0;
320 virtual int isAvailable(PulsesProtocol proto
, int port
=0) = 0;
322 const int getFlashSize();
324 static Firmware
* getFirmwareForId(const QString
& id
);
326 static QVector
<Firmware
*> getRegisteredFirmwares()
328 return registeredFirmwares
;
330 static void addRegisteredFirmware(Firmware
* fw
)
332 registeredFirmwares
.append(fw
);
335 static Firmware
* getDefaultVariant()
337 return defaultVariant
;
339 static void setDefaultVariant(Firmware
* value
)
341 defaultVariant
= value
;
344 static Firmware
* getCurrentVariant()
346 return currentVariant
;
348 static void setCurrentVariant(Firmware
* value
)
350 currentVariant
= value
;
354 QList
<const char *> languages
;
355 QList
<const char *> ttslanguages
;
356 QList
< QList
<Option
> > opts
;
363 unsigned int variantBase
;
365 EEPROMInterface
* eepromInterface
;
367 static QVector
<Firmware
*> registeredFirmwares
;
368 static Firmware
* defaultVariant
;
369 static Firmware
* currentVariant
;
376 inline Firmware
* getCurrentFirmware()
378 return Firmware::getCurrentVariant();
381 inline EEPROMInterface
* getCurrentEEpromInterface()
383 return Firmware::getCurrentVariant()->getEEpromInterface();
386 inline Board::Type
getCurrentBoard()
388 return Firmware::getCurrentVariant()->getBoard();
391 inline int divRoundClosest(const int n
, const int d
)
393 return ((n
< 0) ^ (d
< 0)) ? ((n
- d
/2)/d
) : ((n
+ d
/2)/d
);
396 inline int calcRESXto100(int x
)
398 return divRoundClosest(x
*100, 1024);
401 #define CHECK_IN_ARRAY(T, index) ((unsigned int)index < DIM(T) ? T[(unsigned int)index] : "???")
403 extern QList
<EEPROMInterface
*> eepromInterfaces
;
405 bool loadFile(RadioData
& radioData
, const QString
& filename
);
408 #endif // _EEPROMINTERFACE_H_