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
,
96 TelemetryCustomScreens
,
97 TelemetryCustomScreensFieldsPerLine
,
98 TelemetryMaxMultiplier
,
107 HastxCurrentCalibration
,
136 MultiposPotsPositions
,
146 class SimulatorInterface
;
147 class EEPROMInterface
151 EEPROMInterface(Board::Type board
):
156 virtual ~EEPROMInterface() {}
158 inline Board::Type
getBoard() { return board
; }
160 virtual unsigned long load(RadioData
&radioData
, const uint8_t * eeprom
, int size
) = 0;
162 virtual unsigned long loadBackup(RadioData
& radioData
, const uint8_t * eeprom
, int esize
, int index
) = 0;
164 virtual int save(uint8_t * eeprom
, const RadioData
& radioData
, uint8_t version
=0, uint32_t variant
=0) = 0;
166 virtual int getSize(const ModelData
&) = 0;
168 virtual int getSize(const GeneralSettings
&) = 0;
180 /* EEPROM string conversion functions */
181 void setEEPROMString(char *dst
, const char *src
, int size
);
182 void getEEPROMString(char *dst
, const char *src
, int size
);
184 float ValToTim(int value
);
185 int TimToVal(float value
);
187 inline int applyStickMode(int stick
, unsigned int mode
)
189 if (mode
== 0 || mode
> 4) {
190 std::cerr
<< "Incorrect stick mode" << mode
;
194 if (stick
>= 1 && stick
<= 4)
195 return modn12x3
[mode
-1][stick
-1];
200 void registerEEpromInterfaces();
201 void unregisterEEpromInterfaces();
202 void registerOpenTxFirmwares();
203 void unregisterOpenTxFirmwares();
205 enum EepromLoadErrors
{
208 UNSUPPORTED_NEWER_VERSION
,
218 BACKUP_NOT_SUPPORTED
,
222 WARNING_WRONG_FIRMWARE
,
227 void ShowEepromErrors(QWidget
*parent
, const QString
&title
, const QString
&mainMessage
, unsigned long errorsFound
);
228 void ShowEepromWarnings(QWidget
*parent
, const QString
&title
, unsigned long errorsFound
);
240 Firmware(const QString
& id
, const QString
& name
, Board::Type board
):
246 eepromInterface(NULL
)
250 Firmware(Firmware
* base
, const QString
& id
, const QString
& name
, Board::Type board
):
256 eepromInterface(NULL
)
264 inline const Firmware
* getFirmwareBase() const
266 return base
? base
: this;
269 virtual Firmware
* getFirmwareVariant(const QString
& id
) { return NULL
; }
271 unsigned int getVariantNumber();
273 virtual void addLanguage(const char *lang
);
275 virtual void addTTSLanguage(const char *lang
);
277 virtual void addOption(const char *option
, QString tooltip
="", uint32_t variant
=0);
279 virtual void addOptions(Option options
[]);
281 virtual QString
getStampUrl() = 0;
283 virtual QString
getReleaseNotesUrl() = 0;
285 virtual QString
getFirmwareUrl() = 0;
287 Board::Type
getBoard() const
292 void setEEpromInterface(EEPROMInterface
* eeprom
)
294 eepromInterface
= eeprom
;
297 EEPROMInterface
* getEEpromInterface()
299 return eepromInterface
;
302 QString
getName() const
307 QString
getId() const
312 virtual int getCapability(Capability
) = 0;
314 virtual QString
getAnalogInputName(unsigned int index
) = 0;
316 virtual QTime
getMaxTimerStart() = 0;
318 virtual int isAvailable(PulsesProtocol proto
, int port
=0) = 0;
320 const int getFlashSize();
322 static Firmware
* getFirmwareForId(const QString
& id
);
324 static QVector
<Firmware
*> getRegisteredFirmwares()
326 return registeredFirmwares
;
328 static void addRegisteredFirmware(Firmware
* fw
)
330 registeredFirmwares
.append(fw
);
333 static Firmware
* getDefaultVariant()
335 return defaultVariant
;
337 static void setDefaultVariant(Firmware
* value
)
339 defaultVariant
= value
;
342 static Firmware
* getCurrentVariant()
344 return currentVariant
;
346 static void setCurrentVariant(Firmware
* value
)
348 currentVariant
= value
;
352 QList
<const char *> languages
;
353 QList
<const char *> ttslanguages
;
354 QList
< QList
<Option
> > opts
;
361 unsigned int variantBase
;
363 EEPROMInterface
* eepromInterface
;
365 static QVector
<Firmware
*> registeredFirmwares
;
366 static Firmware
* defaultVariant
;
367 static Firmware
* currentVariant
;
374 inline Firmware
* getCurrentFirmware()
376 return Firmware::getCurrentVariant();
379 inline EEPROMInterface
* getCurrentEEpromInterface()
381 return Firmware::getCurrentVariant()->getEEpromInterface();
384 inline Board::Type
getCurrentBoard()
386 return Firmware::getCurrentVariant()->getBoard();
389 inline int divRoundClosest(const int n
, const int d
)
391 return ((n
< 0) ^ (d
< 0)) ? ((n
- d
/2)/d
) : ((n
+ d
/2)/d
);
394 inline int calcRESXto100(int x
)
396 return divRoundClosest(x
*100, 1024);
399 #define CHECK_IN_ARRAY(T, index) ((unsigned int)index < DIM(T) ? T[(unsigned int)index] : "???")
401 extern QList
<EEPROMInterface
*> eepromInterfaces
;
403 bool loadFile(RadioData
& radioData
, const QString
& filename
);
406 #endif // _EEPROMINTERFACE_H_